- Posts: 7
- Thank you received: 0
onAfterOrderConfirm not triggering
13 years 1 month ago - 13 years 1 month ago #117346
by eleventy
onAfterOrderConfirm not triggering was created by eleventy
I'm getting there 
Below is the code I'm working on to integrate Hikashop with Kashflow (accounts).
I want to trigger my script onAfterOrderConfirm, but it doesn't trigger. I get the order confirmation sent to the customer, but no invoice in Kashflow. If I change
to
it works, but this is not what I want. I want to be sure payment has been received.
Have I made a mistake with the trigger code change?
Many thanks
Eleventy
Below is the code I'm working on to integrate Hikashop with Kashflow (accounts).
Code:
<?php
defined('_JEXEC') or die('Restricted access');
?><?php
if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }
class plgHikashopkf_insert extends JPlugin
{
function plgHikashopKashflow(&$subject, $config){
parent::__construct($subject, $config);
if(!isset($this->params)){
$plugin =& JPluginHelper::getPlugin('hikashop', 'kf_insert');
jimport('joomla.html.parameter');
$this->params = new JParameter( $plugin->params );
}
}
function onAfterOrderConfirm(&$order, &$methods, $method_id) {
if(!empty($order->order_id)){
$orderClass = hikashop_get('class.order');
$full_order = $orderClass->loadFullOrder($order->order_id, true, false);
require_once("**********.inc.php");
require_once("******.inc.php");
$username = "******";
$password = "*******";
//create variables
$order_user_id = $full_order->order_user_id;
mysql_connect("localhost", "*************", "**************") or die(mysql_error());
mysql_select_db("****************") or die(mysql_error());
$email = mysql_result(mysql_query("SELECT user_email FROM nl7xh_hikashop_user WHERE user_id = '".$order_user_id."';"), 0);
foreach($full_order->products as $product){
$cart = $product->order_product_name;
$subtotal = $product->order_product_price;
}
$inv_name = $full_order->shipping_address->address_firstname . " " . $full_order->shipping_address->address_lastname; //ok
$inv_addr1 = $full_order->shipping_address->address_street;
$inv_addr2 = $full_order->shipping_address->address_city;
$inv_state = $full_order->shipping_address->address_state;
$inv_zip = $full_order->shipping_address->address_post_code;
$inv_country = $full_order->shipping_address->address_country;
$description = $cart;
$qty = '1';
$tax_rate = 20;
$tel = $full_order->shipping_address->address_telephone;
$shipping = $full_order->shipping->shipping_price;
// Kashflow will check if it's available and increment it if already used.
$invoice_number = 1;
// Uses format yyyy-mm-dd.
$invoice_date = date("Y-m-d"); // current date
$due_date = strtotime(date("Y-m-d", strtotime($invoice_date)) . " +30 days"); //net 30
// below is the nominal id code for Sale of Goods.
$nominal_id = 1236497;
$kashflow_customer_id; //First we will try to get this id from an email if not we will create it
//**************** Test For User ***************//
$kashflow = new Kashflow($username,$password);
$results = $kashflow->getCustomerByEmail($email);
//Checks to see if the email exists and creates a new account if not
if($results->StatusDetail == 'There is no customer with that email address'){
$name = $inv_name;
$address = $inv_addr1;
$town = $inv_addr2;
$state = $inv_state;
$postcode = $inv_zip;
$country = $inv_country;
$tel = $tel;
$newCustomerResults = $kashflow->insertCustomer($name,$address,$town,$state,$postcode,$country,$email,$telS);
$kashflow_customer_id = $newCustomerResults->InsertCustomerResult;
}else{
$kashflow_customer_id = $results->GetCustomerByEmailResult->CustomerID;
}
$unit_net = $subtotal + $shipping;
//This should be true unless you use bad data to create account.
if($kashflow_customer_id){
// Connect to Kashflow.
$kashflow = new Kashflow($username,$password);
// Initialise the invoice.
$invoice = new KashflowInvoice($kashflow_customer_id,$invoice_number,$invoice_date,$due_date);
// Add a line to the invoice: 1 unit, with a unit price of £10 @ 20% VAT.
$invoice->addLine($qty,$unit_net,$unit_tax,$tax_rate,$nominal_id,$description);
// Now insert the invoice on Kashflow.
$response = $kashflow->insertInvoice($invoice);
// Done - here's the response!
echo "<pre>";
print_r($response);
echo "</pre>";
}else{
echo "<p>CustomerID is not valid: ".$kashflow_customer_id."</p>";
}
}
return true;
}
}
?>
I want to trigger my script onAfterOrderConfirm, but it doesn't trigger. I get the order confirmation sent to the customer, but no invoice in Kashflow. If I change
Code:
function onAfterOrderConfirm(&$order, &$methods, $method_id) {
Code:
function onAfterOrderCreate(&$order,&$send_email){
Have I made a mistake with the trigger code change?
Many thanks
Eleventy
Last edit: 13 years 1 month ago by eleventy. Reason: redaction
Please Log in or Create an account to join the conversation.
13 years 1 month ago #117350
by nicolas
Replied by nicolas on topic onAfterOrderConfirm not triggering
This function is triggered at the end of the checkout process after the order has been created so that the payment plugin can redirect the user to the payment platform for the payment.
Please make sure that you're extending from the hikashopPaymentPlugin class or you'll be missing a lot of code from your plugin and it won't work properly during the checkout if you're using HikaShop 2.2 or above.
Please make sure that you're extending from the hikashopPaymentPlugin class or you'll be missing a lot of code from your plugin and it won't work properly during the checkout if you're using HikaShop 2.2 or above.
Please Log in or Create an account to join the conversation.
13 years 1 month ago - 13 years 1 month ago #117356
by eleventy
Replied by eleventy on topic onAfterOrderConfirm not triggering
Thanks Nicolas for your continued support 
What would be the best trigger/function to use? I just need my Kashflow script to execute when the customer has paid.
What would be the best trigger/function to use? I just need my Kashflow script to execute when the customer has paid.
Last edit: 13 years 1 month ago by eleventy.
Please Log in or Create an account to join the conversation.
13 years 1 month ago #117364
by eleventy
Replied by eleventy on topic onAfterOrderConfirm not triggering
I think onAfterOrderUpdate will work, if I run my script only when the order is confirmed not created.
Please Log in or Create an account to join the conversation.
13 years 1 month ago #117375
by nicolas
Replied by nicolas on topic onAfterOrderConfirm not triggering
Then my question is : how and when are your orders confirmed ? What is confirming them ?
Normally, it's the payment plugin itself which confirms the orders. So you should actually do that in the plugin. So asking me where to put your script when the order is confirmed is strange since you should be the one confirming it and thus you should already know where to put your script.
Here is how most payment plugins work:
1. the user finish the checkout
2. the order is created
3. the onAfterOrderConfirm function is called
4. in that function the plugin displays the redirection form to the payment platform and also specifies the "notification URL".
5. the user is redirected to the payment platform and pays the order
6. the payment platform notifies the "notification URL" of the payment being successful
7. at that point the onPaymentNotification function of the plugin is called
8. the plugin checks that the notification is valid
9. the plugin finally confirms the order
So basically, in most payment plugins, the two main functions are onAfterOrderConfirm, in order to redirect the user to the payment gateway, and onPaymentNotification, in order to confirm the order.
Normally, it's the payment plugin itself which confirms the orders. So you should actually do that in the plugin. So asking me where to put your script when the order is confirmed is strange since you should be the one confirming it and thus you should already know where to put your script.
Here is how most payment plugins work:
1. the user finish the checkout
2. the order is created
3. the onAfterOrderConfirm function is called
4. in that function the plugin displays the redirection form to the payment platform and also specifies the "notification URL".
5. the user is redirected to the payment platform and pays the order
6. the payment platform notifies the "notification URL" of the payment being successful
7. at that point the onPaymentNotification function of the plugin is called
8. the plugin checks that the notification is valid
9. the plugin finally confirms the order
So basically, in most payment plugins, the two main functions are onAfterOrderConfirm, in order to redirect the user to the payment gateway, and onPaymentNotification, in order to confirm the order.
The following user(s) said Thank You: lionel75
Please Log in or Create an account to join the conversation.
12 years 8 months ago #140719
by mitchie
Replied by mitchie on topic onAfterOrderConfirm not triggering
Hi Nicolas,
I need to trigger my own plugin after payment (paypal) confirm. From your workflow I understand I need step
10. onPaymentConfirm
which unfortunately doesn't exists (if I'm not wrong).
Isn't it?
If so, can I asky you why don't you add that function?
Thanks in advance
I need to trigger my own plugin after payment (paypal) confirm. From your workflow I understand I need step
10. onPaymentConfirm
which unfortunately doesn't exists (if I'm not wrong).
Isn't it?
If so, can I asky you why don't you add that function?
Thanks in advance
Please Log in or Create an account to join the conversation.
12 years 8 months ago #140727
by nicolas
Replied by nicolas on topic onAfterOrderConfirm not triggering
Hi,
There is already such function. It is called onAfterOrderUpdate which is triggered each time the order is changed.
So simply implement that trigger and in it, you verify that the $order->order_status is confirmed and the the $order->old->order_status is created and you'll know that the order has just been confirmed.
You can read more on that trigger in our developer documentation.
There is already such function. It is called onAfterOrderUpdate which is triggered each time the order is changed.
So simply implement that trigger and in it, you verify that the $order->order_status is confirmed and the the $order->old->order_status is created and you'll know that the order has just been confirmed.
You can read more on that trigger in our developer documentation.
Please Log in or Create an account to join the conversation.
12 years 8 months ago #140729
by mitchie
Replied by mitchie on topic onAfterOrderConfirm not triggering
Hi Nicolas,
I'm sorry, I've missed it!
Thanks a lot!
I'm sorry, I've missed it!
Thanks a lot!
Please Log in or Create an account to join the conversation.
Time to create page: 0.213 seconds