PHP code example of n1ghtwind / otpsimplepay

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

    

n1ghtwind / otpsimplepay example snippets


"   ...
    "taki47/otpsimplepay": "^1.0.0"
    ...
},
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/taki47/otpsimplepay"
    }
],

OTP_PAYMENT_CURRENCY="HUF"
OTP_PAYMENT_LANG="HU"
OTP_PAYMENT_HUF_MERCHANT="PUBLICTESTHUF"
OTP_PAYMENT_HUF_SECRET_KEY="FxDa5w314kLlNseq2sKuVwaqZshZT5d6"
OTP_PAYMENT_RETURN_URL="${APP_URL}/payResult"
OTP_PAYMENT_TIMEOUT_IN_SEC="600"
OTP_PAYMENT_LOG=true
OTP_PAYMENT_LOG_CHANNEL="simplePay"
OTP_PAYMENT_SANDBOX=true

use Taki47\Otpsimplepay\SimplePayStart;

class PublicController extends Controller
{
    public function PayStart()
    {
        $simplePay = new SimplePayStart();

        //TWO STEP AUTH
        $simplePay->addData("twoStep", false);
                
        // ORDER REFERENCE NUMBER
        // uniq oreder reference number in the merchant system
        $simplePay->addData('orderRef', str_replace(array('.', ':', '/'), "", @$_SERVER['SERVER_ADDR']) . @date("U", time()) . rand(1000, 9999));

        // customer's registration mehod
        // 01: guest
        // 02: registered
        // 05: third party
        $simplePay->addData('threeDSReqAuthMethod', '02');

        // EMAIL
        // customer's email
        $simplePay->addData('customerEmail', "[email protected]");

        // METHODS
        // CARD or WIRE
        $simplePay->addData('methods', array('CARD'));

        //ORDER ITEMS
        $simplePay->addItems(
            array(
                'ref' => "Test product 1",
                'title' => "Test product 1",
                'description' => 'Test product description',
                'amount' => "2",
                'price' => "12000",
                'tax' => '0',
                )
        );

        // SHIPPING COST
        $simplePay->addData('shippingCost', "450");
        
        // INVOICE DATA
        $simplePay->addGroupData('invoice', 'name', "Test Kft.");
        $simplePay->addGroupData('invoice', 'company', "Test Kft.");
        $simplePay->addGroupData('invoice', 'country', "Hungary");
        $simplePay->addGroupData('invoice', 'state', "Budapest");
        $simplePay->addGroupData('invoice', 'city', "Budapest");
        $simplePay->addGroupData('invoice', 'zip', "1111");
        $simplePay->addGroupData('invoice', 'address', "Teszt road 11.");

        // DELIVERY DATA
        $simplePay->addGroupData('delivery', 'name', "Test Kft.");
        $simplePay->addGroupData('delivery', 'company', "Test Kft.");
        $simplePay->addGroupData('delivery', 'country', "Hungary");
        $simplePay->addGroupData('delivery', 'state', "Budapest");
        $simplePay->addGroupData('delivery', 'city', "Budapest");
        $simplePay->addGroupData('delivery', 'zip', "1111");
        $simplePay->addGroupData('delivery', 'address', "Teszt road 11.");
        $simplePay->addGroupData('delivery', 'phone', "+3611111111");

        //create transaction in SimplePay system
        $simplePay->runStart();

        $returnData = $simplePay->getReturnData();

        return redirect($returnData["paymentUrl"]);
    }
}

use Taki47\Otpsimplepay\SimplePayBack;

class PublicController extends Controller
{
    public function PayBack(Request $request)
    {
        $simplePayBack = new SimplePayBack();

        $result = array();
        if (isset($request->r) && isset($request->s)) {
            if ($simplePayBack->isBackSignatureCheck($request->r, $request->s)) {
                $result = $simplePayBack->getRawNotification();
            }
        }

        /**
         * DO SOMETHING WITH $result ARRAY
         */
    }
}