Ross Beer Ross Beer - 1 year ago 178
PHP Question

OpenCart PHP Callback Array Trouble

I am trying to write a Netbanx API extension and accessing the array is failing.
I get PHP errors for Undifined index on interrogation.

Array dump is:

Array (
[transaction_status] => success
[transaction_merchantRefNum] => 476
[id] => 271ZH271ZH271Z
[transaction_amount] => 4200 )

my Callback function is:

public function callback() {
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$this->log->write(print_r($_POST, 1)); //FOR DEBUGGING
$orderId = $_POST['transaction_merchantRefNum'];
if(in_array($orderId, $_POST)){
$message = '';

if (isset($_POST[1])) {
$message .= 'transaction_merchantRefNum: ' . $_POST[1] . "\n";

if (isset($_POST[3])) {
$message .= 'transaction_amount: ' . $_POST[3] . "\n";

if (isset($_POST[2])) {
$message .= 'id: ' . $_POST[2] . "\n";

if ($_POST[0] == 'success') {
$this->model_checkout_order->update($this->request->get['order_id'], $this->config->get('netbanx_payments_order_status_id'), $message, false);
} else {
$this->model_checkout_order->update($this->request->get['order_id'], $this->config->get('config_order_status_id'), $message, false);


Answer Source

You are getting those warnings very correctly!

In your code you are accessing the $_POST indexes as they were numbers but they are not.

Thus you cannot do


If your POST array has only string indexes, instead of this you have to do


And in OpenCart I recommend to use the libraries you have at hand, thus instead of accessing the $_POST directly, access it via system library, i.e. $this->request->post.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download