Skip to content

Fruitsbytes/Laravel-Moncash-Example

Repository files navigation

Laravel-Moncash-Example

(Online Business)

🌎 i18n: 🇺🇸🇫🇷🇭🇹

banner

Here you will find alist of examples on how to integrate the base MonCash Rest API in your Laravel project without any SDK.

Available examples for an online business:

  • Advanced, Using Facades + Service Providers + Strategies + i18n + Cart + Checkout
  • Basic, One page + Fixed prices

Available examples for onsite experience :

  • 🚧 Advanced, CashIn + POS / Cashier dashboard with QR code Scanner
  • 🚧 Basic, CashOut

How to

You can find a guide explaining how we consume the MonCash API here: How To.

You can use it to make your own implementation from scratch.

Installation

  1. Clone the repository
gh repo clone Fruitsbytes/Laravel-Moncash-Example
  1. Navigate to the example you want to run:
cd ./laravel-moncash-example
  1. Install the packages
php composer install

or using Laravel Sail + Docker

docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v $(pwd):/var/www/html \
    -w /var/www/html \
    laravelsail/php81-composer:latest \
    composer install --ignore-platform-reqs

Note: Some extensions are required for specific strategies but you can switch strategies in the config/moncash.php file.

  1. Migrate the database (make sure the configurations is OK)
php artisan migrate

or if you are using Docker

sail artisan migrate
  1. Add the credentials to the .env file or diretcly in the ./config/moncash.php (⚠ unsafe) file.

By default the demo site will be available in http://localhost/

Demo

E-commerce website

Advance client facing example: view

demo1 demo1
demo1 demo1

Fund a cause

Basic GoFundMe-like example view

demo-basic demo-basic
demo-basic demo-basic

Order an Item

Example uan external libraty, FruitsBytes/PHP-MonCash

view

demo-php-moncash

Usage

Add products to the cart from the product list. In the cart, use MonCash as a payment method. You can check the status of a transaction

You will need a valid test phone number or you will not be able to go through with the.

You can use Ngrok to tunnel server responses

Setup a Business

In the MonCadh portal, create a new online business and get the credentals. You will also need to stup the Return URL + Alert URL

Return Url

MonCash server will signal your server directly to that URL

example : http://localhost/api/notify

In production, a good pratice would be that you put MonCash IP/DomainName in the Allowlist (Acceptlist or Whitelist) of the server for that specific endpoint.

To illustrate that this is not a connection initiated by you to the MonCash server, we put it in the /api routes.

In a real world application, It can be a different server that is specifically tailored to fulfill the transaction, working in sync with the one used to display the products.

On a local server, you can use Ngrok to tunnel or sail share if you are using Laravel Sail

Alert Url

After the transaction is finished, the transactionId is appended to the URL so you can check the value

result : http://localhost/success?transactionId=2185608546

NOTE: If you share Your local server via a proxie or use an online instance, make sure to configure the Business in the MonCash admin portal accordingly

Ngrok example

General concept

We proposed several service providers to handle the business logic.

Authentication + Cache

If we can cache the token and re-use it until it expires this will reduce the number of new token requests we make to the API.

Configure the cache in the config/cache.php

  • Redis (default)
  • MySQL
  • File
  • MemCache
  • No Cache , pure HTTP (fallback)
  • ...

Payment log

Store the Payment for later use, example: Approve the delivery of the products after the payment is verified as successful, or use this information for accounting reports.

Configure the Database connection for the Payment Model.

  • Redis (fast)
  • MySQL (default)
  • File (Slow, needs permission)

OrderID (Reference Id)

Get a uniq orderID that we can use to reference the transaction later, especially if we don' t have a transactionID yet to link to the cirrent order.

  • UUID (low risk of collision)
  • 🚧 MySQL (No collision but slow. The toll increases in distributed infrastructure )
  • Random Uniq ID (Not too reliable, expecially with distributed infrastructure )

Security

If you discover a security vulnerability within this package, please send an email to security@anbapyezanman.com. All security vulnerabilities will be addressed as soon as possible. You may view our full security policy here.

Need Help?

Don't hesitate to check the discussion page and check if the issue is not addressed yet. You can start a new discussion ineed be.

We offer assistance on projects you can contactus here:

business@anbapyezanman.com

If you are an upcoming startup, a student or don't have the budget for consultation fees, it will take longer but we can submit a public repo illustrating the help you need as long as it will benefit the rest of the community:

help@anbapyezanman.com

YT You can also check our Youtube Channel

License

This project is available under MIT license.