PHP code example of adnane-ka / omnipay-sepay

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

    

adnane-ka / omnipay-sepay example snippets


use Omnipay\Omnipay;

$gateway = Omnipay::create('Sepay');
$gateway->setApiKey('YOUR_API_KEY');
$gateway->setBankAccountNumber('YOUR_BANK_ACCOUNT_NUMBER');
$gateway->setBankName('YOUR_BANK_NAME');

$response = $gateway->purchase([
    'amount' => 100000, // the amount in VND
    'checkoutUrl' => 'http://localhost:8000/checkout.php', // the page where the QR image is displayed
    'returnUrl' => 'http://localhost:8000/complete.php', // the URL to return to after the operation is fully proccessed
    'transactionId' => uniqid() // A unique identifier for the operation
])->send();

if ($response->isRedirect()) {
    // The QR code is generated successfully and you're ready to be redirected to checkout
    $response->redirect(); 
} else {
    // An error occured
    echo $response->getMessage();
}

$response = $gateway->completePurchase([
    'transactionId' => 'FGJAKANMCHK', // This should be retrieved from request redirect
    'amount' => 100000, // Locate this from your system 
    'webhookResponse' => /*This should be located from the webhook*/ 
    json_decode('{
        "id": 92704,                              
        "gateway":"Vietcombank",                  
        "transactionDate":"2024-07-25 14:02:37",  
        "accountNumber":"0010000000355",             
        "code":null,                              
        "content":"chuyen tien mua iphone",        
        "transferType":"in",                      
        "transferAmount":100000,                 
        "accumulated":19077000,                    
        "subAccount":null,                         
        "referenceCode":"MBVCB.3278907687",       
        "description":"FGJAKANMCHK"
    }', true)
])->send();

if($response->isSuccessful()){
    // Payment was successful and charge was captured
    // $response->getData()
    // $response->getTransactionReference() // payment reference
}else{
    // Charge was not captured and payment failed
    // $response->getData()
}
html
<!-- The return URL is going be injected as encoded URL `completeUrl` -->
<form action=" echo urldecode($_GET['completeUrl']);