Переглянути джерело

hambit代付

回调和代付下单已完成
查询未完成
增加sunpay查询Kyc
test 7 місяців тому
батько
коміт
83bcc03916

+ 24 - 0
src/modules/dj/controller/admin/open.ts

@@ -147,6 +147,18 @@ export class PayOpenController extends BaseController {
     };
   }
 
+  @CoolTag(TagTypes.IGNORE_TOKEN)
+  @Post('/hambit/bra/notifyWithdraw', { summary: '巴西交易订单回调通知' })
+  public async hambitBraNotifyWithdraw(@Body(ALL) payload: any) {
+    const headers = this.ctx.headers;
+    this.logger.error('hambit收到代付订单回调数据', JSON.stringify(payload), headers);
+    await this.withdrawService.handleWithdrawNotify('HB_BRA', payload, headers);
+    this.ctx.body = {
+      "code": "200",
+      "success": "true"
+    };
+  }
+
   @CoolTag(TagTypes.IGNORE_TOKEN)
   @Post('/hambit/inr/notifyOrder', { summary: '印度交易订单回调通知' })
   public async hambitInrNotifyOrderGet(@Body(ALL) payload: any) {
@@ -159,6 +171,18 @@ export class PayOpenController extends BaseController {
     };
   }
 
+  @CoolTag(TagTypes.IGNORE_TOKEN)
+  @Post('/hambit/inr/notifyWithdraw', { summary: '巴西交易订单回调通知' })
+  public async hambitInrNotifyWithdraw(@Body(ALL) payload: any) {
+    const headers = this.ctx.headers;
+    this.logger.error('hambit收到代付订单回调数据', JSON.stringify(payload), headers);
+    await this.withdrawService.handleWithdrawNotify('HB_INR', payload, headers);
+    this.ctx.body = {
+      "code": "200",
+      "success": "true"
+    };
+  }
+
   @CoolTag(TagTypes.IGNORE_TOKEN)
   @Post('/kyc/level', { summary: 'kyc level 查询' })
   public async kycLevel(@Body(ALL) payload: any) {

+ 2 - 2
src/modules/dj/service/channels/dispatch.ts

@@ -124,10 +124,10 @@ export class DispatchService extends BaseService {
     }
   }
 
