astimpay / laravel-sdk

AstimPay为孟加拉国的小企业家提供一系列支付自动化解决方案。

1.0.0 2024-07-26 19:52 UTC

This package is auto-updated.

Last update: 2024-09-28 13:46:04 UTC


README

AstimPay Logo

AstimPay Laravel SDK 允许您无缝地将 AstimPay 支付网关集成到您的 Laravel 应用程序中。

目录

安装

在您的项目目录中运行以下命令

composer require astimpay/laravel-sdk

用法

初始化 SDK

use AstimPay\LaravelSDK\AstimPay;

初始化支付

要发起支付,请按照以下步骤操作

  1. 使用您的 API 密钥和基本 URL 初始化 AstimPay
$apiKey = "4a59f023cbc02521417f21a0add4e028febb2ca8"; // API KEY
$apiBaseURL = "https://sandbox.astimpay.com/api/checkout-v1"; // API URL
$astimpay = new AstimPay($apiKey, $apiBaseURL);
  1. 准备支付请求数据并发起支付
// Example request data for initializing a payment
$requestData = [
    'full_name'     => "John Doe",
    'email'         => "test@test.com",
    'amount'        => 100,
    'metadata'      => [
        'example_metadata_key' => "example_metadata_value",
        // ... Add more key-value pairs for dynamic metadata ...
    ],
    'redirect_url'  => 'https:///success.php', // add your success route
    'return_type'   => 'GET',
    'cancel_url'    => 'https:///cancel.php', // add your cancel route
    'webhook_url'   => 'https:///ipn.php', // add your ipn route
];

try {
    $paymentUrl = $astimpay->initPayment($requestData);
    return redirect($paymentUrl);
} catch (\Exception $e) {
     dd("Initialization Error: " . $e->getMessage());
}

可用的 API 类型

使用 initPayment 方法允许您将 API 类型指定为第二个参数。可用的选项有:

  • checkout-v1:高级结账 API(默认,仅成功页面通知)。

验证支付

要验证支付,请按照以下步骤操作

  1. 按照前面的步骤初始化 AstimPay 类。

  2. 从支付成功页面获取发票 ID

$invoiceId = $request->invoice_id;
  1. 验证支付
try {
    $response = $astimpay->verifyPayment($invoiceId);
    dd($response); // Display the verification response
} catch (\Exception $e) {
    dd("Verification Error: " . $e->getMessage());
}

处理 IPN 通知(可选)

要处理 IPN(即时支付通知)请求,请按照以下步骤操作

  1. 按照前面的步骤初始化 AstimPay 类。

  2. 使用 executePayment 方法

try {
    $ipnResponse = $astimpay->executePayment();
    dd($ipnResponse);
} catch (\Exception $e) {
     dd("Error: " . $e->getMessage());
}

注意

  • "API KEY" 替换为您的实际 API 密钥。
  • 根据项目要求调整请求数据和其它细节。
  • 字段 metadata 是动态的;您可以根据需要添加多个键值对。
  • 确保使用上面演示的 try-catch 块来处理错误。