xentixar/esewa-sdk

v1.0.03 2024-09-15 03:54 UTC

This package is auto-updated.

Last update: 2024-09-15 03:57:19 UTC


README

此PHP SDK提供了一种简单的方式将Esewa支付网关功能集成到您的应用程序中。使用此SDK,您可以轻松配置支付详情、生成支付表单、解码响应和验证交易,使用Esewa的API。

安装

您可以通过Composer安装此SDK。在您的终端中运行以下命令

composer require xentixar/esewa-sdk

要生成自动加载器,在您的终端中运行以下命令

composer dump-autoload

用法

配置

  • 要配置Esewa支付详情,您可以使用config方法
use Xentixar\EsewaSdk\Esewa;

$esewa = new Esewa();
$esewa->config('https://your-success-url.com', 'https://your-failure-url.com', 1000.00, 'your-transaction-uuid')

初始化支付表单

开发环境

  • 要为开发环境生成支付表单,请使用init方法而不传递任何参数
$esewa->init();

生产环境

  • 要为生产环境生成支付表单,请使用init方法并将$production参数设置为true
$esewa->init(true);

解码响应

  • 支付过程完成后,您可以使用decode方法解码Esewa的响应
$responseData = $esewa->decode();

验证交易

  • 您可以使用validate方法验证交易
$response = $esewa->validate('1000.00', 'your-transaction-uuid', true);

方法

config(string $success_url, string $failure_url, float $amount, string $transaction_uuid, string $product_code = 'EPAYTEST', string $secret_key = '8gBm/:&EnhH.1/q', float $tax_amount = 0, float $product_service_charge = 0, float $product_delivery_charge = 0)

  • 配置Esewa支付详情。

init(bool $production = false)

  • 根据$production标志初始化开发或生产环境的支付表单。

decode(): ?array

  • 解码Esewa响应,如果GET请求中设置了data参数。

validate(string $total_amount, string $transaction_uuid, bool $production = false, string $product_code = 'EPAYTEST'): string

  • 通过发送cURL请求检查交易状态,验证交易。

安全提示

  • 确保安全地存储密钥,不要将其暴露在代码库或版本控制系统中的代码中。
  • 处理交易和安全问题时,始终确保验证交易响应以验证其真实性,避免欺诈交易。