Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add card clone adapter #181

Merged
merged 7 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": true,
"bracketSameLine": true,
"jsxSingleQuote": true,
"printWidth": 180,
"proseWrap": "preserve",
Expand Down
18 changes: 18 additions & 0 deletions samples/payment/CloneStoredCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const Craftgate = require('../../dist');

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


const request = {
sourceCardUserKey: 'c356a934-3460-46f4-ba76-3ecea197de6a', // change it with valid cardUserKey
sourceCardToken: 'e6f66ad4-cf05-48df-b6ff-09186980848e', // change it with valid cardToken
targetMerchantId: 1,
};

craftgate.payment().cloneCard(request)
.then(results => console.info('Clone stored card response', results))
.catch(err => console.error('Failed to clone stored card', err));
7 changes: 6 additions & 1 deletion src/adapter/PaymentAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {calculateHash} from '../lib/utils';
import ApplePayMerchantSessionCreateRequest from '../request/ApplePayMerchantSessionCreateRequest';
import ApprovePaymentTransactionsRequest from '../request/ApprovePaymentTransactionsRequest';
import BnplPaymentOfferRequest from '../request/BnplPaymentOfferRequest';
import CloneCardRequest from '../request/CloneCardRequest';
import CompleteApmPaymentRequest from '../request/CompleteApmPaymentRequest';
import CompletePosApmPaymentRequest from '../request/CompletePosApmPaymentRequest';
import CompleteThreeDSPaymentRequest from '../request/CompleteThreeDSPaymentRequest';
Expand Down Expand Up @@ -42,14 +43,14 @@ import InitCheckoutPaymentResponse from '../response/InitCheckoutPaymentResponse
import InitGarantiPayPaymentResponse from '../response/InitGarantiPayPaymentResponse';
import InitPosApmPaymentResponse from '../response/InitPosApmPaymentResponse';
import InitThreeDSPaymentResponse from '../response/InitThreeDSPaymentResponse';
import InstantTransferBanksResponse from '../response/InstantTransferBanksResponse';
import PaymentRefundResponse from '../response/PaymentRefundResponse';
import PaymentResponse from '../response/PaymentResponse';
import PaymentTransactionApprovalListResponse from '../response/PaymentTransactionApprovalListResponse';
import PaymentTransactionRefundResponse from '../response/PaymentTransactionRefundResponse';
import PaymentTransactionResponse from '../response/PaymentTransactionResponse';
import RetrieveLoyaltiesResponse from '../response/RetrieveLoyaltiesResponse';
import StoredCardResponse from '../response/StoredCardResponse';
import InstantTransferBanksResponse from '../response/InstantTransferBanksResponse';

import BaseAdapter from './BaseAdapter';

Expand Down Expand Up @@ -158,6 +159,10 @@ export default class PaymentAdapter extends BaseAdapter {
return this._client.post('/payment/v1/cards/update', request);
}

async cloneCard(request: CloneCardRequest): Promise<StoredCardResponse> {
return this._client.post('/payment/v1/cards/clone', request);
}

async searchStoredCards(request: SearchStoredCardsRequest): Promise<DataResponse<StoredCardResponse>> {
return this._client.get('/payment/v1/cards', request);
}
Expand Down
8 changes: 8 additions & 0 deletions src/request/CloneCardRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type CloneCardRequest = {
sourceCardUserKey: string;
sourceCardToken: string;
targetCardUserKey: string;
targetMerchantId: number;
};

export default CloneCardRequest;
Loading