abdullahhafizh / jokul-php-library

2.0.41 2023-01-20 08:06 UTC

README

官方Jokul PHP库。有关产品更多信息,请访问 https://jokul.doku.com,有关技术文档,请访问 https://jokul.doku.com/docs

目录

支持的支付渠道

虚拟账户

  • BCA VA
  • Bank Mandiri VA
  • Bank Syariah Indonesia VA
  • DOKU VA

要求

  • PHP 7.2 或更高版本

安装

如果您使用 Composer,可以通过命令行安装

composer require doku/jokul-php-library

将此 require 行添加到您的 composer.json 文件中

示例

{
    "require": {
        "doku/jokul-php-library": "2.1.0"
    }
}

然后在您的终端上运行 composer install

使用

设置配置

从 Jokul 后台办公室获取您的客户端 ID 和共享密钥。Sandbox Jokul 后台办公室(用于测试目的) / 生产 Jokul 后台办公室(用于真实支付)

设置您的配置

// Instantiate class
$DOKUClient = new DOKU\Client;
// Set your Client ID
$DOKUClient->setClientID('[YOUR_CLIENT_ID]');
// Set your Shared Key
$DOKUClient->setSharedKey('[YOUR_SHARED_KEY]');
// Call this function for production use
$DOKUClient->isProduction(true);

如果您想访问沙盒环境,请更改为 $DOKUClient->isProduction(false);

虚拟账户

首先准备您的支付请求数据

// Setup VA payment request data
$params = array(
    'customerEmail' => $arr["email"],
    'customerName' => $arr["customerName"],
    'amount' => $arr["amount"],
    'invoiceNumber' => random_strings(20),
    'expiryTime' => $arr["expiredTime"],
    'info1' => $arr["info1"],
    'info2' => $arr["info2"],
    'info3' => $arr["info3"],
    'reusableStatus' => $arr["reusableStatus"]
);

有关每个参数的详细信息,请参阅我们的 Jokul 文档

BCA VA

准备好上面的支付请求后,调用此函数生成 BCA VA

// Call this function to generate BCA VA
$DOKUClient->generateBcaVa($params);

Bank Mandiri VA

准备好上面的支付请求后,调用此函数生成 Bank Mandiri VA

// Call this function to generate Bank Mandiri VA
$DOKUClient->generateMandiriVa($params);

Bank Syariah Indonesia VA

准备好上面的支付请求后,调用此函数生成 Bank Syariah Indonesia VA

// Call this function to generate Bank Syariah Indonesia VA
$DOKUClient->generateBsiVa($params);

DOKU VA

准备好上面的支付请求后,调用此函数生成 DOKU VA

// Call this function to generate DOKU VA
$DOKUClient->generateDokuVa($params);

处理HTTP通知

对于这些渠道的异步支付

  • 虚拟账户

在您的客户完成支付后,我们将发送 HTTP 通知。因此,您需要处理通知以更新您的交易状态。以下是步骤

  1. 在您的服务器上创建通知 URL(端点)以接收 Jokul 的 HTTP POST 通知。每当在 Jokul 端更新交易状态时,都会向您发送通知。有关示例代码,请参阅 Jokul Java 示例
  2. 将您创建的通知 URL 设置到 Jokul 后台办公室的支付配置上。Sandbox Jokul 后台办公室(用于测试目的) / 生产 Jokul 后台办公室(用于真实支付)
  3. 使用我们的 支付模拟器 测试支付(用于测试目的)

以下是您需要设置的通知端点示例

// Mapping the notification received from Jokul
$notifyHeaders = getallheaders();
$notifyBody = json_decode(file_get_contents('php://input'), true); // You can use to parse the value from the notification body
$targetPath = '/payments/notifications'; // Put this value with your payment notification path
$secretKey = 'SK-xxxxxxx'; // Put this value with your Secret Key

// Prepare Signature to verify the notification authenticity
$signature = \DOKU\Common\Utils::generateSignature($notifyHeaders, $targetPath, file_get_contents('php://input'), $secretKey);

// Verify the notification authenticity
if ($signature == $notifyHeaders['Signature']) {
    http_response_code(200); // Return 200 Success to Jokul if the Signature is match
    // TODO update transaction status on your end to 'SUCCESS'
} else {
    http_response_code(401); // Return 401 Unauthorized to Jokul if the Signature is not match
    // TODO Do Not update transaction status on your end yet
}

有关进一步参考,请参阅我们的 Jokul 文档

示例项目

请参考此仓库中的示例项目: Jokul PHP 示例

帮助和支持

有任何问题?发现错误?有功能需求?您可以通过 新建问题

如需更多信息,您可以联系 care@doku.com