PHP code example of nikajorjika / bog-payment

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

    

nikajorjika / bog-payment example snippets


use Jorjika\BogPayment\Facades\Pay;
use App\Models\Transaction;

// Step 1: Create a transaction record
$transaction = Transaction::create([
    'user_id'    => auth()->id(),
    'amount'     => $data['total_amount'],
    'status'     => 'pending', // Initial status
]);

// Step 2: Process the payment
$paymentDetails = Pay::orderId($transaction->id)
    ->redirectUrl(route('bog.v1.transaction.status', ['transaction_id' => $transaction->id]))
    ->amount($transaction->amount)
    ->process();

// Step 3: Update the transaction with payment details
$transaction->update([
    'transaction_id'   => $paymentDetails['id'],
]);

// Step 4: Redirect user to the payment gateway
return redirect($paymentDetails['redirect_url']);

$paymentDetails = [
    'id' => 'test-id',
    'redirect_url' => 'https://example.com/redirect',
    'details_url' => 'https://example.com/details',
]

use Jorjika\BogPayment\Facades\Pay;

// SaveCard method will initiate another request that notifies bank to save card details
$response = Pay::orderId($external_order_id)->amount($amount)->saveCard()->process();

// Example response
$response = [
    'id' => 'test-id',
    'redirect_url' => 'https://example.com/redirect',
    'details_url' => 'https://example.com/details',
];

use Jorjika\BogPayment\Facades\Card;

$response = Card::orderId($external_order_id)->amount($amount)->charge("test-id");

// Example response
$response = [
    'id' => 'test-id',
    'redirect_url' => 'https://example.com/redirect',
    'details_url' => 'https://example.com/details',
];


getPayload(): // Retrieves the current payload array.

orderId($externalOrderId): // Sets the external order ID for the payment.

callbackUrl($callbackUrl): // Sets a custom callback URL for the payment process.

redirectUrl($statusUrl): // Sets both success and fail URLs to the same value for redirection after the payment.

redirectUrls($failUrl, $successUrl): // Sets separate fail and success URLs for redirection after the payment.

saveCard(): // Sets the save card flag to true for the payment.

amount($totalAmount, $currency = 'GEL', $basket = []): // Defines the total amount, currency, and optionally, the basket details for the payment.

// These methods allow for easy customization of the payment payload to suit various payment 

use Jorjika\BogPayment\Facades\Pay;

$buyer = [
    'full_name' => 'John Doe',
    'masked_email' => 'john**@gmail.com',
    'masked_phone' => '59512****10',
];
    
$paymentDetails = Pay::orderId($transaction->id)
            ->redirectUrl(route('bog.v1.transaction.status', ['transaction_id' => $transaction->id]))
            ->amount($data['total_amount'])
            ->buyer($buyer) // Set new buyer details
            ->process();

// Optionally you can set buyer details separately

$paymentDetails = Pay::orderId($transaction->id)
            ->redirectUrl(route('bog.v1.transaction.status', ['transaction_id' => $transaction->id]))
            ->amount($data['total_amount'])
            ->buyerName($buyer['full_name']) // Set new buyer full name
            ->buyerEmail($buyer['masked_email']) // Set new buyer masked email
            ->buyerPhone($buyer['masked_phone']) // Set new buyer masked phone
            ->process();

namespace App\Listeners;

use Nikajorjika\BogPayment\Events\TransactionStatusUpdated;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class HandleTransactionStatusUpdate implements ShouldQueue
{
use InteractsWithQueue;

    /**
     * Handle the event.
     *
     * @param  \Nikajorjika\BogPayment\Events\TransactionStatusUpdated  $event
     * @return void
     */
    public function handle(array $event)
    {
        // Implement your logic here
    }

use Jorjika\BogPayment\Facades\Transaction;

$transactionDetails = Transaction::get($order_id); // Returns array of transaction details
bash
php artisan vendor:publish --tag="bog-payment-config"
bash
config/bog-payment.php
bash
    php artisan make:listener HandleTransactionStatusUpdate --event=\Nikajorjika\BogPayment\Events\TransactionStatusUpdated