React Native Payfast Plugin is a React Native library for Payfast payment gateway integration. It allows you to integrate the Payfast payment gateway into your React Native app with ease. It provides a simple interface to accept in-app payments, generate payment links, and tokenize & update card details.
npm install react-native-payfast-plugin
Expo?
expo install react-native-payfast-plugin
- Once of payment
- Recurring payment
- Tokenization
- In-app payment
- Generate payment link
- Update card details (for tokenized cards)
- Split payment (coming soon)
- Charge tokenized card (coming soon)
import Payfast from 'react-native-payfast-plugin';
...
<PayFast
data={{
merchantDetails: {
merchant_id: "10031584",
merchant_key: "5n52c1qu5501c",
notify_url: "https://webhook.site/f30e4b32-15b5-44e6-ae0b-c75486b8797d",
},
customerDetails: {
name_first: "First Name",
name_last: "Last Name",
email_address: "[email protected]",
cell_number: "0885....",
},
transactionDetails: {
m_payment_id: "1234",
amount: "10.00",
item_name: "Item Name",
item_description: "Item Description",
},
transactionOptions: {
email_confirmation: 0,
confirmation_address: "[email protected]",
},
}}
sandbox={true}
passphrase="thisisatestforthe"
onCancel={(data) => {
console.log("Payment cancelled: ", data.transaction_id);
}}
onMessage={(message) => {
console.log(message);
}}
onSuccess={({ data, transaction_id }) => {
console.log(transaction_id);
}}
onClose={() => {
console.log("Payment closed");
}}
/>
...
import { LinkPayment } from "react-native-payfast-plugin";
const link = new LinkPayment(
{
merchantDetails: {
merchant_id: "10031584",
merchant_key: "5n52c1qu5501c",
notify_url: "https://webhook.site/f30e4b32-15b5-44e6-ae0b-c75486b8797d",
},
customerDetails: {
name_first: "First Name",
name_last: "Last Name",
email_address: "[email protected]",
cell_number: "088...",
},
transactionDetails: {
m_payment_id: "1234",
amount: "10.00",
item_name: "Item Name",
item_description: "Item Description",
},
transactionOptions: {
email_confirmation: 0,
confirmation_address: "[email protected]",
},
},
true,
"thisisatestforthe"
);
// Optional - change to your own urls defaults to https://payfast.io/
link.cancel_url = "https://www.google.com/search?q=cancel";
link.return_url = "https://www.google.com/search?q=success";
const handleLink = async () => {
link.getLink().then((link) => {
setLink(link);
});
};
// In your render function
...
<Button title="Generate Link" onPress={handleLink} />
<Text>{link}</Text>
...
import { UpdateCard } from "react-native-payfast-plugin";
...
<UpdateCard
token="...e90c2-....-....-9ccb-...."
onComplete={(data) => console.log(data)}
sandbox={true}
/>
....
// Use the same PayFast component as in-app payment on the data prop add the following
recurringBilling: {
subscription_type: "2",
},
Prop | Type | Description |
---|---|---|
data | object | Data object for in-app payment |
sandbox | boolean | Set to true for sandbox mode |
passphrase | string | Passphrase for sandbox mode |
onCancel | function | Callback function when payment is cancelled |
onMessage | function | Callback function when payment is in progress |
onSuccess | function | Callback function when payment is successful |
onClose | function | Callback function when payment is closed |
onComplete | function | Callback function when card update is complete |
Prop | Type | Description |
---|---|---|
merchantDetails | object | Merchant details. See |
customerDetails | object | Customer details See |
transactionDetails | object | Transaction details See |
transactionOptions | object | Transaction options See |
recurringBilling | object | Recurring billing options See |
Same as PayFast data
Prop | Type | Description |
---|---|---|
token | string | Token for card to be updated |
sandbox | boolean | Set to true for sandbox mode |
onComplete | function | Callback function when card update is complete |
MIT
Axole Maranjana
This project is open for contributions. All contributions must be made via pull requests. Feel free to create issues and pull requests.
- Charge tokenized card v1.1.0
- Get subscription details v1.2.0
- Cancel subscription v1.3.0
- Pause subscription v1.4.0
- Resume subscription v1.5.0
- Split payment v1.6.0