Giter Club home page Giter Club logo

laravel-myfatoorah's Introduction

Laravel Myfatoorah

laravel myfatoorah is a php package written by Ayman Elmalah with laravel to handle myfatoorah functionality by making it's api more easy .

Features

  • Creating invoices
  • Returning payments
  • Check that payment is success or not
  • Change the token on the fly
  • Refund invoice

Installation Guide

Composer installation

composer require ayman-elmalah/laravel-myfatoorah

The package is compatible with laravel ^6.0|^7.0|^8.0|^9.0 so you don't need to set providers or aliases for the package, we're using laravel auto discovery

Configuration

To publish config run

php artisan vendor:publish --provider="AymanElmalah\MyFatoorah\MyFatoorahServiceProvider"

and modify the config file with your own information. File is located in /config/myfatoorah.php

Get Your Credentials From Myfatoorah

  • Go to My fatoorah
  • You will get access token
  • Go to your .env file and paste your credentials to be like this
  • MYFATOORAH_MODE options ["test", "live", "live-sa"]
MYFATOORAH_MODE=test
MYFATOORAH_TOKEN=token

or you can add it using setAccessToken($token?)->setMode($mode?)

You are now ready to use the package

Test cards page

You can get test cards from DOCS

Usage examples

Create payment page

Route::get('payment', [\App\Http\Controllers\MyFatoorahController::class, 'index']);
Route::get('payment/callback', [\App\Http\Controllers\MyFatoorahController::class, 'callback']);
Route::get('payment/error', [\App\Http\Controllers\MyFatoorahController::class, 'error']);

At the controller, you can get the data from payment page at DOCS

use AymanElmalah\MyFatoorah\Facades\MyFatoorah;

public function index() {
     $data = [
       'CustomerName' => 'New user',
       'NotificationOption' => 'all',
       'MobileCountryCode' => '+966',
       'CustomerMobile' => '0000000000',
       'DisplayCurrencyIso' => 'SAR',
       'CustomerEmail' => '[email protected]',
       'InvoiceValue' => '100',
       'Language' => 'en',
       'CallBackUrl' => 'https://yourdomain.test/callback',
       'ErrorUrl' => 'https://yourdomain.test/error',
   ];

// If you want to set the credentials and the mode manually.
//    $myfatoorah = MyFatoorah::setAccessToken($token)->setMode('test')->createInvoice($data);

// And this one if you need to access token from config
   $myfatoorah = MyFatoorah::createInvoice($data);

 // when you got a response from myFatoorah API, you can redirect the user to the myfatoorah portal 
 return response()->json($myfatoorah);
}

Get callback to check if success payment

public function callback(Request $request) {
   $myfatoorah = MyFatoorah::payment($request->paymentId);

   // It will check that payment is success or not
   // return response()->json($myfatoorah->isSuccess());
   
   // It will return payment response with all data
   return response()->json($myfatoorah->get());
}

Error page

public function error(Request $request) {
   // Show error actions
   return response()->json(['status' => 'fail']);
}

Refund payment

Route::get('reund', [\App\Http\Controllers\MyFatoorahController::class, 'refund']);

At the controller, you can get the data from payment page at DOCS

use AymanElmalah\MyFatoorah\Facades\MyFatoorah;

public function refund() {
     $data = [
       'KeyType' => 'invoiceid',     // can be invoiceId or PaymentId
       'Key' => '94272',             // key value like payment reference id, you can got it from the $request->paymentId in callback function 
       'RefundChargeOnCustomer' => false,
       'ServiceChargeOnCustomer' => false,
       'Amount' => 210,
       'Comment' => 'Refund',
       'AmountDeductedFromSupplier' => 0
     ];

   // If you want to set the credentials and the mode manually.
   // $myfatoorah = MyFatoorah::setAccessToken($token)->setMode('test')->refundInvoice($data);

   // And this one if you need to access token from config
   $myfatoorah = MyFatoorah::refundInvoice($data);

   // You can check the output
   return response()->json($myfatoorah);
}

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • If yo have any questions, issues or PRs feel free to contact me.

laravel-myfatoorah's People

Contributors

ayman-elmalah avatar ousid avatar saifallak avatar

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.