I am working on a React Native Application and I need to place a card on file. I can’t find instructions on how to do so in the Reader SDK documentation.
Bryan, the link you shared is for a native java or swift project, the project I’m working on is on React Native, do you have any documentation for a React Native project?
You’ll want to use startStoreCardAsync to store a card for a customer.
- On success: returns information about the stored card as a Card object.
-
On failure: throws
USAGE_ERROR
,STORE_CUSTOMER_CARD_CANCELED
,STORE_CUSTOMER_CARD_INVALID_CUSTOMER_ID
,STORE_CUSTOMER_CARD_SDK_NOT_AUTHORIZED
orSTORE_CUSTOMER_CARD_NO_NETWORK
For example:
import {
startStoreCardAsync,
StoreCustomerCardCancelled,
StoreCustomerCardInvalidCustomerId,
StoreCustomerCardSdkNotAuthorized,
StoreCustomerCardNoNetwork,
UsageError,
} from 'react-native-square-reader-sdk';
...
const customerId = 'DRYKVK5Y6H5R4JH9ZPQB3XPZQC';
try {
const card = await startStoreCardAsync(customerId);
// Customer's card is stored successfully and card infomation is available
} catch (ex) {
let errorMessage = ex.message;
switch (ex.code) {
case StoreCustomerCardCancelled:
// Handle canceled
break;
case StoreCustomerCardInvalidCustomerId:
// Handle invalid customer id error
break;
case StoreCustomerCardNoNetwork:
// Handle no network error
break;
case StoreCustomerCardSdkNotAuthorized:
// Handle sdk not authorized
break;
default:
if (__DEV__) {
errorMessage += `\n\nDebug Message: ${ex.debugMessage}`;
console.log(`${ex.code}:${ex.debugCode}:${ex.debugMessage}`);
}
Alert.alert('Error', errorMessage);
break;
}
}