From c3f81a825f7b7c8ee5b6c00109ecd94596d5af70 Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 27 Mar 2023 14:19:37 +0800 Subject: [PATCH] feat: Refactor AlchemyController's callback function for usability and clarity. - Add constant and callback URL to AlchemyController for Alchemy Pay - Improve parameter validations and error handling in `alchemyCallback` function - Remove unused variable `redirectUrl` in AlchemyController - Update `.env.development` with Alchemy Pay callback URL --- .env.development | 1 + src/controllers/alchemy.controller.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.env.development b/.env.development index f9703b7..9e8bc34 100644 --- a/.env.development +++ b/.env.development @@ -15,3 +15,4 @@ ALCHEMY_APPID="f83Is2y7L425rxl8" ALCHEMY_APP_SECRET="4Yn8RkxDXN71Q3p0" ALCHEMY_API_BASE="https://openapi-test.alchemypay.org" ALCHEMY_PAGE_BASE="https://ramptest.alchemypay.org" +ALCHEMY_PAY_CB_URL="https://wallet.cebg.games" diff --git a/src/controllers/alchemy.controller.ts b/src/controllers/alchemy.controller.ts index 09a0b51..ed75080 100644 --- a/src/controllers/alchemy.controller.ts +++ b/src/controllers/alchemy.controller.ts @@ -6,6 +6,7 @@ import { checkPayResultSign, createPageSign, refreshToken } from 'service/alchem import { generateKVStr } from 'utils/net.util' import { PayRecord, PayStatus } from 'modules/PayRecord' +const CALL_BACK_URL = `${process.env.ALCHEMY_PAY_CB_URL}/pay/alchemy/cb` class AlchemyController extends BaseController { @router('post /pay/alchemy/buy') async beginPay(req, res) { @@ -19,7 +20,6 @@ class AlchemyController extends BaseController { } const { id, email, accessToken } = tokenResult.data const redirectUrl = '' - const callbackUrl = '' let record = new PayRecord({ account: user.id, address, chain, currency }) await record.save() const merchantOrderNo = record.id @@ -29,6 +29,7 @@ class AlchemyController extends BaseController { id, showTable: 'buy', merchantOrderNo, + callbackUrl: CALL_BACK_URL, } if (chain) dataOrign.network = chain if (currency) dataOrign.crypto = currency