Giter Club home page Giter Club logo

laravel-payfort's Introduction

Laravel Payfort Package

Software License

Laravel Payfort provides a simple and rich way to perform and handle operations for Payfort (MEA based online payment gateway) check here to read more Payfort.
This package supports a set of Payfort operations as listed below, other operations are open for future work and contribution.

  • AUTHORIZATION/PURCHASE
  • TOKENIZATION
  • SDK_TOKEN
  • CHECK_STATUS

You have to read the Payfort documentation very well before proceeding in using any package, the package author will not write about Payfort operations, what and how to use.

Installation

You can install the package via composer:

composer require wshurafa/laravel-payfort

You can publish the config file with:

php artisan vendor:publish --provider "LaravelPayfort\Providers\PayfortServiceProvider"

This is the contents of the file that will be published at config/payfort.php :

return [
    /**
     * Defines wether to activate the Payfort sandbox enviroment or not.
     */
    'sandbox' => env('PAYFORT_USE_SANDBOX', false),

    /**
     * The Payfort merchant account identifier.
     */
    'merchant_identifier' => env('PAYFORT_MERCHANT_IDENTIFIER'),

    /**
     * The Payfort account access code.
     */
    'access_code' => env('PAYFORT_ACCESS_CODE'),

    /**
     * The Payfort account sha type (sha256/sha512).
     */
    'sha_type' => env('PAYFORT_SHA_TYPE', 'sha256'),

    /**
     * The Payfort account sha request phrase.
     */
    'sha_request_phrase' => env('PAYFORT_SHA_REQUEST_PHRASE'),

    /**
     * The Payfort account sha response phrase.
     */
    'sha_response_phrase' => env('PAYFORT_SHA_RESPONSE_PHRASE'),

    /**
     * The default currency for you app. Currency ISO code 3.
     */
    'currency' => env('PAYFORT_CURRENCY', 'USD'),

    /**
     * The URL to return after submitting Payfort forms.
     */
    'return_url' => env('PAYFORT_RETURN_URL', '/')
];

Then you have to add the following constants in the .env file:

PAYFORT_USE_SANDBOX=true                      # Defines wether to activate the payfort sandbox enviroment or not.
PAYFORT_MERCHANT_IDENTIFIER=s2b3rj1vrjrhc1x   # The payfort merchant account identifier
PAYFORT_ACCESS_CODE=s31bpM1ebfNnwqo           # The payfort account access code
PAYFORT_SHA_TYPE=sha256                       # The payfort account sha type. sha256/sha512
PAYFORT_SHA_REQUEST_PHRASE=keljhgiergh        # The payfort account sha request phrase
PAYFORT_SHA_RESPONSE_PHRASE=lkejgoegj         # The payfort account sha response phrase
PAYFORT_CURRENCY=USD                          # The default currency for you app. Currency ISO code 3.
PAYFORT_RETURN_URL=/payfort/handle            # The url to return after submitting payfort forms.

You can find most of these values in your Payfort account

Usage

Once all configuration steps are done, you are ready to use payfort operations in your app. Here is some examples on how to use this package:

Authorization/Purchase request (Redirection)

To display payfort authorization or purchase page, in your controller's method add the following code snippet:

return Payfort::redirection()->displayRedirectionPage([
    'command' => 'AUTHORIZATION',              # AUTHORIZATION/PURCHASE according to your operation.
    'merchant_reference' => 'ORDR.34562134',   # You reference id for this operation (Order id for example).
    'amount' => 100,                           # The operation amount.
    'currency' => 'QAR',                       # Optional if you need to use another currenct than set in config.
    'customer_email' => '[email protected]'  # Customer email.
]); 

Other optional parameters that can be passed to displayRedirectionPage method as follows:

  • token_name
  • payment_option
  • sadad_olp
  • eci
  • order_description
  • customer_ip
  • customer_name
  • merchant_extra
  • merchant_extra1
  • merchant_extra2
  • merchant_extra3

Payfort page will be displayed and once user submits the payment form, the return url defined in the environment configurations will be called.

See Payfort documentation for more info.

Tokenization request

To display payfort tokenization page, in your controller's method add the following code snippet:

return Payfort::redirection()->displayTokenizationPage([
    'merchant_reference' => 'ORDR.34562134',   # You reference id for this operation (Order id for example).
]); 

Payfort page will be displayed and once user submits the payment form, the return url defined in the config file will be called.

See Payfort documentation for more info.

Handling Payfort Authorization/Purchase response

