PHP code example of rmscms / payment

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

    

rmscms / payment example snippets


return [
    'default' => env('PAYMENT_GATEWAY', 'sandbox'),
    'currency' => 'IRT',
    'amount_scale' => 1,
    'callback_url' => '/payment/callback',
    'certificates_path' => storage_path('payment/certs'),
    'admin' => [
        'enabled' => env('PAYMENT_ADMIN_ENABLED', true),
        'prefix' => env('PAYMENT_ADMIN_PREFIX', 'payment'),
        'route_name' => 'payment',
    ],
    'gateways' => [
        'sandbox' => [
            'driver' => RMS\Payment\Gateways\SandboxGateway::class,
            'merchant_id' => env('PAYMENT_SANDBOX_MERCHANT'),
            'secret_key' => env('PAYMENT_SANDBOX_SECRET'),
            'mode' => 'form',
            'title' => 'Sandbox Gateway',
            'migrations' => [
                // 'packages/rms/payment/database/migrations'
            ],
        ],
        'zarinpal' => [
            'driver' => RMS\Payment\Gateways\ZarinpalGateway::class,
            'merchant_id' => env('PAYMENT_ZARINPAL_MERCHANT'),
            'sandbox' => env('PAYMENT_ZARINPAL_SANDBOX', true),
            'description' => env('PAYMENT_ZARINPAL_DESCRIPTION', 'پرداخت اینترنتی'),
            'default_currency' => 'IRT',
            'title' => 'زرین‌پال',
            'migrations' => [
                'packages/rms/payment/database/migrations',
            ],
        ],
        // بانک‌های دیگر...
    ],
];

use RMS\Payment\DTO\PaymentRequest;
use RMS\Payment\Facades\Payment;

$request = new PaymentRequest(
    orderId: 'ORDER-10023',
    amount: 250000,
    currency: 'IRT',
    callbackUrl: route('payments.callback'),
    customerName: 'Ali Customer',
    customerMobile: '09120000000',
    description: 'پرداخت سفارش 10023',
    metadata: ['email' => '[email protected]']
);

$init = Payment::start($request); // InitializationResult

if ($init->successful) {
    return redirect()->away($init->redirectUrl);
}

$result = Payment::verify($request->all());

if ($result->successful) {
    // ثبت سفارش قطعی
} else {
    // نمایش خطا و لغو تراکنش
}

   'gateways' => [
       'zarinpal' => [
           'driver' => App\Payment\Gateways\ZarinpalGateway::class,
           'merchant_id' => env('ZARINPAL_MERCHANT'),
           'sandbox' => false,
       'mode' => 'form',
       'cert_path' => storage_path('payment/certs/zarinpal'),
           'migrations' => [
               'database/migrations/payment/zarinpal',
           ],
       ],
   ],
   
bash
php artisan payment:install
bash
php artisan payment:install --driver=zarinpal
bash
   php artisan vendor:publish --provider="RMS\Payment\PaymentServiceProvider" --tag=payment-config
   
bash
   php artisan migrate --path=packages/rms/payment/database/migrations
   
bash
   php artisan payment:install-driver zarinpal
   
bash
php artisan payment:install-driver        # استفاده از درایور پیش‌فرض
php artisan payment:install-driver zarinpal