承接 durianpay/dpay-php 相关项目开发

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

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

durianpay/dpay-php

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);
}

durianpay/dpay-php 适用场景与选型建议

durianpay/dpay-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.68k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 18.68k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-20