PHP code example of pralhadstha / omnipay-fonepay

1. Go to this page and download the library: Download pralhadstha/omnipay-fonepay 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/ */

    

pralhadstha / omnipay-fonepay example snippets


    use Omnipay\Omnipay;
    use Exception;

    $gateway = Omnipay::create('Fonepay_FonepayQr');

    $gateway->setUsername('fonepay_username_or_email');
    $gateway->setPassword('fonepay_password');
    $gateway->setMerchantCode('merchant_code_provided_by_fonepay');
    $gateway->setTestMode(false);

    try {
        $response = $gateway->purchase([
            'amount' => 1000.00,
            'productNumber' => "PN-100",
            'remarks1' => "Remark 1",
            'remarks2' => "Remark 2 if needed",
        ])->send();

        if ($response->isCustomRedirect()) {
            // provide the page to display the QR code.
        }
    } catch (Exception $e) {
        return $e->getMessage();
    }

    $gateway = Omnipay::create('Fonepay_FonepayQr');

    $gateway->setUsername('fonepay_username_or_email');
    $gateway->setPassword('fonepay_password');
    $gateway->setMerchantCode('merchant_code_provided_by_fonepay');
    $gateway->setTestMode(false);

    try {
        $response = $gateway->completePurchase([
            'productNumber' => "PN-100",
        ])->send();

        if ($response->isSuccessful()) {
            // Payment is successful and will have fonepayTraceId.
        } else {
            // Payment is received as failed and need to again check if payment is completed.
        }
    } catch (Exception $e) {
        return $e->getMessage();
    }