PHP code example of notchpay / notchpay-php

1. Go to this page and download the library: Download notchpay/notchpay-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

notchpay / notchpay-php example snippets


use NotchPay\NotchPay;
use NotchPay\Payment;

NotchPay::setApiKey('sk_1234abcd');

try {
    $tranx = Payment::initialize([
        'amount'=>$amount,       // according to currency format
        'email'=>$email,         // unique to customers
        'currency'=>$currency,         // currency iso code
        'callback'=>$callback,         // optional callback url
        'reference'=>$reference, // unique to transactions
    ]);
} catch(\NotchPay\Exceptions\ApiException $e){
    print_r($e->errors);
    die($e->getMessage());
}
// redirect to page so User can pay
header('Location: ' . $tranx->authorization_url);


    $reference = isset($_GET['reference']) ? $_GET['reference'] : '';
    if(!$reference){
      die('No reference supplied');
    }

    // initiate the Library's NotchPay Object
    NotchPay::setApiKey('sk_1234abcd');

    try {
    $tranx = Payment::verify($reference);

    if ($tranx->transaction->status === 'complete') {
      // transaction was successful...
      // please check other things like whether you already gave value for this ref
      // if the email matches the customer who owns the product etc
      // Give value
    }
} catch(\NotchPay\Exceptions\ApiException $e){
    print_r($e->errors);
    die($e->getMessage());
}

bash
composer