
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
rn-apple-pay-api
Advanced tools
npm install rn-apple-pay-api
ios
directory and run: cd ios
pod install
Note: Make sure CocoaPods is installed and up to date. If you encounter issues, try updating pods with:
pod repo update
In your iOS project, open the Info.plist file and add the following key:
<key>ApplePayMerchantIdentifier</key>
<string>your merchant id</string>
###Usage
import { getApplePayApi } from "rn-apple-pay-api";
// Example usage
const paymentDetails = {
amount: 150.55, // The payment amount
charge: 10.2, // Additional charges, e.g., service fees
total: amount + charge, // Total amount (amount + charge)
countryCode: "US", // Country code for the transaction
currencyCode: "USD", // Currency code for the payment
title: "Payment Title", // Title of the payment
description: "This is a test payment", // Description of the payment
cardTypes: ["Debit", "3DS"], // Accepted card types (TAppleCardTypeEnum[])
authToken: "api token", // Bearer token for API authentication
apiUrl: "https://test-api-younis-rahmans-projects.vercel.app/apple-pay", // API URL (test API provided)
noApi: false, // If true, returns the Apple Pay token for manual handling
isReject: false, // If true, rejects the request (useful for testing purposes)
isSimulator: true, // Set to true when testing on a simulator
data: { data: "data" }, // Additional data (optional, as required)
};
async function handlePayment() {
try {
const result = await getApplePayApi(paymentDetails);
console.log("Payment Success:", result);
} catch (error) {
console.error("Payment Failed:", error);
}
}
isMakePayment()
Checks if Apple Pay is available on the current device and returns a boolean.getApplePayApi(paymentDetails)
Processes Apple Pay transactions and sends the payment token to your API.openApplePay(paymentDetails)
Property | Type | Required | Description |
---|---|---|---|
amount | number | Yes | The payment amount. |
charge | number | Yes | Any additional charges (e.g., taxes, fees). |
total | number | Yes | The total payment amount (amount + charge ). |
countryCode | string | Yes | The country code for the transaction (e.g., "US" ). |
currencyCode | string | Yes | The currency code for the transaction (e.g., "USD" ). |
title | string | Yes | The title for the payment request. |
description | string | Yes | A brief description of the payment purpose. |
cardTypes | TAppleCardTypeEnum[] | Yes | The list of allowed card types (e.g., ['Debit', '3DS'] ). |
authToken | string | Yes | Bearer token for backend API authentication. |
apiUrl | string | Yes | The URL of the API endpoint handling the payment request. |
noApi | boolean | No | If true , bypasses API calls and returns the Apple Pay token directly, returns the Apple Pay token for manual handling. |
isReject | boolean | No | If true , simulates a rejected payment request (for testing purposes). |
isSimulator | boolean | No | Set to true if testing on an iOS simulator. |
data | object | No | Any additional data to pass to the API. |
Overview
1.1 Purpose of the paymentDetails
object
1.2 Context of use
Properties
2.1 amount
2.2 charge
2.3 total
2.4 countryCode
2.5 currencyCode
2.6 title
2.7 description
2.8 cardTypes
2.9 authToken
2.10 apiUrl
2.11 noApi
2.12 isReject
2.13 isSimulator
2.14 data
paymentDetails
objectThe paymentDetails
object provides a structured representation of all parameters required to initiate an Apple Pay transaction.
The paymentDetails
object is used to configure and handle Apple Pay payment requests in your application.
amount
number
charge
number
total
amount + charge
.number
countryCode
'US'
string
currencyCode
'USD'
string
title
"Payment Title"
string
description
"This is a test payment"
string
cardTypes
['Debit', '3DS']
TAppleCardTypeEnum[]
authToken
"api token"
string
apiUrl
"https://test-api-younis-rahmans-projects.vercel.app/apple-pay"
string
noApi
false
boolean
isReject
false
boolean
isSimulator
true
boolean
data
{ data: "data" }
object
import React, { useState } from 'react';
import {
StyleSheet,
Text,
View,
TouchableOpacity
} from 'react-native';
import { TAppleCardTypeEnum, getApplePayApi, isMakePayment } from 'rn-apple-pay-api';
function App(): React.JSX.Element {
const [isApplePayActive, setIsApplePayActive] = useState<boolean | null | undefined>();
const canMakePayment = async () => {
const canMakeApplePayment = await isMakePayment();
setIsApplePayActive(canMakeApplePayment);
console.log('=============canMakeApplePayment=======================');
console.log(canMakeApplePayment);
console.log('====================================');
};
const makePayment = async () => {
const amount = 150.55;
const charge = 10.20;
const total = amount + charge;
const countryCode = 'US';
const currencyCode = "USD";
const title = "Payment Title";
const description = 'This is is test payment';
const cardTypes: TAppleCardTypeEnum[] = ['Debit', '3DS'];
const authToken = 'api token ';
const apiUrl = "https://test-api-younis-rahmans-projects.vercel.app/apple-pay";
const noApi = false;
const isReject = false;
const isSimulator = true;
const data = { data: "data" };
try {
getApplePayApi(
{
amount,
charge,
total,
countryCode,
currencyCode,
description,
title,
cardTypes,
authToken,
apiUrl,
noApi,
isReject,
isSimulator,
data,
}
)
.then(token => {
if (token) {
console.log('====Api success================================');
console.log(token);
console.log('====================================');
}
})
.catch(error => {
console.log('===Api failed=================================');
console.log(error);
console.log('====================================');
});
} catch (error) {
console.log('==Apple error==================================');
console.log(error);
console.log('====================================');
}
};
return (
<View style={styles.container}>
<View>
<Text>
This is a Apple pay test
</Text>
<Text>
Is a Apple pay available : {isApplePayActive ? 'Available' : 'Not Available'}
</Text>
</View>
<TouchableOpacity
onPress={() => canMakePayment()}
style={styles.checkApplePay}
>
<Text style={styles.checkText} >Check Apple Pay Availability</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => makePayment()}
style={styles.button}
>
<Text style={styles.text} >Apple Pay</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
container: {
justifyContent: 'center',
alignItems: 'center',
height: '100%'
},
checkApplePay: {
height: 50,
width: '80%',
borderColor: 'black',
borderWidth: 2,
borderRadius: 10,
marginTop: 30,
justifyContent: 'center',
alignItems: 'center',
},
button: {
height: 50,
width: '80%',
backgroundColor: 'black',
borderRadius: 10,
marginTop: 30,
justifyContent: 'center',
alignItems: 'center',
},
text: {
fontWeight: '600',
color: 'white',
fontSize: 16
},
checkText: {
fontWeight: '600',
color: 'black',
fontSize: 16
}
});
export default App;
To ensure a seamless integration and proper functionality, follow these testing guidelines:
isSimulator
property to true
when running the payment integration on an iOS simulator.const paymentDetails = {
isSimulator: true,
// other properties
};
### Bypassing API Calls
For custom workflows or manual handling of Apple Pay tokens, set `noApi` to `true` to bypass API calls.
Example:
```javascript
const paymentDetails = {
noApi: true,
// other properties
};
What happens if noApi
is set to true?
If noApi
is set to true, the API call is bypassed, and the function directly retrieves and returns the Apple Pay token for custom processing.
Is it safe to use isReject
in production?
No, the isReject
property is for testing purposes only. It should not be used in production as it simulates failed payment scenarios.
What are the valid values for cardTypes
?
Valid values include:
['Debit']
['3DS']
['Debit', '3DS']
These represent accepted card types for Apple Pay transactions.
Can isSimulator
be used on a real device?
No, isSimulator
is specifically for iOS simulators. For real devices, ensure this property is set to false.
How do I handle errors during API calls?
Ensure proper error handling is implemented in your API integration to catch and display errors gracefully. You can log the response for debugging purposes.
Here are some helpful resources for understanding and implementing Apple Pay integration:
This package is licensed under the MIT License
.
Contributions are welcome! If you have suggestions or find bugs
, please create an issue or submit
a pull request on GitHub
.
FAQs
A full functional Apple Pay package for React Native
The npm package rn-apple-pay-api receives a total of 2 weekly downloads. As such, rn-apple-pay-api popularity was classified as not popular.
We found that rn-apple-pay-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.