@tonder.io/ionic-lite-sdk 0.0.41-beta.1 → 0.0.42-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +28 -28
- package/README.md +532 -532
- package/dist/classes/3dsHandler.d.ts +3 -1
- package/dist/classes/BaseInlineCheckout.d.ts +3 -2
- package/dist/classes/liteCheckout.d.ts +1 -1
- package/dist/data/cardApi.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/types/commons.d.ts +1 -0
- package/dist/types/liteInlineCheckout.d.ts +1 -1
- package/jest.config.ts +14 -14
- package/package.json +41 -41
- package/rollup.config.js +16 -16
- package/src/classes/3dsHandler.ts +347 -337
- package/src/classes/BaseInlineCheckout.ts +424 -415
- package/src/classes/errorResponse.ts +16 -16
- package/src/classes/liteCheckout.ts +589 -591
- package/src/data/api.ts +20 -20
- package/src/data/businessApi.ts +18 -18
- package/src/data/cardApi.ts +91 -87
- package/src/data/checkoutApi.ts +84 -84
- package/src/data/customerApi.ts +31 -31
- package/src/data/openPayApi.ts +12 -12
- package/src/data/paymentMethodApi.ts +37 -37
- package/src/data/skyflowApi.ts +20 -20
- package/src/helpers/constants.ts +63 -63
- package/src/helpers/mercadopago.ts +15 -15
- package/src/helpers/skyflow.ts +91 -91
- package/src/helpers/utils.ts +120 -120
- package/src/helpers/validations.ts +55 -55
- package/src/index.ts +12 -12
- package/src/shared/catalog/paymentMethodsCatalog.ts +247 -247
- package/src/shared/constants/messages.ts +10 -10
- package/src/shared/constants/paymentMethodAPM.ts +63 -63
- package/src/shared/constants/tonderUrl.ts +8 -8
- package/src/types/card.ts +35 -35
- package/src/types/checkout.ts +123 -123
- package/src/types/commons.ts +143 -142
- package/src/types/customer.ts +22 -22
- package/src/types/liteInlineCheckout.ts +216 -216
- package/src/types/paymentMethod.ts +23 -23
- package/src/types/requests.ts +114 -114
- package/src/types/responses.ts +192 -192
- package/src/types/skyflow.ts +17 -17
- package/src/types/transaction.ts +101 -101
- package/src/types/validations.d.ts +11 -11
- package/tests/classes/liteCheckout.test.ts +57 -57
- package/tests/methods/createOrder.test.ts +141 -141
- package/tests/methods/createPayment.test.ts +121 -121
- package/tests/methods/customerRegister.test.ts +118 -118
- package/tests/methods/getBusiness.test.ts +114 -114
- package/tests/methods/getCustomerCards.test.ts +112 -112
- package/tests/methods/registerCustomerCard.test.ts +117 -117
- package/tests/methods/startCheckoutRouter.test.ts +119 -119
- package/tests/methods/startCheckoutRouterFull.test.ts +138 -138
- package/tests/utils/defaultMock.ts +21 -21
- package/tests/utils/mockClasses.ts +659 -659
- package/tsconfig.json +18 -18
package/README.md
CHANGED
|
@@ -1,532 +1,532 @@
|
|
|
1
|
-
# Tonder SDK
|
|
2
|
-
|
|
3
|
-
Tonder SDK helps to integrate the services Tonder offers in your own mobile app
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
## Table of Contents
|
|
7
|
-
|
|
8
|
-
1. [Installation](#installation)
|
|
9
|
-
2. [Usage](#usage)
|
|
10
|
-
3. [Configuration Options](#configuration-options)
|
|
11
|
-
4. [Mobile Settings](#mobile-settings)
|
|
12
|
-
5. [Payment Data Structure](#payment-data-structure)
|
|
13
|
-
6. [Field Validation Functions](#field-validation-functions)
|
|
14
|
-
7. [API Reference](#api-reference)
|
|
15
|
-
8. [Examples](#examples)
|
|
16
|
-
9. [Deprecated Fields](#deprecated-fields)
|
|
17
|
-
10. [Deprecated Functions](#deprecated-functions)
|
|
18
|
-
11. [License](#license)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
## Installation
|
|
22
|
-
|
|
23
|
-
You can install using NPM
|
|
24
|
-
```bash
|
|
25
|
-
npm i @tonder.io/ionic-lite-sdk
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Add dependencies to the root of the app (index.html)
|
|
29
|
-
```html
|
|
30
|
-
<script src=https://openpay.s3.amazonaws.com/openpay.v1.min.js></script>
|
|
31
|
-
<script src=https://openpay.s3.amazonaws.com/openpay-data.v1.min.js></script>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Usage
|
|
35
|
-
LiteCheckout allows you to build a custom checkout interface using Tonder's core functionality
|
|
36
|
-
### Import LiteCheckout class
|
|
37
|
-
```javascript
|
|
38
|
-
import { LiteCheckout } from "@tonder.io/ionic-lite-sdk"
|
|
39
|
-
```
|
|
40
|
-
### Create instance
|
|
41
|
-
|
|
42
|
-
```javascript
|
|
43
|
-
const liteCheckout = new LiteCheckout({
|
|
44
|
-
signal,
|
|
45
|
-
baseUrlTonder,
|
|
46
|
-
apiKeyTonder
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
// The configureCheckout function allows you to set initial information,
|
|
50
|
-
// such as the customer's email, which is used to retrieve a list of saved cards, save new card, etc.
|
|
51
|
-
inlineCheckout.configureCheckout({ customer: { email: "example@email.com" } });
|
|
52
|
-
|
|
53
|
-
// Initialize the checkout
|
|
54
|
-
await liteCheckout.injectCheckout();
|
|
55
|
-
|
|
56
|
-
// To verify a 3ds transaction you can use the following method
|
|
57
|
-
// It should be called after the injectCheckout method
|
|
58
|
-
// The response status will be one of the following
|
|
59
|
-
// ['Declined', 'Cancelled', 'Failed', 'Success', 'Pending', 'Authorized']
|
|
60
|
-
|
|
61
|
-
inlineCheckout.verify3dsTransaction().then(response => {
|
|
62
|
-
console.log('Verify 3ds response', response)
|
|
63
|
-
})
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
```javascript
|
|
67
|
-
// Retrieve customer's saved cards
|
|
68
|
-
const cards = await liteCheckout.getCustomerCards();
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
```javascript
|
|
72
|
-
// Save a new card
|
|
73
|
-
const newCard = await liteCheckout.saveCustomerCard(cardData);
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
```javascript
|
|
77
|
-
// Remove a saved card
|
|
78
|
-
await liteCheckout.removeCustomerCard(cardId);
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
```javascript
|
|
82
|
-
// Get available payment methods
|
|
83
|
-
const paymentMethods = await liteCheckout.getCustomerPaymentMethods();
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
```javascript
|
|
87
|
-
// Process a payment
|
|
88
|
-
const paymentResponse = await liteCheckout.payment(paymentData);
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## Configuration Options
|
|
92
|
-
|
|
93
|
-
| Property | Type | Description |
|
|
94
|
-
|:---------:|:--------:|:--------------------------------------------------------------------------------------------:|
|
|
95
|
-
| mode | string | Environment mode. Options: 'stage', 'production', 'sandbox', 'development'. Default: 'stage' |
|
|
96
|
-
| apiKey | string | Your API key from the Tonder Dashboard |
|
|
97
|
-
| returnrl | string | URL where the checkout form is mounted (used for 3DS) |
|
|
98
|
-
| callBack | function | Callback function to be invoked after the payment process ends successfully. |
|
|
99
|
-
|
|
100
|
-
## Mobile settings
|
|
101
|
-
|
|
102
|
-
<font size="3">If you are deploying to Android, edit your AndroidManifest.xml file to add the Internet permission.</font>
|
|
103
|
-
|
|
104
|
-
```xml
|
|
105
|
-
<!-- Required to fetch data from the internet. -->
|
|
106
|
-
<uses-permission android:name="android.permission.INTERNET" />
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
<font size="3">Likewise, if you are deploying to macOS, edit your macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements files to include the network client entitlement.</font>
|
|
110
|
-
|
|
111
|
-
```xml
|
|
112
|
-
<!-- Required to fetch data from the internet. -->
|
|
113
|
-
<key>com.apple.security.network.client</key>
|
|
114
|
-
<true>
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## Payment Data Structure
|
|
118
|
-
|
|
119
|
-
When calling the `payment` method, use the following data structure:
|
|
120
|
-
|
|
121
|
-
### Field Descriptions
|
|
122
|
-
|
|
123
|
-
- **customer**: Object containing the customer's personal information to be registered in the transaction.
|
|
124
|
-
|
|
125
|
-
- **cart**: Object containing the total amount and an array of items to be registered in the Tonder order.
|
|
126
|
-
|
|
127
|
-
- **total**: The total amount of the transaction.
|
|
128
|
-
- **items**: An array of objects, each representing a product or service in the order.
|
|
129
|
-
- name: name of the product
|
|
130
|
-
- price_unit: valid float string with the price of the product
|
|
131
|
-
- quantity: valid integer string with the quantity of this product
|
|
132
|
-
|
|
133
|
-
- **currency**: String representing the currency code for the transaction (e.g., "MXN" for Mexican Peso).
|
|
134
|
-
|
|
135
|
-
- **metadata**: Object for including any additional information about the transaction. This can be used for internal references or tracking.
|
|
136
|
-
|
|
137
|
-
- **card**: (for LiteCheckout) Object containing card information. This is used differently depending on whether it's a new card or a saved card:
|
|
138
|
-
|
|
139
|
-
- For a new card: Include `card_number`, `cvv`, `expiration_month`, `expiration_year`, and `cardholder_name`.
|
|
140
|
-
- For a saved card: Include only the `skyflow_id` of the saved card.
|
|
141
|
-
- This is only used when not paying with a payment_method.
|
|
142
|
-
|
|
143
|
-
- **payment_method**: (for LiteCheckout) String indicating the alternative payment method to be used (e.g., "Spei"). This is only used when not paying with a card.
|
|
144
|
-
|
|
145
|
-
```javascript
|
|
146
|
-
const paymentData = {
|
|
147
|
-
customer: {
|
|
148
|
-
firstName: "John",
|
|
149
|
-
lastName: "Doe",
|
|
150
|
-
country: "USA",
|
|
151
|
-
address: "123 Main St",
|
|
152
|
-
city: "Anytown",
|
|
153
|
-
state: "CA",
|
|
154
|
-
postCode: "12345",
|
|
155
|
-
email: "john.doe@example.com",
|
|
156
|
-
phone: "1234567890",
|
|
157
|
-
},
|
|
158
|
-
cart: {
|
|
159
|
-
total: "100.00",
|
|
160
|
-
items: [
|
|
161
|
-
{
|
|
162
|
-
description: "Product description",
|
|
163
|
-
quantity: 1,
|
|
164
|
-
price_unit: "100.00",
|
|
165
|
-
discount: "0.00",
|
|
166
|
-
taxes: "0.00",
|
|
167
|
-
product_reference: "PROD123",
|
|
168
|
-
name: "Product Name",
|
|
169
|
-
amount_total: "100.00",
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
},
|
|
173
|
-
currency: "MXN",
|
|
174
|
-
metadata: {
|
|
175
|
-
order_id: "ORDER123",
|
|
176
|
-
},
|
|
177
|
-
// For a new card:
|
|
178
|
-
card: {
|
|
179
|
-
card_number: "4111111111111111",
|
|
180
|
-
cvv: "123",
|
|
181
|
-
expiration_month: "12",
|
|
182
|
-
expiration_year: "25",
|
|
183
|
-
cardholder_name: "John Doe",
|
|
184
|
-
},
|
|
185
|
-
// card: "skyflow_id" // for a selected saved card.
|
|
186
|
-
// payment_method: "Spei", // For the selected payment method.
|
|
187
|
-
};
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
## Field Validation Functions
|
|
191
|
-
|
|
192
|
-
For LiteCheckout implementations, the SDK provides validation functions to ensure the integrity of card data before submitting:
|
|
193
|
-
|
|
194
|
-
- `validateCardNumber(cardNumber)`: Validates the card number using the Luhn algorithm.
|
|
195
|
-
- `validateCardholderName(name)`: Checks if the cardholder name is valid.
|
|
196
|
-
- `validateCVV(cvv)`: Ensures the CVV is in the correct format.
|
|
197
|
-
- `validateExpirationDate(expirationDate)`: Validates the expiration date in MM/YY format.
|
|
198
|
-
- `validateExpirationMonth(month)`: Checks if the expiration month is valid.
|
|
199
|
-
- `validateExpirationYear(year)`: Validates the expiration year.
|
|
200
|
-
|
|
201
|
-
Example usage:
|
|
202
|
-
|
|
203
|
-
```javascript
|
|
204
|
-
import {
|
|
205
|
-
validateCardNumber,
|
|
206
|
-
validateCardholderName,
|
|
207
|
-
validateCVV,
|
|
208
|
-
validateExpirationDate,
|
|
209
|
-
} from "@tonder.io/ionic-lite-sdk";
|
|
210
|
-
|
|
211
|
-
const cardNumber = "4111111111111111";
|
|
212
|
-
const cardholderName = "John Doe";
|
|
213
|
-
const cvv = "123";
|
|
214
|
-
const expirationDate = "12/25";
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
validateCardNumber(cardNumber) &&
|
|
218
|
-
validateCardholderName(cardholderName) &&
|
|
219
|
-
validateCVV(cvv) &&
|
|
220
|
-
validateExpirationDate(expirationDate)
|
|
221
|
-
) {
|
|
222
|
-
// Proceed with payment
|
|
223
|
-
} else {
|
|
224
|
-
// Show error message
|
|
225
|
-
}
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
## API Reference
|
|
230
|
-
|
|
231
|
-
### LiteCheckout Methods
|
|
232
|
-
|
|
233
|
-
- `configureCheckout(data)`: Set initial checkout data
|
|
234
|
-
- `injectCheckout()`: Initialize the checkout
|
|
235
|
-
- `getCustomerCards()`: Retrieve saved cards
|
|
236
|
-
- `saveCustomerCard(cardData)`: Save a new card
|
|
237
|
-
- `removeCustomerCard(cardId)`: Remove a saved card
|
|
238
|
-
- `getCustomerPaymentMethods()`: Get available payment methods
|
|
239
|
-
- `payment(data)`: Process a payment
|
|
240
|
-
- `verify3dsTransaction()`: Verify a 3DS transaction
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
## Examples
|
|
244
|
-
|
|
245
|
-
Here are examples of how to implement Tonder Lite SDK:
|
|
246
|
-
|
|
247
|
-
### Angular
|
|
248
|
-
|
|
249
|
-
For Angular, we recommend using a service to manage the Tonder instance:
|
|
250
|
-
|
|
251
|
-
```typescript
|
|
252
|
-
// tonder.service.ts
|
|
253
|
-
import { Injectable } from "@angular/core";
|
|
254
|
-
import { LiteCheckout } from "@tonder.io/ionic-lite-sdk";
|
|
255
|
-
import {ILiteCheckout} from "@tonder.io/ionic-lite-sdk/dist/types/liteInlineCheckout";
|
|
256
|
-
|
|
257
|
-
@Injectable({
|
|
258
|
-
providedIn: "root",
|
|
259
|
-
})
|
|
260
|
-
export class TonderService {
|
|
261
|
-
private liteCheckout!: ILiteCheckout;
|
|
262
|
-
|
|
263
|
-
constructor(@Inject(Object) private sdkParameters: IInlineLiteCheckoutOptions) {
|
|
264
|
-
this.initializeInlineCheckout();
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
private initializeInlineCheckout(): void {
|
|
268
|
-
this.liteCheckout = new LiteCheckout({ ...this.sdkParameters });
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
configureCheckout(customerData: IConfigureCheckout): void {
|
|
272
|
-
return this.liteCheckout.configureCheckout({ ...customerData });
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
async injectCheckout(): Promise<void> {
|
|
276
|
-
return await this.liteCheckout.injectCheckout();
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
verify3dsTransaction(): Promise<ITransaction | IStartCheckoutResponse | void> {
|
|
280
|
-
return this.liteCheckout.verify3dsTransaction();
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
payment(
|
|
284
|
-
checkoutData: IProcessPaymentRequest,
|
|
285
|
-
): Promise<IStartCheckoutResponse> {
|
|
286
|
-
return this.inlineCheckout.payment(checkoutData);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Add more functions, for example for lite sdk: get payment methods
|
|
290
|
-
|
|
291
|
-
// getCustomerPaymentMethods(): Promise<IPaymentMethod[]> {
|
|
292
|
-
// return this.liteCheckout.getCustomerPaymentMethods();
|
|
293
|
-
// }
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// checkout.component.ts
|
|
297
|
-
import { Component, OnInit, OnDestroy } from "@angular/core";
|
|
298
|
-
import { TonderService } from "./tonder.service";
|
|
299
|
-
|
|
300
|
-
@Component({
|
|
301
|
-
selector: "app-tonder-checkout",
|
|
302
|
-
template: `
|
|
303
|
-
<div id="container">
|
|
304
|
-
<form [formGroup]="paymentForm">
|
|
305
|
-
<div class="lite-container-tonder">
|
|
306
|
-
<div id="id-name" class="empty-div">
|
|
307
|
-
<label for="name">Namess: </label>
|
|
308
|
-
<input id="name" type="text" formControlName="name">
|
|
309
|
-
</div>
|
|
310
|
-
<div id="id-cardNumber" class="empty-div">
|
|
311
|
-
<label for="cardNumber">Card number: </label>
|
|
312
|
-
<input id="cardNumber" type="text" formControlName="cardNumber">
|
|
313
|
-
</div>
|
|
314
|
-
<div class="collect-row">
|
|
315
|
-
<div class="empty-div">
|
|
316
|
-
<label for="month">Month: </label>
|
|
317
|
-
<input id="month" type="text" formControlName="month">
|
|
318
|
-
</div>
|
|
319
|
-
<div class="expiration-year">
|
|
320
|
-
<label for="expirationYear">Year: </label>
|
|
321
|
-
<input id="expirationYear" type="text" formControlName="expirationYear">
|
|
322
|
-
</div>
|
|
323
|
-
<div class="empty-div">
|
|
324
|
-
<label for="cvv">CVV: </label>
|
|
325
|
-
<input id="cvv" type="text" formControlName="cvv">
|
|
326
|
-
</div>
|
|
327
|
-
</div>
|
|
328
|
-
<div id="msgError">{{ errorMessage }}</div>
|
|
329
|
-
<div id="msgNotification"></div>
|
|
330
|
-
<div class="container-pay-button">
|
|
331
|
-
<button class="lite-pay-button" (click)="onPayment($event)">Pay</button>
|
|
332
|
-
</div>
|
|
333
|
-
</div>
|
|
334
|
-
|
|
335
|
-
</form>
|
|
336
|
-
</div>
|
|
337
|
-
`,
|
|
338
|
-
providers: [
|
|
339
|
-
{
|
|
340
|
-
provide: TonderInlineService,
|
|
341
|
-
// Initialization of the Tonder Lite SDK.
|
|
342
|
-
// Note: Replace these credentials with your own in development/production.
|
|
343
|
-
useFactory: () =>
|
|
344
|
-
new TonderInlineService({
|
|
345
|
-
apiKey: "11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27",
|
|
346
|
-
returnUrl: "http://localhost:8100/tabs/tab5",
|
|
347
|
-
mode: "stage",
|
|
348
|
-
}),
|
|
349
|
-
},
|
|
350
|
-
],
|
|
351
|
-
})
|
|
352
|
-
export class TonderCheckoutComponent implements OnInit, OnDestroy {
|
|
353
|
-
loading = false;
|
|
354
|
-
checkoutData: IProcessPaymentRequest;
|
|
355
|
-
paymentForm = new FormGroup({
|
|
356
|
-
name: new FormControl('Pedro Paramo'),
|
|
357
|
-
cardNumber: new FormControl('4242424242424242'),
|
|
358
|
-
month: new FormControl('12'),
|
|
359
|
-
expirationYear: new FormControl('28'),
|
|
360
|
-
cvv: new FormControl('123')
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
constructor(private tonderService: TonderService) {
|
|
364
|
-
this.checkoutData = {
|
|
365
|
-
customer: {
|
|
366
|
-
firstName: "Jhon",
|
|
367
|
-
lastName: "Doe",
|
|
368
|
-
email: "john.c.calhoun@examplepetstore.com",
|
|
369
|
-
phone: "+58452258525"
|
|
370
|
-
},
|
|
371
|
-
cart: {
|
|
372
|
-
total: 25,
|
|
373
|
-
items: [
|
|
374
|
-
{
|
|
375
|
-
description: "Test product description",
|
|
376
|
-
quantity: 1,
|
|
377
|
-
price_unit: 25,
|
|
378
|
-
discount: 1,
|
|
379
|
-
taxes: 12,
|
|
380
|
-
product_reference: 89456123,
|
|
381
|
-
name: "Test product",
|
|
382
|
-
amount_total: 25
|
|
383
|
-
}
|
|
384
|
-
]
|
|
385
|
-
},
|
|
386
|
-
metadata: {},
|
|
387
|
-
currency: "MXN"
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
ngOnInit() {
|
|
392
|
-
this.initCheckout();
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
async initCheckout() {
|
|
396
|
-
this.tonderService.configureCheckout({
|
|
397
|
-
customer: { email: "example@email.com" },
|
|
398
|
-
});
|
|
399
|
-
await this.tonderService.injectCheckout();
|
|
400
|
-
this.tonderService.verify3dsTransaction().then((response) => {
|
|
401
|
-
console.log("Verify 3ds response", response);
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
// Calls more functions to get payment methods, saved cards, etc.
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
async pay() {
|
|
408
|
-
this.loading = true;
|
|
409
|
-
try {
|
|
410
|
-
const response = await this.tonderService.payment({
|
|
411
|
-
...this.checkoutData,
|
|
412
|
-
card: { // Card details, if not using a payment method.
|
|
413
|
-
card_number: this.paymentForm.value.cardNumber || "",
|
|
414
|
-
cvv: this.paymentForm.value.cvv || "",
|
|
415
|
-
expiration_month: this.paymentForm.value.month || "",
|
|
416
|
-
expiration_year: this.paymentForm.value.expirationYear || "",
|
|
417
|
-
cardholder_name: this.paymentForm.value.name || ""
|
|
418
|
-
},
|
|
419
|
-
// card: "skyflow_id" // In case a saved card is selected.
|
|
420
|
-
// payment_method: "" // Payment method if not using the card form
|
|
421
|
-
});
|
|
422
|
-
console.log("Payment successful:", response);
|
|
423
|
-
alert("Payment successful");
|
|
424
|
-
} catch (error) {
|
|
425
|
-
console.error("Payment failed:", error);
|
|
426
|
-
alert("Payment failed");
|
|
427
|
-
} finally {
|
|
428
|
-
this.loading = false;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
## Request secure token
|
|
435
|
-
|
|
436
|
-
```typescript
|
|
437
|
-
|
|
438
|
-
const jsonResponse = await liteCheckout.getSecureToken(
|
|
439
|
-
secretApiKey //You can take this from you Tonder Dashboard
|
|
440
|
-
);
|
|
441
|
-
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
## Return secure token
|
|
445
|
-
|
|
446
|
-
```typescript
|
|
447
|
-
{
|
|
448
|
-
access: string;
|
|
449
|
-
}
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
## Deprecated Fields
|
|
453
|
-
|
|
454
|
-
The following fields have been deprecated and should no longer be used. Consider using the recommended alternatives:
|
|
455
|
-
|
|
456
|
-
## Register customer card
|
|
457
|
-
### `apiKeyTonder` Property
|
|
458
|
-
|
|
459
|
-
- **Deprecated Reason:** The `apiKeyTonder` property in the constructor and `IInlineLiteCheckoutOptions` interface is no longer required.
|
|
460
|
-
- **Alternative:** Use the `apiKey` field.
|
|
461
|
-
|
|
462
|
-
### `baseUrlTonder` Property
|
|
463
|
-
|
|
464
|
-
- **Deprecated Reason:** The `baseUrlTonder` property in the constructor and `IInlineLiteCheckoutOptions` interface is no longer required.
|
|
465
|
-
- **Alternative:** Use the `mode` field with `stage` | `development` | `sandbox` | `production` options.
|
|
466
|
-
|
|
467
|
-
### `signal` Property
|
|
468
|
-
|
|
469
|
-
- **Deprecated Reason:** The `signal` property in the constructor and `IInlineLiteCheckoutOptions` interface is no longer required.
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
## Deprecated Functions
|
|
473
|
-
|
|
474
|
-
The following functions have been deprecated and should no longer be used. Consider using the recommended alternatives:
|
|
475
|
-
|
|
476
|
-
### `customerRegister`
|
|
477
|
-
|
|
478
|
-
- **Deprecated Reason:** This function is no longer necessary as registration is now automatically handled during payment processing or when using card management methods.
|
|
479
|
-
|
|
480
|
-
### `createOrder` and `createPayment`
|
|
481
|
-
|
|
482
|
-
- **Deprecated Reason:** These functions have been replaced by the `payment` function, which now automatically handles order creation and payment processing.
|
|
483
|
-
- **Alternative:** Use the `payment` function.
|
|
484
|
-
|
|
485
|
-
### `startCheckoutRouter` and `startCheckoutRouterFull`
|
|
486
|
-
|
|
487
|
-
- **Deprecated Reason:** These functions have been replaced by the `payment` function.
|
|
488
|
-
- **Alternative:** Use the `payment` function.
|
|
489
|
-
|
|
490
|
-
### `registerCustomerCard`
|
|
491
|
-
|
|
492
|
-
- **Deprecated Reason:** This function has been renamed to `saveCustomerCard` to better align with its purpose. The method's usage has also been updated.
|
|
493
|
-
- **Alternative:** Use the `saveCustomerCard` method and update your implementation to reflect the changes.
|
|
494
|
-
|
|
495
|
-
### `deleteCustomerCard`
|
|
496
|
-
|
|
497
|
-
- **Deprecated Reason:** This function has been renamed to `removeCustomerCard` to better align with its purpose. The method's usage has also been updated.
|
|
498
|
-
- **Alternative:** Use the `removeCustomerCard` method and update your implementation to reflect the changes.
|
|
499
|
-
|
|
500
|
-
### `getActiveAPMs`
|
|
501
|
-
|
|
502
|
-
- **Deprecated Reason:** This function has been renamed to `getCustomerPaymentMethods` to better align with its purpose. The method's usage has also been updated.
|
|
503
|
-
- **Alternative:** Use the `getCustomerPaymentMethods` method and update your implementation to reflect the changes.
|
|
504
|
-
|
|
505
|
-
### `getSkyflowTokens`
|
|
506
|
-
|
|
507
|
-
- **Deprecated Reason:** Card registration and checkout are now automatically handled during the payment process or through card management methods, making this method unnecessary.
|
|
508
|
-
|
|
509
|
-
### `getOpenpayDeviceSessionID`
|
|
510
|
-
|
|
511
|
-
- **Deprecated Reason:** It is no longer necessary to use this method is now automatically handled during the payment process.
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
## Notes
|
|
515
|
-
|
|
516
|
-
### General
|
|
517
|
-
|
|
518
|
-
- Replace `apiKey`, `mode`, `returnUrl` with your actual values.
|
|
519
|
-
- Remember to use the `configureCheckout` function after creating an instance of `LiteCheckout`. This ensures that functions such as payment processing, saving cards, deleting cards, and others work correctly.
|
|
520
|
-
|
|
521
|
-
### Script Dependencies
|
|
522
|
-
|
|
523
|
-
For all implementations, ensure you include the necessary scripts:
|
|
524
|
-
|
|
525
|
-
```html
|
|
526
|
-
<script src="https://openpay.s3.amazonaws.com/openpay.v1.min.js"></script>
|
|
527
|
-
<script src="https://openpay.s3.amazonaws.com/openpay-data.v1.min.js"></script>
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
## License
|
|
531
|
-
|
|
532
|
-
[MIT](https://choosealicense.com/licenses/mit/)
|
|
1
|
+
# Tonder SDK
|
|
2
|
+
|
|
3
|
+
Tonder SDK helps to integrate the services Tonder offers in your own mobile app
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Table of Contents
|
|
7
|
+
|
|
8
|
+
1. [Installation](#installation)
|
|
9
|
+
2. [Usage](#usage)
|
|
10
|
+
3. [Configuration Options](#configuration-options)
|
|
11
|
+
4. [Mobile Settings](#mobile-settings)
|
|
12
|
+
5. [Payment Data Structure](#payment-data-structure)
|
|
13
|
+
6. [Field Validation Functions](#field-validation-functions)
|
|
14
|
+
7. [API Reference](#api-reference)
|
|
15
|
+
8. [Examples](#examples)
|
|
16
|
+
9. [Deprecated Fields](#deprecated-fields)
|
|
17
|
+
10. [Deprecated Functions](#deprecated-functions)
|
|
18
|
+
11. [License](#license)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
You can install using NPM
|
|
24
|
+
```bash
|
|
25
|
+
npm i @tonder.io/ionic-lite-sdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Add dependencies to the root of the app (index.html)
|
|
29
|
+
```html
|
|
30
|
+
<script src=https://openpay.s3.amazonaws.com/openpay.v1.min.js></script>
|
|
31
|
+
<script src=https://openpay.s3.amazonaws.com/openpay-data.v1.min.js></script>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
LiteCheckout allows you to build a custom checkout interface using Tonder's core functionality
|
|
36
|
+
### Import LiteCheckout class
|
|
37
|
+
```javascript
|
|
38
|
+
import { LiteCheckout } from "@tonder.io/ionic-lite-sdk"
|
|
39
|
+
```
|
|
40
|
+
### Create instance
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
const liteCheckout = new LiteCheckout({
|
|
44
|
+
signal,
|
|
45
|
+
baseUrlTonder,
|
|
46
|
+
apiKeyTonder
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// The configureCheckout function allows you to set initial information,
|
|
50
|
+
// such as the customer's email, which is used to retrieve a list of saved cards, save new card, etc.
|
|
51
|
+
inlineCheckout.configureCheckout({ customer: { email: "example@email.com" } });
|
|
52
|
+
|
|
53
|
+
// Initialize the checkout
|
|
54
|
+
await liteCheckout.injectCheckout();
|
|
55
|
+
|
|
56
|
+
// To verify a 3ds transaction you can use the following method
|
|
57
|
+
// It should be called after the injectCheckout method
|
|
58
|
+
// The response status will be one of the following
|
|
59
|
+
// ['Declined', 'Cancelled', 'Failed', 'Success', 'Pending', 'Authorized']
|
|
60
|
+
|
|
61
|
+
inlineCheckout.verify3dsTransaction().then(response => {
|
|
62
|
+
console.log('Verify 3ds response', response)
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
// Retrieve customer's saved cards
|
|
68
|
+
const cards = await liteCheckout.getCustomerCards();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
// Save a new card
|
|
73
|
+
const newCard = await liteCheckout.saveCustomerCard(cardData);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
// Remove a saved card
|
|
78
|
+
await liteCheckout.removeCustomerCard(cardId);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
// Get available payment methods
|
|
83
|
+
const paymentMethods = await liteCheckout.getCustomerPaymentMethods();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
// Process a payment
|
|
88
|
+
const paymentResponse = await liteCheckout.payment(paymentData);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Configuration Options
|
|
92
|
+
|
|
93
|
+
| Property | Type | Description |
|
|
94
|
+
|:---------:|:--------:|:--------------------------------------------------------------------------------------------:|
|
|
95
|
+
| mode | string | Environment mode. Options: 'stage', 'production', 'sandbox', 'development'. Default: 'stage' |
|
|
96
|
+
| apiKey | string | Your API key from the Tonder Dashboard |
|
|
97
|
+
| returnrl | string | URL where the checkout form is mounted (used for 3DS) |
|
|
98
|
+
| callBack | function | Callback function to be invoked after the payment process ends successfully. |
|
|
99
|
+
|
|
100
|
+
## Mobile settings
|
|
101
|
+
|
|
102
|
+
<font size="3">If you are deploying to Android, edit your AndroidManifest.xml file to add the Internet permission.</font>
|
|
103
|
+
|
|
104
|
+
```xml
|
|
105
|
+
<!-- Required to fetch data from the internet. -->
|
|
106
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
<font size="3">Likewise, if you are deploying to macOS, edit your macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements files to include the network client entitlement.</font>
|
|
110
|
+
|
|
111
|
+
```xml
|
|
112
|
+
<!-- Required to fetch data from the internet. -->
|
|
113
|
+
<key>com.apple.security.network.client</key>
|
|
114
|
+
<true>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Payment Data Structure
|
|
118
|
+
|
|
119
|
+
When calling the `payment` method, use the following data structure:
|
|
120
|
+
|
|
121
|
+
### Field Descriptions
|
|
122
|
+
|
|
123
|
+
- **customer**: Object containing the customer's personal information to be registered in the transaction.
|
|
124
|
+
|
|
125
|
+
- **cart**: Object containing the total amount and an array of items to be registered in the Tonder order.
|
|
126
|
+
|
|
127
|
+
- **total**: The total amount of the transaction.
|
|
128
|
+
- **items**: An array of objects, each representing a product or service in the order.
|
|
129
|
+
- name: name of the product
|
|
130
|
+
- price_unit: valid float string with the price of the product
|
|
131
|
+
- quantity: valid integer string with the quantity of this product
|
|
132
|
+
|
|
133
|
+
- **currency**: String representing the currency code for the transaction (e.g., "MXN" for Mexican Peso).
|
|
134
|
+
|
|
135
|
+
- **metadata**: Object for including any additional information about the transaction. This can be used for internal references or tracking.
|
|
136
|
+
|
|
137
|
+
- **card**: (for LiteCheckout) Object containing card information. This is used differently depending on whether it's a new card or a saved card:
|
|
138
|
+
|
|
139
|
+
- For a new card: Include `card_number`, `cvv`, `expiration_month`, `expiration_year`, and `cardholder_name`.
|
|
140
|
+
- For a saved card: Include only the `skyflow_id` of the saved card.
|
|
141
|
+
- This is only used when not paying with a payment_method.
|
|
142
|
+
|
|
143
|
+
- **payment_method**: (for LiteCheckout) String indicating the alternative payment method to be used (e.g., "Spei"). This is only used when not paying with a card.
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
const paymentData = {
|
|
147
|
+
customer: {
|
|
148
|
+
firstName: "John",
|
|
149
|
+
lastName: "Doe",
|
|
150
|
+
country: "USA",
|
|
151
|
+
address: "123 Main St",
|
|
152
|
+
city: "Anytown",
|
|
153
|
+
state: "CA",
|
|
154
|
+
postCode: "12345",
|
|
155
|
+
email: "john.doe@example.com",
|
|
156
|
+
phone: "1234567890",
|
|
157
|
+
},
|
|
158
|
+
cart: {
|
|
159
|
+
total: "100.00",
|
|
160
|
+
items: [
|
|
161
|
+
{
|
|
162
|
+
description: "Product description",
|
|
163
|
+
quantity: 1,
|
|
164
|
+
price_unit: "100.00",
|
|
165
|
+
discount: "0.00",
|
|
166
|
+
taxes: "0.00",
|
|
167
|
+
product_reference: "PROD123",
|
|
168
|
+
name: "Product Name",
|
|
169
|
+
amount_total: "100.00",
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
currency: "MXN",
|
|
174
|
+
metadata: {
|
|
175
|
+
order_id: "ORDER123",
|
|
176
|
+
},
|
|
177
|
+
// For a new card:
|
|
178
|
+
card: {
|
|
179
|
+
card_number: "4111111111111111",
|
|
180
|
+
cvv: "123",
|
|
181
|
+
expiration_month: "12",
|
|
182
|
+
expiration_year: "25",
|
|
183
|
+
cardholder_name: "John Doe",
|
|
184
|
+
},
|
|
185
|
+
// card: "skyflow_id" // for a selected saved card.
|
|
186
|
+
// payment_method: "Spei", // For the selected payment method.
|
|
187
|
+
};
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Field Validation Functions
|
|
191
|
+
|
|
192
|
+
For LiteCheckout implementations, the SDK provides validation functions to ensure the integrity of card data before submitting:
|
|
193
|
+
|
|
194
|
+
- `validateCardNumber(cardNumber)`: Validates the card number using the Luhn algorithm.
|
|
195
|
+
- `validateCardholderName(name)`: Checks if the cardholder name is valid.
|
|
196
|
+
- `validateCVV(cvv)`: Ensures the CVV is in the correct format.
|
|
197
|
+
- `validateExpirationDate(expirationDate)`: Validates the expiration date in MM/YY format.
|
|
198
|
+
- `validateExpirationMonth(month)`: Checks if the expiration month is valid.
|
|
199
|
+
- `validateExpirationYear(year)`: Validates the expiration year.
|
|
200
|
+
|
|
201
|
+
Example usage:
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
import {
|
|
205
|
+
validateCardNumber,
|
|
206
|
+
validateCardholderName,
|
|
207
|
+
validateCVV,
|
|
208
|
+
validateExpirationDate,
|
|
209
|
+
} from "@tonder.io/ionic-lite-sdk";
|
|
210
|
+
|
|
211
|
+
const cardNumber = "4111111111111111";
|
|
212
|
+
const cardholderName = "John Doe";
|
|
213
|
+
const cvv = "123";
|
|
214
|
+
const expirationDate = "12/25";
|
|
215
|
+
|
|
216
|
+
if (
|
|
217
|
+
validateCardNumber(cardNumber) &&
|
|
218
|
+
validateCardholderName(cardholderName) &&
|
|
219
|
+
validateCVV(cvv) &&
|
|
220
|
+
validateExpirationDate(expirationDate)
|
|
221
|
+
) {
|
|
222
|
+
// Proceed with payment
|
|
223
|
+
} else {
|
|
224
|
+
// Show error message
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
## API Reference
|
|
230
|
+
|
|
231
|
+
### LiteCheckout Methods
|
|
232
|
+
|
|
233
|
+
- `configureCheckout(data)`: Set initial checkout data
|
|
234
|
+
- `injectCheckout()`: Initialize the checkout
|
|
235
|
+
- `getCustomerCards()`: Retrieve saved cards
|
|
236
|
+
- `saveCustomerCard(cardData)`: Save a new card
|
|
237
|
+
- `removeCustomerCard(cardId)`: Remove a saved card
|
|
238
|
+
- `getCustomerPaymentMethods()`: Get available payment methods
|
|
239
|
+
- `payment(data)`: Process a payment
|
|
240
|
+
- `verify3dsTransaction()`: Verify a 3DS transaction
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
## Examples
|
|
244
|
+
|
|
245
|
+
Here are examples of how to implement Tonder Lite SDK:
|
|
246
|
+
|
|
247
|
+
### Angular
|
|
248
|
+
|
|
249
|
+
For Angular, we recommend using a service to manage the Tonder instance:
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
// tonder.service.ts
|
|
253
|
+
import { Injectable } from "@angular/core";
|
|
254
|
+
import { LiteCheckout } from "@tonder.io/ionic-lite-sdk";
|
|
255
|
+
import {ILiteCheckout} from "@tonder.io/ionic-lite-sdk/dist/types/liteInlineCheckout";
|
|
256
|
+
|
|
257
|
+
@Injectable({
|
|
258
|
+
providedIn: "root",
|
|
259
|
+
})
|
|
260
|
+
export class TonderService {
|
|
261
|
+
private liteCheckout!: ILiteCheckout;
|
|
262
|
+
|
|
263
|
+
constructor(@Inject(Object) private sdkParameters: IInlineLiteCheckoutOptions) {
|
|
264
|
+
this.initializeInlineCheckout();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
private initializeInlineCheckout(): void {
|
|
268
|
+
this.liteCheckout = new LiteCheckout({ ...this.sdkParameters });
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
configureCheckout(customerData: IConfigureCheckout): void {
|
|
272
|
+
return this.liteCheckout.configureCheckout({ ...customerData });
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async injectCheckout(): Promise<void> {
|
|
276
|
+
return await this.liteCheckout.injectCheckout();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
verify3dsTransaction(): Promise<ITransaction | IStartCheckoutResponse | void> {
|
|
280
|
+
return this.liteCheckout.verify3dsTransaction();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
payment(
|
|
284
|
+
checkoutData: IProcessPaymentRequest,
|
|
285
|
+
): Promise<IStartCheckoutResponse> {
|
|
286
|
+
return this.inlineCheckout.payment(checkoutData);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Add more functions, for example for lite sdk: get payment methods
|
|
290
|
+
|
|
291
|
+
// getCustomerPaymentMethods(): Promise<IPaymentMethod[]> {
|
|
292
|
+
// return this.liteCheckout.getCustomerPaymentMethods();
|
|
293
|
+
// }
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// checkout.component.ts
|
|
297
|
+
import { Component, OnInit, OnDestroy } from "@angular/core";
|
|
298
|
+
import { TonderService } from "./tonder.service";
|
|
299
|
+
|
|
300
|
+
@Component({
|
|
301
|
+
selector: "app-tonder-checkout",
|
|
302
|
+
template: `
|
|
303
|
+
<div id="container">
|
|
304
|
+
<form [formGroup]="paymentForm">
|
|
305
|
+
<div class="lite-container-tonder">
|
|
306
|
+
<div id="id-name" class="empty-div">
|
|
307
|
+
<label for="name">Namess: </label>
|
|
308
|
+
<input id="name" type="text" formControlName="name">
|
|
309
|
+
</div>
|
|
310
|
+
<div id="id-cardNumber" class="empty-div">
|
|
311
|
+
<label for="cardNumber">Card number: </label>
|
|
312
|
+
<input id="cardNumber" type="text" formControlName="cardNumber">
|
|
313
|
+
</div>
|
|
314
|
+
<div class="collect-row">
|
|
315
|
+
<div class="empty-div">
|
|
316
|
+
<label for="month">Month: </label>
|
|
317
|
+
<input id="month" type="text" formControlName="month">
|
|
318
|
+
</div>
|
|
319
|
+
<div class="expiration-year">
|
|
320
|
+
<label for="expirationYear">Year: </label>
|
|
321
|
+
<input id="expirationYear" type="text" formControlName="expirationYear">
|
|
322
|
+
</div>
|
|
323
|
+
<div class="empty-div">
|
|
324
|
+
<label for="cvv">CVV: </label>
|
|
325
|
+
<input id="cvv" type="text" formControlName="cvv">
|
|
326
|
+
</div>
|
|
327
|
+
</div>
|
|
328
|
+
<div id="msgError">{{ errorMessage }}</div>
|
|
329
|
+
<div id="msgNotification"></div>
|
|
330
|
+
<div class="container-pay-button">
|
|
331
|
+
<button class="lite-pay-button" (click)="onPayment($event)">Pay</button>
|
|
332
|
+
</div>
|
|
333
|
+
</div>
|
|
334
|
+
|
|
335
|
+
</form>
|
|
336
|
+
</div>
|
|
337
|
+
`,
|
|
338
|
+
providers: [
|
|
339
|
+
{
|
|
340
|
+
provide: TonderInlineService,
|
|
341
|
+
// Initialization of the Tonder Lite SDK.
|
|
342
|
+
// Note: Replace these credentials with your own in development/production.
|
|
343
|
+
useFactory: () =>
|
|
344
|
+
new TonderInlineService({
|
|
345
|
+
apiKey: "11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27",
|
|
346
|
+
returnUrl: "http://localhost:8100/tabs/tab5",
|
|
347
|
+
mode: "stage",
|
|
348
|
+
}),
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
})
|
|
352
|
+
export class TonderCheckoutComponent implements OnInit, OnDestroy {
|
|
353
|
+
loading = false;
|
|
354
|
+
checkoutData: IProcessPaymentRequest;
|
|
355
|
+
paymentForm = new FormGroup({
|
|
356
|
+
name: new FormControl('Pedro Paramo'),
|
|
357
|
+
cardNumber: new FormControl('4242424242424242'),
|
|
358
|
+
month: new FormControl('12'),
|
|
359
|
+
expirationYear: new FormControl('28'),
|
|
360
|
+
cvv: new FormControl('123')
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
constructor(private tonderService: TonderService) {
|
|
364
|
+
this.checkoutData = {
|
|
365
|
+
customer: {
|
|
366
|
+
firstName: "Jhon",
|
|
367
|
+
lastName: "Doe",
|
|
368
|
+
email: "john.c.calhoun@examplepetstore.com",
|
|
369
|
+
phone: "+58452258525"
|
|
370
|
+
},
|
|
371
|
+
cart: {
|
|
372
|
+
total: 25,
|
|
373
|
+
items: [
|
|
374
|
+
{
|
|
375
|
+
description: "Test product description",
|
|
376
|
+
quantity: 1,
|
|
377
|
+
price_unit: 25,
|
|
378
|
+
discount: 1,
|
|
379
|
+
taxes: 12,
|
|
380
|
+
product_reference: 89456123,
|
|
381
|
+
name: "Test product",
|
|
382
|
+
amount_total: 25
|
|
383
|
+
}
|
|
384
|
+
]
|
|
385
|
+
},
|
|
386
|
+
metadata: {},
|
|
387
|
+
currency: "MXN"
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
ngOnInit() {
|
|
392
|
+
this.initCheckout();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async initCheckout() {
|
|
396
|
+
this.tonderService.configureCheckout({
|
|
397
|
+
customer: { email: "example@email.com" },
|
|
398
|
+
});
|
|
399
|
+
await this.tonderService.injectCheckout();
|
|
400
|
+
this.tonderService.verify3dsTransaction().then((response) => {
|
|
401
|
+
console.log("Verify 3ds response", response);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// Calls more functions to get payment methods, saved cards, etc.
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async pay() {
|
|
408
|
+
this.loading = true;
|
|
409
|
+
try {
|
|
410
|
+
const response = await this.tonderService.payment({
|
|
411
|
+
...this.checkoutData,
|
|
412
|
+
card: { // Card details, if not using a payment method.
|
|
413
|
+
card_number: this.paymentForm.value.cardNumber || "",
|
|
414
|
+
cvv: this.paymentForm.value.cvv || "",
|
|
415
|
+
expiration_month: this.paymentForm.value.month || "",
|
|
416
|
+
expiration_year: this.paymentForm.value.expirationYear || "",
|
|
417
|
+
cardholder_name: this.paymentForm.value.name || ""
|
|
418
|
+
},
|
|
419
|
+
// card: "skyflow_id" // In case a saved card is selected.
|
|
420
|
+
// payment_method: "" // Payment method if not using the card form
|
|
421
|
+
});
|
|
422
|
+
console.log("Payment successful:", response);
|
|
423
|
+
alert("Payment successful");
|
|
424
|
+
} catch (error) {
|
|
425
|
+
console.error("Payment failed:", error);
|
|
426
|
+
alert("Payment failed");
|
|
427
|
+
} finally {
|
|
428
|
+
this.loading = false;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## Request secure token
|
|
435
|
+
|
|
436
|
+
```typescript
|
|
437
|
+
|
|
438
|
+
const jsonResponse = await liteCheckout.getSecureToken(
|
|
439
|
+
secretApiKey //You can take this from you Tonder Dashboard
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
## Return secure token
|
|
445
|
+
|
|
446
|
+
```typescript
|
|
447
|
+
{
|
|
448
|
+
access: string;
|
|
449
|
+
}
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## Deprecated Fields
|
|
453
|
+
|
|
454
|
+
The following fields have been deprecated and should no longer be used. Consider using the recommended alternatives:
|
|
455
|
+
|
|
456
|
+
## Register customer card
|
|
457
|
+
### `apiKeyTonder` Property
|
|
458
|
+
|
|
459
|
+
- **Deprecated Reason:** The `apiKeyTonder` property in the constructor and `IInlineLiteCheckoutOptions` interface is no longer required.
|
|
460
|
+
- **Alternative:** Use the `apiKey` field.
|
|
461
|
+
|
|
462
|
+
### `baseUrlTonder` Property
|
|
463
|
+
|
|
464
|
+
- **Deprecated Reason:** The `baseUrlTonder` property in the constructor and `IInlineLiteCheckoutOptions` interface is no longer required.
|
|
465
|
+
- **Alternative:** Use the `mode` field with `stage` | `development` | `sandbox` | `production` options.
|
|
466
|
+
|
|
467
|
+
### `signal` Property
|
|
468
|
+
|
|
469
|
+
- **Deprecated Reason:** The `signal` property in the constructor and `IInlineLiteCheckoutOptions` interface is no longer required.
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
## Deprecated Functions
|
|
473
|
+
|
|
474
|
+
The following functions have been deprecated and should no longer be used. Consider using the recommended alternatives:
|
|
475
|
+
|
|
476
|
+
### `customerRegister`
|
|
477
|
+
|
|
478
|
+
- **Deprecated Reason:** This function is no longer necessary as registration is now automatically handled during payment processing or when using card management methods.
|
|
479
|
+
|
|
480
|
+
### `createOrder` and `createPayment`
|
|
481
|
+
|
|
482
|
+
- **Deprecated Reason:** These functions have been replaced by the `payment` function, which now automatically handles order creation and payment processing.
|
|
483
|
+
- **Alternative:** Use the `payment` function.
|
|
484
|
+
|
|
485
|
+
### `startCheckoutRouter` and `startCheckoutRouterFull`
|
|
486
|
+
|
|
487
|
+
- **Deprecated Reason:** These functions have been replaced by the `payment` function.
|
|
488
|
+
- **Alternative:** Use the `payment` function.
|
|
489
|
+
|
|
490
|
+
### `registerCustomerCard`
|
|
491
|
+
|
|
492
|
+
- **Deprecated Reason:** This function has been renamed to `saveCustomerCard` to better align with its purpose. The method's usage has also been updated.
|
|
493
|
+
- **Alternative:** Use the `saveCustomerCard` method and update your implementation to reflect the changes.
|
|
494
|
+
|
|
495
|
+
### `deleteCustomerCard`
|
|
496
|
+
|
|
497
|
+
- **Deprecated Reason:** This function has been renamed to `removeCustomerCard` to better align with its purpose. The method's usage has also been updated.
|
|
498
|
+
- **Alternative:** Use the `removeCustomerCard` method and update your implementation to reflect the changes.
|
|
499
|
+
|
|
500
|
+
### `getActiveAPMs`
|
|
501
|
+
|
|
502
|
+
- **Deprecated Reason:** This function has been renamed to `getCustomerPaymentMethods` to better align with its purpose. The method's usage has also been updated.
|
|
503
|
+
- **Alternative:** Use the `getCustomerPaymentMethods` method and update your implementation to reflect the changes.
|
|
504
|
+
|
|
505
|
+
### `getSkyflowTokens`
|
|
506
|
+
|
|
507
|
+
- **Deprecated Reason:** Card registration and checkout are now automatically handled during the payment process or through card management methods, making this method unnecessary.
|
|
508
|
+
|
|
509
|
+
### `getOpenpayDeviceSessionID`
|
|
510
|
+
|
|
511
|
+
- **Deprecated Reason:** It is no longer necessary to use this method is now automatically handled during the payment process.
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
## Notes
|
|
515
|
+
|
|
516
|
+
### General
|
|
517
|
+
|
|
518
|
+
- Replace `apiKey`, `mode`, `returnUrl` with your actual values.
|
|
519
|
+
- Remember to use the `configureCheckout` function after creating an instance of `LiteCheckout`. This ensures that functions such as payment processing, saving cards, deleting cards, and others work correctly.
|
|
520
|
+
|
|
521
|
+
### Script Dependencies
|
|
522
|
+
|
|
523
|
+
For all implementations, ensure you include the necessary scripts:
|
|
524
|
+
|
|
525
|
+
```html
|
|
526
|
+
<script src="https://openpay.s3.amazonaws.com/openpay.v1.min.js"></script>
|
|
527
|
+
<script src="https://openpay.s3.amazonaws.com/openpay-data.v1.min.js"></script>
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
## License
|
|
531
|
+
|
|
532
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|