Skip to content

Commit 7abf93b

Browse files
Merge pull request #6 from tonderio/DEV-1799
DEV-1799: Adds getCardSummary method to enrollment and lite SDKs
2 parents bfb0ae8 + 8b69c5e commit 7abf93b

File tree

17 files changed

+478
-254
lines changed

17 files changed

+478
-254
lines changed

README.md

Lines changed: 111 additions & 60 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,16 +374,115 @@ 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);
389+
// Reset the state and regenerate the SDK to use it again
390+
reset();
391+
await initializeEnrollment();
392+
};
393+
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+
405+
return (
406+
<SafeAreaView>
407+
<TonderEnrollment />
408+
</SafeAreaView>
409+
);
410+
}
411+
```
412+
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);
375462
// Reset the state and regenerate the SDK to use it again
376463
reset();
377464
await initializeEnrollment();
378465
};
379466

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+
380477
return (
381478
<SafeAreaView>
382479
<TonderEnrollment />
480+
{/*Custom button*/}
481+
<TouchableOpacity
482+
onPress={handleSaveCard}
483+
>
484+
<Text>Guardar</Text>
485+
</TouchableOpacity>
383486
</SafeAreaView>
384487
);
385488
}
@@ -708,7 +811,6 @@ interface IBaseProcessPaymentRequest {
708811
amount_total: number;
709812
description: string;
710813
price_unit: number;
711-
product_reference: string;
712814
quantity: number;
713815
discount?: number;
714816
taxes?: number;
@@ -738,7 +840,6 @@ interface IProcessPaymentRequest {
738840
amount_total: number;
739841
description: string;
740842
price_unit: number;
741-
product_reference: string;
742843
quantity: number;
743844
discount?: number;
744845
taxes?: number;
@@ -1030,6 +1131,7 @@ The LITE integration provides full control over the payment flow with individual
10301131
- payment: Processes a payment using the configured payment data.
10311132
- saveCustomerCard: Tokenizes and saves the current card information.
10321133
- getCustomerCards: Retrieves the list of saved cards for the customer.
1134+
- getCardSummary: Retrieves detailed information about a saved card using its Skyflow ID.
10331135
- getPaymentMethods: Retrieves available payment methods.
10341136
- removeCustomerCard: Deletes a saved card.
10351137

@@ -1038,7 +1140,7 @@ The LITE integration provides full control over the payment flow with individual
10381140
> **Note:** For card methods, it is necessary to obtain and use your secure token when calling the create function.
10391141
10401142
```typescript
1041-
const { create, payment, saveCustomerCard, getCustomerCards,
1143+
const { create, payment, saveCustomerCard, getCustomerCards, getCardSummary,
10421144
removeCustomerCard, getPaymentMethods, reset } = useTonder<SDKType.LITE>();
10431145
```
10441146

@@ -1047,66 +1149,15 @@ const { create, payment, saveCustomerCard, getCustomerCards,
10471149
The ENROLLMENT integration provides methods for handling full enrollment with built-in UI components.
10481150

10491151
- saveCustomerCard: Tokenizes and saves the current card information.
1152+
- getCardSummary: Retrieves detailed information about a saved card using its Skyflow ID.
10501153

10511154
> **Note:** The saveCustomerCard It is only necessary when you want to control the enrollment button on your own.
10521155
10531156
> **Note:** For card methods, it is necessary to obtain and use your secure token when calling the create function.
10541157
10551158
```typescript
1056-
const { create, saveCustomerCard, reset } = useTonder<SDKType.LITE>();
1159+
const { create, saveCustomerCard, getCardSummary, reset } = useTonder<SDKType.ENROLLMENT>();
10571160
```
1058-
#### Example with custom button
1059-
```tsx
1060-
1061-
export default function EnrollmentButtonScreen() {
1062-
const { create, saveCustomerCard } = useTonder<SDKType.ENROLLMENT>();
1063-
1064-
useEffect(() => {
1065-
createSDK()
1066-
}, [])
1067-
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-
});
1078-
1079-
if (error) {
1080-
// Manage error
1081-
console.error('Error creating SDK', error);
1082-
}
1083-
};
1084-
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-
};
1094-
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-
```
1108-
1109-
11101161

11111162
## Events
11121163
The SDK provides event handling capabilities for card form input fields, supporting both Full/Enrollment SDK and Lite SDK implementations.

example/ios/Podfile.lock

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ PODS:
12421242
- ReactCommon/turbomodule/bridging
12431243
- ReactCommon/turbomodule/core
12441244
- Yoga
1245-
- react-native-safe-area-context (4.14.0):
1245+
- react-native-safe-area-context (4.14.1):
12461246
- DoubleConversion
12471247
- glog
12481248
- hermes-engine
@@ -1255,8 +1255,8 @@ PODS:
12551255
- React-featureflags
12561256
- React-graphics
12571257
- React-ImageManager
1258-
- react-native-safe-area-context/common (= 4.14.0)
1259-
- react-native-safe-area-context/fabric (= 4.14.0)
1258+
- react-native-safe-area-context/common (= 4.14.1)
1259+
- react-native-safe-area-context/fabric (= 4.14.1)
12601260
- React-NativeModulesApple
12611261
- React-RCTFabric
12621262
- React-rendererdebug
@@ -1265,7 +1265,7 @@ PODS:
12651265
- ReactCommon/turbomodule/bridging
12661266
- ReactCommon/turbomodule/core
12671267
- Yoga
1268-
- react-native-safe-area-context/common (4.14.0):
1268+
- react-native-safe-area-context/common (4.14.1):
12691269
- DoubleConversion
12701270
- glog
12711271
- hermes-engine
@@ -1286,7 +1286,7 @@ PODS:
12861286
- ReactCommon/turbomodule/bridging
12871287
- ReactCommon/turbomodule/core
12881288
- Yoga
1289-
- react-native-safe-area-context/fabric (4.14.0):
1289+
- react-native-safe-area-context/fabric (4.14.1):
12901290
- DoubleConversion
12911291
- glog
12921292
- hermes-engine
@@ -1308,7 +1308,7 @@ PODS:
13081308
- ReactCommon/turbomodule/bridging
13091309
- ReactCommon/turbomodule/core
13101310
- Yoga
1311-
- react-native-webview (13.12.5):
1311+
- react-native-webview (13.12.4):
13121312
- DoubleConversion
13131313
- glog
13141314
- hermes-engine
@@ -1596,7 +1596,7 @@ PODS:
15961596
- React-logger (= 0.76.3)
15971597
- React-perflogger (= 0.76.3)
15981598
- React-utils (= 0.76.3)
1599-
- RNScreens (3.35.0):
1599+
- RNScreens (3.37.0):
16001600
- DoubleConversion
16011601
- glog
16021602
- hermes-engine
@@ -1617,9 +1617,9 @@ PODS:
16171617
- ReactCodegen
16181618
- ReactCommon/turbomodule/bridging
16191619
- ReactCommon/turbomodule/core
1620-
- RNScreens/common (= 3.35.0)
1620+
- RNScreens/common (= 3.37.0)
16211621
- Yoga
1622-
- RNScreens/common (3.35.0):
1622+
- RNScreens/common (3.37.0):
16231623
- DoubleConversion
16241624
- glog
16251625
- hermes-engine
@@ -1641,7 +1641,7 @@ PODS:
16411641
- ReactCommon/turbomodule/bridging
16421642
- ReactCommon/turbomodule/core
16431643
- Yoga
1644-
- RNSVG (15.10.1):
1644+
- RNSVG (15.9.0):
16451645
- DoubleConversion
16461646
- glog
16471647
- hermes-engine
@@ -1661,9 +1661,9 @@ PODS:
16611661
- ReactCodegen
16621662
- ReactCommon/turbomodule/bridging
16631663
- ReactCommon/turbomodule/core
1664-
- RNSVG/common (= 15.10.1)
1664+
- RNSVG/common (= 15.9.0)
16651665
- Yoga
1666-
- RNSVG/common (15.10.1):
1666+
- RNSVG/common (15.9.0):
16671667
- DoubleConversion
16681668
- glog
16691669
- hermes-engine
@@ -1684,7 +1684,7 @@ PODS:
16841684
- ReactCommon/turbomodule/bridging
16851685
- ReactCommon/turbomodule/core
16861686
- Yoga
1687-
- RNVectorIcons (10.2.0):
1687+
- RNVectorIcons (10.3.0):
16881688
- DoubleConversion
16891689
- glog
16901690
- hermes-engine
@@ -1959,8 +1959,8 @@ SPEC CHECKSUMS:
19591959
React-logger: 26155dc23db5c9038794db915f80bd2044512c2e
19601960
React-Mapbuffer: ad1ba0205205a16dbff11b8ade6d1b3959451658
19611961
React-microtasksnativemodule: e771eb9eb6ace5884ee40a293a0e14a9d7a4343c
1962-
react-native-safe-area-context: 2500e4fe998caad50ad3bc51ec23ef951308569e
1963-
react-native-webview: 40b8823be3fac70f0404016e6aed754ef4307517
1962+
react-native-safe-area-context: 782fec0553f14a630a2bac87b116e512a9f35500
1963+
react-native-webview: 0bd56be54d01756f20eb942dad37a2cd22a6def2
19641964
React-nativeconfig: aeed6e2a8ac02b2df54476afcc7c663416c12bf7
19651965
React-NativeModulesApple: c5b7813da94136f50ef084fa1ac077332dcfc658
19661966
React-perflogger: 6afb7eebf7d9521cc70481688ccddf212970e9d3
@@ -1988,9 +1988,9 @@ SPEC CHECKSUMS:
19881988
React-utils: 2bcaf4f4dfe361344bce2fae428603d518488630
19891989
ReactCodegen: ae99a130606068ed40d1d9c0d5f25fda142a0647
19901990
ReactCommon: 89c87b343deacc8610b099ac764848f0ce937e3e
1991-
RNScreens: e389d6a6a66a4f0d3662924ecae803073ccce8ec
1992-
RNSVG: ec2e9d524612ee95db5df143a54518c5404d93f0
1993-
RNVectorIcons: 07792a9538e8577c1263fcad187712e90d65d8fb
1991+
RNScreens: ba9fa64df3e24f25d9f50406d46fd5b37dd9fa74
1992+
RNSVG: b2fbe96b2bb3887752f8abc1f495953847e90384
1993+
RNVectorIcons: 67fb9844e2355e70e240cb778e6cd2a10f3f0aea
19941994
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
19951995
Yoga: f6dc1b6029519815d5516a1241821c6a9074af6d
19961996

0 commit comments

Comments
 (0)