Forráskód Böngészése

更新

1 代收通道更新为货币单位和通道编码为组合ID(数据库不做强制,非强制)
2 更新sunpay正式环境
test 8 hónapja
szülő
commit
48714ceddd

+ 3 - 1
src/modules/dj/entity/channel.ts

@@ -9,10 +9,12 @@ export class ChannelEntity extends BaseEntity {
   @Column({ comment: '通道名' })
   name: string;
 
-  @Index({ unique: true })
   @Column({ comment: '通道编码' })
   code: string;
 
+  @Column({ comment: '货币单位' })
+  currency: string;
+
   @Column({ comment: '支付方式' })
   payType: string;
 

+ 3 - 0
src/modules/dj/entity/mchChannel.ts

@@ -15,6 +15,9 @@ export class MchChannelEntity extends BaseEntity {
   @Column({ comment: '通道编码' })
   code: string;
 
+  @Column({ comment: '货币单位' })
+  currency: string;
+
   @Column({ comment: '权重' })
   weight: number;
 

+ 1 - 1
src/modules/dj/service/channel.ts

@@ -15,7 +15,7 @@ export class ChannelService extends BaseService {
       where: {
         status: 1
       },
-      select: ['name', 'code', 'payType']
+      select: ['id', 'name', 'code', 'payType', 'currency']
     })
   }
 

+ 10 - 12
src/modules/dj/service/channels/sunpay.ts

@@ -9,20 +9,18 @@ import { ILogger } from '@midwayjs/logger';
 import * as FormData from 'form-data';
 import * as fs from 'fs';
 
-const URL = 'https://sandbox-oapi.sunpay.pro/api/v3-2/Fiat/Direct/PayIn';
-const BASIC_KEY_URL = 'https://sandbox-oapi.sunpay.pro/api/v3-2/Fiat/Kyc/CreateBasicUser';
-const ADVANCED_KEY_URL = 'https://sandbox-oapi.sunpay.pro/api/v3-2/Fiat/Kyc/CreateAdvancedUser';
-const PREMINUM_KEY_URL = 'https://sandbox-oapi.sunpay.pro/api/v3-2/Fiat/Kyc/CreatePremiumUser';
-const COUNTRIES_URL = 'https://sandbox-oapi.sunpay.pro/api/v3-2/Fiat/Countries';
+// const HOST = 'https://sandbox-oapi.sunpay.pro'
+const HOST = 'https://oapi.sunpay.pro';
 
-// const URL = 'https://oapi.sunpay.pro/api/v3/Crypto/PayIn'
-// const BASIC_KEY_URL = 'https://oapi.sunpay.pro/api/v3-2/Fiat/Kyc/CreateBasicUser'
-// const ADVANCED_KEY_URL = 'https://oapi.sunpay.pro/api/v3-2/Fiat/Kyc/CreateAdvancedUser'
-// const PREMINUM_KEY_URL = 'https://oapi.sunpay.pro/api/v3-2/Fiat/Kyc/CreatePremiumUser'
-// const COUNTRIES_URL = 'https://oapi.sunpay.pro/api/v3-2/Fiat/Countries';
+const URL = HOST + '/api/v3-2/Fiat/Direct/PayIn';
+const BASIC_KEY_URL = HOST + '/api/v3-2/Fiat/Kyc/CreateBasicUser';
+const ADVANCED_KEY_URL = HOST + '/api/v3-2/Fiat/Kyc/CreateAdvancedUser';
+const PREMINUM_KEY_URL = HOST + '/api/v3-2/Fiat/Kyc/CreatePremiumUser';
+const COUNTRIES_URL = HOST + '/api/v3-2/Fiat/Countries';
 
-const API_KEY = '08dcd396-a91a-486a-8ca5-02150819d7ae';
-const API_SERECT = '8357086ffbd2cc610afe8a5f5359f7f8563bd887f9e6c376bc3b86b512e2e74e';
+// const API_KEY = '08dcd396-a91a-486a-8ca5-02150819d7ae';
+const API_KEY = '08dd0477-8676-4f68-83c1-215dceeffa2e';
+const API_SERECT = 'c87e8df7bfd93887c2c0f8dfa2e9190ef1d010fb0de5bca0615138e318767b36';
 const NOTIFY_HOST = `http://157.175.73.225/api/admin/dj/open/SunCard/notifyOrder`;
 
 @Provide()

+ 2 - 1
src/modules/dj/service/mchChannel.ts

@@ -21,10 +21,11 @@ export class MchChannelService extends BaseService {
     return this.sqlRenderPage(sql, query);
   }
 
-  async getByMchIdAndType(mchId, payType) {
+  async getByMchIdAndType(mchId, payType, currency) {
     return await this.mchChannelEntity.findBy({
       mchId,
       payType,
+      currency,
       status: 1
     })
   }

+ 7 - 6
src/modules/dj/service/pay.ts

@@ -86,15 +86,15 @@ export class PayService extends BaseService {
       await this.validParam(payload);
       const merchant = await this.validMerchant(payload.mchId);
       const rate = await this.validRate(payload.mchId, payload.payType, payload.currency);
-      const channel = await this.validPayWay(payload.mchId, payload.payType, payload.amount);
+      const channel = await this.validPayWay(payload.mchId, payload.payType, payload.amount, payload.currency);
       await this.validSign(payload, merchant);
       await this.validOutOrderNo(payload);
       let channelCharge = (+payload.amount * +channel.rate) / 100 + +channel.basicFee;
-      if(channelCharge < channel.feeMin) {
+      if (channelCharge < channel.feeMin) {
         channelCharge = channel.feeMin;
       }
       let charge = (+payload.amount * +rate.rate) / 100 + +rate.basicFee;
-      if(charge < rate.feeMin) {
+      if (charge < rate.feeMin) {
         charge = rate.feeMin;
       }
       order = {
@@ -192,8 +192,8 @@ export class PayService extends BaseService {
     return rate;
   }
 
-  async validPayWay(mchId, payType, amount) {
-    const mchChannels = await this.mchChannelService.getByMchIdAndType(mchId, payType);
+  async validPayWay(mchId, payType, amount, currency) {
+    const mchChannels = await this.mchChannelService.getByMchIdAndType(mchId, payType, currency);
     if (mchChannels.length === 0) {
       throw new Error('暂无可用支付路由');
     }
@@ -201,6 +201,7 @@ export class PayService extends BaseService {
     if (channels.length === 0) {
       throw new Error('暂无可用支付路由');
     }
+    channels = channels.filter(item => item.currency === currency);
     // 筛选出金额范围符合的,并且计算出所有可用通道的最大金额和最小金额
     let allMax = 0;
     let allMin = 0;
@@ -211,7 +212,7 @@ export class PayService extends BaseService {
         allMax = item.max;
       }
       if (item.min < allMin) {
-        allMin = 0;
+        allMin = item.min;
       }
       const mchChannel = mchChannels.find(i => i.code === item.code);
       item['weight'] = mchChannel.weight || 0;