|
@@ -1,13 +1,10 @@
|
|
|
-import { BaseService } from '@cool-midway/core';
|
|
|
-import { ILogger, Inject, Provide } from '@midwayjs/core';
|
|
|
-import { WebHookCommonService } from './common';
|
|
|
-import {
|
|
|
- OpenPaymentOrderEntity,
|
|
|
- OrderType,
|
|
|
-} from '../../entity/open_payment_order';
|
|
|
-import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
|
-import { Repository } from 'typeorm';
|
|
|
-import { EasyPayAdapter } from '../../../payment/adapter/easypay.adapter';
|
|
|
+import {BaseService} from '@cool-midway/core';
|
|
|
+import {ILogger, Inject, Provide} from '@midwayjs/core';
|
|
|
+import {WebHookCommonService} from './common';
|
|
|
+import {OpenPaymentOrderEntity, OrderType,} from '../../entity/open_payment_order';
|
|
|
+import {InjectEntityModel} from '@midwayjs/typeorm';
|
|
|
+import {Repository} from 'typeorm';
|
|
|
+import {EasyPayAdapter} from '../../../payment/adapter/easypay.adapter';
|
|
|
import * as md5 from 'md5';
|
|
|
|
|
|
/**
|
|
@@ -38,7 +35,7 @@ export class TransferSuccessService extends BaseService {
|
|
|
try {
|
|
|
/*
|
|
|
2025-03-11 16:58:09.069 INFO 113849 [-/::ffff:127.0.0.1/-/1ms POST /api/open/easypay-webhook/notification] easypay的webhook_notification: params{"type":"deposit_success","data":{"id":"85a2e73b90d94354b14b925c8e23b876","bank_account_id":"7021a5e645574004b5678213f94df8a5","order_no":"20250311165807046795","account_id":"590f080eb299590385c7aa628274e73c","bic_number":null,"account_number":"79765000168","inward_amount":90000,"fee":0,"amount":90000,"currency":"EUR","payer":"付款信息 格式:{sender.name};{sender.address};{sender.country};{sender.account_number} or {sender.iban};{sender.bic};{sender.routing_code};附言","comment":"附言","payment_type":"SWIFT","order_type":"DEPOSIT","payment_id":null,"clearing_system":null,"status":"SUCCESS","create_time":"2025-03-11T16:58:08+08:00","update_time":"2025-03-11T16:58:08+08:00","completed_time":"2025-03-11T16:58:08+08:00"}}
|
|
|
-
|
|
|
+
|
|
|
// 转账成功 transfer_success
|
|
|
// 如果付款成功,则收取手续费
|
|
|
/*
|
|
@@ -68,7 +65,6 @@ export class TransferSuccessService extends BaseService {
|
|
|
params.data.account_id
|
|
|
);
|
|
|
if (!accountInfo) {
|
|
|
- // TODO 如果不存在的话,则为白标用户
|
|
|
// 转账延迟4秒处理
|
|
|
await this.webHookCommonService.waitByTime(4000);
|
|
|
this.ctx.status = 400;
|
|
@@ -88,12 +84,12 @@ export class TransferSuccessService extends BaseService {
|
|
|
});
|
|
|
|
|
|
// 注意避免重复截取利润, 如果是手续费直接忽略,只需更新订单谢谢即可
|
|
|
- const isDuplicateOrder = this.isDuplicateOrder(params.data.id);
|
|
|
- if(isDuplicateOrder) {
|
|
|
- const res = await this.openPaymentOrderEntity.save({
|
|
|
- where: {
|
|
|
-
|
|
|
- },
|
|
|
+ const isDuplicateOrder = await this.isDuplicateOrder(params.data.id);
|
|
|
+ if (isDuplicateOrder) {
|
|
|
+ Promise.resolve().then(async () => {
|
|
|
+ await this.webHookCommonService.waitByTime(10000);
|
|
|
+ isDuplicateOrder.status = 'SUCCESS';
|
|
|
+ await this.openPaymentOrderEntity.save(isDuplicateOrder);
|
|
|
});
|
|
|
this.ctx.status = 200;
|
|
|
this.ctx.body = {};
|
|
@@ -107,8 +103,7 @@ export class TransferSuccessService extends BaseService {
|
|
|
amount: params.data.amount,
|
|
|
order_type: OrderType.TRANSFER,
|
|
|
});
|
|
|
-
|
|
|
- // 记录入账流水
|
|
|
+ // 记录转账流水
|
|
|
const openPaymentOrderParams = {
|
|
|
mch_id: accountInfo.mch_id,
|
|
|
amount: params.data.amount / 100,
|
|
@@ -133,48 +128,43 @@ export class TransferSuccessService extends BaseService {
|
|
|
// 通知上游之后,间隔10秒执行利润截取操作
|
|
|
Promise.resolve().then(async () => {
|
|
|
await this.webHookCommonService.waitByTime(10000);
|
|
|
- let accountInfo = null;
|
|
|
- // 获取回调用户的详情
|
|
|
- let withdrawChannelFee = null;
|
|
|
- if (accountInfo && withdrawChannelFee) {
|
|
|
- // 收取手续费: 转账
|
|
|
- // /v1/transfers
|
|
|
- const transfers_params = {
|
|
|
- // ...openOrderObj,
|
|
|
- request_id: md5(`${accountInfo.mch_id}_${params.data.id}`),
|
|
|
- from_account_id: params.data.account_id,
|
|
|
- to_account_id: this.easyPayAdapter.baseInfo.account_id,
|
|
|
- currency: params.data.currency,
|
|
|
- amount: withdrawChannelFee * 100,
|
|
|
- purpose: '收取手续费用',
|
|
|
- };
|
|
|
- this.logger.info(
|
|
|
- `记录转账流水的费率, ${JSON.stringify(transfers_params)}`
|
|
|
- );
|
|
|
- // 截取流水的转账
|
|
|
- const res = await this.easyPayAdapter.request(
|
|
|
- 'POST',
|
|
|
- '/v1/transfers',
|
|
|
- transfers_params
|
|
|
- );
|
|
|
- // 记录入账手续费的流水
|
|
|
- await this.openPaymentOrderEntity.insert({
|
|
|
- request_id: transfers_params.request_id,
|
|
|
- mch_id: accountInfo.mch_id,
|
|
|
- amount: withdrawChannelFee,
|
|
|
- account_id: params.data.account_id,
|
|
|
- from_account_id: params.data.account_id,
|
|
|
- to_account_id: this.easyPayAdapter.baseInfo.account_id,
|
|
|
- event_id: params.data.id,
|
|
|
- currency: params.data.currency,
|
|
|
- status: params.data.status,
|
|
|
- order_type: OrderType.TRANSACTION_FEE_ORDER,
|
|
|
- payment_type: params.data.payment_type,
|
|
|
- order_id: res.data.order_no, // 这里是转账的订单编号
|
|
|
- fee: 0,
|
|
|
- additional_info: {},
|
|
|
- });
|
|
|
- }
|
|
|
+
|
|
|
+ // 收取手续费: 转账
|
|
|
+ // /v1/transfers
|
|
|
+ const transfers_params = {
|
|
|
+ request_id: md5(`${accountInfo.mch_id}_${params.data.id}`),
|
|
|
+ from_account_id: params.data.account_id,
|
|
|
+ to_account_id: this.easyPayAdapter.baseInfo.account_id,
|
|
|
+ currency: params.data.currency,
|
|
|
+ amount: withdrawChannelFee * 100,
|
|
|
+ purpose: '收取手续费用',
|
|
|
+ };
|
|
|
+ this.logger.info(
|
|
|
+ `记录转账流水的费率, ${JSON.stringify(transfers_params)}`
|
|
|
+ );
|
|
|
+ // 截取流水的转账
|
|
|
+ const res = await this.easyPayAdapter.request(
|
|
|
+ 'POST',
|
|
|
+ '/v1/transfers',
|
|
|
+ transfers_params
|
|
|
+ );
|
|
|
+ // 记录入账手续费的流水
|
|
|
+ await this.openPaymentOrderEntity.insert({
|
|
|
+ request_id: transfers_params.request_id,
|
|
|
+ mch_id: accountInfo.mch_id,
|
|
|
+ amount: withdrawChannelFee,
|
|
|
+ account_id: params.data.account_id,
|
|
|
+ from_account_id: params.data.account_id,
|
|
|
+ to_account_id: this.easyPayAdapter.baseInfo.account_id,
|
|
|
+ event_id: params.data.id,
|
|
|
+ currency: params.data.currency,
|
|
|
+ status: params.data.status,
|
|
|
+ order_type: OrderType.TRANSACTION_FEE_ORDER,
|
|
|
+ payment_type: params.data.payment_type,
|
|
|
+ order_id: res.data.order_no, // 这里是转账的订单编号
|
|
|
+ fee: 0,
|
|
|
+ additional_info: {},
|
|
|
+ });
|
|
|
});
|
|
|
this.ctx.status = 200;
|
|
|
this.ctx.body = {};
|
|
@@ -184,13 +174,13 @@ export class TransferSuccessService extends BaseService {
|
|
|
this.logger.error(error);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// 根据 event_id 判断是否有重复订单
|
|
|
- async isDuplicateOrder(event_id) {
|
|
|
- const res = await this.openPaymentOrderEntity.findOne({
|
|
|
+ async isDuplicateOrder(event_id: any) {
|
|
|
+ return await this.openPaymentOrderEntity.findOne({
|
|
|
where: {
|
|
|
event_id,
|
|
|
},
|
|
|
});
|
|
|
- return res
|
|
|
}
|
|
|
}
|