I'm getting there
Below is the code I'm working on to integrate Hikashop with Kashflow (accounts).
<?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
function onAfterOrderConfirm(&$order, &$methods, $method_id) {
to
function onAfterOrderCreate(&$order,&$send_email){
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