Order tables in prestashop when should be it created? - paypal

When should actually an order must be created in PrestaShop, We integrated a local payment module which will redirect to there page and after entering card details and validating the payment it returns back , and it creates an order at that time.
My problem is that if the payment is declined , (or if I close the browser when the payment is processing in the payment page ) order is not created in the ps_order table but cart is created and if I query the bank with another WEB service the payment response is success for that cart_id and id_order is 0,
but I dont have an order or entry in ps_order table created in my ps_order table .How to cater this scenario?
Is it correct to create the order (insert into the order table )before payment processing and put current_state field as 3 status 3 means Processing in progress and change the current_state field if the payment is success or not.
select * from ps_orders
this is how the payemnt module does
if($reponseParameters[8]=='00000'){
// Update the Respose to the ps_networkonline_payment
$sql_response = " UPDATE `"._DB_PREFIX_."networkonline_payment` SET response = '".$text."' , `status` = '".$reponseParameters[4]."', error_code = '".$reponseParameters[8]."' WHERE order_id = '".$cart->id."' ";
Db::getInstance()->execute($sql_response);
// Create Order In prestashop pass the values to order-confrimation class
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$this->module->validateOrder($cart->id, Configuration::get('PS_OS_PAYMENT'), $total, $this->module->displayName, 'Transaction Reference: ' . $reponseParameters[5], array(), (int)$currency->id, false, $customer->secure_key);
// Update the ps_order_payment table to make the PrestaShop Payment success
$q_orders = 'SELECT `reference` FROM ' . _DB_PREFIX_ . 'orders WHERE `id_cart` = ' . (int) $cart->id;
if ($r_orders = Db::getInstance()->getRow($q_orders)){
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'order_payment` SET `transaction_id` = \'' . pSQL($reponseParameters[5]) . '\' , `card_brand` = \'' . pSQL($reponseParameters[7]) . '\' WHERE `order_reference` = \'' . pSQL($r_orders['reference']) . '\'');
}
Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key);
return;
}else{
$this->error = $reponseParameters[9];//$this->module->getErrorMessage($object->error_code);
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$this->module->validateOrder($cart->id, Configuration::get('PS_OS_ERROR'), $total, $this->module->displayName, $this->error, array(), (int)$currency->id, false, $customer->secure_key);
}
}else{
//fail
$this->error = $reponseParameters[9];//$this->module->getErrorMessage($object->error_code);
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$this->module->validateOrder($cart->id, Configuration::get('PS_OS_ERROR'), $total, $this->module->displayName, $this->error, array(), (int)$currency->id, false, $customer->secure_key);
}
}

What payments modules usually have is a way for the bank to query your website when your customers are redirected to their platform, this way the order is created on your side no matter what happens on their side (leaving you with a freshly created order with a state like "pending payment").
Then the order is updated on the customer's return to your website, by a call from the bank (be it with a status "blocked", "cancelled", or "payment accepted").

Related

WooCommerce pdf attachment to custom email is not working

I am using WooCommerce order status manager plugin for custom order statuses and emails notifications. I have created custom status for paid orders via card pay - card-on-hold.
I have also created custom email which will be triggered when statuses will change from receivet to card-on-hold.
my code is:
add_filter( 'woocommerce_email_attachments', 'attach_manual_pdf_to_email', 10, 3);
function attach_manual_pdf_to_email ( $attachments, $status , $order ) {
$allowed_statuses = array( 'customer_processing_order', 'customer_on_hold_order', 'customer_order_status_email' );
if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
$dokument = get_template_directory() . '/woocommerce/emails/attach.pdf';
$attachments = $dokument;
}
return $attachments;
}
Email Ids customer_processing_order and customer_on_hold_order works like a charm.
But customer_order_status_email which is php template for order status manager is not working. It is located in betheme/woocommerce/emails/customer-order-status-email.php and I did also try to move it to same locations where other templates are but that did not help.
Any idea how to make this working please?
okay i did find a solution:
i did use echo '<pre>'; print_r($email->id); echo '</pre>' in template of an email which printed me an email ID. i used this id in my allowed statuses and it is working now.

How Seblod affects the work of authorization in Joomla