Handling callback (return)

In your handling controller that handle the return url, you can simply use the PayfortResponse trait as follows:

use LaravelPayfort\Traits\PayfortResponse as PayfortResponse;

class PayfortOrdersController extends Controller{
    use PayfortResponse;
    
    public function processReturn(Request $request){
        $payfort_return = $this->handlePayfortCallback($request);
        # Here you can process the response and make your decision.
        # The response structure is as described in payfort documentation
    }
}

See Payfort documentation for more info.

Handling Direct Transaction Feedback

Same as handling payfort response except that you have to call handlePayfortFeedback instead of handlePayfortCallback

Localization

The redirect page can be translated by simply using the json file of the language wihtin the lang directory of your app.

For example, ar.json file:

{
    ...
    "Payment redirect page": "صفحة إعادة توجيه الدفع",
    "Click here to proceed to payment if you are not automatically redirected": "انقر هنا لمتابعة الدفع إذا لم تتم إعادة توجيهك تلقائيًا",
    ...
}

Contribution

Want to improve this package or found a bug ?. Open an issue or do this contribution by yourself and get this honor.

Simply, fork => do you work => make pull request.

Write clear comments and description ;-).

License

Laravel Payfort is open-sourced software licensed under the MIT license

laravel-payfort's People

Contributors

ali-alharthi avatar jomonkj avatar sarphu avatar wshurafa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-payfort's Issues

I am trying to install payfort payment gateway wshurafa/laravel-payfort in laravel 5.4 version giving error

Please help me I am trying to use payfort in my laravel(5.4) application using composer command "composer require wshurafa/laravel-payfort ". But it is giving fallowing error message.

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest]
[--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--
ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|
--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<
packages>]...

error laravel install 5.8.2

i have error "Your requirements could not be resolved to an installable set of packages" install laravel 5.8.2

syntax error after deployed in server.

I got this error when i deploy my application in server. And i found that the error is in the library

FatalErrorException in PayfortServiceProvider.php line 18:
syntax error, unexpected '.', expecting ',' or ';'

Error is in

"/var/www/html/myapp/vendor/wshurafa/laravel-payfort/src/Providers/PayfortServiceProvider.php"
And i changed

    private $configPath = __DIR__ . '/../../config/payfort.php';
    private $translationsPath = __DIR__ . '/../../resources/lang';
    private $viewsPath = __DIR__ . '/../../resources/views';

to

    private $configPath = '/var/www/myapp/vendor/wshurafa/laravel-payfort/config/payfort.php';
    private $translationsPath = '/var/www/myapp/vendor/wshurafa/laravel-payfort/resources/lang';
    private $viewsPath = '/var/www/myapp/vendor/wshurafa/laravel-payfort/resources/views';

And its works fine for me.

Currency Error if you remove [optional] currency parameter.

I don't have permission to update branch so let me give you the solution here.

Solution:
There was an error if we don't use optional currency in controller. It was under displayRedirectionPage function in PayfortRedirectRequest trait. Amount parameter was expecting a value from that array. I have updated the trait function by using laravel data_get as used for currency attribute.

Update the following parameter currency as follows.

// Traits/PayfortRedirectRequest.php

public function displayRedirectionPage($data)
{
//Other Parameters

  'amount' => $this->getPayfortAmount($data['amount'], data_get($data, 'currency', $this->config['currency'])),

//Other Parameters
}

Please update the repository, Thank you. Great work by the way.

response view

My application is in Laravel 5.1. Iam using a this library for integrating it. When i am using purchase request api, it returns a html page. When i check it in postman, for pretty, got a html response. But for preview, i got a blank page. What should i do? I couldnt proceed without getting that preview

error during installation

[InvalidArgumentException]
Could not find package wshurafa/laravel-payfort at any version for your min
imum-stability (stable). Check the package spelling or your minimum-stabili
ty

issue of receiving response after payment.

I am using return_url as a POST method after payment but when redirecting to return_url I am getting response params as a Form Data show in figure and also API type I shown is document.
photo_2022-09-01 11 21 38

Even I am not getting response using handlePayfortCallback method in controller. So, How can I get FormData params any other way to get data in query parameters or any other ways?

Error in Installing Package

composer require wshurafa/laravel-payfort:dev-master
I am using this command tom install it again in my another project. But i got this error 👍

The requested package orangehill/iseed (locked at dev-master) is satisfiable by orangehill/iseed[dev-master] but these conflict with your requirements or minimum-stability.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.