- Posts: 21
- Thank you received: 0
How to store transaction id in hikashop order table as a new field
6 years 3 months ago #321534
by ajdev33
-- HikaShop version -- : 4.3.0
-- Joomla version -- : 3.9.19
-- PHP version -- : 7.3
I am working on a custom third party payment plugin. I have installed it and have implemented code to redirect on payment page and back on shop successfully. Now I want to store transaction id retrieved from payment gateway in order table as a new field.
I don't know how to store/add transaction id in order table.
I tried below code, but it is also not working.
So if anyone can help me out from this would be very helpful for me.
Thanks
-- Joomla version -- : 3.9.19
-- PHP version -- : 7.3
I am working on a custom third party payment plugin. I have installed it and have implemented code to redirect on payment page and back on shop successfully. Now I want to store transaction id retrieved from payment gateway in order table as a new field.
I don't know how to store/add transaction id in order table.
I tried below code, but it is also not working.
Code:
$orderClass = hikashop_get('class.order');
$order = $orderClass->get($order_id);
if(isset($order->custom_auth_number)){
$order->custom_auth_number = $authNumber;
}
if(isset($order->custom_txn_id)){
$order->custom_txn_id = $transactionId;
}
$orderClass->save($order);
So if anyone can help me out from this would be very helpful for me.
Thanks
Please Log in or Create an account to join the conversation.
6 years 3 months ago #321549
by nicolas
Replied by nicolas on topic How to store transaction id in hikashop order table as a new field
Hi,
This should be fine. However, I would recommend to only add the attributes you want in the $order object, like this:
Note that you first need to have the columns custom_auth_number and custom_txn_id in the hikashop_order table.
If you don't, the MySQL query will crash.
So you first want to do an ALTER on that table to add these columns if you don't already have them.
This should be fine. However, I would recommend to only add the attributes you want in the $order object, like this:
Code:
$orderClass = hikashop_get('class.order');
$order = new stdClass();
$order->order_id = $order_id;
$order->custom_auth_number = $authNumber;
$order->custom_txn_id = $transactionId;
$orderClass->save($order);
If you don't, the MySQL query will crash.
So you first want to do an ALTER on that table to add these columns if you don't already have them.
The following user(s) said Thank You: ajdev33
Please Log in or Create an account to join the conversation.
6 years 2 months ago #321564
by ajdev33
Replied by ajdev33 on topic How to store transaction id in hikashop order table as a new field
Isn't this possible to run Alter table or new table SQL script on plugin install ? Because I want field like transaction id to be added in order table dynamically not manually.
Please suggest any solution.
Please suggest any solution.
Please Log in or Create an account to join the conversation.
6 years 2 months ago #321571
by nicolas
Replied by nicolas on topic How to store transaction id in hikashop order table as a new field
Hi,
You can use the preflight function of Joomla plugins to do that:
books.google.fr/books?id=FNA3CwAAQBAJ&pg...gin%20joomla&f=false
Or what you could do is actually do a :
$orderClass->get($order_id);
To get the data already in the database, add such check:
directly before your code in the plugin
You can use the preflight function of Joomla plugins to do that:
books.google.fr/books?id=FNA3CwAAQBAJ&pg...gin%20joomla&f=false
Or what you could do is actually do a :
$orderClass->get($order_id);
To get the data already in the database, add such check:
Code:
if(!isset($orderInDb->xxx)) {
// run ALTER MySQL query to add the column xxx to hikashop_order
}
Please Log in or Create an account to join the conversation.
Time to create page: 0.138 seconds