承接 jwn25/php-esewa 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jwn25/php-esewa

Composer 安装命令:

composer require jwn25/php-esewa

包简介

Package to integrate esewa with php/Laravel for Omnipay payment library

README 文档

README

php-esewa is a package which is developed to implement esewa support for Omnipay. Omnipay is a payment processing library for PHP.

Installation

As this package is esewa support for Omnipay, installation of omnipay library is must.

composer require league/omnipay

composer require jwn25/php-esewa

Laravel Usage

Config

Add following lines on config/services.php

'esewa' => [  
  'merchant_code' => env('ESEWA_MERCHANT_CODE', 'epay_payment'),  
  'test_mode' => env('ESEWA_TEST_MODE', true)  
]

ENV

Update your .env with credentials provided by esewa.

ESEWA_MERCHANT_CODE=YOUR_MERCHANT_CODE
ESEWA_TEST_MODE=false

Routes

Route::post('/order/{order_id}/payment-process', 'PaymentController@processPayment');

Route::get('/order/{order_id}/payment-failed', 'PaymentController@paymentFailed')->name('payment-failed');  
  
Route::get('/order/{order_id}/payment-completed', 'PaymentController@paymentCompleted')->name('payment-completed');

Controller

<?php  
  
namespace App\Http\Controllers;  
  
use Illuminate\Http\Request;  
use Omnipay\Omnipay;  
  
class PaymentController extends Controller {
  protected $payment_gateway;
    
  public function __construct() {
    $this->payment_gateway = Omnipay::create('PhpEsewa_Secure');
    $this->payment_gateway->setScd(config('services.esewa.merchant_code'));
    $this->payment_gateway->setTestMode(config('services.esewa.test_mode'));
  }

  public function processPayment($order_id) {
    try {  
      $response = $this->payment_gateway->purchase([  
          'amt' => 100,  
          'txAmt' => 0,  
          'psc' => 0,  
          'pdc' => 0,  
          'tAmt' => 100,  
          'pid' => rand(10, 10000), //Your Purchase Unique ID
          'su' => route('payment-completed', $order_id),  
          'fu' => route('payment-failed', $order_id),  
      ])->send();  
    } catch (Exception $e) {  
      //return back with some proper payment somehow failed message.
    }
    if ($response->isRedirect()) {  
      $response->redirect();  
    } else {  
      //return back with some proper payment somehow failed message.
    }
  }
	
  public function paymentCompleted($order_id, Request $request)  
  {  
    $response = $this->payment_gateway->verifyPayment([  
      'amt' => $request->get(amt),  
      'rid' => $request->get('refId'),  
      'pid' => $request->get('oid'),  
     ])->send();  
      
      
    if ($response->isSuccessful()) {
       // Update your order payment status using $order_id
       //redirect users to show some congratulations message (To make them feel good)
     } else {
       //IF SOMEHOW SOMETHING WENT WRONG INTERNALLY. Redirect users to route with proper message.
       // return redirect()->route('YOUR_ROUTE')->with('message', 'Your payment has been declined. Please retry.')
     }
    }
    
  public function paymentFailed($order_id) {  
    //Redirect user back with payment failed message  
  }
}  

Simple PHP Usage

Making Purchase

use Omnipay\Omnipay;
use Exception;

$payment_gateway = Omnipay::create('PhpEsewa_Secure');

$payment_gateway->setScd('MERCHANT_CODE');
$payment_gateway->setTestMode(true); //set it false if you want live mode.

try {
    $resp = $payment_gateway->purchase([
      'amt' => 100,  
      'txAmt' => 0,  
      'psc' => 0,  
      'pdc' => 0,  
      'tAmt' => 100,  
      'pid' => rand(10,10000),  //Your Purchase Unique ID
      'su' => 'https://yoursite.com/payment/success,  
      'fu' => 'https://yoursite.com/payment/failed',
    ])->send();

    if ($resp->isRedirect()) {
        $resp->redirect();
    }
} catch (Exception $e) {
    return $e->getMessage();
}

Payment Verification

$payment_gateway = Omnipay::create('PhpEsewa_Secure');

$payment_gateway->setScd('MERCHANT_CODE');
$payment_gateway->setTestMode(true); //set it false if you want live mode.

$resp = $payment_gateway->verifyPayment([
	'amt' => '100',  
	'rid' => 'ABCD', //rid from url (attached by esewa) 
	'pid' => '1234-5678', //pid from url (attached by esewa)
])->send();

if($resp->isSuccessful()) {
 //DO WHATEVER YOU WANT AFTER PAYMENT SUCCESS
}
//DO SOMETHING IF FAILED

ESEWA Documentation

Visit and go through Esewa Offical Developer's Guide to know about parameters and payment processes in detail.

Confusion?

Feel free to contact me on jeewandhakal25@gmail.com if you are confused.

jwn25/php-esewa 适用场景与选型建议

jwn25/php-esewa 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 83 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 05 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payment」 「laravel」 「esewa」 「nepali payment gateway」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jwn25/php-esewa 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jwn25/php-esewa 我们能提供哪些服务?
定制开发 / 二次开发

基于 jwn25/php-esewa 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 83
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-14