From 56a1cbcddc8510a5d4dc91a628f13f6b24ad1494 Mon Sep 17 00:00:00 2001 From: Beran Santur Date: Tue, 13 Feb 2024 15:40:10 +0300 Subject: [PATCH] Adds Juzdan integration to Node.js client (#173) --- samples/juzdan/InitJuzdanPayment.js | 33 +++++++++++++++++++++++ samples/juzdan/RetrieveJuzdanPayment.js | 13 +++++++++ src/CraftgateClient.ts | 7 +++++ src/adapter/JuzdanPaymentAdapter.ts | 20 ++++++++++++++ src/model/ClientType.ts | 6 +++++ src/model/index.ts | 4 ++- src/request/InitJuzdanPaymentRequest.ts | 24 +++++++++++++++++ src/response/InitJuzdanPaymentResponse.ts | 6 +++++ 8 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 samples/juzdan/InitJuzdanPayment.js create mode 100644 samples/juzdan/RetrieveJuzdanPayment.js create mode 100644 src/adapter/JuzdanPaymentAdapter.ts create mode 100644 src/model/ClientType.ts create mode 100644 src/request/InitJuzdanPaymentRequest.ts create mode 100644 src/response/InitJuzdanPaymentResponse.ts diff --git a/samples/juzdan/InitJuzdanPayment.js b/samples/juzdan/InitJuzdanPayment.js new file mode 100644 index 0000000..3a93f4a --- /dev/null +++ b/samples/juzdan/InitJuzdanPayment.js @@ -0,0 +1,33 @@ +const Craftgate = require("../../dist"); + +const craftgate = new Craftgate.Client({ + apiKey: "api-key", + secretKey: "secret-key", + baseUrl: "https://sandbox-api.craftgate.io" +}); + +const request = { + price: 100.0, + paidPrice: 100.0, + currency: Craftgate.Model.Currency.TRY, + paymentGroup: Craftgate.Model.PaymentGroup.ListingOrSubscription, + conversationId: '456d1297-908e-4bd6-a13b-4be31a6e47d5', + externalId: 'testExternalId', + callbackUrl: 'https://www.your-website.com/juzdan-payment-callback', + paymentPhase: Craftgate.Model.PaymentPhase.Auth, + paymentChannel: 'testPaymentChannel', + bankOrderId: 'testBankOrderID', + items: [ + { + name: 'Item 1', + price: 30.0, + externalId: '123d1297-839e-4bd6-a13b-4be31a6e12a8' + } + ], + clientType: Craftgate.Model.ClientType.W, + loanCampaignId: 1 +}; + +craftgate.juzdan().initJuzdanPayment(request) + .then(result => console.info("Juzdan Payment init successful, qrUrl is generated", result)) + .catch(err => console.error("Juzdan Payment init failed", err)); diff --git a/samples/juzdan/RetrieveJuzdanPayment.js b/samples/juzdan/RetrieveJuzdanPayment.js new file mode 100644 index 0000000..f28509b --- /dev/null +++ b/samples/juzdan/RetrieveJuzdanPayment.js @@ -0,0 +1,13 @@ +const Craftgate = require("../../dist"); + +const craftgate = new Craftgate.Client({ + apiKey: "api-key", + secretKey: "secret-key", + baseUrl: "https://sandbox-api.craftgate.io" +}); + +const referenceId = "testReferenceId" + +craftgate.juzdan().retrieveJuzdanPayment(referenceId) + .then(result => console.info("Retrieve Juzdan payment is successful", result)) + .catch(err => console.error("Retrieve Juzdan payment failed", err)); diff --git a/src/CraftgateClient.ts b/src/CraftgateClient.ts index cd9a54e..f8d6a62 100644 --- a/src/CraftgateClient.ts +++ b/src/CraftgateClient.ts @@ -14,6 +14,7 @@ import SettlementAdapter from './adapter/SettlementAdapter'; import SettlementReportingAdapter from './adapter/SettlementReportingAdapter'; import WalletAdapter from './adapter/WalletAdapter'; import {ClientCreationOptions} from './lib/HttpClient'; +import JuzdanPaymentAdapter from './adapter/JuzdanPaymentAdapter'; export default class CraftgateAdapter extends BaseAdapter { private _installmentAdapter: InstallmentAdapter; @@ -30,6 +31,7 @@ export default class CraftgateAdapter extends BaseAdapter { private _masterpassPaymentAdapter: MasterpassPaymentAdapter; private _bankAccountTrackingAdapter: BankAccountTrackingAdapter; private _merchantAdapter: MerchantAdapter; + private _juzdanPaymentAdapter: JuzdanPaymentAdapter; constructor(options: ClientCreationOptions) { super(options); @@ -47,6 +49,7 @@ export default class CraftgateAdapter extends BaseAdapter { this._masterpassPaymentAdapter = new MasterpassPaymentAdapter(options); this._bankAccountTrackingAdapter = new BankAccountTrackingAdapter(options); this._merchantAdapter = new MerchantAdapter(options); + this._juzdanPaymentAdapter = new JuzdanPaymentAdapter(options); } installment(): InstallmentAdapter { @@ -104,4 +107,8 @@ export default class CraftgateAdapter extends BaseAdapter { merchant(): MerchantAdapter { return this._merchantAdapter; } + + juzdan(): JuzdanPaymentAdapter { + return this._juzdanPaymentAdapter; + } } diff --git a/src/adapter/JuzdanPaymentAdapter.ts b/src/adapter/JuzdanPaymentAdapter.ts new file mode 100644 index 0000000..8afa697 --- /dev/null +++ b/src/adapter/JuzdanPaymentAdapter.ts @@ -0,0 +1,20 @@ +import {ClientCreationOptions} from '../lib/HttpClient'; + +import PaymentResponse from '../response/PaymentResponse'; +import BaseAdapter from './BaseAdapter'; +import InitJuzdanPaymentRequest from '../request/InitJuzdanPaymentRequest'; +import InitJuzdanPaymentResponse from '../response/InitJuzdanPaymentResponse'; + +export default class JuzdanPaymentAdapter extends BaseAdapter { + constructor(options: ClientCreationOptions) { + super(options); + } + + async initJuzdanPayment(request: InitJuzdanPaymentRequest): Promise { + return this._client.post('/payment/v1/juzdan-payments/init', request); + } + + async retrieveJuzdanPayment(referenceId: string): Promise { + return this._client.get(`/payment/v1/juzdan-payments/${referenceId}`); + } +} diff --git a/src/model/ClientType.ts b/src/model/ClientType.ts new file mode 100644 index 0000000..7b3536a --- /dev/null +++ b/src/model/ClientType.ts @@ -0,0 +1,6 @@ +enum ClientType { + W = 'W', + M = 'M' +} + +export default ClientType; diff --git a/src/model/index.ts b/src/model/index.ts index 8672458..09d65e2 100644 --- a/src/model/index.ts +++ b/src/model/index.ts @@ -49,6 +49,7 @@ import WalletTransactionRefundTransactionType from './WalletTransactionRefundTra import WalletTransactionType from './WalletTransactionType'; import WebhookEventType from './WebhookEventType'; import WebhookStatus from './WebhookStatus'; +import ClientType from './ClientType'; export = { AccountOwner, @@ -101,5 +102,6 @@ export = { PaymentAuthenticationType, PosUserType, PosOperationType, - CardBrand + CardBrand, + ClientType }; diff --git a/src/request/InitJuzdanPaymentRequest.ts b/src/request/InitJuzdanPaymentRequest.ts new file mode 100644 index 0000000..320a3ca --- /dev/null +++ b/src/request/InitJuzdanPaymentRequest.ts @@ -0,0 +1,24 @@ +import Currency from '../model/Currency'; +import PaymentGroup from '../model/PaymentGroup'; +import PaymentPhase from '../model/PaymentPhase'; +import PaymentItem from './dto/PaymentItem'; +import ClientType from '../model/ClientType'; + +type InitJuzdanPaymentRequest = { + price: number; + paidPrice: number; + currency: Currency; + paymentGroup: PaymentGroup; + conversationId?: string; + externalId?: string; + callbackUrl: string; + paymentPhase: PaymentPhase; + paymentChannel?: string; + buyerMemberId?: number; + bankOrderId?: string; + items: PaymentItem[]; + loanCampaignId?: number; + clientType: ClientType; +}; + +export default InitJuzdanPaymentRequest; diff --git a/src/response/InitJuzdanPaymentResponse.ts b/src/response/InitJuzdanPaymentResponse.ts new file mode 100644 index 0000000..6fe232b --- /dev/null +++ b/src/response/InitJuzdanPaymentResponse.ts @@ -0,0 +1,6 @@ +type InitJuzdanPaymentResponse = { + referenceId: string; + juzdanQrUrl: string; +}; + +export default InitJuzdanPaymentResponse;