douglastycho / payfast-php-sdk-php71
PayFast PHP 库
v1.0.0
2022-08-26 15:35 UTC
Requires
- php: >=7.1
- ext-json: *
- guzzlehttp/guzzle: >=6.0.0
Requires (Dev)
- phpunit/phpunit: 5.7.27
This package is auto-updated.
Last update: 2024-09-26 20:30:00 UTC
README
PayFast PHP SDK 提供了一个易于使用的库,可轻松将 PayFast 支付集成到您的项目中。这包括自定义集成、站内集成以及所有 API。
要求
PHP 7.2.5 及更高版本。
文档
请参阅 开发者文档
Composer
您可以通过 Composer 安装此库。运行以下命令:
composer require payfast/payfast-php-sdk
要使用此库,请使用 Composer 的 自动加载
require_once('vendor/autoload.php');
入门指南
自定义集成
构建一个结算表单,并通过 PayFast 支付平台安全地接收付款。
请参阅 开发者文档
try { $payfast = new PayFastPayment( [ 'merchantId' => '10000100', 'merchantKey' => '46f0cd694581a', 'passPhrase' => '', 'testMode' => true ] ); $data = [ 'amount' => '100.00', 'item_name' => 'Order#123' ]; echo $payfast->custom->createFormFields($data, ['value' => 'PAY NOW', 'class' => 'btn']); } catch(Exception $e) { echo 'There was an exception: '.$e->getMessage(); }
站内支付
直接将 PayFast 的安全支付引擎集成到您的结算页面上。
请参阅 开发者文档
// Include: <script src="https://www.payfast.co.za/onsite/engine.js"></script> try { $payfast = new PayFastPayment( [ 'merchantId' => '10000100', 'merchantKey' => '46f0cd694581a', 'passPhrase' => '', 'testMode' => false ] ); $data = [ 'amount' => '100.00', 'item_name' => 'Order#123' ]; // Generate payment identifier $identifier = $payfast->onsite->generatePaymentIdentifier($data); if($identifier!== null){ echo '<script type="text/javascript">window.payfast_do_onsite_payment({"uuid":"'.$identifier.'"});</script>'; } } catch(Exception $e) { echo 'There was an exception: '.$e->getMessage(); }
API
定期账单
订阅支付 API 允许商家与他们的账户中的订阅进行交互。
请参阅 开发者文档
try { $api = new PayFastApi( [ 'merchantId' => '10018867', 'passPhrase' => '2uU_k5q_vRS_', 'testMode' => true ] ); $fetchArray = $api->subscriptions->fetch('2afa4575-5628-051a-d0ed-4e071b56a7b0'); $pauseArray = $api->subscriptions->pause('2afa4575-5628-051a-d0ed-4e071b56a7b0', ['cycles' => 1]); $unpauseArray = $api->subscriptions->unpause('2afa4575-5628-051a-d0ed-4e071b56a7b0'); $cancelArray = $api->subscriptions->cancel('2afa4575-5628-051a-d0ed-4e071b56a7b0'); $updateArray = $api->subscriptions->update('2afa4575-5628-051a-d0ed-4e071b56a7b0', ['cycles' => 1]); $adhocArray = $api->subscriptions->adhoc('290ac9a6-25f1-cce4-5801-67a644068818', ['amount' => 500, 'item_name' => 'Test adhoc']); } catch(Exception $e) { echo 'There was an exception: '.$e->getMessage(); }
更新卡
更新卡端点允许您为买家提供链接,以便他们在定期账单订阅或令牌化费用中更新他们的卡详情。
请参阅 开发者文档
try { $payfast = new PayFastPayment( [ 'merchantId' => '10000100', 'merchantKey' => '46f0cd694581a', 'passPhrase' => '', 'testMode' => false ] ); echo $payfast->custom->createCardUpdateLink('2afa4575-5628-051a-d0ed-4e071b56a7b0', 'https://www.example.com/return', 'Update your card', ['target' => '_blank']); } catch(Exception $e) { echo 'There was an exception: '.$e->getMessage(); }
交易历史记录
交易历史记录 API 允许商家与他们的 PayFast 账户进行交互。
请参阅 开发者文档
try { $api = new PayFastApi( [ 'merchantId' => '10018867', 'passPhrase' => '2uU_k5q_vRS_', 'testMode' => true ] ); $rangeArray = $api->transactionHistory->range(['from' => '2020-08-01', 'to' => '2020-08-07', 'offset' => 0, 'limit' => 1000]); $dailyArray = $api->transactionHistory->daily(['date' => '2020-08-07', 'offset' => 0, 'limit' => 1000]); $weeklyArray = $api->transactionHistory->weekly(['date' => '2020-08-07', 'offset' => 0, 'limit' => 1000]); $monthlyArray = $api->transactionHistory->monthly(['date' => '2020-08', 'offset' => 0, 'limit' => 1000]); } catch(Exception $e) { echo 'There was an exception: '.$e->getMessage(); }
信用卡交易查询
信用卡交易查询 API 允许商家查询信用卡交易。
请参阅 开发者文档
try { $api = new PayFastApi( [ 'merchantId' => '10018867', 'passPhrase' => '2uU_k5q_vRS_', 'testMode' => true ] ); $creditCardArray = $api->creditCardTransactions->fetch('1124148'); } catch(Exception $e) { echo 'There was an exception: '.$e->getMessage(); }
退款
退款 API 允许商家在其账户上执行退款。
请参阅 开发者文档
try { $api = new PayFastApi( [ 'merchantId' => '10018867', 'passPhrase' => '2uU_k5q_vRS_', 'testMode' => false ] ); $refundFetchArray = $api->refunds->fetch('dc0521d3-55fe-269b-fa00-b647310d760f'); $refundCreateArray = $api->refunds->create('dc0521d3-55fe-269b-fa00-b647310d760f', ['amount' => 50, 'reason' => 'Product returned', 'acc_type' => 'savings']); } catch(Exception $e) { echo 'There was an exception: '.$e->getMessage(); }