-  async handleWithdrawNotify(code, data) {
+  async handleWithdrawNotify(code, data, headers) {
     try {
       const channel = await this.WithdrawChannelService.queryByCode(code);
-      return await this[channel.service].handleWithdrawNotify(data);
+      return await this[channel.service].handleWithdrawNotify(data, headers);
     } catch (e) {
       throw new Error('代付回调处理接口失败,失败原因:' + e.message);
     }

+ 41 - 8
src/modules/dj/service/channels/hambitBra.ts

@@ -14,9 +14,10 @@ const PAY_URL = '/api/v3/bra/createCollectingOrder';
 const QUERY_URL = '/api/v3/bra/query/collectingOrder'
 const BALANCE_URL = '/api/v3/bra/query/balance'
 const BANK_URL = '/api/v3/bra/query/bank';
-const WITHDRAW_URL = '/api/v3/bra/pix/createTransferOrder';
+const WITHDRAW_URL = '/api/v3/bra/createTransferOrder';
 
 const NOTIFY_HOST = `http://157.175.73.225/api/admin/dj/open/hambit/bra/notifyOrder`;
+const WITHDRAW_NOTIFY_HOST = `http://157.175.73.225/api/admin/dj/open/hambit/bra/notifyWithdraw`;
 
 const CHANNEL_TYPE = "PIX";
 
@@ -125,7 +126,7 @@ export class HambitBraService extends BaseService {
       throw new Error('order no success');
     }
     return {
-      date: new Date(1690429623000),
+      date: new Date(),
       orderNo: payload.externalOrderId,
       traceNo: payload.orderId,
     };
@@ -199,13 +200,15 @@ export class HambitBraService extends BaseService {
 
   async withdraw(payload) {
     const param = {
-      currencyAmount: payload.amount.toFixed(2),
+      currencyAmount: (+payload.amount).toFixed(2),
       channelType: CHANNEL_TYPE,
       externalOrderId: payload.orderNo,
       personIdType: payload.personIdType,
       personId: payload.personId,
       personName: payload.personName,
-      accountType: payload.bankCode
+      accountType: payload.bankCode,
+      accountId: payload.accountNo,
+      notifyUrl: WITHDRAW_NOTIFY_HOST
     };
     const timestamp = +moment();
     const nonce = uuidv4();
@@ -224,15 +227,45 @@ export class HambitBraService extends BaseService {
         'sign': sign
       }
     });
-    this.logger.info('下单接口返回', param, JSON.stringify(res.data));
+    this.logger.info('代付接口返回', param, JSON.stringify(res.data));
     const { success, msg, data } = res.data;
-    if (success && data.cashierUrl) {
+    if (success && data.orderId) {
       return {
-        payUrl: data.cashierUrl,
-        traceNo: data?.currencyOrderVo?.orderId
+        traceNo: data.orderId
       };
     } else {
       throw new Error(msg);
     }
   }
+
+  async handleWithdrawNotify(payload, headers) {
+    // const sign = headers['sign'];
+    // const timestamp = headers['timestamp'];
+    // const nonce = headers['nonce'];
+    // const signStr = this.utils.signSort({
+    //   timestamp,
+    //   nonce,
+    //   access_key: ACCESS_KEY,
+    //   ...payload
+    // });
+    // const validSign = this.utils.signByHmacSha1(signStr, SECRET_KEY);
+    // if (sign !== validSign) {
+    //   throw new Error('sign error');
+    // }
+    if (+payload.orderStatusCode !== 8 && +payload.orderStatusCode !== 4 && +payload.orderStatusCode !== 16) {
+      throw new Error('order no result');
+    }
+    let status = 2;
+    if (+payload.orderStatusCode === 8) {
+      status = 8;
+    } else if (+payload.orderStatusCode === 4 || +payload.orderStatusCode === 16) {
+      status = 3;
+    }
+    return {
+      date: new Date(),
+      status: status,
+      message: payload.errorMsg,
+      orderNo: payload.externalOrderId
+    };
+  }
 }

+ 1 - 1
src/modules/dj/service/channels/hambitInr.ts

@@ -122,7 +122,7 @@ export class HambitInrService extends BaseService {
       throw new Error('order no success');
     }
     return {
-      date: new Date(1690429623000),
+      date: new Date(),
       orderNo: payload.externalOrderId,
       traceNo: payload.orderId,
     };

+ 0 - 1
src/modules/dj/service/channels/sunpay.ts

@@ -343,7 +343,6 @@ export class SunPayService extends BaseService {
     const data = timestamp + nonce;
     const sign = this.utils.signBySha256(data, API_SERECT).toUpperCase();
     const URL = KYC_QUERY + '?out_user_id=' + outUserId;
-    console.log(URL)
     const res = await this.httpService.get(URL, {
       headers: {
         'SunPay-Key': API_KEY,

+ 0 - 1
src/modules/dj/service/pay.ts

@@ -214,7 +214,6 @@ export class PayService extends BaseService {
       if (item.min > allMin) {
         allMin = item.min;
       }
-      console.log(item.min, allMax, allMin)
       const mchChannel = mchChannels.find(i => i.code === item.code);
       item['weight'] = mchChannel.weight || 0;
       return +amount >= +min && +amount <= max

+ 2 - 2
src/modules/dj/service/withdraw.ts

@@ -208,8 +208,8 @@ export class WithdrawService extends BaseService {
     }
   }
 
-  async handleWithdrawNotify(code, payload) {
-    const data = await this.dispatchService.handleWithdrawNotify(code, payload);
+  async handleWithdrawNotify(code, payload, headers) {
+    const data = await this.dispatchService.handleWithdrawNotify(code, payload, headers);
     const withdraw = await this.withdrawEntity.findOneBy({
       orderNo: data.orderNo,
     });