bojanvmk/laravel-cpay

为Laravel的cPay (CaSys) 集成

v0.2.3 2022-04-05 19:28 UTC

This package is auto-updated.

Last update: 2024-09-04 23:21:34 UTC


README

cPay (CaSys) 集成于Laravel

本包可以帮助您更轻松地集成cPay,它可以处理所有指定的cPay参数、验证和校验和生成与验证。

这是一个辅助类,您仍需要创建自己的视图/表单,并使用自己的设计,同时提供自己的成功/失败路由。在使用此包之前,您应熟悉“Cpay商户集成规范”文档。

安装

composer require bojanvmk/laravel-cpay

php artisan vendor:publish

编辑cpay.php配置文件,使用自己的值

基本用法

use Bojanvmk\CPay\CPay;

$amount = 100;   // in the currency specified in the cpay.php config file
$orderId = 1325; // unique order/subscription id
$description = 'Some description here';

// It will automatically validate and generate all the needed parameters
// based on these 3 params and the config file
$cPay = new CPay($amount, $orderId, $description);

// set additional optional parameters
// see the Cpay.php class for all the other supported cpay parameters
// more details about them can be found in the official cpay docs
$cPay->setEmail('test@test.com') 
      ->setRecurringPayment('1M')
      ...
        
// Get all the needed cpay params which should be included in your form (as hidden inputs)
$cPayParams = $cPay->getParameters($withChecksums = true);

// This package can also generate a ready html with these parameters as hidden inputs
$html = $cPay->renderHiddenInputs();

验证来自cPay的返回校验和

// Create a new instance from existing parameters
// you'll ideally keep a copy of the sent parameters in db for each payment
$cPay = CPay::initFromParameters($params);

// verify that the return checksum matches the original payment data
// note: $cPayPaymentRef is returned by cpay
if ($cPay->verifyReturnChecksum($cPayPaymentRef, $returnCheckSum)) {
    // we're good to go
}