-1

I am making a custom payment wordpress plugin for my local bank. When processing payment I've got error messages such as "Notice Undefined index:....... on line 4" like screenshot below: error message

index.php script from screenshot above

<?php
ini_set('display_errors',1);  error_reporting(E_ALL);
$data = array(
           'MerchantID' => $_POST['MerchantID'],     
            'TransactionID' => $_POST['TransactionID'],   
            'RequestDate' =>  $_POST['RequestDate'], 
            'Amount' => $_POST['Amount'],    
            'CurrencyCode' =>$_POST['CurrencyCode'],   
            'Tax' => $_POST['Tax'],    
            'Signature' => $_POST['Signature'],   
            'Description' =>$_POST['Description'],       
            'CallbackURL' => $_POST['CallbackURL'], 
            'UserSession'  => $_POST['UserSession'],   
            'TransactionNote' => $_POST['TransactionNote']  
);

$url_send ="http://simpg.sprintasia.net:8779/bcasakuku/bak/InquiryProc";
$str_data = json_encode($data);

function sendPostData($url, $post){
  $ch = curl_init($url);
  $curl_header = array('Accept: application/json', 'Content-Type: application/json');
  curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_header);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $result = curl_exec($ch);
  curl_close($ch);  // Seems like good practice
  return $result;
}


echo " " . sendPostData($url_send, $str_data);

?>

For detail please try this product and using BCA sakuku as payment option like screenshot below: bca sakuku payment option

And its weird because these plugin working like charm in localhost not in dev.galerigadget.com

How I can fix it?

Cheers

UPDATED FEB 02 2016

Its new script index.php based on another question but still not luck

<?php
ini_set('display_errors',1);  error_reporting(E_ALL);

//Checking to fix error
$MerchantID  = $_POST['MerchantID'];
if (!isset($MerchantID)) $MerchantID = '';
$TransactionID = $_POST['TransactionID'];
if (!isset($TransactionID)) $TransactionID = '';
$RequestDate = $_POST['RequestDate'];
if (!isset($RequestDate)) $RequestDate = '';
$Amount = $_POST['Amount'];
if (!isset($Amount)) $Amount = '';
$CurrencyCode = $_POST['CurrencyCode'];
if (!isset($CurrencyCode)) $CurrencyCode = '';
$Tax = $_POST['Tax'];
if (!isset($Tax)) $Tax = '';
$Signature = $_POST['Signature'];
if (!isset($Signature)) $Signature = '';
$Description = $_POST['Description'];
if (!isset($Description)) $Description = '';
$CallbackURL = $_POST['CallbackURL'];
if (!isset($CallbackURL)) $CallbackURL = '';
$UserSession = $_POST['UserSession'];
if (!isset($UserSession)) $UserSession = '';
$TransactionNote = $_POST['TransactionNote'];
if (!isset($TransactionNote)) $TransactionNote = '';

$data = array(
           'MerchantID' => $MerchantID,     
            'TransactionID' => $TransactionID,   
            'RequestDate' =>  $RequestDate, 
            'Amount' => $Amount,    
            'CurrencyCode' => $CurrencyCode,   
            'Tax' => $Tax,    
            'Signature' => $Signature,   
            'Description' => $Description,       
            'CallbackURL' => $CallbackURL, 
            'UserSession'  => $UserSession,   
            'TransactionNote' => $TransactionNote, 
);

$url_send ="http://simpg.sprintasia.net:8779/bcasakuku/bak/InquiryProc";
$str_data = json_encode($data);

function sendPostData($url, $post){
  $ch = curl_init($url);
  $curl_header = array('Accept: application/json', 'Content-Type: application/json');
  curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_header);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $result = curl_exec($ch);
  curl_close($ch);  // Seems like good practice
  return $result;
}


echo " " . sendPostData($url_send, $str_data);

?>
Community
  • 1
  • 1
user3077416
  • 271
  • 2
  • 10
  • 31
  • Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Epodax Feb 02 '16 at 11:38
  • @epodax Please recheck my updated above – user3077416 Feb 03 '16 at 05:17

4 Answers4

0

If everything works fine on localhost, it may be because of not properly performed migration. Try read this article of codex https://codex.wordpress.org/Moving_WordPress

When your domain name or URLs change there are additional concerns. The files and database can be moved, however references to the old domain name or location will remain in the database, and that can cause issues with links or theme display.

If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break.

Or use this script to be sure, that you migrate correctly with all database changes.

https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

Community
  • 1
  • 1
Codeartist
  • 793
  • 5
  • 13
0

If you moved the website it is possible for the serialized data and url adresses to be wrong and things like this well happends.

To migrate a website properly you should install the plugin WP Migrate DB - it handles serialized data and changes the urls in the database by just specifying which url to search for and which should be it's replacement.

knif3r
  • 439
  • 4
  • 13
0

//Checking to fix error
$MerchantID = $_POST['MerchantID'];
if (!isset($MerchantID)) $MerchantID = '';

As stated in the E_NOTICE message...

Notice: Undefined index: MerchantID The E_NOTICE is because

$_POST['MerchantID'] is not set. In other words, the MerchantID index of the $_POST array is undefined. It would seem the data has not been POST'd (submitted) to this script?

You should be assigning your data something like:

$MerchantID = isset($_POST['MerchantID']) ? $_POST['MerchantID'] : '';

This will solve your immediate problem of the E_NOTICE messages, however, it is not the solution to the bigger problem of why your data has not been submitted to begin with.

You will still need some kind of validation check later...

If (empty($MerchantID)) {
    /* ABORT! */
}
MrWhite
  • 43,179
  • 8
  • 60
  • 84
0

Finally my plugin works as well after reported to my webhosting customer service fixed about the port from my website which connect to third party server got blocked.

user3077416
  • 271
  • 2
  • 10
  • 31