rajtika / sslcommerz
SSLCommerce支付网关集成库,用于Laravel
dev-master
2021-04-14 04:35 UTC
Requires
- php: >=5.6
- guzzlehttp/guzzle: ~6.0
This package is auto-updated.
Last update: 2024-10-01 00:08:56 UTC
README
SSLCommerz支付网关集成
本包将使您的SSLCommerz支付网关集成简单且易于实现
安装
您可以通过composer安装此包
composer require rajtika/sslcommerz
发布配置
发布配置文件
php artisan vendor:publish
设置和配置
更新您的应用环境 (.env)
SSL_LOCALHOST=[TRUE/FALSE]
SSL_SANDBOX_MODE=[TRUE/FALSE]
SSL_STORE_ID=[YOUR SSLCOMMERZ STORE ID]
SSL_STORE_PASSWORD=[YOUR SSLCOMMERZ STORE_PASSWORD]
SSL_SUCCESS_URL=sslcommerz/success
SSL_CANCEL_URL=sslcommerz/cancel
SSL_FAIL_URL=sslcommerz/fail
SSL_IPN_URL=sslcommerz/ipn
SSL_STORE_CURRENCY=[STORE CURRENCY eg. BDT]
为SSLCommerz创建四个POST路由
Route::post('sslcommerz/success','SSLPaymentController@success'); Route::post('sslcommerz/fail','SSLPaymentController@fail'); Route::post('sslcommerz/cancel','SSLPaymentController@cancel'); Route::post('sslcommerz/ipn','SSLPaymentController@ipn');
注意 这些路由在.env文件中使用
在app\Http\Middleware\VerifyCsrfToken.php中添加异常
protected $except = [ 'sslcommerz/*' ];
注意 这将是这四个路由的初始组
配置完成后
php artisan config:cache
用法
进行支付
现在您可以从路由或控制器方法中调用支付
路由方式
Route::post('make-payment', function() { SSLCommerz::setParams([ 'tran_id' => 'your_unique_transaction_id', 'product_name' => 'Name of your product', 'product_category' => 'Product category', 'product_profile' => 'general', 'total_amount' => 100, 'currency' => 'BDT', 'cus_name' => 'John Doe', 'cus_email' => 'customer@example.com', 'cus_phone' => '01911XXXXXX', 'cus_add1' => 'Dhaka' ]) //Shipping is required when your order need shipment ->setShippingInfo([ 'shipping_method' => "YES", 'num_of_item' => 2 ]) ->makePayment() ->hosted(); //this method will redirect your customer to ssl commerz payment page //or ->checkout(); //this method will return a json response for your checkout popup });
控制器方式
use Rajtika\SSLCommerz\SSLCommerz; class PaymentController extends Controller { public function paymentRedirectWay() { ... // DO YOU ORDER SAVING PROCESS TO DB OR ANYTHING ... // You can generate an unique transaction id by using uniqueid() $transaction_id = uniqid(); //this transaction id must save your order or payment table for referencing / validate payment status return SSLCommerz::setParams([ 'tran_id' => $transaction_id, 'product_name' => 'Name of your product', 'product_category' => 'Product category', 'product_profile' => 'general', 'total_amount' => 100, 'currency' => 'BDT', 'cus_name' => 'John Doe', 'cus_email' => 'customer@example.com', 'cus_phone' => '01911XXXXXX', 'cus_add1' => 'Dhaka' ]) //Shipping is required when your order need shipment ->setShippingInfo([ 'shipping_method' => "YES", 'num_of_item' => 2 ]) ->makePayment() ->hosted(); //this method will redirect your customer to ssl commerz payment page } //or public function popupWay() { ... // DO YOU ORDER SAVING PROCESS TO DB OR ANYTHING ... // You can generate an unique transaction id by using uniqueid() /* * this transaction id must save your order or payment table * for referencing / validate payment status * You can make this more unique by passing prefix to it */ $transaction_id = uniqid(); return SSLCommerz::setParams([ 'tran_id' => $transaction_id, 'product_name' => 'Name of your product', 'product_category' => 'Product category', 'product_profile' => 'general', 'total_amount' => 100, 'currency' => 'BDT', 'cus_name' => 'John Doe', 'cus_email' => 'customer@example.com', 'cus_phone' => '01911XXXXXX', 'cus_add1' => 'Dhaka' ]) //Shipping is required when your order need shipment ->setShippingInfo([ 'shipping_method' => "YES", 'num_of_item' => 2 ]) ->makePayment() ->checkout(); //this method will return a json response for your checkout popup } }
注意 这是最基本的支付需求。
变更日志
请参阅变更日志获取更多信息。
许可协议
MIT许可协议(MIT)。请参阅许可文件获取更多信息。