react-native-braintree-sdk
v0.2.0
Published
A small wrapper to access Braintree's most recent iOS/Android SDK on React Native
Downloads
57
Readme
react-native-braintree-sdk
A small wrapper to access Braintree's most recent iOS/Android SDK on React Native
Installation
npm install react-native-braintree-sdk
Usage
import * as Braintree from "react-native-braintree-sdk";
// ...
const App = () => {
const [isApplePayAvailable, setIsApplePayAvailable] = React.useState(false);
useEffect(() => {
const setup = async () => {
await Braintree.setup('clientToken');
Braintree.isApplePayAvailable()
.then(setIsApplePayAvailable)
.catch(showError);
}
}, []);
const onPressApplePay = React.useCallback(async () => {
try {
const result = await Braintree.authorizeApplePay({
merchantId: 'test-merchant-id',
lineItems: [
{
label: 'Total',
amount: 10,
},
],
contactFields: ['postalAddress'],
supportedNetworks: ['AmEx', 'Visa', 'MasterCard'],
});
Alert.alert('Apple Pay Result', `Nonce: ${result.nonce}`);
} catch (error) {
showError(error);
}
}, []);
return (
<View>
{isApplePayAvailable && <Button title='Pay with Venmo' onPress={onPressApplePay} />}
</View>
);
}
API
setup ⇒ void
Sets up the native Braintree client
| Param | Type | Description | | --- | --- | --- | | clientAuthorization | string | See Braintre's Docs |
isVenmoAvailable ⇒ Promise<boolean>
Checks if the device can launch Venmo on iOS, on Android always returns true
Returns: Promise - Promise resolving to the status
authorizeVenmo ⇒ Promise<VenmoResponse>
Asks the user to start a Venmo request, if the user approves, returns a nonce to use for a transaction
Returns: Promise.<VenmoResponse> - Promise resolving to nonce and the user's venmo username
| Param | Type | Description | | --- | --- | --- | | params | AuthorizeVenmoParams | See Braintre's Docs to find out more on the use / vaulting options |
isGooglePayAvailable ⇒ Promise<boolean>
Checks if the device can use Google Pay. Always returns false on iOS devices
Returns: Promise - Promise resolving to the status
authorizeGooglePay ⇒ Promise<NonceResponse>
Presents the Google Pay popup, if the user approves, returns a nonce to use for a transaction
Returns: Promise.<NonceResponse> - Promise resolving to nonce
| Param | Type | Description | | --- | --- | --- | | params | AuthorizeGooglePayParams | The price for the transaction that the nonce will be used with |
isApplePayAvailable ⇒ Promise<boolean>
Checks if the device can use Apple Pay. Always returns false on Android devices
Returns: Promise - Promise resolving to the status
authorizeApplePay ⇒ Promise<NonceResponse>
Presents the Apple Pay popup, if the user approves, returns a nonce to use for a transaction
Returns: Promise.<NonceResponse> - Promise resolving to nonce
| Param | Type | Description | | --- | --- | --- | | params | AuthorizeGooglePayParams | See Braintre's Docs to learn more about the Apple Pay payment request options |
getCardNonce ⇒ Promise<CardResponse>
Creates a nonce for a card
Returns: Promise.<CardResponse> - Promise resolving to nonce and card informatiom
| Param | Type | Description | | --- | --- | --- | | card | CardDetails | The card details you collect on the device |
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT