dofinity / pelecard
PHP库,用于集成Pelecard支付。
dev-master
2019-02-19 15:39 UTC
Requires
- php: ^5.6 || ^7.0
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- phpunit/phpunit: >=5.7.27
This package is not auto-updated.
Last update: 2024-09-15 04:05:29 UTC
README
pelecard
一个轻量级的PHP辅助库,用于集成Pelecard Iframe V2支付。
使用Composer安装
$ composer require dofinity/pelecard:dev-master
基本用法
支付页面设置
require __DIR__ . '/vendor/autoload.php'; // change terminal, user and password to real credentials $terminal = '0123456'; $user = 'user'; $password = 'password'; // change to your own callback url $GoodURL = 'http://yourdomain/callback.php'; $Total = 100; // PaymentRequest accepts a lot of params, but in this case we use only required ones $PaymentRequest = new \Pelecard\PaymentRequest( $terminal, $user, $password, $GoodURL, $Total ); $payment = new \Pelecard\PelecardPayment(); $payment->setPaymentRequest($PaymentRequest); $result = $payment->SubmitPaymentRequest(); $resultJson = json_decode($result, true); $URL = $resultJson['URL']; $ConfirmationKey = $resultJson['ConfirmationKey']; $Error = $resultJson['Error']; // redirect to payment page header("Location: {$URL}");
支付验证
// callback.php require __DIR__ . '/vendor/autoload.php'; $PelecardTransactionId = $_GET['PelecardTransactionId']; $PelecardStatusCode = $_GET['PelecardStatusCode']; $ConfirmationKey = $_GET['ConfirmationKey']; $Total = 100; $PaymentResponse = new \Pelecard\PaymentResponse( $PelecardStatusCode, $PelecardTransactionId, '', '', $ConfirmationKey, 100 ); $payment = new \Pelecard\PelecardPayment(); $payment->setPaymentResponse($PaymentResponse); if ($payment->ValidatePayment()) { echo 'Ok. Payment has been verified'; } else { echo 'Fail. Payment forged'; }
获取交易信息
// callback.php require __DIR__ . '/vendor/autoload.php'; // change terminal, user and password to real credentials $terminal = '0123456'; $user = 'user'; $password = 'password'; $PelecardTransactionId = $_GET['PelecardTransactionId']; $transaction = new \Pelecard\PelecardTransaction( $terminal, $user, $password, $PelecardTransactionId ); // use properties from src/Pelecard/PelecardTransaction.php class var_dump($transaction);