Upayments Gateway Integration PHP - Laravel

  • 06-12-2022
  • 1913
  • Laravel 9
  • Haresh Chauhan

Upayments Gateway Integration PHP - Laravel; Upayments integration using cURL in this post I will teach you; after a lot's searching finally i integrated this payment gateway in the laravel also in PHP, there is no document available on the internet for integration, Upayment only official document providing by this payment only, there is no any external document for integration upayments.

Using cURL we will send a payment request to the Upayments, The redirect URL for the payment accepted will provide by the upayment and redirect. after successfully done the payment you will redirect back to your given redirect back URL with a successful response. In this tutorial, I am teaching you all the things about this payment very easily and with a quick understanding.

The upayment sandbox and production payment URL below are provided, choose your payment link and start integration. fox sandbox and production both payment testing and accepting URL different that noted.

Sandbox: https://api.upayments.com/test-payment
Production: https://api.upayments.com/payment-request

Sandbox Test card details, below are provided card details for the sandbox, if you are testing payment, use below card details for the testing payment.

KNET Test Card Details:
Name: Knet Test Card [KNET1]
Card Number: 8888880000000001
Expiry Date: 09/2021
PIN: 1234

You must post the following parameters:

FieldName Field value (Sandbox) Field Value (Production)
merchant_id 1201 Your Provided Id
username test Your Provided Username
password test Your Provided Password
api_key jtest123 Your Provided Password
Unique ID - Store in your database
- It will be used for future reference
- Use a strong hashing with time
- Min 15, Max 35 characters
- Store in your database
- It will be used for future reference
- Use a strong hashing with time
- Min 15, Max 35 characters
total_price Payable amount (max 3 decimal points) Payable amount (max 3 decimal points)
success_url URLto redirect the user on successful transaction URL to redirect the user on successful transaction
error_url URL to redirect the user on unsuccessful transaction Url where user will redirect after error in payment
test_mode 1 for test mode 0 for production mode
CstFName Customer Full Name Customer Full Name
CstEmail Customer Email Address Customer Email Address
CstMobile Customer Mobile Number Customer Mobile Number
payment_gateway NA knetforKNet transaction cc for Credit Card Transaction
whitelabled NA 1 = true (must be enabled by admin) 0 = false
ProductTitle Product Name/Description Product Name/Description
ProductName NA Encoded array of product names
ProductPrice NA Encoded array of product prices
ProductQty NA Encoded array of product quantities
Reference NA Merchant Order ID or Reference number
notifyURL Webhook notification - like IPN (Instant Payment Notification) Notification URL that you can provide with every call to receive confirmations
x-Authorization hWFfEkzkYE1X691J4qmcuZHAoet7Ds7ADhL

Send post request for payment, below provided $request_data array, all the post-payment request fields added with the details, I have to explain each field above in table format look at this for the field more information, also you need to specify test payment and production payment URL, base on the test payment you need to send status value 1 or 0 for the payment type.

Below provided request data I have given test credentials, use the same credentials for the test payment. Add success_url so that once the payment is successful it will redirect to your success URL so based on the success you can take action. also there is a notification and error URL field, add these URLs also. This URL will help you to handle failed payment actions and the notification URL will notify you after the payment action whatever is done in the payment.


$request_data = array(
     'username' => 'test',
     'password'=>stripslashes('test'), 'api_key'=>'jtest123', // in sandbox request
     /'api_key' =>password_hash('API_KEY',PASSWORD_BCRYPT), //In production mode, please pass API_KEY with BCRYPT function
     'order_id'=>time(), // MIN 30 characters with strong unique function (like hashing function with time)
     'CurrencyCode'=>'KWD',//only works in production mode
     //'CurrencyCode'=>'KWD',//'KWD','SAR','USD','BHD','EUR','OMR','QAR','AED' and others,Please ask our support to activate
     'CstFName'=>'Test Name',
     'test_mode'=>1, // test mode enabled
     'payment_gateway'=>'knet',// only works in production mod

$fields_string = http_build_query($request_data);
$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

if (env('PU_TEST_MODE') == 1) {
     curl_setopt($ch, CURLOPT_URL,"https://api.upayments.com/test-payment"); //Test Request URL

     curl_setopt($ch, CURLOPT_URL,"https://api.upayments.com/payment-request");// Production Request URL

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
$server_output = json_decode($server_output,true);


Example of response: for ERRORS

     [status] => errors
     [error_msg] => Please check configuration values of test mode
     [error_code] =>not_test_credentials

Example of response: for SUCCESS

     [status] => success
     [paymentURL] => https://api.upayments.com/test/payment?ref=ref_id&sess_id=sess_id

We always thanks to you for reading our blogs.


Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us


Haresh Chauhan


We Are Also Recommending You :