📅  最后修改于: 2023-12-03 15:18:16.562000             🧑  作者: Mango
PayFast JavaScript is a library that allows developers to integrate the PayFast payment gateway into their JavaScript applications. With PayFast, you can accept payments from various sources, including credit cards, InstantEFT, and Bitcoin.
You can install PayFast JavaScript library using npm or include it directly from a CDN.
NPM:
npm install payfast-js
CDN:
<script src="https://cdn.example.com/payfast-js/payfast.min.js"></script>
To use PayFast JavaScript library, follow these steps:
Include the PayFast JavaScript library in your HTML file.
<script src="path/to/payfast.min.js"></script>
Initialize PayFast with your merchant details.
<script>
var payfast = new PayFast({
merchant_id: 'YOUR_MERCHANT_ID',
merchant_key: 'YOUR_MERCHANT_KEY',
passphrase: 'YOUR_PASSPHRASE',
sandbox: true // Set to false in production
});
</script>
Generate a payment URL.
<script>
var paymentUrl = payfast.paymentUrl({
amount: 100.00,
item_name: 'Test Item',
return_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel'
});
</script>
Redirect the user to the payment URL.
<script>
window.location.href = paymentUrl;
</script>
Here are a few examples of how you can use PayFast JavaScript:
Accepting credit card payments:
payfast.paymentUrl({
amount: 100.00,
item_name: 'Test Item',
payment_method: 'cc',
return_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel'
});
Accepting InstantEFT payments:
payfast.paymentUrl({
amount: 100.00,
item_name: 'Test Item',
payment_method: 'eft',
return_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel'
});
Accepting Bitcoin payments:
payfast.paymentUrl({
amount: 100.00,
item_name: 'Test Item',
payment_method: 'bitcoin',
return_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel'
});
For detailed documentation and API reference, please visit the official PayFast JavaScript documentation.
This library is licensed under the MIT License.
Note: Replace 'YOUR_MERCHANT_ID'
, 'YOUR_MERCHANT_KEY'
, and 'YOUR_PASSPHRASE'
with your actual PayFast merchant details obtained from PayFast Dashboard.