samdoit / ccavenue
CCAvenue 支付网关 PHP 库
0.1.0
2023-11-02 07:01 UTC
Requires
- php: >=7.1
Suggests
- ext-mcrypt: Required for most features of CCAvenue
README
一个简单的 PHP 扩展,用于在 Laravel 中集成 CCAvenue (www.ccavenue.com) 支付网关
安装
在您的 composer.json 中需要此包,并更新 composer。这将下载该包。
composer require samdoit/ccavenue
Laravel
更新 composer 后,将 ServiceProvider 添加到 config/app.php 中的 providers 数组中
Samdoit\CCAvenue\CCAvenueServiceProvider::class,
对于 Laravel 版本 7.3 或更高版本,包自动发现可用
添加 ServiceProvider 后,运行以下命令
php artisan vendor:publish
请求支付
require_once __DIR__ . '/../vendor/autoload.php';
use Samdoit\CCAvenue\CCAvenuePayment;
$ccavenue = new CCAvenuePayment();
// set details
$ccavenue->setAmount( '<Amount>' );
$ccavenue->setOrderId( '<order_id>' );
$ccavenue->setBillingName( '<billing_cust_name>' );
$ccavenue->setBillingAddress( '<billing_cust_address>' );
$ccavenue->setBillingCity( '<billing_cust_city>' );
$ccavenue->setBillingZip( '<billing_cust_zip>' );
$ccavenue->setBillingState( '<billing_cust_state>' );
$ccavenue->setBillingCountry( '<billing_cust_country>' );
$ccavenue->setBillingEmail( '<billing_cust_email>' );
$ccavenue->setBillingTel( '<billing_cust_tel>' );
$ccavenue->setBillingNotes( '<billing_cust_notes>' );
// copy all the billing details to chipping details
$ccavenue->billingSameAsShipping();
// get encrpyted data to be passed
$data = $ccavenue->getEncryptedData();
// merchant id to be passed along the param
$access_code = $ccavenue->getAccessCode();
HTML 重定向
<html>
<body>
<form method="post" name="redirect" action="https://test.ccavenue.com/transaction/transaction.do?command=initiateTransaction">
<input type=hidden name=encRequest value="{{ $data }}">
<input type=hidden name=access_code value="{{ $access_code }}">
</form>
<script language='javascript'>document.redirect.submit();</script>
</body>
</html>
支付响应
require_once __DIR__ . '/../vendor/autoload.php';
use Samdoit\CCAvenue\CCAvenuePayment;
// Get Response
$response = $_GET_["encResp"];
$ccavenue = new CCAvenuePayment();
// Check if the transaction was successfull.
echo $ccavenue->response($response);