All Projects → Saeed-Pooyanfar → zarinpal-laravel

Saeed-Pooyanfar / zarinpal-laravel

Licence: MIT License
Zarinpal payment for Laravel Framework

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to zarinpal-laravel

laravel-multi-payment
Laravel online gateway payment package with multi driver support
Stars: ✭ 22 (-29.03%)
Mutual labels:  payment, zarinpal
FinanceKit
FinanceKit is a Framework for iOS and Mac to build apps working with financial data, like money, currencies, stocks, portfolio, transactions and other concepts.
Stars: ✭ 15 (-51.61%)
Mutual labels:  payment
nagadApi
This is Bangladeshi nagad payment gateway api development library. This library can be used in any php application.
Stars: ✭ 20 (-35.48%)
Mutual labels:  payment
youzan-pay
基于有赞云和有赞微小店实现个人收款解决方案。
Stars: ✭ 69 (+122.58%)
Mutual labels:  payment
PayumYiiExtension
Rich payment solutions for Yii framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
Stars: ✭ 13 (-58.06%)
Mutual labels:  payment
awesome-payment
A curated list of payment services
Stars: ✭ 22 (-29.03%)
Mutual labels:  payment
react-native-square-reader-sdk
React Native Plugin for Square Reader SDK
Stars: ✭ 94 (+203.23%)
Mutual labels:  payment
paymentgateway
Dokumentace ČSOB platební brány a jejího eAPI pro platby platebními kartami, Apple Pay, mallpay a platebními tlačítky ČSOB.
Stars: ✭ 104 (+235.48%)
Mutual labels:  payment
stripe-update-card
💳 Expose a page that let your customers update their payment information on Stripe.
Stars: ✭ 16 (-48.39%)
Mutual labels:  payment
awesome-ecommerce
Collect and develop Open Source or Free Projects for building ecommerce platform easy and fast and free
Stars: ✭ 39 (+25.81%)
Mutual labels:  payment
paydash
Worker payments dashboard for MGNREGA
Stars: ✭ 44 (+41.94%)
Mutual labels:  payment
adyen-dotnet-api-library
Adyen API Library for .NET
Stars: ✭ 69 (+122.58%)
Mutual labels:  payment
pagarme-go
Pagar.me library in Go
Stars: ✭ 13 (-58.06%)
Mutual labels:  payment
omise-python
Omise Python Library
Stars: ✭ 22 (-29.03%)
Mutual labels:  payment
stencil-payment
Payment request API implementation in Stenciljs
Stars: ✭ 28 (-9.68%)
Mutual labels:  payment
frames-android
Checkout API Client, Payment Form UI and Utilities
Stars: ✭ 26 (-16.13%)
Mutual labels:  payment
nestjs-stripe
Provides an injectable Stripe client to nestjs modules
Stars: ✭ 126 (+306.45%)
Mutual labels:  payment
AndroidSDK
Paycom Android SDK
Stars: ✭ 22 (-29.03%)
Mutual labels:  payment
flutter paystack
💳 A robust Flutter plugin for making payments via Paystack Payment Gateway. Completely supports Android and iOS
Stars: ✭ 146 (+370.97%)
Mutual labels:  payment
wechat-payment
微信支付Node.js基础工具库
Stars: ✭ 26 (-16.13%)
Mutual labels:  payment

Zarinpal payment for Laravel Framework

install it:

composer require saeedpooyanfar/zarinpal

laravel service provider should register automatically, if not, register Zarinpal\ZarinpalServiceProvider::class manually or run:

composer dump-autoload

set 36 chars "ZARINPAL_MERCHANTID" in .env file:

...
ZARINPAL_MERCHANTID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
...

Use it

request new payment:

<?php

...
use GuzzleHttp\Exception\RequestException;
use Zarinpal\Zarinpal;
...

...
function request(Zarinpal $zarinpal) {
    $payment = [
        'callback_url' => route('payment.verify'), // Required
        'amount'       => 5000,                    // Required
        'description'  => 'a short description',   // Required
        'metadata'     => [
            'mobile' => '0933xxx7694',       // Optional
            'email'  => '[email protected]' // Optional
        ]
    ];
    try {
      $response = $zarinpal->request($payment);
      $code = $response['data']['code'];
      $message = $zarinpal->getCodeMessage($code);
      if($code === 100) {
          $authority = $response['data']['authority'];
          return $zarinpal->redirect($authority);
      }
      return "Error, Code: ${code}, Message: ${message}";
    } catch (RequestException $exception) {
        // handle exception
    }
}
...

If you have other redirection methods you can use:

...
$url = $zarinpal->getRedirectUrl($authority);
...

to get the redirect url as a string.

verify the payment:

<?php

...
use GuzzleHttp\Exception\RequestException;
use Illuminate\Http\Request;
use Zarinpal\Zarinpal;
...

...
function verify(Request $request, Zarinpal $zarinpal) {
    $payment = [
        'authority' => $request->input('Authority'), // $_GET['Authority']
        'amount'    => 5000
    ];
    if ($request->input('Status') !== 'OK') abort(406);
    try {
      $response = $zarinpal->verify($payment);
      $code = $response['data']['code'];
      $message = $zarinpal->getCodeMessage($code);
      if($code === 100) {
          $refId = $response['data']['ref_id'];
          return "Payment was successful, RefID: ${refId}, Message: ${message}";
      }
      return "Error, Code: ${code}, Message: ${message}";
    } catch (RequestException $exception) {
        // handle exception
    }
}
...

Use this lib with other frameworks

<?php

...
use Zarinpal\Zarinpal;
use Zarinpal\Clients\GuzzleClient; // OR SoapClient
...

...
$merchantID = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
$sandbox = false;
$zarinGate = false; // OR true
$zarinGatePSP = 'Asan'; // Leave this parameter blank if you don't need a custom PSP zaringate.
$client = new GuzzleClient($sandbox);
$lang = 'fa'; // OR en
$zarinpal = new Zarinpal($merchantID, $client, $lang, $sandbox, $zarinGate, $zarinGatePSP);
// object is ready, call methods now!
...

Available configs

  • ZARINPAL_LANG:
    • messages language
    • possible values: [fa, en]
  • ZARINPAL_ZARINGATE:
    • use zarringate for redirect urls
    • possible values: [0, 1]
  • ZARINPAL_ZARINGATE_PSP:
    • use custom PSP for zaringate
    • possible values: 'Asan', 'Sep', 'Sad', 'Pec', 'Fan', 'Emz'

Run test

# clone repo
# cd zarinpal-laravel
# composer install
cd test
php Request.php

Official documents

Link

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].