Skip to content

mrajaeim/zarinpal-composer-library

 
 

Repository files navigation

How to use this fork as zarinpal/zarinpal

  • Fork this repository and add this code to your composer.json
"repositories": [
        {
            "type": "vcs",
            "url":"https://github.com/<Your_GitHub_Username>/zarinpal-composer-library"
        }
    ],
  • Append "zarinpal/zarinpal": "dev-master" to "require"
  • Execute command composer update
  • Generate GitHub Token key (open link that printed in console by composer for token generating)
  • Enter Token and Done!

zarinpal-composer-library

Build Status StyleCI Coverage Status

transaction request library for zarinpal

usage

installation

composer require zarinpal/zarinpal

request

use Zarinpal\Zarinpal;

$zarinpal = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
$zarinpal->enableSandbox(); // active sandbox mod for test env
// $zarinpal->isZarinGate(); // active zarinGate mode
$results = $zarinpal->request(
    "example.com/testVerify.php",          //required
    1000,                                  //required
    'testing',                             //required
    '[email protected]',                      //optional
    '09000000000',                         //optional
    [                          //optional
        "Wages" => [
            "zp.1.1"'=> [
                "Amount"'=> 120,
                "Description"'=> "part 1"
            ],
            "zp.2.5"'=> [
                "Amount"'=> 60,
                "Description"'=> "part 2"
            ]
        ]
    ]
);
echo json_encode($results);
if (isset($results['Authority'])) {
    file_put_contents('Authority', $results['Authority']);
    $zarinpal->redirect();
}
//it will redirect to zarinpal to do the transaction or fail and just echo the errors.
//$results['Authority'] must save somewhere to do the verification

verify

use Zarinpal\Zarinpal;

$zarinpal = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
$authority = file_get_contents('Authority');
echo json_encode($zarinpal->verify('OK', 1000, $authority));
//'Status'(index) going to be 'success', 'error' or 'canceled'

laravel ready

this package is going to work with all kinds of projects, but for laravel i add provider to make it as easy as possible. just add (if you are using laravel 5.5 or higher skip this one):

'providers' => [
    ...
    Zarinpal\Laravel\ZarinpalServiceProvider::class
    ...
]

to providers list in "config/app.php". then add this to config/services.php

'zarinpal' => [
    'merchantID' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
    'zarinGate' => false,
    'sandbox' => false,
],

and you are good to go (legacy config still works) now you can access the zarinpal lib like this:

use Zarinpal\Laravel\Facade\Zarinpal;

$results = Zarinpal::request(
    "example.com/testVerify.php",          //required
    1000,                                  //required
    'testing',                             //required
    '[email protected]',                      //optional
    '09000000000',                         //optional
    [                          //optional
        "Wages" => [
            "zp.1.1" => [
                "Amount" => 120,
                "Description" => "part 1"
            ],
            "zp.2.5" => [
                "Amount" => 60,
                "Description" => "part 2"
            ]
        ]
    ]
);
// save $results['Authority'] for verifying step
Zarinpal::redirect(); // redirect user to zarinpal

// after that verify transaction by that $results['Authority']
Zarinpal::verify('OK',1000,$results['Authority']);

About

transaction request library for zarinpal

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%