Skip to content

Commit

Permalink
Merge branch 'master' into paycell-type
Browse files Browse the repository at this point in the history
  • Loading branch information
AlicanAkkus authored Feb 16, 2024
2 parents cfb194a + 56a1cbc commit a28a58d
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 2 deletions.
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));
48 changes: 48 additions & 0 deletions samples/payment/InitThreeDsPreauthPayment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const Craftgate = require('@craftgate/craftgate');

const craftgate = new Craftgate.Client({
apiKey: 'sandbox-YEhueLgomBjqsnvBlWVVuFsVhlvJlMHE',
secretKey: 'sandbox-tBdcdKVGmGupzfaWcULcwDLMoglZZvTz',
baseUrl: 'https://sandbox-api.craftgate.io'
});

const request = {
price: 100.0,
paidPrice: 100.0,
walletPrice: 0.0,
installment: 1,
conversationId: '456d1297-908e-4bd6-a13b-4be31a6e47d5',
currency: Craftgate.Model.Currency.TRY,
paymentGroup: Craftgate.Model.PaymentGroup.ListingOrSubscription,
callbackUrl: 'https://www.your-website.com/craftgate-3DSecure-callback',
paymentPhase: Craftgate.Model.PaymentPhase.PreAuth,

card: {
cardHolderName: 'Haluk Demir',
cardNumber: '5258640000000001',
expireYear: '2044',
expireMonth: '07',
cvc: '000'
},
items: [
{
name: 'Item 1',
price: 30.0,
externalId: '123d1297-839e-4bd6-a13b-4be31a6e12a8'
},
{
name: 'Item 2',
price: 50.0,
externalId: '789d1297-839e-4bd6-a13b-4be31a6e13f7'
},
{
name: 'Item 3',
price: 20.0,
externalId: '3a1d1297-839e-4bd6-a13b-4be31a6e18e6'
}
]
};

craftgate.payment().init3DSPayment(request)
.then(result => console.info('Init 3ds payment successful', result))
.catch(err => console.error('Failed to init 3ds payment', 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}`);
}
}
3 changes: 2 additions & 1 deletion src/model/ApmType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ enum ApmType {
Maslak = 'MASLAK',
ALFABANK = 'ALFABANK',
TomFinance = 'TOM_FINANCE',
Paycell = 'PAYCELL'
Paycell = 'PAYCELL',
Haso = 'HASO'
}

export default ApmType;
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;
1 change: 1 addition & 0 deletions src/model/PaymentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum PaymentProvider {
TomFinance = 'TOM_FINANCE',
Alfabank = 'ALFABANK',
Paycell = 'PAYCELL',
Haso = 'HASO',
Offline = 'OFFLINE'
}

Expand Down
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 a28a58d

Please sign in to comment.