yedpay/php-library

Agnostic Library to use the Yedpay API for Online Payment

1.4.2 2024-01-18 06:24 UTC

This package is auto-updated.

Last update: 2024-11-18 08:08:58 UTC


README

Build Status Coverage Status Latest Stable Version composer.lock

Yedpay Transaction PHP Library

Description

A PHP library for Precreate Transactions and Online Payments Using the Yedpay API

Prerequisites

In order to start using the API, you need to get Your Personal Access Token or API Key.

Installation

Installing Dependencies

composer require yedpay/php-library

Running the test

vendor/bin/phpunit

Integration

Request Method

  • Precreate
  • Online Payment
  • Refund
  • Refund by Custom ID
  • Query Online Payment

Result

  • Success
  • Error
  • Example Precreate Transaction Implementation

Input parameters

//mandatory parameters
$accessToken = 'J84OFPAN';
$storeId = '8X4LZW2XLG9V';
$amount = 1.0;
//optional parameter: extraParam (JSON)
$extraParam = json_encode([
    'customer_name' => 'Yed Pay',
    'phone' => '12345678',
]);

Create instance of Client

$client = new Client(Library::STAGING, $accessToken);

(Optional) Setting Transaction parameters

//changing transaction currency (default: HKD)
$client->setCurrency(Client::INDEX_CURRENCY_HKD);
//changing alipay wallet type (default: HK)
$client->setWallet(Client::INDEX_WALLET_CN);

Sending Precreate Request

// general 
$client->precreate($storeId, $amount);
// with extra parameters
$result = $client->precreate(
        $storeId, 
        $amount, 
        json_encode($extraParam)
)->getData();
  • Example Online Payment Implementation

Input parameters

//mandatory parameters
$apiKey = 'qPOcLJsNnnI2wzJdIsRULOwC//KZa+KGrarUIs1ZZa8=';
$customId = 'test-001';
$amount = 1.0;
$currency = 1;
$notifyUrl = 'https://www.example.com/notify';
$returnUrl = 'https://www.example.com/return';

Create instance of Client

$client = new Client(Library::STAGING, $apiKey, false);

(Optional) Setting Transaction parameters

//changing transaction currency (default: HKD)
$client->setCurrency(Client::INDEX_CURRENCY_HKD);

//set transaction gateway code
$client->setGatewayCode(Client::INDEX_GATEWAY_CODE_ALIPAY_ONLINE_PC2MOBILE);

//set transaction gateway wallet type (default: HK)
$client->setWallet(Client::INDEX_WALLET_CN);

//set production name of transaction
$client->setSubject('Product');

//set expiry time of transaction
$client->setExpiryTime(900);

//set metadata of online payment
$metadata = json_encode([
    'woocommerce' => '1.0',
    'yedpay_for_woocommerce' => '1.0',
    'wordpress' => '1.0',
]);
$client->setMetadata($metadata);

//set payment data of online payment
$paymentData = json_encode([
    'first_name' => 'Yedpay',
    'last_name' => 'Yedpay',
    'email' => 'info@example.com',
    'phone' => '12345678',
    'billing_country' => 'HK',
    'billing_city' => 'Hong Kong',
    'billing_address1' => 'Address1',
    'billing_address2' => 'Address2',
    'billing_post_code' => '000000',
]);
$client->setPaymentData($paymentData);

//set checkout domain key of online payment
$client->setCheckoutDomainId('J84OFPAN');

Sending Online Payment Request

$client->onlinePayment($customId, $amount)->getData();
  • Example Refund Transaction Implementation

Input parameters

//mandatory parameters
$transactionId = 'J84OFPAN';
//optional parameter: reason (String)
$reason = 'testing';

Create instance of Client

// with accessToken
$client = new Client(Library::STAGING, $accessToken);
// with apiKey
$client = new Client(Library::STAGING, $apiKey, false);

Sending Refund Request

// general 
$client->refund($transactionId)->getData();
// with reason
$client->refund($transactionId, $reason)->getData();
// with amount
$client->refund($transactionId, $reason, $amount)->getData();
  • Example Refund by Custom ID Implementation

Input parameters

//mandatory parameters
$customId = 'J84OFPAN';
//optional parameter: reason (String)
$reason = 'testing';

Create instance of Client

// with apiKey
$client = new Client(Library::STAGING, $apiKey, false);

Sending Refund by Custom ID Request

// general 
$client->refundByCustomId($customId)->getData();
// with reason
$client->refundByCustomId($customId, $reason)->getData();
// with amount
$client->refundByCustomId($customId, $reason, $amount)->getData();

For the complete Code Check the examples folder