I am tryin to include a global payment gateway (GPG checkout) to my MERN website.
After the payment process is done, the GPG server should send me a post request using cURL to a route I set in the GPG dashboard. The content of this post request is: PayAmount, PAYID, TransStatus, Signature.
This is my route:
router.route('/confirm-payment-detailes').post(async (req,res)=>{
//const {TotalAmount,PAYID,TransStatus,Signature} = req.body;
//console.log({TotalAmount,PAYID,TransStatus,Signature});
// show any post request content to this route
console.log(req.body)
});
I am showing all POST fields I get on that route.
When I test using insomnia or cURL on my laptop, it shows me the data that I did send in server log, But it shows empty object when I complete the payment process (which means that the GPG checkout server knows my notification URL and sends a POST request but it shows empty anyway).
I called support team and they send me a PHP example of notification page:
<?php
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$url = $_SERVER['REQUEST_URI'];
$my_url = explode('wp-content' , $url);
$path = $_SERVER['DOCUMENT_ROOT']."/".$my_url[0];
$PayAmount = $_POST['TotalAmount'];
$PAYID = $_POST['PAYID'];
$TransStatus = $_POST['TransStatus'];
$Signature = $_POST['Signature'];
include_once $path . '/wp-config.php';
include_once $path . '/wp-includes/wp-db.php';
include_once $path . '/wp-includes/pluggable.php';
$sign = sha1( $_POST['TransStatus']. $PAYID . "XXXXXXX" );
if($Signature == $sign){
$order = wc_get_order( $PAYID );
switch ( $TransStatus ) {
case '05' : // refus
$order->update_status( 'wc-failed', $reason );
break;
case '00' : // accord
$order->update_status( 'wc-processing', $reason );
WC()->cart->empty_cart();
break;
case '06' : //annuler
$order->update_status( 'wc-cancelled', $reason );
break;
case '07' : // rembourser
$order->update_status( 'wc-refunded', $reason );
break;
case '08' : // Charge back
default :
break;
}
}
?>
As far as I know, it's just a simple POST request! Why is my server showing empty object? While it works fine when I test with insomnia or cURL with random fields.
This is my app.js file content:
//imports Here :
const express = require('express');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const mongoStore = require('connect-mongo');
//declare app here :
const app = express();
app.disable('x-powered-by');
app.set('view engine','ejs');
app.set('views','Views');
app.use(express.static(__dirname + '/Public'));
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({extended:false}));
app.use(cors());
//Clients API Routes :
app.use(process.env.CLIENT_API_PATH,require('./Routes/clientAPIRoutes'));
//Admin Pages Routes :
app.use(process.env.ADMIN_PATH,require('./Routes/adminPageRoutes'));
module.exports = app;
Does anyone have any idea about this problem?
Edit : I did create a php file on my server to recive the data instead of the node app , and it did work by just using $_POST["field_name"] , so am really confused about that !