esyede/lara-dana

此包已被弃用且不再维护。未建议替代包。

Laravel的不官方Dana支付API包

v1.0.0 2023-09-15 14:16 UTC

This package is auto-updated.

Last update: 2024-07-15 16:08:11 UTC


README

Laravel的不官方Dana支付API包。访问https://dashboard.dana.id/api-docs获取更详细的文档。

需求

  • Laravel >= 10.0

安装

1. 使用composer安装此包

composer require esyede/lara-dana

2. 发布配置文件

php artisan vendor:publish --provider="Esyede\Dana\DanaCoreServiceProvider"

使用方法

配置存储在config/dana.php中。使用您自己的凭证进行自定义。

函数

1. 创建订单

$orderData = [
    [
    'order' => [
        'orderTitle' => 'Dummy product',
        'orderAmount' => [
            'currency' => 'IDR',
            'value' => 100
        ],
        'merchantTransId' => '201505080001',
        'merchantTransType' => 'dummy transaction type',
        'orderMemo' => 'Memo',
        'goods' => [
            [
                'merchantGoodsId' => '24525635625623',
                'description' => 'dummy description',
                'category' => 'dummy category',
                'price' => [
                    'currency' => 'IDR',
                    'value' => 100,
                ],
                'unit' => 'Kg',
                'quantity' => '3.2',
                'merchantShippingId' => '564314314574327545',
                'snapshotUrl' => '[http://snap.url.com]',
                'extendInfo' => [
                    'myInvoiceId' => 'T12345678ASDFG', // optional
                    'remark' => 'DEBIT', // optional
                ]
            ]
        ]
    ],
    'merchantId' => '216820000000006553000',
    'subMerchantId' => '12345678',
    'productCode' => '51051000100000000001',
];

DanaPayment::createOrder($orderData);

有关更详细的文档,请访问https://dashboard.dana.id/api-docs/read/33

2. 获取oAuth URL

$terminalType = 'WEB';
$redirectUrl  = 'https://your-app-url.com/oauth/callback';
DanaPayment::generateOauthUrl($terminalType, $redirectUrl);

有关更详细的文档,请访问https://dashboard.dana.id/api-docs/read/47

3. 获取请求和刷新令牌

$authToken = 'your-auth-token';
DanaPayment::getToken($authToken);

您可以从oAuth回调过程中获取$authToken的值。
从这个函数中,您将接收到tokenrefresh_token
参考:https://dashboard.dana.id/api-docs/read/32

4. 获取用户资料

$accessToken = 'your_user_profile_access_token';
DanaPayment::profile($accessToken);

$accessToken填满为DanaPayment::getToken()的响应,参考:https://dashboard.dana.id/api-docs/read/38

5. 解绑访问令牌

DanaPayment::unbindAllAccount();

此方法用于撤销或解绑所有从商家注册的访问令牌。参考:https://dashboard.dana.id/api-docs/read/46

6. 处理回调响应

$status = true;
DanaPayment::handleFinishNotifyCallback($status);

此函数将为Dana API生成有效的响应。$status是布尔值。

6. 计算MDR的函数

$payAmount = 100000;
$payMethod = 'BALANCE';
DanaCalculation::calculateMDR($payAmount, $payMethod);

此函数将计算danas的MDR费用。从danas回调数据中填写$payMethod$payAmount

贡献

该项目还远未完美。许多dna API尚未实现。如果您能贡献实现其中的任何一部分,我会非常高兴。