PHP code example of nuocgansoi / laravel-onepay

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

    

nuocgansoi / laravel-onepay example snippets


const STATUS_PENDING = 1;
const STATUS_PROCESSING = 2;
const STATUS_PAID = 3;
const STATUS_REJECTED = 4;
const STATUS_CANCELED = 5;
const STATUS_REFUNDED = 9;

return [
    'version' => env('ONEPAY_VERSION', 2),
    'do_url' => env('ONEPAY_DO_URL', 'https://mtf.onepay.vn/onecomm-pay/vpc.op'),
    'return_url' => env('ONEPAY_RETURN_URL', 'http://localhost/return'),
    'ipn_url' => env('ONEPAY_IPN_URL', 'http://localhost/ipn'),
    'merchant_id' => env('ONEPAY_MERCHANT_ID', 'ONEPAY'),
    'access_code' => env('ONEPAY_ACCESS_CODE', 'D67342C2'),
    'secure_secret' => env('ONEPAY_SECURE_SECRET', 'A3EFDFABA8653DF2342E8DAC29B51AF0'),
    'command' => env('ONEPAY_COMMAND', 'pay'),
    'currency' => env('ONEPAY_CURRENCY', 'VND'),
    'locale' => env('ONEPAY_LOCALE', 'vn'),
    'title' => env('ONEPAY_TITLE', 'OnePay Gate'),
    'amount_exchange' => env('ONEPAY_AMOUNT_EXCHANGE', 100),
    'shop' => [
        'book' => [
            'model' => App\Book::class,
            'price' => 'price',
            'order' => [
                'model' => App\BookOrder::class,
                'customer_id' => 'user_id',
                'item_id' => 'book_id',
                'status' => [
                    'attribute' => 'status',
                    'pending' => App\BookOrder::STATUS_PENDING,
                    'processing' => App\BookOrder::STATUS_PROCESSING,
                    'paid' => App\BookOrder::STATUS_PAID,
                    'canceled' => App\BookOrder::STATUS_CANCELED,
                    'rejected' => App\BookOrder::STATUS_REJECTED,
                ],
            ],
        ],
    ],
];

$view = $validator['success'] ? 'onepay::success' : 'onepay::failed';

return view($view, [
    'model' => $model,
    'message' => $validator['message'],
    'response' => $request->all(),
]);

Schema::create('onepay_payments', function (Blueprint $table) {
    $table->increments('id');
    $table->unsignedInteger('order_id')->nullable();
    $table->string('order_type')->nullable();
    $table->unsignedInteger('user_id')->nullable();
    $table->string('item_type')->nullable();
    $table->unsignedInteger('item_id')->nullable();
    $table->tinyInteger('status')->default(\NuocGanSoi\LaravelOnepay\Models\OnepayPayment::STATUS_PENDING);
    $table->string('access_code', 8);
    $table->string('currency', 3);
    $table->string('command', 16);
    $table->string('locale', 2);
    $table->string('merchant', 12);
    $table->string('return_url', 64);
    $table->string('version', 2);
    $table->string('amount', 21);
    $table->string('merch_txn_ref', 40)->index();
    $table->string('order_info', 40);
    $table->string('ticket_no', 16);
    $table->string('secure_hash', 64);
    $table->text('url')->nullable();
    $table->timestamps();
});
Schema::create('onepay_results', function (Blueprint $table) {
    $table->increments('id');
    $table->string('addition_data')->nullable();
    $table->string('amount', 21);
    $table->string('command', 16);
    $table->string('currency_code', 3);
    $table->string('locale', 2);
    $table->string('merch_txn_ref', 40)->index();
    $table->string('merchant', 12);
    $table->string('order_info', 40);
    $table->string('transaction_no', 12);
    $table->string('txn_response_code', 64);
    $table->string('version', 2)->nullable();
    $table->string('message', 200)->nullable();
    $table->string('secure_hash', 64);
    $table->text('response')->nullable();
    $table->timestamps();
});
Schema::create('onepay_ipns', function (Blueprint $table) {
    $table->increments('id');
    $table->string('addition_data')->nullable();
    $table->string('amount', 21);
    $table->string('command', 16);
    $table->string('currency_code', 3);
    $table->string('locale', 2);
    $table->string('merch_txn_ref', 40)->index();
    $table->string('merchant', 12);
    $table->string('order_info', 40);
    $table->string('transaction_no', 12);
    $table->string('txn_response_code', 64);
    $table->string('version', 2)->nullable();
    $table->string('message', 200)->nullable();
    $table->string('secure_hash', 64);
    $table->text('response')->nullable();
    $table->timestamps();
});