I'm using latest version of Joomla and Seblod on my test project. I need to get the email of the administrator of multisite. My Joomla works with two test sites in one Joomla. Documentation of Seblod is poor. Now I'm searching fragment of code, that can be used to calculate authorization.
$CurrentSiteGroups = JCckDatabase::loadColumn( 'SELECT groups FROM #__cck_core_sites WHERE name = "'.$_SERVER["HTTP_HOST"].'"' );
$AdminsGroups = JCckDatabase::loadColumn( 'SELECT id FROM #__usergroups WHERE id in (' . implode(',', $CurrentSiteGroups) . ') AND title LIKE "%Administrator%"');
$AdminsId = JCckDatabase::loadColumn( 'SELECT user_id FROM #__user_usergroup_map WHERE group_id in (' . implode(',', $AdminsGroups) . ')');
foreach($AdminsId as $AdminId){
$SiteAdmin = JCck::getUser($AdminId);
array_push($dest,$SiteAdmin->email);
}
JFactory::getMailer()->sendMail( $from, $fromName, $dest, $subject, $body, $format, $cc, $bcc, $attach, $reply_to, $reply_to_name );

Woocommerce - Change order received text after redirecting from PayPal with IPN

I like to change the thank you page text in case the customer already paid via paypal.
Redirecting via PayPal works fine. Order status is "processing", ok.
But how can I change the thank you text on the redirecting page (https://www.example.com/checkout/order-received/)
I tried the following, with no success:
function my_update_order_status() {
$order = new WC_Order($order_id);
if ($order_status == 'processing')
echo 'NEW MESSAGE';
else
echo 'NOT PAID TEXT';
}
add_filter('woocommerce_thankyou_order_received_text', 'my_update_order_status', 10, 2);
There is an explanation on how to change the thank you page here:
https://wordpress.org/support/topic/how-to-edit-the-thank-youorder-received-page
If you don't wish to do any template modifying then you can include the order received function to adjust it. For example:
function isa_order_received_text( $text, $order ) {
$new = $text . ' All received and an email is on its way to you!.';
return $new;
}
add_filter('woocommerce_thankyou_order_received_text', 'isa_order_received_text', 10, 2 );
The above with add text to the current text output.

Instagram Real-time API duplicate requests

I have an issue where when I create a real-time subscription I get duplicate notifications from different Instagram IP addresses. I have it set up so that when I get a notification, I send a request for latest updates using the min_tag_id setting. I store that in my db to use it for the next request. I don't always get duplicates, but when I do, everything about the notification is the same (time, object,changed_aspect), except I can tell they are different from my debugging output which lists two almost identical requests... the only differing info being a different IP address and the REQUEST_TIME_FLOAT is different by about 1/10th of a second. They even have the same HTTP_X_HUB_SIGNATURE value.
My general algorithm is:
process_subscription_update($data){
# get old min_id
$min_tag_id = mysqli_fetch_object(mysqli_query($dbconnecti,sprintf("SELECT instagram_min_id+0 as instaid FROM xxxx WHERE xxxx=%d",$_GET['xxxx'])));
$min_id = $min_tag_id->instaid;
# make api call
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://api.instagram.com/v1/tags/'.$_GET['tag'].'/media/recent?client_id=xxxx&min_tag_id='.$min_id.($min_id==0?'&count=1':''));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
curl_close($ch);
$i = json_decode($result);
if ($min_id == $i->pagination->min_tag_id) { exit; }
# write new min_id to db
record_min_id($i->pagination->min_tag_id);
$data2 = $i->data;
foreach($data2 as $d) {
process_instagram($d);
}
// debugging output: ****************
$file = file_get_contents($_SERVER['DOCUMENT_ROOT'].'instagram/updates.txt');
$foo = "\n";
foreach($_SERVER as $key_name => $key_value) {
$foo .= $key_name . " = " . $key_value . "\n";
}
$fulldata = $file . "\n\n\n" . $result . "\n min_id = " . $min_id . $foo;
$fulldata .= "\nTIME:".$data[0]->time;
$fulldata .= "\nOBJECT:".$data[0]->object;
$fulldata .= "\nCHANGED_ASPECT:".$data[0]->changed_aspect;
file_put_contents($_SERVER['DOCUMENT_ROOT'].'instagram/updates.txt', $fulldata);
// end debugging output *************
}
I'd like to avoid checking if the instagram message id already exists in my db within the process_instagram function, and with the duplicates only coming 1/10th of a second apart, I don't know if that would work anyway.
Anybody else experience this and/or have a solution?
I solved this. I don't think there is anything I can do about receiving the duplicate notifications. So, when writing the Instagram to my db, I have a field for the Instagram id and put a unique constraint on the field. After doing the mysqli INSERT, I check to see if the errno = 1062, and if it does, I exit.
mysqli_query($dbconnecti,"INSERT INTO xxx (foo, etc, instagram_id ...")
if ($dbconnecti->errno==1062) { exit; }
...
// more script runs here if we don't have a duplicate.

Virtuemart / User Fields

I have added a field in 'Manage User Fields' & when an email is sent to the administrator notifying them of the new user registration, I want to include this new field.
I have written some code to get this new field from #__vm_user_info in /administrator/components/com_virtuemart/classes/ps_shopper.php, in the _sendMail function, as well as added the variable to $message2.
ASEND_MSG has been modified to accept the parameter, but the field is not included in the email to the admin when a user is created. When I go look in the table, the data is there. So to trouble shoot, I hard coded a user name in the select statement, added another user & the correct value was sent for the hard coded user, not the one just added. I am now thinking that it is a commit issue with MySQL, so I put a sleep(4) in the code before I attempt to get the value...no luck.
Can anyone shine some light on this for me??
LarryR....
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to add with the following code in function add() before "return true" line :
/**************************** ***********************/
$pwd = $_POST['password'];
$db = JFactory::getDBO();
$query = "SELECT id, name, email, username"
. "\n FROM #__users"
. "\n ORDER by id DESC LIMIT 1"
;
$db->setQuery( $query );
$rows = $db->loadObjectList();
$namee = $rows[0]->name;
$emaill = $rows[0]->email;
$usern = $rows[0]->username;
$pwd;
$lid = $rows[0]->id;
$dbv = new ps_DB;
echo $query = "SELECT *"
. "\n FROM #__{vm}_user_info"
. "\n WHERE user_id=$lid"
;
$dbv->setQuery( $query );
$fid = $db->loadObjectList();
$field = $fid[0]->extra_field_1;
$user = clone(JFactory::getUser());
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration') == '0') {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return false;
}
// If user activation is turned on, we need to set the activation information
$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
{
jimport('joomla.user.helper');
$user->set('activation', md5( JUserHelper::genRandomPassword()) );
$user->set('block', '1');
}
$component = 'com_user';
$activation_link = $mosConfig_live_site."/index.php?option=$component&task=activate&activation=".$user->get('activation');
$this->_sendMail( $namee , $emaill, $usern, $pwd, $activation_link);
/************************************************** Spinz ********************************************/
Note : Here we created the mail function for username and password to users mail.
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to comment the line in function register_save() before "return true" line:
// Send the registration email
//$this->_sendMail( $name, $email, $username, $password, $activation_link );
Note: Here the mail function generated we need to comment that mail functions and create another mail function in add() function of ps_shopper.php in first point.
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to get the extra added field (extra_field_1) in jos_vm_user_info table in the function _sendmail() with following code and that field sent through the mail to user.
/****************************************************************/
$db = JFactory::getDBO();
$query = "SELECT id, name, email, username"
. "\n FROM #__users"
. "\n ORDER by id DESC LIMIT 1"
;
$db->setQuery( $query );
$rows = $db->loadObjectList();
$lid = $rows[0]->id;
$dbv = new ps_DB;
$query = "SELECT *"
. "\n FROM #__{vm}_user_info"
. "\n WHERE user_id=$lid"
;
$dbv->setQuery( $query );
$fid = $db->loadObjectList();
$field = $fid[0]->extra_field_1;
$subject = sprintf ($VM_LANG->_('SEND_SUB',false), $name, $mosConfig_sitename);
$subject = vmHtmlEntityDecode($subject, ENT_QUOTES);
if ($mosConfig_useractivation=="1"){
$message = sprintf ($VM_LANG->_('USEND_MSG_ACTIVATE',false), $name, $mosConfig_sitename, $activation_link, $mosConfig_live_site, $username, $pwd, $field );
} else {
$message = sprintf ($VM_LANG->_('PHPSHOP_USER_SEND_REGISTRATION_DETAILS',false), $name, $mosConfig_sitename, $mosConfig_live_site, $username, $pwd, $field);
}
/*************************************/
Note :
Initialize the variable "$field" get the extra added field value using query. Then that the extra field value is assigned by message section of the mail.(initialize variable $field having the a value added extra fields in virtuemart).
administrator/components/com_virtuemart/languages/common/english
replace the messages for the following code:
'USEND_MSG_ACTIVATE' => 'Hello %s,
Thank you for registering at %s. Your account is created and must be activated before you can use it.
To activate the account click on the following link or copy-paste it in your browser:
%s
After activation you may login to %s using the following username and password:
Username - %s
Password - %s
Degree - %s'
2.'PHPSHOP_USER_SEND_REGISTRATION_DETAILS' => 'Hello %s,
Thank you for registering at %s. Your customer account has been created.
You may login to %s using the following username and password:
Username - %s
Password - %s
Degree - %s
'
Note:
The extra added values assigned by the string %s in language file.
The message having the string values of extra added field value in virtuemart.
The degree shows the added extra field