<?php
function onAfterOrderConfirm(&$order,&$methods,$method_id) {
$method =& $methods[$method_id];
$currencyClass = hikashop::get('class.currency');
$currencies = null;
$currencies = $currencyClass->getCurrencies($order->order_currency_id,$currencies);
$currency = $currencies[$order->order_currency_id];
hikashop::loadUser(true,true); //reset user data in case the emails were changed in the email code
$user = hikashop::loadUser(true);
$lang = &JFactory::getLanguage();
$locale = strtolower(substr($lang->get('tag'),0,2));
$httpsHikashop = str_replace('http://','https://', HIKASHOP_LIVE);
$notify_url = $httpsHikashop.'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=googlecheckout&tmpl=component&lang='.$locale;
$return_url = $httpsHikashop.'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=googlecheckout&tmpl=component&user_return=1&lang='.$locale;
$app =& JFactory::getApplication();
$address = $app->getUserState( HIKASHOP_COMPONENT.'.billing_address');
$price = round($order->cart->full_total->prices[0]->price_value_with_tax,(int)$currency->currency_locale['int_frac_digits']);
$data = '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'."\n";
$data .= '<checkout-shopping-cart xmlns="checkout.google.com/schema/2"><shopping-cart><items>';
foreach($order->cart->products as $product){
$data .= '<item><item-name>Order #'.$order->order_id.' - '.$product->order_product_name.'</item-name><item-description></item-description><unit-price currency="'.$currency->currency_code.'">'.$product->order_product_price.'</unit-price><quantity>'.$product->order_product_quantity.'</quantity></item>';
}
$data .= '<item><item-name>Order #'.$order->order_id.' - Shipping</item-name><item-description></item-description>
<unit-price currency="'.$currency->currency_code.'">'.$order->order_shipping_price.'</unit-price><quantity>1</quantity></item>';
$data .= '</items></shopping-cart><checkout-flow-support><merchant-checkout-flow-support/></checkout-flow-support></checkout-shopping-cart>';
if( $method->payment_params->debug ) { echo 'XML Sent to Google<pre>'.htmlentities($data).'</pre>'; }
if( $method->payment_params->server_to_server == true ) {
$ret =& $this->webCall('checkout', $data, $method->payment_params);
if( $ret !== false ) {
if( preg_match('#<redirect-url>(.*)</redirect-url>#iU', $ret, $redirect) ) {
$redirect = html_entity_decode(trim($redirect[1]));
$app =& JFactory::getApplication();
$app->redirect($redirect);
}
if( $method->payment_params->debug ) { echo 'Google call return<pre>'.htmlentities($ret).'</pre>'; }
}
$url = '';
$vars = '';
$app =& JFactory::getApplication();
$app->enqueueMessage('Google Checkout error. Please log-in to the backend of Google Checkout to see the log.');
} else {
$vars = array(
'signature' => base64_encode($this->signature($data, $method->payment_params->merchant_key)),
'cart' => base64_encode($data)
);
if( $method->payment_params->sandbox ) {
$url = 'https://sandbox.google.com/checkout/api/checkout/v2/checkout/Merchant/';
} else {
$url = 'https://checkout.google.com/api/checkout/v2/checkout/Merchant/';
}
$url .= $method->payment_params->merchant_id;
}
JHTML::_('behavior.mootools');
$app =& JFactory::getApplication();
$name = $method->payment_type.'_end.php';
$path = JPATH_THEMES.DS.$app->getTemplate().DS.'hikashoppayment'.DS.$name;
if(!file_exists($path)){
if(version_compare(JVERSION,'1.6','<')){
$path = JPATH_PLUGINS .DS.'hikashoppayment'.DS.$name;
}else{
$path = JPATH_PLUGINS .DS.'hikashoppayment'.DS.$method->payment_type.DS.$name;
}
if(!file_exists($path)){
return true;
}
}
require($path);
return true;
}