|
@@ -24,33 +24,26 @@ export class IndividualService extends BaseService {
|
|
await super.init();
|
|
await super.init();
|
|
this.setEntity(this.individualEntity);
|
|
this.setEntity(this.individualEntity);
|
|
}
|
|
}
|
|
|
|
+ private _isOpenApi: boolean = false
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 添加或者更新当前商户的 individual 客户信息
|
|
* 添加或者更新当前商户的 individual 客户信息
|
|
* @param param
|
|
* @param param
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
async add(param) {
|
|
async add(param) {
|
|
- let merchantId;
|
|
|
|
- const isOpenApi = param.hasOwnProperty('isOpenApi')
|
|
|
|
- ? param.isOpenApi
|
|
|
|
- : false;
|
|
|
|
- if (isOpenApi) {
|
|
|
|
- merchantId = param.out_user_id;
|
|
|
|
- } else {
|
|
|
|
- const { merchant } = this.ctx.admin;
|
|
|
|
- merchantId = merchant.id;
|
|
|
|
- }
|
|
|
|
|
|
+ let merchantId = this.getMerchantId(param);
|
|
const custom = {
|
|
const custom = {
|
|
...param,
|
|
...param,
|
|
- out_user_id: merchantId, // TODO 应该是我们平台的ID
|
|
|
|
- webhook_url: this.config.callback.sunpay,
|
|
|
|
|
|
+ out_user_id: merchantId,
|
|
|
|
+ webhook_url: this.getWebhook_url(param),
|
|
customer_type: 'INDIVIDUAL',
|
|
customer_type: 'INDIVIDUAL',
|
|
};
|
|
};
|
|
let res = await this.paymentService
|
|
let res = await this.paymentService
|
|
.setChannel('SUNPAY')
|
|
.setChannel('SUNPAY')
|
|
.setCustomerInfo(custom);
|
|
.setCustomerInfo(custom);
|
|
param.merchant = {
|
|
param.merchant = {
|
|
- id: merchantId, // TODO 应该是我们平台的ID
|
|
|
|
|
|
+ id: merchantId,
|
|
};
|
|
};
|
|
await super.add({
|
|
await super.add({
|
|
...param,
|
|
...param,
|
|
@@ -59,20 +52,11 @@ export class IndividualService extends BaseService {
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
async update(param) {
|
|
async update(param) {
|
|
- let merchantId;
|
|
|
|
- const isOpenApi = param.hasOwnProperty('isOpenApi')
|
|
|
|
- ? param.isOpenApi
|
|
|
|
- : false;
|
|
|
|
- if (isOpenApi) {
|
|
|
|
- merchantId = param.out_user_id;
|
|
|
|
- } else {
|
|
|
|
- const { merchant } = this.ctx.admin;
|
|
|
|
- merchantId = merchant.id;
|
|
|
|
- }
|
|
|
|
|
|
+ let merchantId = this.getMerchantId(param);
|
|
const custom = {
|
|
const custom = {
|
|
...param,
|
|
...param,
|
|
- out_user_id: merchantId, // TODO 应该是我们平台的ID
|
|
|
|
- webhook_url: this.config.callback.sunpay,
|
|
|
|
|
|
+ out_user_id: merchantId,
|
|
|
|
+ webhook_url: this.getWebhook_url(param),
|
|
customer_type: 'INDIVIDUAL',
|
|
customer_type: 'INDIVIDUAL',
|
|
};
|
|
};
|
|
let res = await this.paymentService
|
|
let res = await this.paymentService
|
|
@@ -81,4 +65,25 @@ export class IndividualService extends BaseService {
|
|
await super.update(param);
|
|
await super.update(param);
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
+ setIsOpenApi(payload = false) {
|
|
|
|
+ this._isOpenApi = payload
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ getMerchantId(params) {
|
|
|
|
+ let merchantId;
|
|
|
|
+ if (this._isOpenApi) {
|
|
|
|
+ merchantId = params.out_user_id;
|
|
|
|
+ } else {
|
|
|
|
+ const { merchant } = this.ctx.admin;
|
|
|
|
+ merchantId = merchant.id;
|
|
|
|
+ }
|
|
|
|
+ return merchantId
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ getWebhook_url(params) {
|
|
|
|
+ if (this._isOpenApi) {
|
|
|
|
+ return params.webhook_url
|
|
|
|
+ }
|
|
|
|
+ return this.config.callback.sunpay
|
|
|
|
+ }
|
|
}
|
|
}
|