PHP code example of osa-eg / laravel-upayments

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

    

osa-eg / laravel-upayments example snippets




return [
    'api_key'           => env('UPAYMENTS_API_KEY', ''), // Your Upayments API key
    'api_base_url'      => env('UPAYMENTS_API_URL', 'https://sandboxapi.upayments.com'),
    'logging_channel'   => env('UPAYMENTS_LOGGING_CHANNEL', 'stack'),
    'logging_enabled'   => env('UPAYMENTS_LOGGING_ENABLED', true),
];

'channels' => [
    // Other channels...
    'upayments' => [
        'driver' => 'single',
        'path' => storage_path('logs/upayments.log'),
        'level' => 'info',
    ],
],

    use Upayment;

    $response = Upayments::addProduct('Test Product', 'Description', 100.0, 1)
        ->setOrder([
            'id' => 'ORD123',
            'reference' => 'REF123',
            'description' => 'Order Description',
            'currency' => 'USD',
            'amount' => 100.0,
        ])
        ->setCustomer([
            'uniqueId' => 'CUST123',
            'name' => 'John Doe',
            'email' => '[email protected]',
            'mobile' => '+1234567890',
        ])
        ->setPaymentGateway('knet')
        ->setReturnUrl('https://example.com/return')
        ->setCancelUrl('https://example.com/cancel')
        ->setNotificationUrl('https://example.com/notify')
        ->setReference('REF123')
        ->setLanguage('en')
        ->markAsWhiteLabeled() // or markAsNonWhiteLabeled()
        ->createPayment();
    
    if ($response['status']) {
        echo "Payment link: " . $response['data']['link'];
    } else {
        echo "Error: " . $response['error']['message'];
    }
    

    $response = Upayments::getPaymentStatus('ORD123', 'trackId');
    

    $response = Upayments::createRefund('ORD123', 50.0, [
        'customerFirstName' => 'John',
        'customerEmail' => '[email protected]',
        'reference' => 'REF12345',
        'notifyUrl' => 'https://example.com/refund-notify'
    ]);
    

    $response = Upayments::addRefundVendor([
            'refundRequestId' => 'REF123',
            'ibanNumber' => 'KW91KFHO0000000000051010173254',
            'totalPaid' => '100.0',
            'refundedAmount' => 0.0,
            'remainingLimit' => 100.0,
            'amountToRefund' => 10.0,
            'merchantType' => 'vendor'
        ])
        ->addRefundVendor([
            'refundRequestId' => 'REF124',
            'ibanNumber' => 'KW31NBOK0000000000002010177457',
            'totalPaid' => '200.0',
            'refundedAmount' => 0.0,
            'remainingLimit' => 200.0,
            'amountToRefund' => 20.0,
            'merchantType' => 'vendor'
        ])
        ->createMultiVendorRefund('ORD123', [
            'reference' => 'REF12345',
            'notifyUrl' => 'https://example.com/multi-refund-notify'
        ]);
    
bash
    php artisan vendor:publish --provider="Osama\Upayments\Providers\UpaymentsServiceProvider" --tag="config"