mastani/laravel-idpay

IDPay payment gateway for Laravel https://idpay.ir

dev-master 2022-04-06 18:15 UTC

This package is auto-updated.

Last update: 2024-12-07 00:01:04 UTC


README

IDPay gateway in Laravel.

Total Downloads Latest Stable Version Latest Unstable Version License

Table of contents

Installation in Laravel 5.5 and up

$ composer require mastani/laravel-idpay

The package will automatically register itself.

Installation in Laravel 5.4

$ composer require mastani/laravel-idpay

Next up, the service provider must be registered:

// config/app.php

'providers' => [
    ...
    mastani\IDPay\IDPayServiceProvider::class,
];

Installation without Laravel

Another way is install the component through composer.

Either run

$ composer require mastani/laravel-idpay

or add

"mastani/laravel-idpay": "dev-master"

to the require section of your composer.json.

Usage

Request new payment

$pay = new IDPayPayment();
$response = $pay->setApiKey('IDPay API Key')
            ->setSandbox(true)
            ->setOrderID('10000') // Locally generated
            ->setCallback('https://my-website.com/callback')
            ->setPrice(50000)
            ->setName("Amin") // optional
            ->setPhone("09353361569") // optional
            ->setMail("amin@mail.com") // optional
            ->setDesc("Pay for bronze account") // optional
            ->request();
            
if ($response->is_successful) {
    // save payment details to database here
    
    return redirect()->to($response->link);
} else {
    // handle error
}
Successful response
[response_code] => 201
[is_successful] => true
[id] => 91cb30a55598f6dbdd0d4d7ad9613d88
[link] => https://idpay.ir/p/ws-sandbox/91cb30a55598f6dbdd0d4d7ad9613d88
Failed response
[response_code] => 406
[is_successful] => false
[error_code] => 34
[error_message] => مبلغ `amount` باید بیشتر از 10,000 ریال باشد

Handle callback result

$callback = new IDPayPaymentCallback($_POST);

if ($callback->is_successful) {
    echo 'Order: ' . $callback->orderId;
    echo 'Card Number: ' . $callback->cardNO;

    // verify payment with next method
} else {
    // handle error
}
Successful response
[is_successful] => false
[result] => "در انتظار تایید پرداخت"
[status] => "10"
[trackID] => "46868"
[ID] => "91cb30a55598f6dbdd0d4d7ad9613d88"
[orderID] => "10000"
[amount] => "50000"
[cardNO] => "123456******1234"
[date] => "1553961021"

Verify payment

$verify = new IDPayVerify();
$response = $verify->setApiKey('IDPay API Key')
            ->setSandbox(true)
            ->setID('91cb30a55598f6dbdd0d4d7ad9613d88')
            ->setOrderID('10000')
            ->request();
            
if ($response->is_successful) {
    echo 'Order: ' . $response->order_id;
    echo 'Card Number: ' . $response->payment->card_no;
    
    // handle user credit here
} else {
    // handle error
}
Successful response
[response_code] => 200
[is_successful] => true
[status] => 101
[track_id] => 46826
[id] => 91cb30a55598f6dbdd0d4d7ad9613d88
[order_id] => 10000
[amount] => 50000
[date] => 1553954369
[payment] => stdClass Object
(
    [track_id] => 59670764
    [amount] => 50000
    [card_no] => 123456******1234
    [date] => 1553954369
)
[verify] => stdClass Object
(
    [date] => 1553954623
)
Failed response
[response_code] => 405
[is_successful] => false
[error_code] => 53
[error_message] => تایید پرداخت امکان پذیر نیست.

Inquiry an old payment

$inquiry = new IDPayInquiry();
$response = $inquiry->setApiKey('IDPay API Key')
            ->setSandbox(true)
            ->setID('91cb30a55598f6dbdd0d4d7ad9613d88')
            ->setOrderID('10000')
            ->request();
            
if ($response->is_successful) {
    // handle success here
    
    echo 'Order: ' . $response->order_id;
    echo 'Card Number: ' . $response->payment->card_no;
} else {
    // handle error
}
Successful response
[response_code] => 200
[is_successful] => true
[status] => 100
[track_id] => 46826
[id] => 91cb30a55598f6dbdd0d4d7ad9613d88
[order_id] => 10000
[amount] => 50000
[wage] => stdClass Object
(
    [by] => payee
    [type] => percent
    [amount] => 1000
)
[date] => 1553954369
[payer] => stdClass Object
(
    [name] => Amin
    [phone] => 09353361569
    [mail] => amin@mail.com
    [desc] => Pay for bronze account
)
[payment] => stdClass Object
(
    [track_id] => 59670764
    [amount] => 50000
    [card_no] => 123456******1234
    [date] => 1553954369
)
[verify] => stdClass Object
(
    [date] => 1553954623
)
[settlement] => stdClass Object
(
    [track_id] => 13040079970
    [amount] => 47000
    [date] => 1553984280
)
Failed response
[response_code] => 400
[is_successful] => false
[error_code] => 52
[error_message] => استعلام نتیجه ای نداشت.

Contributor(s)

License

The MIT License (MIT). Please see License File for more information.