Integrate NoonPayment API with Laravel
To install this package through composer run the following command in the terminal
composer require codebuglab/noon-payment-laravel
Refer to Noon docs to get your info then add them to .env
file
NOON_PAYMENT_BUSINESS_ID=
NOON_PAYMENT_APP_NAME=
NOON_PAYMENT_APP_KEY=
NOON_PAYMENT_TOKEN_IDENTIFIER=
NOON_PAYMENT_RETURN_URL=http://127.0.0.1:8000/noon_payment_response
# Change the mode to Live for the Production or set it as Test
NOON_PAYMENT_MODE=Test
# Pre-configured order route categories (the categories will be mentioned also in the initial setup email)
NOON_PAYMENT_ORDER_CATEGORY=
# Channels are pre-defined and limited to Web / Mobile (the channels will be mentioned also in the initial setup email)
NOON_PAYMENT_CHANNEL=web
# Default value - Payment API Endpoint - Chooses
# https://api.noonpayments.com/payment/v1/
# https://api-test.noonpayments.com/payment/v1/
NOON_PAYMENT_PAYMENT_API=https://api-test.noonpayments.com/payment/v1/
Run this command in terminal to publish package files in your app
php artisan vendor:publish --provider="CodeBugLab\NoonPayment\NoonPaymentServiceProvider"
This will publish 2 files
1- App/Http/Controllers/NoonPaymentController.php
2- config/noon_payment.php
- Feel free to change
noon_payment.php
config file and set package configuration on this file instead of.env
if you want - If you don't need the config file you can run this command instead
php artisan vendor:publish --provider="CodeBugLab\NoonPayment\NoonPaymentServiceProvider" --tag=controller
NoonPaymentController.php
is a simple example to use it in your project, consider it as a demo.
This package has two routes using NoonPaymentController.php
file
- Create payment page:
http://yourwebsite/noon_payment
Which call function ( NoonPaymentController@index
) by GET
Request
- Receiving response
http://yourwebsite/noon_payment_response
Which receive a GET
response through function ( NoonPaymentController@response
)
the link for test cards by official documentation => Test Cards
- This will initiate new order.
$data =[
"order" => [
"reference" => "1",
"amount" => "10",
"currency" => "SAR",
"name" => "Sample order name",
],
"configuration" => [
"locale" => "en"
]
]
$response = NoonPayment::getInstance()->initiate($data);
- Simply you can use response and redirect to pay page through this code
if ($response->resultCode == 0) {
return redirect($response->result->checkoutData->postUrl);
}
- After sitting your payment information or cancel the process you will go to response page
- Remember you set it up earlier in
.env
file like this
NOON_PAYMENT_RETURN_URL=http://127.0.0.1:8000/noon_payment_response
- For more information about request and response for initiate visit documentation ( Payment Initiate )
- This will get your order information by order id that retrieved by initiate function
$response = NoonPayment::getInstance()->getOrder($orderId);
- Simply you can check if transaction is success by using
$response
variable like this
if (
$response->result->transactions[0]->type == "SALE" &&
$response->result->transactions[0]->status == "SUCCESS"
) {
//success Message
}
- For more information about response and request for initiate visit documentation ( Payment Get Order )
- If you facing any problems using this package try use Publish and Routes this will give you a simple example in
NoonPaymentController.php
file. - If you want to make
Refund
orCancel
for order then this package doesn't provide these methods yet, So we highly recommend to read full Documentation before try this and making a pull request.
This package is a free software distributed under the terms of the MIT license.