0

He integrate MPGS (show checkout page) but we cant get responses in the return Url can someone give us what the PHP code to be add in the checkout page and in the payment results page?

Here our checkout page code:

<?php
$id=$_GET['id'];
//echo $id;
$sql="SELECT * FROM `invoice` WHERE `order` = '".$id."'";
$result = mysqli_query($conn,$sql);
if (!$result) {
    echo 'Could not run query: ' . mysqli_error();
    exit;
}
$row = mysqli_fetch_assoc($result);
$name= $row['name']; 
$email=$row['email'];
$amount= $row['amount']; 
$currency=$row['currency'];
$order= $row['order']; 
$description=$row['order_description'];
$days=$row['extra2'];
$pax=$row['extra3'];
$rate=$row['extra4'];
$child=$row['child'];
$childrate=$row['childrate'];
$bookingfee=$row['bookinfee'];
$fee=$row['fee'];




?>


<?php

$url = 'https://cibpaynow.gateway.mastercard.com/api/nvp/version/72';
$data = array(
    'apiOperation' => 'INITIATE_CHECKOUT',
    'apiPassword' => 'xxxxxxxxxxxxxxxxxxx',
    'apiUsername' => 'merchant.xxxxxxxxxxxx',  
    'merchant' => 'xxxxxxxxxxx',
    'interaction.returnUrl' => 'https://www.website.com/payment/',
'interaction.merchant.logo' => 'https://www.website.com/logo.png',
'interaction.operation' => 'PURCHASE',
'customer.email' => $email,
    'interaction.merchant.name' => 'xxxxx',  
    'order.id' => $id,  
    'order.amount' => $amount,
    'order.currency' => 'USD',
    'order.description' => $description  
);

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

// Execute cURL session and get the response
$response = curl_exec($ch);

// Check for cURL errors
if (curl_errno($ch)) {
    echo 'cURL Error: ' . curl_error($ch);
}

// Close cURL session
curl_close($ch);

// Output the API response
$session_id = '';
if (preg_match('/session\.id=([^&]+)/', $response, $matches)) {
    $session_id = $matches[1];
}

// Print the extracted session.id
if (!empty($session_id)) {
    //echo 'Session ID: ' . $session_id;
} else {
    echo 'Session ID not found in the response.';
}

?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<!-- BEGIN HEAD -->

<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<head>
   <meta charset="utf-8"/>
   <title>Payments</title>
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
   <link href="https://www.website.com/favicon/favicon.ico" type="image/x-icon" rel="shortcut icon"/>
   <meta name="MobileOptimized" content="320">
      <link rel="stylesheet" type="text/css" href="https://www.website.com/checkout-invoice-data/metro_css.v1557299660.css"/>    <input type="hidden" id="is_mobile" value="0">
   <script type="text/javascript">jQuery.noConflict();</script>
    <script src="https://cibpaynow.gateway.mastercard.com/static/checkout/checkout.min.js" data-error="errorCallback" data-cancel="cancelCallback"
></script>

        <script type="text/javascript">
            function errorCallback(error) {
                  console.log(JSON.stringify(error));
            }
            function cancelCallback() {
                  console.log('Payment cancelled');
            }
            Checkout.configure({
              session: { 
                id: '<?=$session_id?>'
                }
            });
        </script>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body style="background: none !important;" class="page-full-width">
      <!-- BEGIN CONTAINER -->
   <div class="page-container">
      <!-- BEGIN SIDEBAR -->

      <!-- BEGIN PAGE -->
    <div style="border: none !important;" class="page-content">
              <h2 align="center">
<img style="max-height:100px;max-width:500px" src="https://www.website.com/logo/logo-big.png" class="img" data-pagespeed-url-hash="1845928804" onload="pagespeed.CriticalImages.checkImageForCriticality(this);">
                  <br>
<br>
Secured Payment Gateway</h2>
<div class="col-md-offset-2 col-md-8">
</div>  <div class="col-md-offset-3 col-md-6">
    <div class="portlet box grey">
                          <div class="portlet-title">
                             <div class="caption ">
                                Invoice Details</div>
                             <div class="tools">
                                 <a class="collapse" href="javascript:;">&nbsp;</a>
                             </div>
                              <div class="actions">
                             
                             </div>

                          </div><div style="" class="portlet-body t-">      
    <div class="table"><table id="paymentInfo" class="table table-responsive table-bordered table-striped"><thead>  </thead><tbody class="Checkout" id="5d40526011137"> <tr>
        <th colspan="3">Booking Referece: <?php echo $order; ?></th>
    </tr>
    <tr>
        <th>Client Name:</th>
        <td width="70%" colspan="2"><?php echo $name; ?></td>
    </tr>
    <tr>
        <th>Client Email:</th>
        <td colspan="2"><?php echo $email; ?></td>
    </tr>

    <tr>
        <th>Tour Description:</th>
        <td colspan="2"><?php echo $description; ?></td>
    </tr>
    <tr>
      <th>Amount</th>
      <td colspan="2"><strong>$<?php echo $amount; ?></strong></td>
      </tr>
        
        
        
        
        
    </tbody>
        <tbody>
            
          <!--to keep the close tablebody below -->
          </tbody></table></div>        <div class="form-actions last pull-right">
              <?php    echo $htmlOutput; ?>
              <button onclick="Checkout.showPaymentPage();"  class="btn green-jungle" type="submit"> Process Payment / Checkout</button>
</div>      </div>
                    </div>  </div>
    </div>
   
      <!-- END PAGE -->
   </div>
</body>

 

<!-- END BODY -->

</html>

And here PHP code in the return Url:

<?php
// Get the resultIndicator parameter from the gateway response (replace with actual method to get the parameter)
$resultIndicator = $_GET['resultIndicator'];

// Get the successIndicator parameter returned in the Initiate Checkout response (replace with the actual value)
$successIndicator = "your_success_indicator_value";

// Compare the resultIndicator with the successIndicator
if ($resultIndicator === $successIndicator) {
    // Payment was successful
    // You can perform the necessary actions here, such as updating the order status, sending a confirmation email, etc.
    echo "Payment successful! Thank you for your order.";
} else {
    // Payment was not successful
    // You can handle this case accordingly, maybe show an error message to the user
    echo "Payment failed. Please contact our support for assistance.";
}
?>

Can anyone help please to get results in the return Url?

0 Answers0