Skip to content

Commit

Permalink
Adds Juzdan integration to Node.js client (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
beransantur authored Feb 13, 2024
1 parent 277e711 commit 56a1cbc
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 1 deletion.
33 changes: 33 additions & 0 deletions samples/juzdan/InitJuzdanPayment.js
Original file line number Diff line number Diff line change
@@ -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));
13 changes: 13 additions & 0 deletions samples/juzdan/RetrieveJuzdanPayment.js
Original file line number Diff line number Diff line change
@@ -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));
7 changes: 7 additions & 0 deletions src/CraftgateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -104,4 +107,8 @@ export default class CraftgateAdapter extends BaseAdapter {
merchant(): MerchantAdapter {
return this._merchantAdapter;
}

juzdan(): JuzdanPaymentAdapter {
return this._juzdanPaymentAdapter;
}
}
20 changes: 20 additions & 0 deletions src/adapter/JuzdanPaymentAdapter.ts
Original file line number Diff line number Diff line change
@@ -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<InitJuzdanPaymentResponse> {
return this._client.post('/payment/v1/juzdan-payments/init', request);
}

async retrieveJuzdanPayment(referenceId: string): Promise<PaymentResponse> {
return this._client.get(`/payment/v1/juzdan-payments/${referenceId}`);
}
}
6 changes: 6 additions & 0 deletions src/model/ClientType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum ClientType {
W = 'W',
M = 'M'
}

export default ClientType;
4 changes: 3 additions & 1 deletion src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -101,5 +102,6 @@ export = {
PaymentAuthenticationType,
PosUserType,
PosOperationType,
CardBrand
CardBrand,
ClientType
};
24 changes: 24 additions & 0 deletions src/request/InitJuzdanPaymentRequest.ts
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 6 additions & 0 deletions src/response/InitJuzdanPaymentResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type InitJuzdanPaymentResponse = {
referenceId: string;
juzdanQrUrl: string;
};

export default InitJuzdanPaymentResponse;

0 comments on commit 56a1cbc

Please sign in to comment.