(Online Business)
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 :
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.
- Clone the repository
gh repo clone Fruitsbytes/Laravel-Moncash-Example
- Navigate to the example you want to run:
cd ./laravel-moncash-example
- 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.
- Migrate the database (make sure the configurations is OK)
php artisan migrate
or if you are using Docker
sail artisan migrate
- 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/
Advance client facing example: view
Basic GoFundMe-like example view
Example uan external libraty, FruitsBytes/PHP-MonCash
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
In the MonCadh portal, create a new online business and get the credentals. You will also need to stup the Return URL + Alert 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
After the transaction is finished, the transactionId is appended to the URL so you can check the value
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
We proposed several service providers to handle the business logic.
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)
- ...
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)
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 )
If you discover a security vulnerability within this package, please send an email to [email protected]. All security vulnerabilities will be addressed as soon as possible. You may view our full security policy here.
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:
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:
You can also check our Youtube Channel |
This project is available under MIT license.