Skip to content

Commit f153b07

Browse files
author
David Hernandez
committed
Merge branch 'develop'
2 parents a3c76ac + 0a6c949 commit f153b07

File tree

17 files changed

+530
-252
lines changed

17 files changed

+530
-252
lines changed

README.md

Lines changed: 164 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ The SDK supports three integration types:
6262
- Card saving
6363
- Card listing
6464
- Card deletion
65+
- Card summary
6566
- Payment methods retrieval
6667

6768
- `SDKType.ENROLLMENT`: Card saving functionality
6869
- Card tokenization
6970
- Card validation
71+
- Card summary
7072
- Secure storage
7173
- Input field event handling (onChange, onFocus, onBlur)
7274

@@ -214,7 +216,7 @@ export default function FullPaymentScreen() {
214216
};
215217

216218
const callbackFinish = async (response) => {
217-
console.log('FINISH PAYMENT ===== ', response);
219+
console.log('Callback finish payment', response);
218220

219221
// Reset the state and regenerate the SDK to use it again.
220222
reset();
@@ -269,7 +271,7 @@ export default function LitePaymentScreen() {
269271
}
270272
};
271273

272-
useEffect(() => {
274+
useEffect(() => {
273275
initializePayment();
274276
}, []);
275277

@@ -340,7 +342,9 @@ import {
340342
TonderEnrollment,
341343
useTonder,
342344
SDKType,
343-
ICustomer
345+
ICustomer,
346+
type IBaseResponse,
347+
type ISaveCardResponse,
344348
} from '@tonder.io/rn-sdk';
345349

346350
export default function EnrollmentScreen() {
@@ -370,13 +374,34 @@ export default function EnrollmentScreen() {
370374
}
371375
};
372376

373-
const handleSaveFinish = async (response) => {
377+
const handleSaveFinish = async (response: IBaseResponse<ISaveCardResponse>) => {
378+
console.log('Callback finish save card', response);
379+
380+
if (response.error) {
381+
// Manage the error
382+
Alert.alert('Error', 'Failed to save card. Please try again.');
383+
console.log('Save Card ERROR', response.error);
384+
return;
385+
}
374386
console.log('Card saved successfully:', response);
387+
388+
await handleGetSummaryCard(response.response.skyflow_id);
375389
// Reset the state and regenerate the SDK to use it again
376390
reset();
377391
await initializeEnrollment();
378392
};
379393

394+
const handleGetSummaryCard = async (id: string) => {
395+
const { response, error } = await getCardSummary(id);
396+
if (error) {
397+
//Manage error
398+
Alert.alert('Error', 'Failed to get summary card');
399+
console.error('Error get summary card: ', error);
400+
return;
401+
}
402+
console.log('Response get summary: ', response);
403+
};
404+
380405
return (
381406
<SafeAreaView>
382407
<TonderEnrollment />
@@ -385,6 +410,84 @@ export default function EnrollmentScreen() {
385410
}
386411
```
387412

413+
#### Example with custom button
414+
```tsx
415+
import {
416+
TonderEnrollment,
417+
useTonder,
418+
SDKType,
419+
ICustomer
420+
} from '@tonder.io/rn-sdk';
421+
422+
export default function EnrollmentScreen() {
423+
const { create, reset, saveCustomerCard, getCardSummary } = useTonder<SDKType.ENROLLMENT>();
424+
425+
const customerData: ICustomer = {
426+
email: 'test@example.com',
427+
firstName: 'John',
428+
lastName: 'Doe'
429+
};
430+
431+
useEffect(() => {
432+
initializeEnrollment();
433+
}, []);
434+
435+
const initializeEnrollment = async () => {
436+
const { error } = await create({
437+
secureToken: 'your-secure-token',
438+
customer: customerData,
439+
customization: {
440+
saveButton: {
441+
show: false, // hidde default button
442+
},
443+
},
444+
});
445+
446+
if (error) {
447+
console.error('Enrollment initialization error:', error);
448+
}
449+
};
450+
451+
const handleSaveCard = async () => {
452+
const { response, error } = await saveCustomerCard();
453+
if (error) {
454+
//Manage error
455+
console.error('Error saving card: ', error);
456+
return;
457+
}
458+
console.log('Response save card: ', response);
459+
460+
// Get card summary using the skyflow_id from the save response
461+
await handleGetCardSummary(response.skyflow_id);
462+
// Reset the state and regenerate the SDK to use it again
463+
reset();
464+
await initializeEnrollment();
465+
};
466+
467+
const handleGetCardSummary = async (skyflowId: string) => {
468+
const { response, error } = await getCardSummary(skyflowId);
469+
if (error) {
470+
console.error('Error getting card summary:', error);
471+
return;
472+
}
473+
console.log('Card summary:', response);
474+
// Response contains: user_id and card details
475+
};
476+
477+
return (
478+
<SafeAreaView>
479+
<TonderEnrollment />
480+
{/*Custom button*/}
481+
<TouchableOpacity
482+
onPress={handleSaveCard}
483+
>
484+
<Text>Guardar</Text>
485+
</TouchableOpacity>
486+
</SafeAreaView>
487+
);
488+
}
489+
```
490+
388491
### Card Enrollment Lite Integration
389492

390493
For saving cards with individual components, before create the mobile SDK, your checkout page should:
@@ -420,7 +523,7 @@ import {
420523
} from '@tonder.io/rn-sdk';
421524

422525
export default function EnrollmentLiteScreen() {
423-
const { create, saveCustomerCard, reset } = useTonder<SDKType.ENROLLMENT>();
526+
const { create, saveCustomerCard, reset, getCardSummary } = useTonder<SDKType.ENROLLMENT>();
424527

425528
const customerData: ICustomer = {
426529
email: 'test@example.com',
@@ -451,7 +554,8 @@ export default function EnrollmentLiteScreen() {
451554
return;
452555
}
453556
console.log('Card saved successfully:', response);
454-
557+
// GET summary card
558+
await handleGetSummaryCard(response.skyflow_id);
455559
// Reset and reinitialize for next use
456560
reset();
457561
await initializeEnrollment();
@@ -460,6 +564,17 @@ export default function EnrollmentLiteScreen() {
460564
}
461565
};
462566

567+
const handleGetSummaryCard = async (id: string) => {
568+
const { response, error } = await getCardSummary(id);
569+
if (error) {
570+
//Manage error
571+
Alert.alert('Error', 'Failed to get summary card');
572+
console.error('Error get summary card: ', error);
573+
return;
574+
}
575+
console.log('Response get summary: ', response);
576+
};
577+
463578
return (
464579
<SafeAreaView>
465580
<CardHolderInput />
@@ -708,7 +823,6 @@ interface IBaseProcessPaymentRequest {
708823
amount_total: number;
709824
description: string;
710825
price_unit: number;
711-
product_reference: string;
712826
quantity: number;
713827
discount?: number;
714828
taxes?: number;
@@ -738,7 +852,6 @@ interface IProcessPaymentRequest {
738852
amount_total: number;
739853
description: string;
740854
price_unit: number;
741-
product_reference: string;
742855
quantity: number;
743856
discount?: number;
744857
taxes?: number;
@@ -1030,6 +1143,7 @@ The LITE integration provides full control over the payment flow with individual
10301143
- payment: Processes a payment using the configured payment data.
10311144
- saveCustomerCard: Tokenizes and saves the current card information.
10321145
- getCustomerCards: Retrieves the list of saved cards for the customer.
1146+
- getCardSummary: Retrieves detailed information about a saved card using its Skyflow ID.
10331147
- getPaymentMethods: Retrieves available payment methods.
10341148
- removeCustomerCard: Deletes a saved card.
10351149

@@ -1038,7 +1152,7 @@ The LITE integration provides full control over the payment flow with individual
10381152
> **Note:** For card methods, it is necessary to obtain and use your secure token when calling the create function.
10391153
10401154
```typescript
1041-
const { create, payment, saveCustomerCard, getCustomerCards,
1155+
const { create, payment, saveCustomerCard, getCustomerCards, getCardSummary,
10421156
removeCustomerCard, getPaymentMethods, reset } = useTonder<SDKType.LITE>();
10431157
```
10441158

@@ -1047,67 +1161,59 @@ const { create, payment, saveCustomerCard, getCustomerCards,
10471161
The ENROLLMENT integration provides methods for handling full enrollment with built-in UI components.
10481162

10491163
- saveCustomerCard: Tokenizes and saves the current card information.
1164+
- getCardSummary: Retrieves detailed information about a saved card using its Skyflow ID.
10501165

1051-
> **Note:** The saveCustomerCard It is only necessary when you want to control the enrollment button on your own.
1166+
<details>
1167+
<summary>Input Interface</summary>
10521168

1053-
> **Note:** For card methods, it is necessary to obtain and use your secure token when calling the create function.
1169+
| Parameter | Type | Description |
1170+
|-----------|--------|------------------------------------------------|
1171+
| skyflowId | string | The Skyflow ID of the card to retrieve |
10541172

1055-
```typescript
1056-
const { create, saveCustomerCard, reset } = useTonder<SDKType.LITE>();
1057-
```
1058-
#### Example with custom button
1059-
```tsx
1173+
</details>
10601174

1061-
export default function EnrollmentButtonScreen() {
1062-
const { create, saveCustomerCard } = useTonder<SDKType.ENROLLMENT>();
1175+
<details>
1176+
<summary>Response Interface</summary>
10631177

1064-
useEffect(() => {
1065-
createSDK()
1066-
}, [])
1178+
**IBaseResponse<ICardsSummaryResponse>**
10671179

1068-
const createSDK = async (token) => {
1069-
const { error } = await create({
1070-
secureToken: token,
1071-
customer: { ...customerData },
1072-
customization: {
1073-
saveButton: {
1074-
show: false, // hidde default button
1075-
},
1076-
},
1077-
});
1180+
The response follows the base response pattern:
10781181

1079-
if (error) {
1080-
// Manage error
1081-
console.error('Error creating SDK', error);
1082-
}
1083-
};
1182+
```typescript
1183+
export type IBaseResponse<T> =
1184+
| { response: ICardsSummaryResponse; error?: TonderError }
1185+
| { response?: never; error: TonderError };
1186+
```
10841187

1085-
const handleSaveCard = async () => {
1086-
const { response, error } = await saveCustomerCard();
1087-
if (error) {
1088-
//Manage error
1089-
console.error('Error save: ', error);
1090-
return;
1091-
}
1092-
console.log('Response save: ', response);
1093-
};
1188+
**Success Response (ICardsSummaryResponse)**
10941189

1095-
return (
1096-
<SafeAreaView style={styles.safeArea}>
1097-
<TonderEnrollment />
1098-
{/*Custom button*/}
1099-
<TouchableOpacity
1100-
onPress={handleSaveCard}
1101-
>
1102-
<Text>Guardar</Text>
1103-
</TouchableOpacity>
1104-
</SafeAreaView>
1105-
);
1106-
}
1107-
```
1190+
| Property | Type | Description |
1191+
|----------|--------|------------------------------------------------|
1192+
| user_id | number | The ID of the user who owns the card |
1193+
| card | object | Object containing the card fields |
1194+
1195+
**Card Fields (ICardSkyflowFields)**
1196+
1197+
| Property | Type | Description |
1198+
|-------------------|--------|--------------------------------------------|
1199+
| card_number | string | The masked card number |
1200+
| expiration_month | string | The expiration month of the card |
1201+
| expiration_year | string | The expiration year of the card |
1202+
| skyflow_id | string | The unique Skyflow identifier for the card |
1203+
| card_scheme | string | The card brand (e.g., Visa, Mastercard) |
1204+
| cardholder_name | string | The name of the cardholder |
11081205

1206+
</details>
11091207

11101208

1209+
> **Note:** The saveCustomerCard It is only necessary when you want to control the enrollment button on your own.
1210+
1211+
> **Note:** For card methods, it is necessary to obtain and use your secure token when calling the create function.
1212+
1213+
```typescript
1214+
const { create, saveCustomerCard, getCardSummary, reset } = useTonder<SDKType.ENROLLMENT>();
1215+
```
1216+
11111217
## Events
11121218
The SDK provides event handling capabilities for card form input fields, supporting both Full/Enrollment SDK and Lite SDK implementations.
11131219

0 commit comments

Comments
 (0)