astimpay/laravel-sdk
最新稳定版本:1.0.0
Composer 安装命令:
composer require astimpay/laravel-sdk
包简介
AstimPay offers a range of payment automation solutions for small entrepreneurs in Bangladesh.
README 文档
README
The AstimPay Laravel SDK allows you to seamlessly integrate the AstimPay payment gateway into your Laravel applications.
Table of Contents
Installation
Run the following command in your project directory:
composer require astimpay/laravel-sdk
Usage
Initializing the SDK
use AstimPay\LaravelSDK\AstimPay;
Initializing a Payment
To initiate a payment, follow these steps:
- Initialize the
AstimPayclass with your API key and base URL:
$apiKey = "4a59f023cbc02521417f21a0add4e028febb2ca8"; // API KEY $apiBaseURL = "https://sandbox.astimpay.com/api/checkout-v1"; // API URL $astimpay = new AstimPay($apiKey, $apiBaseURL);
- Prepare payment request data and initiate payment:
// 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' => 'http://localhost/success.php', // add your success route 'return_type' => 'GET', 'cancel_url' => 'http://localhost/cancel.php', // add your cancel route 'webhook_url' => 'http://localhost/ipn.php', // add your ipn route ]; try { $paymentUrl = $astimpay->initPayment($requestData); return redirect($paymentUrl); } catch (\Exception $e) { dd("Initialization Error: " . $e->getMessage()); }
Available API Types
The initPayment method allows you to specify the API type as the second parameter. The available options are:
checkout-v1: Advanced checkout API (default, Success Page notification only).
Verifying a Payment
To verify a payment, follow these steps:
-
Initialize the
AstimPayclass as shown in the previous steps. -
Get the invoice ID from the payment success page:
$invoiceId = $request->invoice_id;
- Verify the payment:
try { $response = $astimpay->verifyPayment($invoiceId); dd($response); // Display the verification response } catch (\Exception $e) { dd("Verification Error: " . $e->getMessage()); }
Handling IPN Notifications (Optional)
To handle IPN (Instant Payment Notification) requests, follow these steps:
-
Initialize the
AstimPayclass as shown in the previous steps. -
Use the
executePaymentmethod:
try { $ipnResponse = $astimpay->executePayment(); dd($ipnResponse); } catch (\Exception $e) { dd("Error: " . $e->getMessage()); }
Notes
- Replace
"API KEY"with your actual API key. - Adjust the request data and other details according to your project requirements.
- The
metadatafield is dynamic; you can add multiple key-value pairs as needed. - Make sure to handle errors using try-catch blocks as demonstrated above.
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-28