GithubHelp home page GithubHelp logo

payment's Introduction

Ajaxy Payment

Installation

composer require ajaxy/payment

Examples

//using paypal
$__URL__ = 'http://www.example.com';
$paypal = new \Ajaxy\Payment\Gateway\Paypal(array(
    'email' => '',
    'custom' => array('user_id' => ''),
    'notify_url' => $__URL__.'/validate_ipn.php',
    'return_url' => $__URL__,
    'cancel_return' => $__URL__
));

$paypal->addItem('test1', 10, 1);
$paypal->addItem('test2', 10, 3);
//print the form
$paypal->getForm(true);

//or echo the url
echo '<a href="'.$paypal->getRequestUrl(false).'">Pay</a>';

//using al mashreq bank
$__URL__ = "http://www.example.com";
$_SECURE_HASH_ = ''; //should be sent by the bank
$_MID_ = ''; //merchant id
$_ACCESS_CODE_ = ''; //access code

$almashreq = new \Ajaxy\Payment\Gateway\AlMashreq(array(

    'notify_url' => $__URL__.'/validate_mh.php',
    'return_url' => $__URL__.'/validate_mh.php',

    'order_number' => __ORDER__NO__,

    //pass any order info to the payment, you will receive this back
    'custom' => array('test' => 1),

    //the order total, maximum of 2 decimal places
    'total' => '321',

    //sandbox or live
    'mode' => 'sandbox',

    //merchant details, those details are sent by the bank
    'endpoint' => 'https://migs.mastercard.com.au',
    'access_code' => $_ACCESS_CODE_,
    'merchant' => $_MID_,
    'currency_code' => 'AED',
    'secure_hash' => $_SECURE_HASH_,

));

//print the form
$almashreq->getForm(true);

//or echo the url
echo '<a href="'.$almashreq->getRequestUrl(false, true).'">Pay</a>';

Validation

//you will receive the response at the return_url you have set before
//al mashreq
$response = new \Ajaxy\Payment\Gateway\AlMashreq\Response(_SECURE_HASH_, null);
if($response->validate()){
    $custom = $response->getCustom();
    print_r($custom);
    echo 'payment is valid';
}else{
    $code = $response->getResponseCode();
    echo $response->getResultDescription($code);
}

//paypal
$ipn = new \Ajaxy\Payment\Gateway\Paypal\IPN('php://input', true);
if($ipn->validate()){
    echo "valid";
}else{
    echo "failed";
}

//you can also pass a psr4 logger to log the response

use \Ajaxy\Logger\Logger;
use \Ajaxy\Logger\Handler\Stream;

$log = new Logger();
$log->addHandler(new Stream(dirname(__FILE__).'/log/'));
$ipn = new \Ajaxy\Payment\Gateway\Paypal\IPN('php://input', true, $log);

$response = new \Ajaxy\Payment\Gateway\AlMashreq\Response(_SECURE_HASH_, null, $log);

About

Requirements

  • Ajaxy\Logger works with PHP 5.6 or above.

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub

Author

Naji Amer - [email protected] - http://ajaxy.org

License

Ajaxy\Payment is licensed under the MIT License - see the LICENSE file for details

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.