jrodella / payment-form-api
Common API to make Lyra payment platform integration easier in PHP based websites.
Requires
- php: >=5.3.0
Requires (Dev)
- php: >=5.3.0
- phpunit/phpunit: >=4.0
This package is auto-updated.
Last update: 2024-11-16 08:07:36 UTC
README
Lyra payment form API is an open source PHP SDK that allows integration of secured payment gateway developped by Lyra Network inside e-commerce websites.
Requirements
PHP 5.3.0 and later.
Installation
Composer
You can install the API via Composer. Run the following command:
composer require lyranetwork/payment-form-api
To use the API, 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 API, include the init.php
file.
require_once('/path/to/payment-form-api/init.php');
Usage
To create payment form do :
$ctxMode = 'TEST'; $keyTest = '1111111111111111'; $keyProd = '2222222222222222'; $algo = 'SHA-1'; $request = new \Lyranetwork\Request(); $request->set('ctx_mode', $ctxMode); $request->set('key_test', $keyTest); $request->set('key_prod', $keyProd); $request->set('sign_algo', $algo); $request->set('site_id', '12345678'); $request->set('amount', '100'); // amount in cents $request->set('currency', '978'); $request->set('capture_delay', ''); $request->set('validation_mode', ''); echo $request->getRequestHtmlForm(); // display generated payment form
To process payment result, do :
$keyTest = '1111111111111111'; $keyProd = '2222222222222222'; $algo = 'SHA-1'; $response = new \LyraNetwork\Response($_REQUEST, $keyTest, $keyProd, $algo); if (! $response->isAuthentified()) { // Unauthenticated response received die('An error occurred while computing the signature.'); } $order = get_my_order($response->get('order_id')); if ($response->isAcceptedPayment()) { // update order status, reduce products stock, send customer notifications, ... update_my_order($order, 'success'); // redirect to success page } elseif ($response->isCancelledPayment()) { // redirect to cart page to allow re-order } else { // failed payment logic here update_my_order($order, 'failed'); // redirect to failure or cart page }
License
Each Lyra payment form API source file included in this distribution is licensed under GNU GENERAL PUBLIC LICENSE (GPL 3.0).
Please see LICENSE file for the full text of the GPL 3.0 license. It is also available through the world-wide-web at this URL: http://www.gnu.org/licenses/.