From 1436d57c0d0bab0b2c8f58a0c3063f924ad90988 Mon Sep 17 00:00:00 2001 From: Serhat Tunca Date: Mon, 15 Apr 2024 15:01:41 +0300 Subject: [PATCH] add pay by link multi payment support --- samples/payment/RetrieveMultiPayment.js | 12 ++++++++++++ src/adapter/PaymentAdapter.ts | 5 +++++ src/model/MultiPaymentStatus.ts | 6 ++++++ src/model/index.ts | 2 ++ src/request/CreateProductRequest.ts | 1 + src/response/MultiPaymentResponse.ts | 15 +++++++++++++++ 6 files changed, 41 insertions(+) create mode 100644 samples/payment/RetrieveMultiPayment.js create mode 100644 src/model/MultiPaymentStatus.ts create mode 100644 src/response/MultiPaymentResponse.ts diff --git a/samples/payment/RetrieveMultiPayment.js b/samples/payment/RetrieveMultiPayment.js new file mode 100644 index 0000000..44f6aed --- /dev/null +++ b/samples/payment/RetrieveMultiPayment.js @@ -0,0 +1,12 @@ +const Craftgate = require('../../dist'); + +const craftgate = new Craftgate.Client({ + apiKey: 'api-key', + secretKey: 'secret-key', + baseUrl: 'https://sandbox-api.craftgate.io' +}); + +// change multi payment token below with a valid one +craftgate.payment().retrieveMultiPayment('6d7e66b5-9b1c-4c1d-879a-2557b651096e') + .then(payment => console.info('Multi payment retrieved', payment)) + .catch(err => console.error('Failed to retrieve multi payment', err)); diff --git a/src/adapter/PaymentAdapter.ts b/src/adapter/PaymentAdapter.ts index e0e612b..7920b8b 100644 --- a/src/adapter/PaymentAdapter.ts +++ b/src/adapter/PaymentAdapter.ts @@ -44,6 +44,7 @@ import InitGarantiPayPaymentResponse from '../response/InitGarantiPayPaymentResp import InitPosApmPaymentResponse from '../response/InitPosApmPaymentResponse'; import InitThreeDSPaymentResponse from '../response/InitThreeDSPaymentResponse'; import InstantTransferBanksResponse from '../response/InstantTransferBanksResponse'; +import MultiPaymentResponse from '../response/MultiPaymentResponse'; import PaymentRefundResponse from '../response/PaymentRefundResponse'; import PaymentResponse from '../response/PaymentResponse'; import PaymentTransactionApprovalListResponse from '../response/PaymentTransactionApprovalListResponse'; @@ -207,6 +208,10 @@ export default class PaymentAdapter extends BaseAdapter { return this._client.get(`/payment/v1/instant-transfer-banks`); } + async retrieveMultiPayment(token: string): Promise { + return this._client.get(`/payment/v1/multi-payments/${token}`); + } + async is3DSecureCallbackVerified(threeDSecureCallbackKey: string, params: Map): Promise { const hash = params['hash']; const hashString: string = [ diff --git a/src/model/MultiPaymentStatus.ts b/src/model/MultiPaymentStatus.ts new file mode 100644 index 0000000..59a2101 --- /dev/null +++ b/src/model/MultiPaymentStatus.ts @@ -0,0 +1,6 @@ +enum MultiPaymentStatus { + Created = 'CREATED', + Completed = 'COMPLETED' +} + +export default MultiPaymentStatus; diff --git a/src/model/index.ts b/src/model/index.ts index b7fff6d..1e9268f 100644 --- a/src/model/index.ts +++ b/src/model/index.ts @@ -17,6 +17,7 @@ import FraudValueType from './FraudValueType'; import LoyaltyType from './LoyaltyType'; import MemberType from './MemberType'; import MerchantType from './MerchantType'; +import MultiPaymentStatus from './MultiPaymentStatus'; import PaymentAuthenticationType from './PaymentAuthenticationType'; import PaymentGroup from './PaymentGroup'; import PaymentMethod from './PaymentMethod'; @@ -68,6 +69,7 @@ export = { LoyaltyType, MemberType, MerchantType, + MultiPaymentStatus, PaymentGroup, PaymentPhase, PaymentMethod, diff --git a/src/request/CreateProductRequest.ts b/src/request/CreateProductRequest.ts index c54b96e..a0b26e9 100644 --- a/src/request/CreateProductRequest.ts +++ b/src/request/CreateProductRequest.ts @@ -10,6 +10,7 @@ type CreateProductRequest = { stock: number; currency: Currency; description: string; + multiPayment: boolean; enabledInstallments: number[]; }; diff --git a/src/response/MultiPaymentResponse.ts b/src/response/MultiPaymentResponse.ts new file mode 100644 index 0000000..6583779 --- /dev/null +++ b/src/response/MultiPaymentResponse.ts @@ -0,0 +1,15 @@ +import MultiPaymentStatus from '../model/MultiPaymentStatus'; + +type MultiPaymentResponse = { + id: number; + multiPaymentStatus: MultiPaymentStatus; + token: string; + conversationId: string; + externalId: string; + paidPrice: number; + remainingAmount: number; + tokenExpireDate: Date; + paymentIds: number[]; +}; + +export default MultiPaymentResponse;