金融科技系统 / laravel-payfast-onsite
此包已 弃用 并不再维护。未建议替代包。
为Laravel设计的PayFast本地支付集成,旨在简化订阅计费。包含Livewire视图。
v0.8.0
2022-05-30 12:37 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^8.37
- livewire/livewire: ^2.8
- moneyphp/money: ^4.0
- payfast/payfast-php-sdk: ^1.1
- spatie/ray: ^1.32
- symfony/dotenv: ^5.3
Requires (Dev)
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.20
- phpunit/phpunit: ^8.0|^9.0
- spatie/laravel-ray: ^1.23
- vimeo/psalm: ^4.8
README
更新日期 2024年7月17日
此仓库正在归档。
大部分工作已转移到以下仓库继续: https://github.com/eugenefvdm/payfast-onsite-subscriptions
为Laravel设计的PayFast本地支付实现,旨在简化订阅计费。包含Livewire视图。
这是测试软件
- 可能存在一些错误,但核心功能应该正常工作。
要求
- PHP 8.0
- Laravel
- 一个PayFast账户
安装
通过composer安装包
composer require fintech-systems/laravel-payfast-onsite
发布配置和视图
使用以下命令发布配置文件
php artisan vendor:publish --provider="FintechSystems\Payfast\PayfastServiceProvider" --tag="payfast-config"
发布成功和取消视图以及订阅和收据的Livewire组件。
php artisan vendor:publish --provider="FintechSystems\Payfast\PayfastServiceProvider" --tag="payfast-views"
Nova集成
可选发布Laravel Nova订阅和收据资源
php artisan vendor:publish --provider="FintechSystems\Payfast\PayfastServiceProvider" --tag="payfast-nova-resource"
迁移
需要迁移来创建客户、订单、收据和订阅表
php artisan migrate
示例配置
config/payfast.php
:
<?php return [ 'merchant_id' => env('PAYFAST_MERCHANT_ID', '10004002'), 'merchant_key' => env('PAYFAST_MERCHANT_KEY', 'q1cd2rdny4a53'), 'passphrase' => env('PAYFAST_PASSPHRASE', 'payfast'), 'testmode' => env('PAYFAST_TESTMODE', true), 'return_url' => env('PAYFAST_RETURN_URL', config('app.url') . '/payfast/success'), 'cancel_url' => env('PAYFAST_CANCEL_URL', config('app.url') . '/payfast/cancel'), 'notify_url' => env('PAYFAST_NOTIFY_URL', config('app.url') . '/payfast/webhook'), 'card_update_link_css' => env('CARD_UPDATE_LINK_CSS', 'inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:ring focus:ring-gray-300 disabled:opacity-25 transition'), 'card_updated_return_url' => env('CARD_UPDATED_RETURN_URL', config('app.url') . '/user/profile'), 'plans' => [ 3 => [ 'name' => 'Monthly R 99', 'start_date' => \Carbon\Carbon::now()->addDay()->format('Y-m-d'), 'payfast_frequency' => 3, 'initial_amount' => 5.99, 'recurring_amount' => 5.99, ], 6 => [ 'name' => 'Yearly R 1089', 'start_date' => \Carbon\Carbon::now()->format('Y-m-d'), 'payfast_frequency' => 6, 'initial_amount' => 6.89, 'recurring_amount' => 6.89, ] ], 'cancelation_reasons' => [ 'Too expensive', 'Lacks features', 'Not what I expected', ], ];
Livewire设置
Jetstream
我已经将一些Livewire视图建模为适合Laravel Jetstream用户个人资料页面。
在调用Livewire组件时,您可以通过指定一个mergeFields
数组来覆盖任何PayFast表单字段。
示例修改Jetstream Livewire的resources/views/profiles/show.php
<!-- Subscriptions --> <div class="mt-10 sm:mt-0"> @livewire('jetstream-subscriptions', ['mergeFields' => [ 'name_first' => $user->name, 'name_last' => $user->name, 'item_description' => 'Subscription to Online Service' ]] ) </div> <x-jet-section-border /> <!-- End Subscriptions --> <!-- Receipts --> <div class="mt-10 sm:mt-0"> @livewire('jetstream-receipts') </div> <x-jet-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'); });
测试
vendor/bin/phpunit
更新日志
请参阅更新日志以获取有关最近更改的更多信息。
截图
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。