-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPaymentAdapter.ts
More file actions
295 lines (239 loc) · 14.7 KB
/
Copy pathPaymentAdapter.ts
File metadata and controls
295 lines (239 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import {ClientCreationOptions} from '../lib/HttpClient';
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 CompleteBnplLimitInquiryRequest from '../request/CompleteBnplLimitInquiryRequest';
import CompletePosApmPaymentRequest from '../request/CompletePosApmPaymentRequest';
import CompleteThreeDSPaymentRequest from '../request/CompleteThreeDSPaymentRequest';
import CreateApmPaymentRequest from '../request/CreateApmPaymentRequest';
import CreateDepositPaymentRequest from '../request/CreateDepositPaymentRequest';
import CreateFundTransferDepositPaymentRequest from '../request/CreateFundTransferDepositPaymentRequest';
import CreatePaymentRequest from '../request/CreatePaymentRequest';
import DeleteStoredCardRequest from '../request/DeleteStoredCardRequest';
import DisapprovePaymentTransactionsRequest from '../request/DisapprovePaymentTransactionsRequest';
import InitApmDepositPaymentRequest from '../request/InitApmDepositPaymentRequest';
import InitApmPaymentRequest from '../request/InitApmPaymentRequest';
import InitBnplLimitInquiryRequest from '../request/InitBnplLimitInquiryRequest';
import InitBnplPaymentRequest from '../request/InitBnplPaymentRequest';
import InitCheckoutCardVerifyRequest from '../request/InitCheckoutCardVerifyRequest';
import InitCheckoutPaymentRequest from '../request/InitCheckoutPaymentRequest';
import InitGarantiPayPaymentRequest from '../request/InitGarantiPayPaymentRequest';
import InitMultiPaymentRequest from '../request/InitMultiPaymentRequest';
import InitPosApmPaymentRequest from '../request/InitPosApmPaymentRequest';
import InitThreeDSPaymentRequest from '../request/InitThreeDSPaymentRequest';
import PostAuthPaymentRequest from '../request/PostAuthPaymentRequest';
import RefundPaymentRequest from '../request/RefundPaymentRequest';
import RefundPaymentTransactionMarkAsRefundedRequest from '../request/RefundPaymentTransactionMarkAsRefundedRequest';
import RefundPaymentTransactionRequest from '../request/RefundPaymentTransactionRequest';
import RefundWaitingPaymentRequest from '../request/RefundWaitingPaymentRequest';
import RetrieveCardFromIvrRequest from '../request/RetrieveCardFromIvrRequest';
import RetrieveLoyaltiesRequest from '../request/RetrieveLoyaltiesRequest';
import RetrieveProviderCardRequest from '../request/RetrieveProviderCardRequest';
import SearchStoredCardsRequest from '../request/SearchStoredCardsRequest';
import StoreCardRequest from '../request/StoreCardRequest';
import UpdateCardRequest from '../request/UpdateCardRequest';
import UpdatePaymentTransactionRequest from '../request/UpdatePaymentTransactionRequest';
import VerifyCardRequest from '../request/VerifyCardRequest';
import ApmDepositPaymentResponse from '../response/ApmDepositPaymentResponse';
import BnplLimitInquiryResponse from '../response/BnplLimitInquiryResponse';
import BnplPaymentOfferResponse from '../response/BnplPaymentOfferResponse';
import BnplPaymentVerifyResponse from '../response/BnplPaymentVerifyResponse';
import CompleteApmPaymentResponse from '../response/CompleteApmPaymentResponse';
import DataResponse from '../response/DataResponse';
import DepositPaymentResponse from '../response/DepositPaymentResponse';
import FundTransferDepositPaymentResponse from '../response/FundTransferDepositPaymentResponse';
import InitApmPaymentResponse from '../response/InitApmPaymentResponse';
import InitBnplPaymentResponse from '../response/InitBnplPaymentResponse';
import InitCheckoutCardVerifyResponse from '../response/InitCheckoutCardVerifyResponse';
import InitCheckoutPaymentResponse from '../response/InitCheckoutPaymentResponse';
import InitGarantiPayPaymentResponse from '../response/InitGarantiPayPaymentResponse';
import InitMultiPaymentResponse from '../response/InitMultipaymentPaymentResponse';
import InitPosApmPaymentResponse from '../response/InitPosApmPaymentResponse';
import InitThreeDSPaymentResponse from '../response/InitThreeDSPaymentResponse';
import InstantTransferBanksResponse from '../response/InstantTransferBanksResponse';
import IVRCardTokenizationResponse from '../response/IVRCardTokenizationResponse';
import MultiPaymentResponse from '../response/MultiPaymentResponse';
import PaymentRefundResponse from '../response/PaymentRefundResponse';
import PaymentResponse from '../response/PaymentResponse';
import PaymentTransactionApprovalListResponse from '../response/PaymentTransactionApprovalListResponse';
import PaymentTransactionRefundListResponse from '../response/PaymentTransactionRefundListResponse';
import PaymentTransactionRefundResponse from '../response/PaymentTransactionRefundResponse';
import PaymentTransactionResponse from '../response/PaymentTransactionResponse';
import RetrieveCheckoutCardVerifyResponse from '../response/RetrieveCheckoutCardVerifyResponse';
import RetrieveLoyaltiesResponse from '../response/RetrieveLoyaltiesResponse';
import StoredCardResponse from '../response/StoredCardResponse';
import VerifyCardResponse from '../response/VerifyCardResponse';
import WaitingPaymentRefundResponse from '../response/WaitingPaymentRefundResponse';
import BaseAdapter from './BaseAdapter';
export default class PaymentAdapter extends BaseAdapter {
constructor(options: ClientCreationOptions) {
super(options);
}
async createPayment(request: CreatePaymentRequest): Promise<PaymentResponse> {
return this._client.post('/payment/v1/card-payments', request);
}
async retrievePayment(id: number): Promise<PaymentResponse> {
return this._client.get(`/payment/v1/card-payments/${id}`);
}
async postAuthPayment(paymentId: number, request: PostAuthPaymentRequest): Promise<PaymentResponse> {
return this._client.post(`/payment/v1/card-payments/${paymentId}/post-auth`, request);
}
async init3DSPayment(request: InitThreeDSPaymentRequest): Promise<InitThreeDSPaymentResponse> {
return this._client.post('/payment/v1/card-payments/3ds-init', request);
}
async complete3DSPayment(request: CompleteThreeDSPaymentRequest): Promise<PaymentResponse> {
return this._client.post('/payment/v1/card-payments/3ds-complete', request);
}
async initCheckoutPayment(request: InitCheckoutPaymentRequest): Promise<InitCheckoutPaymentResponse> {
return this._client.post('/payment/v1/checkout-payments/init', request);
}
async initCheckoutCardVerify(request: InitCheckoutCardVerifyRequest): Promise<InitCheckoutCardVerifyResponse> {
return this._client.post('/payment/v1/checkout-card-verify/init', request);
}
async retrieveCheckoutCardVerify(token: string): Promise<RetrieveCheckoutCardVerifyResponse> {
return this._client.get(`/payment/v1/checkout-card-verify/${token}`);
}
async retrieveCheckoutPayment(token: string): Promise<PaymentResponse> {
return this._client.get(`/payment/v1/checkout-payments/${token}`);
}
async expireCheckoutPayment(token: string): Promise<void> {
await this._client.delete(`/payment/v1/checkout-payments/${token}`);
}
async createDepositPayment(request: CreateDepositPaymentRequest): Promise<DepositPaymentResponse> {
return this._client.post('/payment/v1/deposits', request);
}
async init3DSDepositPayment(request: CreateDepositPaymentRequest): Promise<InitThreeDSPaymentResponse> {
return this._client.post('/payment/v1/deposits/3ds-init', request);
}
async complete3DSDepositPayment(request: CompleteThreeDSPaymentRequest): Promise<DepositPaymentResponse> {
return this._client.post('/payment/v1/deposits/3ds-complete', request);
}
async createFundTransferDepositPayment(request: CreateFundTransferDepositPaymentRequest): Promise<FundTransferDepositPaymentResponse> {
return this._client.post('/payment/v1/deposits/fund-transfer', request);
}
async initApmDepositPayment(request: InitApmDepositPaymentRequest): Promise<ApmDepositPaymentResponse> {
return this._client.post('/payment/v1/deposits/apm-init', request);
}
async initGarantiPayPayment(request: InitGarantiPayPaymentRequest): Promise<InitGarantiPayPaymentResponse> {
return this._client.post('/payment/v1/garanti-pay-payments', request);
}
async initApmPayment(request: InitApmPaymentRequest): Promise<InitApmPaymentResponse> {
return this._client.post('/payment/v1/apm-payments/init', request);
}
async completeApmPayment(request: CompleteApmPaymentRequest): Promise<CompleteApmPaymentResponse> {
return this._client.post('/payment/v1/apm-payments/complete', request);
}
async createApmPayment(request: CreateApmPaymentRequest): Promise<PaymentResponse> {
return this._client.post('/payment/v1/apm-payments', request);
}
async initPosApmPayment(request: InitPosApmPaymentRequest): Promise<InitPosApmPaymentResponse> {
return this._client.post('/payment/v1/pos-apm-payments/init', request);
}
async completePosApmPayment(request: CompletePosApmPaymentRequest): Promise<PaymentResponse> {
return this._client.post('/payment/v1/pos-apm-payments/complete', request);
}
async refundPaymentTransaction(request: RefundPaymentTransactionRequest): Promise<PaymentTransactionRefundResponse> {
return this._client.post('/payment/v1/refund-transactions', request);
}
async retrievePaymentTransactionRefund(paymentTransactionRefundId: number): Promise<PaymentTransactionRefundResponse> {
return this._client.get(`/payment/v1/refund-transactions/${paymentTransactionRefundId}`);
}
async refundPaymentTransactionMarkAsRefunded(request: RefundPaymentTransactionMarkAsRefundedRequest): Promise<PaymentTransactionRefundResponse> {
return this._client.post('/payment/v1/refund-transactions/mark-as-refunded', request);
}
async refundPayment(request: RefundPaymentRequest): Promise<PaymentRefundResponse> {
return this._client.post('/payment/v1/refunds', request);
}
async refundWaitingPayment(request: RefundWaitingPaymentRequest): Promise<WaitingPaymentRefundResponse> {
return this._client.post('/payment/v1/refunds/refund-waiting-payment', request);
}
async retrievePaymentRefund(refundId: number): Promise<PaymentRefundResponse> {
return this._client.get(`/payment/v1/refunds/${refundId}`);
}
async refundPaymentMarkAsRefunded(request: RefundPaymentRequest): Promise<PaymentTransactionRefundListResponse> {
return this._client.post('/payment/v1/refunds/mark-as-refunded', request);
}
async storeCard(request: StoreCardRequest): Promise<StoredCardResponse> {
return this._client.post('/payment/v1/cards', request);
}
async updateCard(request: UpdateCardRequest): Promise<StoredCardResponse> {
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);
}
async deleteStoredCard(request: DeleteStoredCardRequest): Promise<void> {
await this._client.post('/payment/v1/cards/delete', request);
}
async verifyCard(request: VerifyCardRequest): Promise<VerifyCardResponse> {
return this._client.post('/payment/v1/cards/verify', request);
}
async approvePaymentTransactions(request: ApprovePaymentTransactionsRequest): Promise<PaymentTransactionApprovalListResponse> {
return this._client.post('/payment/v1/payment-transactions/approve', request);
}
async disapprovePaymentTransactions(request: DisapprovePaymentTransactionsRequest): Promise<PaymentTransactionApprovalListResponse> {
return this._client.post('/payment/v1/payment-transactions/disapprove', request);
}
async retrieveLoyalties(request: RetrieveLoyaltiesRequest): Promise<RetrieveLoyaltiesResponse> {
return this._client.post('/payment/v1/card-loyalties/retrieve', request);
}
async updatePaymentTransaction(paymentTransactionId: number, request: UpdatePaymentTransactionRequest): Promise<PaymentTransactionResponse> {
return this._client.put(`/payment/v1/payment-transactions/${paymentTransactionId}`, request);
}
async createApplePayMerchantSession(request: ApplePayMerchantSessionCreateRequest): Promise<any> {
return this._client.post(`/payment/v1/apple-pay/merchant-sessions`, request);
}
async retrieveBnplOffers(request: BnplPaymentOfferRequest): Promise<BnplPaymentOfferResponse> {
return this._client.post(`/payment/v1/bnpl-payments/offers`, request);
}
async initBnplPayment(request: InitBnplPaymentRequest): Promise<InitBnplPaymentResponse> {
return this._client.post(`/payment/v1/bnpl-payments/init`, request);
}
async approveBnplPayment(paymentId: number): Promise<PaymentResponse> {
return this._client.post(`/payment/v1/bnpl-payments/${paymentId}/approve`);
}
async verifyBnplPayment(paymentId: number): Promise<BnplPaymentVerifyResponse> {
return this._client.post(`/payment/v1/bnpl-payments/${paymentId}/verify`);
}
async bnplLimitInquiryInit(request: InitBnplLimitInquiryRequest): Promise<BnplLimitInquiryResponse> {
return this._client.post(`/payment/v1/bnpl-payments/limit-inquiry/init`, request);
}
async bnplLimitInquiry(request: CompleteBnplLimitInquiryRequest): Promise<BnplLimitInquiryResponse> {
return this._client.post(`/payment/v1/bnpl-payments/limit-inquiry`, request);
}
async retrieveActiveBanks(): Promise<InstantTransferBanksResponse> {
return this._client.get(`/payment/v1/instant-transfer-banks`);
}
async initMultiPayment(request: InitMultiPaymentRequest): Promise<InitMultiPaymentResponse> {
return this._client.post(`/payment/v1/multi-payments/init`, request);
}
async retrieveMultiPayment(token: string): Promise<MultiPaymentResponse> {
return this._client.get(`/payment/v1/multi-payments/${token}`);
}
async retrieveProviderCards(request: RetrieveProviderCardRequest): Promise<DataResponse<StoredCardResponse>> {
return this._client.get('/payment/v1/cards/provider-card-mappings', request);
}
async retrieveCardFromIvr(request: RetrieveCardFromIvrRequest): Promise<IVRCardTokenizationResponse> {
return this._client.get('/payment/v1/ivr-cards', request);
}
async is3DSecureCallbackVerified(threeDSecureCallbackKey: string, params: Map<string, string>): Promise<boolean> {
const hash = params['hash'];
const hashString: string = [
threeDSecureCallbackKey,
params['status'],
params['completeStatus'],
params['paymentId'],
params['conversationData'],
params['conversationId'],
params['callbackStatus']
].join('###');
const hashed = calculateHash(hashString);
return hash == hashed;
}
}