durianpay/dpay-php
最新稳定版本:1.0.0
Composer 安装命令:
composer require durianpay/dpay-php
包简介
SDK that wraps collections of Durianpay's APIs, written in php
README 文档
README
API References
For full documentations regarding Durianpay APIs, visit our docs.
Getting Started
If you already set up composer in your project, then type the command below:
composer require durianpay/dpay-php
Initialize the SDK
Set up the SDK by passing your dashboard API key to Durianpay class.
use Durianpay\Durianpay; Durianpay::setApiKey('<YOUR_API_KEY>');
To find your API key, go to your dashboard settings and click on API keys.
Features and Resources
Orders
For detailed information regarding Order APIs, visit our docs.
1. Create Order
$res = \Durianpay\Resources\Order::create($body);
Pass order details to function.
Example call:
$res = \Durianpay\Resources\Order::create( [ 'amount' => '10000', 'payment_option' => 'full_payment', 'currency' => 'IDR', 'order_ref_id' => 'order_ref_001', 'customer' => [ 'customer_ref_id' => 'cust_001', 'given_name' => 'Jane Doe', 'email' => 'jane_doe@nomail.com', 'mobile' => '85722173217', ], 'items' => [ [ 'name' => 'LED Television', 'qty' => 1, 'price' => '10000', 'logo' => 'https://merchant.com/product_001/tv_image.jpg', ], ] ] ); var_dump($res);
2. Fetch Orders
$res = \Durianpay\Resources\Order::fetch($queryParams);
Note: Passing $queryParams is optional. If limit property is not specified in the $queryParams, then the SDK immediately limits the amount of orders returned to the five latest ones.
Example call:
$res = \Durianpay\Resources\Order::fetch( [ 'from' => '2021-01-01', 'to' => '2022-12-31', 'skip' => '0', 'limit' => '8' ] ); var_dump($res);
3. Fetch a Single Order
$res = \Durianpay\Resources\Order::fetchOne($id);
Pass order id as an argument to the function.
Example call:
$res = \Durianpay\Resources\Order::fetchOne('ord_JYF9EqFOiJ8812'); var_dump($res);
4. Create a Payment Link
$res = \Durianpay\Resources\Order::createPaymentLink($body);
Pass order details to function. This function will automatically append property 'is_payment_link' => true to the request body.
Example call:
$res = \Durianpay\Resources\Order::createPaymentLink( [ 'amount' => '10000', 'currency' => 'IDR', 'customer' => [ 'given_name' => 'John Doe', 'email' => 'john_doe@nomail.com', 'mobile' => '01234567890', 'given_name' => 'John Doe' ], 'items' => [[ 'name' => 'LED Television', 'qty' => 1, 'price' => '10000', 'logo' => 'https://merchant.com/product_001/tv_image.jpg' ]] ] ); var_dump($res);
Payments
For detailed information regarding Payment APIs, visit our docs.
1. Create Payment Charge
$res = \Durianpay\Resources\Payment::charge($type, $request);
Pass order details to function.
Example call:
$type = 'EWALLET'; // EWALLET, VA, RETAILSTORE, ONLINE_BANKING, BNPL, or QRIS $res = \Durianpay\Resources\Payment::charge($type, [ 'order_id' => 'ord_xrc0BvcVIF1680', 'wallet_type' => 'DANA', 'mobile' => '01234567890', 'amount' => '15000' ]); var_dump($res);
2. Fetch Payments
$res = \Durianpay\Resources\Payment::fetch($queryParams);
Note: Passing $queryParams is optional. If limit property is not specified in the $queryParams, then the SDK immediately limits the amount of payments returned to the five latest ones.
Example call:
$res = \Durianpay\Resources\Payment::fetch(); var_dump($res);
3. Fetch a Single Payment
$res = \Durianpay\Resources\Payment::fetchOne($id);
Pass payment id as an argument to the function.
Example call:
$res = \Durianpay\Resources\Order::fetchOne('pay_7UnK1zvIjB5787'); var_dump($res);
4. Check Payment Status
$res = \Durianpay\Resources\Payment::checkStatus($id);
The function will return the current state of the payment (completed, processing, cancelled, or failed).
Example call:
$res = \Durianpay\Resources\Order::checkStatus('pay_7UnK1zvIjB5787'); var_dump($res);
5. Verify Payments
$res = \Durianpay\Resources\Payment::verify($id, $verificationSignature);
Example call:
$signature = 'adf9a1a37af514c91225f6680e2df723fefebb7638519bcc7e7c9de02f2a3ab2'; $res = \Durianpay\Resources\Order::checkStatus('pay_7UnK1zvIjB5787', $signature); var_dump($res);
6. Cancel Payment
$res = \Durianpay\Resources\Payment::cancel($id);
Will immediately set the payment status to cancelled.
Example call:
$res = \Durianpay\Resources\Order::cancel('pay_7UnK1zvIjB5787'); var_dump($res);
7. Calculate MDR Fees
$res = \Durianpay\Resources\Payment::calculateMDRFees($queryParams);
Example call:
$res = \Durianpay\Resources\Order::calculateMDRFees(['amount' => '50000']); var_dump($res);
Other Durianpay Resources
We are continuously expanding this documentation, so stay tune for more features. Meanwhile, you can explore our docs first at https://durianpay.id/docs.
Error Handling
Our SDK comes with various exception handlers. Whenever you call a function, it is recommended to always wrap it inside a try-catch block.
use Durianpay\Exceptions\BadRequestException; try { // Some Durianpay functions } catch(BadRequestException $error) { $errorDesc = $error->getDetailedErrorDesc(); echo $error; var_dump($errorDesc); }
统计信息
- 总下载量: 18.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-20