ソースを参照

feat(): 获取关联银行账户、关联银行账户、获取银行账户信息api转发

zerogo 7 ヶ月 前
コミット
8ae9c935fb

+ 20 - 9
src/modules/api/controller/associateBankAccount.ts

@@ -7,8 +7,10 @@ import {
   Post,
   Provide,
   Put,
+  Query
 } from '@midwayjs/decorator';
 import { BusinessEntity } from '../../payment/entity/business';
+import { AssociateBankAccount } from "../../payment/service/associateBankAccount";
 
 /**
  * 关联银行账户
@@ -16,6 +18,8 @@ import { BusinessEntity } from '../../payment/entity/business';
 @Provide()
 @CoolController('/api/v1/Fiat')
 export class AssociateBankAccountController extends BaseController {
+  @Inject()
+  associateBankAccount: AssociateBankAccount;
   /**
    * 获取关联银行账户必填字段
    */
@@ -23,7 +27,7 @@ export class AssociateBankAccountController extends BaseController {
     summary: '获取关联银行账户必填字段',
   })
   async AssociateBankAccountRequiredFieldsAsync(
-    @Body(ALL) business: BusinessEntity
+    @Query('currency') currency: string,
   ) {
     // if (!this.allowKeys.includes(key)) {
     //   return this.fail('非法操作');
@@ -31,8 +35,8 @@ export class AssociateBankAccountController extends BaseController {
     // 关键参数校验
     // 数据落库
     // 回调
-    console.log(business);
-    return this.ok('hello, cool-admin!!!');
+    console.log('AssociateBankAccountRequiredFieldsAsync-=-=-',currency);
+    return this.ok(await this.associateBankAccount.associateBankAccountRequiredFieldsAsync(currency));
   }
   /**
    * 关联银行账户
@@ -45,23 +49,30 @@ export class AssociateBankAccountController extends BaseController {
     // 关键参数校验
     // 数据落库
     // 回调
-    console.log(business);
-    return this.ok('hello, cool-admin!!!');
+    console.log('associateBankAccount-=-=',business);
+    return this.ok(await this.associateBankAccount.associateBankAccount(business));
   }
   /**
    * 获取银行账户信息
    * /api/v3/Fiat/GetAssociateBankAccounts
    */
-  @Post('/GetAssociateBankAccounts', { summary: '获取银行账户信息' })
-  async GetAssociateBankAccounts(@Body(ALL) business: BusinessEntity) {
+  @Get('/GetAssociateBankAccounts', { summary: '获取银行账户信息' })
+  async GetAssociateBankAccounts(
+    @Query('currency') currency: string,
+    @Query('customer_id') customer_id: string,
+  ) {
     // if (!this.allowKeys.includes(key)) {
     //   return this.fail('非法操作');
     // }
     // 关键参数校验
     // 数据落库
     // 回调
-    console.log(business);
-    return this.ok('hello, cool-admin!!!');
+    const business = {
+      currency: currency,
+      customer_id: customer_id,
+    }
+    console.log('GetAssociateBankAccounts-=-=-=',business);
+    return this.ok(await this.associateBankAccount.getAssociateBankAccounts(business));
   }
   /**
    * TODO 关联银行账户回调通知

+ 18 - 0
src/modules/payment/adapter/sunpay.adapter.ts

@@ -181,12 +181,29 @@ export class SunPayAdapter implements ChannelAdapter {
     const { data } = await this.request('POST', '/Fiat/Wallet', params);
     return data;
   }
+
+  /**
+   * 获取关联银行账户
+   * @param params
+   * @returns
+   */
+  async associateBankAccountRequiredFieldsAsync(params: any): Promise<any> {
+    console.log('associateBankAccountRequiredFieldsAsync-==-=-',params)
+    const res = await this.request(
+      'GET',
+      '/Fiat/AssociateBankAccountRequiredFieldsAsync',
+      params
+    );
+    return res;
+  }
+
   /**
    * 关联银行账户
    * @param params
    * @returns
    */
   async associateBankAccount(params: any): Promise<any> {
+    console.log('associateBankAccountRequiredFieldsAsync-==-=-adapter',params)
     const { data } = await this.request(
       'POST',
       '/Fiat/AssociateBankAccount',
@@ -300,6 +317,7 @@ export class SunPayAdapter implements ChannelAdapter {
     return res;
   }
   async getBank(params: any = {}) {
+    console.log('getBank-=--=',params)
     const res = await this.request(
       'GET',
       '/Fiat/GetAssociateBankAccounts',

+ 2 - 0
src/modules/payment/interface/channel.adapter.ts

@@ -69,6 +69,8 @@ export interface ChannelAdapter {
   createWallet(params: any): Promise<string>;
   // 获取钱包
   getWallet(params: any): Promise<any>;
+  // 获取关联银行账户
+  associateBankAccountRequiredFieldsAsync(params: any): Promise<any>;
   // 关联银行账户
   associateBankAccount(params: any): Promise<any>;
   // 获取钱包余额

+ 58 - 0
src/modules/payment/service/associateBankAccount.ts

@@ -0,0 +1,58 @@
+import { CustomerEntity } from './../entity/customer';
+import { Init, Inject, Provide } from '@midwayjs/decorator';
+import { BaseService, CoolCommException } from '@cool-midway/core';
+import { InjectEntityModel } from '@midwayjs/typeorm';
+import { Repository } from 'typeorm';
+import { WalletEntity } from '../entity/wallet';
+import { PaymentService } from './payment';
+import { MerchantEntity } from '../entity/merchant';
+/**
+ * 描述
+ */
+@Provide()
+export class AssociateBankAccount extends BaseService {
+  @InjectEntityModel(WalletEntity)
+  walletEntity: Repository<WalletEntity>;
+  @InjectEntityModel(MerchantEntity)
+  merchantEntity: Repository<MerchantEntity>;
+  @InjectEntityModel(CustomerEntity)
+  customerEntity: Repository<CustomerEntity>;
+  @Inject()
+  paymentService: PaymentService;
+  @Inject()
+  ctx;
+
+
+    /**
+   * 获取关联银行账户
+   */
+    async associateBankAccountRequiredFieldsAsync(param: any) {
+      console.log('getAssociateBankAccountRequiredFieldsAsync',param)
+      const res = await this.paymentService.setChannel('SUNPAY').getAssociateBankAccountRequiredFieldsAsync({
+        currency: param,
+      });
+      return res;
+    }
+
+     /**
+   * 关联银行账户
+   */
+     async associateBankAccount(param: any) {
+      console.log('associateBankAccount',param)
+      const res = await this.paymentService.setChannel('SUNPAY').associateBankAccount({
+        currency: param,
+      });
+      return res;
+     }
+
+      /**
+   * 获取银行账户信息
+   */
+    async getAssociateBankAccounts(param: any) {
+      console.log('getAssociateBankAccounts',param)
+      const res = await this.paymentService.setChannel('SUNPAY').getBank({
+        currency: param,
+      });
+      return res;
+    }
+}

+ 9 - 1
src/modules/payment/service/payment.ts

@@ -66,7 +66,7 @@ export class PaymentService extends BaseService {
     const wallet = {
       currency: param.currency,
       customer_id: param.customerId,
-      webhook_url: 'http://localhost:8001/callback/sunpay',
+      webhook_url: param.webhook_url,
     };
     const res = await adapter.createWallet(wallet);
     await adapter.associateBankAccount(wallet);
@@ -76,6 +76,14 @@ export class PaymentService extends BaseService {
     const adapter = this.getChannelAdapter(this.channel);
     return adapter.getWallet(params);
   }
+  async getAssociateBankAccountRequiredFieldsAsync(params: any) {
+    const adapter = this.getChannelAdapter(this.channel);
+    return adapter.associateBankAccountRequiredFieldsAsync(params);
+  }
+  async associateBankAccount(params: any) {
+    const adapter = this.getChannelAdapter(this.channel);
+    return adapter.associateBankAccount(params);
+  }
   async getWalletBalance(params: any) {
     const adapter = this.getChannelAdapter(this.channel);
     return adapter.getWalletBalance(params);

+ 2 - 2
src/modules/payment/service/wallet.ts

@@ -108,7 +108,7 @@ export class WalletService extends BaseService {
    */
   async getWallet(param: any) {
     console.log('getWallet',param)
-    const res = await this.paymentService.setChannel('SUNPAY').getWallet({
+    const res = await this.paymentService.setChannel('SUNPAY').getWallet({//TODO setChannel 需要调整为动态的
       customer_id: param,
     });
     return res;
@@ -119,7 +119,7 @@ export class WalletService extends BaseService {
    */
   async getWalletBalance(param: any) {
     console.log('getWalletBalance',param)
-    const res = await this.paymentService.setChannel('SUNPAY').getWalletBalance({
+    const res = await this.paymentService.setChannel('SUNPAY').getWalletBalance({//TODO setChannel 需要调整为动态的
       customer_id: param,
     });
     return res;