Get Charged Pay Express Payment Gateway Documentation

Payer

If payer wants to fund payments using Get Charged Pay, set payer to Get Charged Pay.
(Other payment method ex: paypal, stripe, coinpayments etc not available yet).

Amount

Specify a payment amount and the currency.

Transaction

It’s a Transaction resource where amount object has to set.

RedirectUrls

Set the urls where buyer should redirect after transaction is completed or cancelled.

payment

It’s a payment resource where all Payer, Amount, RedirectUrls and Credentials of merchant (Client ID and Client Secret) have to set. After initialized into payment object, need to call create method. It will generate a redirect URL. Users have to redirect into this URL to complete the transaction.


Installation Instruction :

Click download for the package download

Now, go to php-sdk/src/GetChargedPay/Rest/Connection.php, then change BASE_URL value to your domain name
(i.e: If the domain is - 'your-domain.com' then, define( 'BASE_URL' , 'http://your-domain.com/' ) )

Example :
    require 'vendor/autoload.php';

    //if you want to change the namespace/path from 'GetChargedPay' - lines[1-5] - to your desired name,
    i.e. (use GetChargedPay\Api\Amount; to use MyDomain\Api\Amount;), then you must change the folders name that holds
    the API classes as well as change the property 'GetChargedPay' in (autoload->psr-0) of (php-sdk/composer.json) file to your
    desired name and run "composer dump-autoload" command from sdk root

    use GetChargedPay\Api\Amount;
    use GetChargedPay\Api\Payer;
    use GetChargedPay\Api\Payment;
    use GetChargedPay\Api\RedirectUrls;
    use GetChargedPay\Api\Transaction;

    //Payer Object
    $payer = new Payer();
    $payer->setPaymentMethod('all'); //set getchargedpay for wallet only
    $payer->setOrderNo('1234');
    $payer->setItemName('Test Item');
    $payer->setFirstName('Customer First Name');
    $payer->setLastName('Customer Last Name');
    $payer->setEmail('Email Address');
    $payer->setPhone('Phone');

    //Amount Object
    $amountIns = new Amount();
    $amount = 1;
    $convenience_fee = 0; //convience fee purcent if you want to add a part of your merchant fee
    $total = $amount+(($amount*$convenience_fee)/100);
    $amountIns->setTotal($total)->setCurrency('INR'); //must give a valid currency code and must exist in merchant wallet list

    //Transaction Object
    $trans = new Transaction();
    $trans->setAmount($amountIns);

    //RedirectUrls Object
    $urls = new RedirectUrls();
    $urls->setSuccessUrl('http://localhost/getchargedpay_sdk/example-success.php') //success url - the merchant domain page, to redirect after successful payment, see sample example-success.php file in sdk root, example - http://example.com/example-success.php
    ->setCancelUrl('http://localhost/getchargedpay_sdk/example-failure.php'); //cancel url - the merchant domain page, to redirect after cancellation of payment, see sample example-success.php file in sdk root, example - http://example.com/example-failure.php

    //Payment Object
    $payment = new Payment();
    $payment->setCredentials([ //client id & client secret, see merchants->setting(gear icon)
    'client_id' => 'place your client id here', //must provide correct client id of an express merchant
    'client_secret' => 'place your client secret here' //must provide correct client secret of an express merchant
    ])->setRedirectUrls($urls)
    ->setPayer($payer)
    ->setTransaction($trans);

    try {
     $payment->create(); //create payment
     header("Location: ".$payment->getApprovedUrl()); //checkout url
    } catch (Exception $ex) {
     print $ex;
     exit;
    }

Success or Failure Handeling

     /*
    This is the sample success page.

    You must decode the response and get status - success (in case of failure status will be success), in the following pattern (as data is encrypted)

    and then you can do anything you desire, example - display the user success message or insert into your merchant domain's database

     */

    if ($_GET)
    {
        try {
            $encoded = json_encode($_GET, JSON_THROW_ON_ERROR);
        } catch (JsonException $e) {
            print_r($e);
        }

        try {
            $decoded = json_decode(base64_decode($encoded), TRUE, 512, JSON_THROW_ON_ERROR);
        } catch (JsonException $e) {
            print_r($e);
        }

        if ($decoded["status"] === 'success')
        if ($decoded["status"] === 'failure') //in case of failure
        {
            // do anything here, i.e. display to merchant domain pages or insert data into merchant domain's  database
            echo "Status => " . $decoded["status"] . "
"; echo "Transaction ID => " . $decoded["transaction_id"] . "
"; echo "Merchant => " . $decoded["merchant"] . "
"; echo "Currency => " . $decoded["currency"] . "
"; echo "Amount => " . $decoded["amount"] . "
"; echo "Fee => " . $decoded["fee"] . "
"; echo "Total =>" . $decoded["total"] . "
"; echo "Payment Method =>" . $decoded["payment_method"] . "
"; echo "Order No => " . $decoded["order_no"] . "
"; echo "Item Name => " . $decoded["item_name"] . "
"; echo "Customer First Name => " . $decoded["firstname"] . "
"; echo "Customer Last Name => " . $decoded["lastname"] . "
"; echo "Customer Email => " . $decoded["email"] . "
"; echo "Customer Phone => " . $decoded["phone"] . "
"; } }

Optional Instructions


If you don't see changes after configuring and extracting SDK, go to your SDK root and run the commands below:-

composer clear-cache

composer install

composer dump-autoload