PHP code example of mdiqbal / laravel-payments

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

    

mdiqbal / laravel-payments example snippets


return [
    'default' => env('PAYMENT_DEFAULT_GATEWAY', 'stripe'),

    'gateways' => [
        'stripe' => [
            'mode' => env('STRIPE_MODE', 'sandbox'),
            'sandbox' => [
                'secret_key' => env('STRIPE_SANDBOX_SECRET'),
                'api_key' => env('STRIPE_SANDBOX_KEY'),
            ],
            'live' => [
                'secret_key' => env('STRIPE_LIVE_SECRET'),
                'api_key' => env('STRIPE_LIVE_KEY'),
            ],
            'webhook_secret' => env('STRIPE_WEBHOOK_SECRET'),
        ],

        'paypal' => [
            'mode' => env('PAYPAL_MODE', 'sandbox'),
            'sandbox' => [
                'client_id' => env('PAYPAL_SANDBOX_CLIENT_ID'),
                'client_secret' => env('PAYPAL_SANDBOX_CLIENT_SECRET'),
            ],
            'live' => [
                'client_id' => env('PAYPAL_LIVE_CLIENT_ID'),
                'client_secret' => env('PAYPAL_LIVE_CLIENT_SECRET'),
            ],
            'webhook_id' => env('PAYPAL_WEBHOOK_ID'),
        ],

        // ... other gateways
    ],
];

use Mdiqbal\LaravelPayments\Facades\Payment;
use Mdiqbal\LaravelPayments\DTO\PaymentRequest;

// Create a payment request
$paymentRequest = new PaymentRequest(
    amount: 100.00,
    currency: 'USD',
    description: 'Payment for Order #12345'
);

// Set optional parameters
$paymentRequest->setTransactionId('order_' . uniqid());
$paymentRequest->setReturnUrl(route('payment.success'));
$paymentRequest->setCancelUrl(route('payment.cancel'));

// Process payment with default gateway
$response = Payment::pay($paymentRequest);

// Or process with a specific gateway
$response = Payment::gateway('stripe')->pay($paymentRequest);

// Handle response
if ($response->isSuccess()) {
    if ($response->isRedirect()) {
        return redirect($response->getRedirectUrl());
    }

    $transactionId = $response->getTransactionId();
    // Save transaction ID to database
} else {
    $errorMessage = $response->getMessage();
    // Handle error
}

use Mdiqbal\LaravelPayments\Facades\Payment;

$transactionId = 'txn_1234567890';
$response = Payment::gateway('stripe')->retrievePayment($transactionId);

if ($response->isSuccess()) {
    $status = $response->getData()['status'];
    $amount = $response->getData()['amount'];
    // Update order status
}

use Mdiqbal\LaravelPayments\Facades\Payment;

$transactionId = 'txn_1234567890';
$refundAmount = 50.00;
$reason = 'Customer requested refund';

try {
    $success = Payment::gateway('stripe')->refund($transactionId, $refundAmount, $reason);

    if ($success) {
        // Refund processed successfully
    }
} catch (\Exception $e) {
    // Handle refund failure
}

$response = Payment::gateway('stripe')->pay($paymentRequest);
$clientSecret = $response->getData()['client_secret'];

$response = Payment::gateway('paypal')->pay($paymentRequest);
$approvalUrl = $response->getRedirectUrl();

$response = Payment::gateway('paystack')->pay($paymentRequest);
$authorizationUrl = $response->getRedirectUrl();

$response = Payment::gateway('razorpay')->pay($paymentRequest);
$orderId = $response->getData()['id'];

$response = Payment::gateway('paytm')->pay($paymentRequest);
$txnToken = $response->getData()['txnToken'];

$response = Payment::gateway('flutterwave')->pay($paymentRequest);
$paymentLink = $response->getRedirectUrl();

$response = Payment::gateway('sslcommerz')->pay($paymentRequest);
$gatewayUrl = $response->getRedirectUrl();

$response = Payment::gateway('mollie')->pay($paymentRequest);
$checkoutUrl = $response->getRedirectUrl();

$response = Payment::gateway('senangpay')->pay($paymentRequest);
$paymentUrl = $response->getRedirectUrl();

$response = Payment::gateway('bkash')->pay($paymentRequest);
$paymentID = $response->getData()['paymentID'];

$response = Payment::gateway('mercadopago')->pay($paymentRequest);
$initPoint = $response->getData()['init_point'];

$response = Payment::gateway('cashfree')->pay($paymentRequest);
$paymentLink = $response->getRedirectUrl();

$response = Payment::gateway('payfast')->pay($paymentRequest);
$redirectUrl = $response->getRedirectUrl();

$response = Payment::gateway('skrill')->pay($paymentRequest);
$sessionId = $response->getData()['sessionid'];

$response = Payment::gateway('phonepe')->pay($paymentRequest);
$paymentUrl = $response->getRedirectUrl();

$response = Payment::gateway('telr')->pay($paymentRequest);
$orderUrl = $response->getRedirectUrl();

$response = Payment::gateway('iyzico')->pay($paymentRequest);
$paymentPageUrl = $response->getData()['paymentPageUrl'];

$response = Payment::gateway('pesapal')->pay($paymentRequest);
$redirectUrl = $response->getRedirectUrl();

$response = Payment::gateway('midtrans')->pay($paymentRequest);
$redirectUrl = $response->getRedirectUrl();

$response = Payment::gateway('myfatoorah')->pay($paymentRequest);
$invoiceURL = $response->getData()['InvoiceURL'];

$response = Payment::gateway('easypaisa')->pay($paymentRequest);
$transactionUrl = $response->getRedirectUrl();
bash
php artisan vendor:publish --provider="Mdiqbal\LaravelPayments\PaymentsServiceProvider"