Skip to content

Commit

Permalink
Add card clone adapter (#181)
Browse files Browse the repository at this point in the history
* Add card clone adapter

* Add card clone adapter

* Add card clone adapter

* Add card clone adapter

* Add card clone adapter

* Add card clone adapter

* fix .prettierrc

---------

Co-authored-by: Emre INAL <[email protected]>
  • Loading branch information
abalikci and reywyn authored Mar 28, 2024
1 parent 09f8206 commit f6f648a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
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;

0 comments on commit f6f648a

Please sign in to comment.