kaypay/sdk

This is the Kaypay SDK for PHP

1.0.1 2022-11-11 02:28 UTC

This package is not auto-updated.

Last update: 2024-04-26 09:07:52 UTC


README

Installation

The recommended way to install Kaypay SDK for PHP is through Composer:

composer require kaypay/sdk

Usage

Setup API instance

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

For sandbox environment:

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

Create Kaypay order

// 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();