kaypay / sdk

这是 Kaypay SDK for PHP

1.0.1 2022-11-11 02:28 UTC

This package is not auto-updated.

Last update: 2024-09-27 10:57:43 UTC


README

安装

安装 Kaypay SDK for PHP 的推荐方式是通过 Composer

composer require kaypay/sdk

使用

设置 API 实例

// obtain the credential from Kaypay Account Manager
$merchantCode = 'AWESOME_MERCHANT';
$secretKey = 's3cret';

// call the constructor
$signer = new \Kaypay\Sdk\Signer($secretKey);
$api = new \Kaypay\Sdk\Api\OrderApi($signer);

对于沙盒环境

$sandbox = new \Kaypay\Sdk\SandboxConfiguration();
$api = new \Kaypay\Sdk\Api\OrderApi($signer, null, $sandbox);

创建 Kaypay 订单

// prepare the request body with order details
// `$merchantRefId` will be used in webhook callbacks to identify orders
$requestBody = (new \Kaypay\Sdk\Model\OrderCreateRequestBody())
    ->setMerchantCode($merchantCode)
    ->setMerchantRefId($merchantRefId)
    ->setTotalAmount(1000000);

// send the API request
$result = $this->api->postV1Orders($requestBody);

// redirect user to start the payment flow
$redirectUrl = $result->getData()->getRedirectUrl();