PHP code example of opsofts / laravel-tgipay

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

    

opsofts / laravel-tgipay example snippets


use Opsofts\LaravelTgipay\Facades\Tgipay;

// Initialize a transaction (initiate + get checkout URL in one call)
$transaction = Tgipay::initializeTransaction([
    'customerFirstName' => $customer->first_name,
    'customerLastName' => $customer->last_name,
    'customerEmail' => $customer->email,
    'amount' => 1000, // decimal Naira, NOT kobo
    'transactionReference' => (string) Str::uuid(), // you generate this
    'currency' => 'NGN', // the only currency TGIPay's docs currently mention
]);
// redirect the payer to $transaction['data']['url']

// ...or do it in two explicit steps if you want to store the reference
// between initiating and generating the checkout link:
Tgipay::initiatePayment($payload);
$transaction = Tgipay::getPaymentUrl($payload['transactionReference']);

// After the customer returns via your callback URL, ALWAYS verify
// server-side before giving value -- see "What's missing" below for why
// this step is not optional with TGIPay specifically.
$result = Tgipay::verifyTransaction($transactionReference);

if ($result['data']['paymentStatus'] === 'completed') {
    // mark the order/payment as paid
}