aotearoait / laravel-paytm-wallet
使用此包轻松集成Paytm钱包。此包使用官方的Paytm PHP SDK,并包含订阅服务。
Requires
- php: >=5.4.0
- illuminate/contracts: ~5.0
- illuminate/support: ~5.0
This package is auto-updated.
Last update: 2024-09-06 00:15:34 UTC
README
适用于Laravel 5.0及以上版本
简介
此分支已私下修改,以允许计划内的交易。除非PayTM批准一个计划内的支付账户,否则无法完成,这并不属于他们的常规账户。使用此包可以轻松地将Paytm钱包集成到您的Laravel应用程序中。此包使用官方的Paytm PHP SDK。
许可证
Laravel Paytm Wallet开源软件,许可协议为MIT许可证
入门指南
要开始使用,请使用以下命令将以下包添加到您的composer.json文件中。
composer require aotearoait/laravel-paytm-wallet
配置
注意:对于Laravel 5.5及以上版本,自动发现负责以下配置。
当Composer成功安装Laravel Paytm Wallet库时,请在您的config/app.php配置文件中注册Anand\LaravelPaytmWallet\PaytmWalletServiceProvider。
'providers' => [ // Other service providers... Anand\LaravelPaytmWallet\PaytmWalletServiceProvider::class, ],
此外,将PaytmWallet外观添加到您的app配置文件中的aliases数组中
'aliases' => [ // Other aliases 'PaytmWallet' => Anand\LaravelPaytmWallet\Facades\PaytmWallet::class, ],
再走一步...
在您的config/services.php中添加以下配置
'paytm-wallet' => [ 'env' => 'production', // values : (local | production) 'merchant_id' => 'YOUR_MERCHANT_ID', 'merchant_key' => 'YOUR_MERCHANT_KEY', 'merchant_website' => 'YOUR_WEBSITE', 'channel' => 'YOUR_CHANNEL', 'industry_type' => 'YOUR_INDUSTRY_TYPE', 'SUBS_SERVICE_ID' => 'YOUR SUBSCRIPTION ID', 'SUBS_AMOUNT_TYPE' => 'SUBSCRIPTION TYPE', 'SUBS_FREQUENCY _UNIT' => 'SUBSCRIPTION FREQUENCY', 'SUBS_ENABLE_RETRY' => 'ALLOW RETRY', 'SUBS_EXPIRY_DATE' => 'SUBSCRIPTION EXPIRES ON', 'SUBS_MAX_AMOUNT' => 'MAX AMOUNT CHARGE PER TRANSACTION', 'SUBS_START_DATE' => 'START DATE', 'SUBS_GRACE_DAYS' => 'GRACE PERIOD DAYS' ],
注意:所有提到的凭证都是作为商家注册后由Paytm提供的。
用法
进行交易
<?php namespace App\Http\Controllers; use PaytmWallet; class OrderController extends Controller { /** * Redirect the user to the Payment Gateway. * * @return Response */ public function order() { $payment = PaytmWallet::with('receive'); $payment->prepare([ 'order' => $order->id, 'user' => $user->id, 'mobile_number' => $user->phonenumber, 'email' => $user->email, 'amount' => $order->amount, 'callback_url' => 'http://example.com/payment/status' ]); return $payment->receive(); } /** * Obtain the payment information. * * @return Object */ public function paymentCallback() { $transaction = PaytmWallet::with('receive'); $response = $transaction->response() // To get raw response as object //Check out response parameters sent by paytm here -> http://paywithpaytm.com/developer/paytm_api_doc?target=interpreting-response-sent-by-paytm if($transaction->isSuccessful()){ //Transaction Successful }else if($transaction->isFailed()){ //Transaction Failed }else if($transaction->isOpen()){ //Transaction Open/Processing } $transaction->getResponseMessage(); //Get Response Message If Available //get important parameters via public methods $transaction->getOrderId(); // Get order id $transaction->getTransactionId(); // Get transaction id } }
确保您在接收付款时在routes.php文件中指定的callback_url是post,例如以下示例
Route::post('/payment/status', 'OrderController@paymentCallback');
重要:callback_url不得受csrf保护在此处查看如何操作
使用订单号获取交易状态/信息
<?php namespace App\Http\Controllers; use PaytmWallet; class OrderController extends Controller { /** * Obtain the transaction status/information. * * @return Object */ public function statusCheck(){ $status = PaytmWallet::with('status'); $status->prepare(['order' => $order->id]); $status->check(); $response = $status->response() // To get raw response as object //Check out response parameters sent by paytm here -> http://paywithpaytm.com/developer/paytm_api_doc?target=txn-status-api-description if($status->isSuccessful()){ //Transaction Successful }else if($status->isFailed()){ //Transaction Failed }else if($status->isOpen()){ //Transaction Open/Processing } $status->getResponseMessage(); //Get Response Message If Available //get important parameters via public methods $status->getOrderId(); // Get order id $status->getTransactionId(); // Get transaction id } }
启动退款
<?php namespace App\Http\Controllers; use PaytmWallet; class OrderController extends Controller { /** * Initiate refund. * * @return Object */ public function refund(){ $refund = PaytmWallet::with('refund'); $refund->prepare([ 'order' => $order->id, 'reference' => "refund-order-4", // provide refund reference for your future reference (should be unique for each order) 'amount' => 300, // refund amount 'transaction' => $order->transaction_id // provide paytm transaction id referring to this order ]); $refund->initiate(); $response = $refund->response() // To get raw response as object if($refund->isSuccessful()){ //Refund Successful }else if($refund->isFailed()){ //Refund Failed }else if($refund->isOpen()){ //Refund Open/Processing }else if($refund->isPending()){ //Refund Pending } } }
检查退款状态
<?php namespace App\Http\Controllers; use PaytmWallet; class OrderController extends Controller { /** * Initiate refund. * * @return Object */ public function refund(){ $refundStatus = PaytmWallet::with('refund_status'); $refundStatus->prepare([ 'order' => $order->id, 'reference' => "refund-order-4", // provide reference number (the same which you have entered for initiating refund) ]); $refundStatus->check(); $response = $refundStatus->response() // To get raw response as object if($refundStatus->isSuccessful()){ //Refund Successful }else if($refundStatus->isFailed()){ //Refund Failed }else if($refundStatus->isOpen()){ //Refund Open/Processing }else if($refundStatus->isPending()){ //Refund Pending } } }
自定义处理中的交易页面
考虑到现代应用程序用户界面,默认的“处理中的交易页面”过于单调,这是此包附带的内容。如果您想修改它,您有这个选项。以下是操作方法:您只需更改OrderController代码中的1行。
<?php namespace App\Http\Controllers; use PaytmWallet; class OrderController extends Controller { /** * Redirect the user to the Payment Gateway. * * @return Response */ public function order() { $payment = PaytmWallet::with('receive'); $payment->prepare([ 'order' => $order->id, 'user' => $user->id, 'mobile_number' => $user->phonenumber, 'email' => $user->email, 'amount' => $order->amount, 'callback_url' => 'http://example.com/payment/status' ]); return $payment->view('your_custom_view')->receive(); }
在这里,$payment->receive()被替换为$payment->view('your_custom_view')->receive()。将your_custom_view替换为您的视图名称,该视图位于您的resources/views/your_custom_view.blade.php中。
并在您的视图文件中确保在</body>之前(即在关闭body标签之前)添加此行代码,该代码将重定向到支付网关。
@yield('payment_redirect')
以下是一个示例自定义视图
<html> <head> </head> <body> <h1>Custom payment message</h1> @yield('payment_redirect') </body> </html>
这就完成了!