PHP code example of fintechsystems / payfast-onsite-subscriptions
1. Go to this page and download the library: Download fintechsystems/payfast-onsite-subscriptions library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fintechsystems / payfast-onsite-subscriptions example snippets
use FintechSystems\Payfast\Billable;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
use Billable;
@if (config('payfast.test_mode'))
<!-- Payfast Test Mode -->
<script src="https://sandbox.payfast.co.za/onsite/engine.js" defer></script>
@else
<script src="https://www.payfast.co.za/onsite/engine.js" defer></script>
@endif
@stack('payfast-event-listener')
@vite(['resources/css/app.css', 'resources/js/app.js'])
@
return [
'merchant_id' => env('PAYFAST_MERCHANT_ID'),
'merchant_key' => env('PAYFAST_MERCHANT_KEY'),
'passphrase' => env('PAYFAST_PASSPHRASE'),
'test_mode' => env('PAYFAST_TEST_MODE'),
'test_mode_callback_url' => env('PAYFAST_TEST_MODE_CALLBACK_URL',config('app.url')),
'trial_days' => env('PAYFAST_TRIAL_DAYS', 30),
'merchant_id_test' => env('PAYFAST_MERCHANT_ID_TEST'),
'merchant_key_test' => env('PAYFAST_MERCHANT_KEY_TEST'),
'passphrase_test' => env('PAYFAST_PASSPHRASE_TEST'),
'debug' => env('PAYFAST_DEBUG', false),
'return_url' => env('PAYFAST_RETURN_URL', '/payfast/return'),
'cancel_url' => env('PAYFAST_CANCEL_URL', '/payfast/cancel'),
'notify_url' => env('PAYFAST_NOTIFY_URL', '/payfast/notify'),
'callback_url' => env('PAYFAST_CALLBACK_URL', config('app.url')),
'callback_url_test' => env('PAYFAST_CALLBACK_URL_TEST', ''),
'billables' => [
'user' => [
'model' => User::class,
'trial_days' => 30,
'default_interval' => 'monthly',
'currency_prefix' => 'R ',
'plans' => [
[
'name' => 'Startup',
'short_description' => "",
'monthly' => [
'setup_amount' => 69000,
'recurring_amount' => 69000,
],
'yearly' => [
'setup_amount' => 700000,
'recurring_amount' => 700000,
],
'features' => [
'Feature 1',
'Feature 2',
'Feature 3',
],
'archived' => false,
'cta' => '30 DAY FREE TRIAL',
'mostPopular' => false,
],
[
'name' => 'Business',
'short_description' => "",
'monthly' => [
'setup_amount' => 199000,
'recurring_amount' => 199000,
],
'yearly' => [
'setup_amount' => 2189000,
'recurring_amount' => 2189000,
],
'features' => [
'Feature 1',
'Feature 2',
'Feature 3',
],
'archived' => false,
'cta' => '30 DAY FREE TRIAL',
'mostPopular' => true,
],
],
],
],
];
<!-- Subscriptions -->
<div class="mt-10 sm:mt-0">
@livewire('subscriptions', ['mergeFields' => [
'name_first' => $user->name,
'name_last' => $user->name,
'item_description' => 'Subscription to Online Service'
]] )
</div>
<x-payfast::section-border />
<!-- End Subscriptions -->
<!-- Receipts -->
<div class="mt-10 sm:mt-0">
@livewire('receipts')
</div>
<x-payfast::section-border />
<!-- End Receipts -->
use FintechSystems\PayFast\Facades\Payfast;
Route::get('/payment', function() {
return Payfast::payment(5,'Order #1');
});
Route::get('/cancel-subscription', function() {
return Payfast::cancelSubscription('73d2a218-695e-4bb5-9f62-383e53bef68f');
});
Route::get('/create-subscription', function() {
return Payfast::createSubscription(
Carbon::now()->addDay()->format('Y-m-d'),
5, // Amount
6 // Frequency (6 = annual, 3 = monthly)
);
});
Route::get('/create-adhoc-token', function() {
return Payfast::createAdhocToken(5);
});
Route::get('/fetch-subscription', function() {
return Payfast::fetchSubscription('21189d52-12eb-4108-9c0e-53343c7ac692');
});
Route::get('/update-card', function() {
return Payfast::updateCardLink('40ab3194-20f0-4814-8c89-4d2a6b5462ed');
});
$user = User::find(x)->createAsCustomer(['trial_ends_at' => now()->addDays(30)]);
bash
php artisan install:api
bash
php artisan vendor:publish --provider="FintechSystems\Payfast\PayfastServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="FintechSystems\Payfast\PayfastServiceProvider" --tag="views"
bash
banner.blade.php
billing.blade.php
cancel.blade.php
pricing.blade.php
receipts.blade.php
subscriptions.blade.php
success.blade.php
bash
php artisan vendor:publish --provider="FintechSystems\Payfast\PayfastServiceProvider" --tag="nova-resources"
bash
php artisan migrate