Giter Site home page Giter Site logo

getloy / getloy-php Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 4.0 37 KB

PHP library for the GetLoy Payment Integration API.

Home Page: https://getloy.com/

License: GNU General Public License v3.0

PHP 100.00%
api-client cambodia online-payments payment-integration php composer credit-card wallet payment payment-methods

getloy-php's Introduction

GetLoy Integration Library for PHP

Latest Stable Version Scrutinizer Code Quality Total Downloads License

The GetLoy Integration Library provides an easy way to access the GetLoy API from applications written in PHP.

The library currently supports the following payment methods:

  • iPay88 Cambodia (all supported payment methods)
  • Pi Pay
  • PayWay by ABA Bank (debit/credit card only, ABA Pay only, debit/credit card only, or both)

Requirements

PHP 5.6.0 or later.

Composer

You can install the bindings via Composer. Run the following command:

composer require getloy/getloy-php

To use the bindings, use Composer's autoload:

require_once('vendor/autoload.php');

Manual Installation

If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the init.php file.

require_once('/path/to/getloy-php/init.php');

Getting Started

A simple usage example:

$gateway = new \Getloy\Gateway('YOUR GETLOY TOKEN');
$gateway->registerPaymentProvider(
    \Getloy\PaymentProviders::PIPAY_KH,
    [
        'testMode' => true,
        'merchantId' => 'YOUR PIPAY MERCHANT ID',
        'storeId' => 'YOUR PIPAY STORE ID',
        'deviceId' => 'YOUR PIPAY DEVICE ID',
    ]
);

$order = new \Getloy\TransactionDetails\OrderDetails(99.99, 'USD');
$payee = new \Getloy\TransactionDetails\PayeeDetails('John', 'Doe', '[email protected]', '012345678');

echo $gateway->widgetHtml(
    'ORDER-123',
    \Getloy\PaymentProviders::PIPAY_KH,
    $order,
    $payee,
    'https://mysite.com/payment-callback.php',
    'https://mysite.com/pages/payment-complete/'
    'https://mysite.com/pages/payment-failed/'
);

Passing additional order details

Most payment systems will display additional order details such as the order line items in the payment interface. This information can be provided in the widgetHtml() call.

$orderItems = new \Getloy\TransactionDetails\OrderItems();

$orderItems->add(
    new \Getloy\TransactionDetails\OrderItem('Item 1', 2, 19.98, 9.99)
);
$orderItems->add(
    new \Getloy\TransactionDetails\OrderItem('Item 2', 1, 12.50, 12.50)
);

$order = new \Getloy\TransactionDetails\OrderDetails(32.48, 'USD', null, $orderItems);

Callback validation

Getloy will make a POST request to the callback URL provided in the widgetHtml() call once the payment was confirmed, but before the user is redirected to the success URL.

The callback content is validated against a hash value that includes the (secret) GetLoy Token.

The following example, $order and lookupOrder() are placeholders for objects/methods provided by your application.

$gateway = new \Getloy\Gateway('YOUR GETLOY TOKEN');

if ('POST' !== $_SERVER['REQUEST_METHOD']) {
    // unsupported request type
    return;
}

try {
    $callbackDetails = $gateway->readCallbackBodyAndParse();
} catch (Exception $exception) {
    // log invalid callback
    return;
}

if (Getloy\CallbackDetails::STATUS_SUCCESS !== $callbackDetails->status()) {
    // log invalid transaction status
    return;
}

// look up the order details using the transaction ID
$order = lookupOrder($callbackDetails->transactionId());

if (
    abs($order->amountPaid - $callbackDetails->amountPaid()) > 0.01
    || $order->currency !== $callbackDetails->currency()
) {
    // log transaction amount/currency mismatch
    return;
}

// update the order status to paid
$order->updateStatus('paid');

If you are developing your application locally, you can use a service like ngrok to redirect callbacks from GetLoy to your local webserver.

getloy-php's People

Contributors

jan-san avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.