name = 'gcheckout';
$this->tab = 'Payment';
$this->version = 1.0;
$this->currencies = true;
$this->currencies_mode = 'radio';
parent::__construct();
$this->displayName = $this->l('Google Checkout');
$this->description = $this->l('Google Checkout API implementation');
if (!sizeof(Currency::checkPaymentCurrencies($this->id)))
$this->warning = $this->l('No currency set for this module');
}
function install()
{
if (!parent::install() OR !$this->registerHook('payment') OR !$this->registerHook('paymentReturn') OR !Configuration::updateValue('GCHECKOUT_MERCHANT_ID', '822305931131113') OR !Configuration::updateValue('GCHECKOUT_MERCHANT_KEY', '2Lv_osMomVIocnLK0aif3A') OR !Configuration::updateValue('GCHECKOUT_LOGS', '1') OR !Configuration::updateValue('GCHECKOUT_MODE', 'real'))
return false;
return true;
}
function uninstall()
{
return (
parent::uninstall() AND
Configuration::deleteByName('GCHECKOUT_MERCHANT_ID') AND
Configuration::deleteByName('GCHECKOUT_MERCHANT_KEY') AND
Configuration::deleteByName('GCHECKOUT_MODE') AND
Configuration::deleteByName('GCHECKOUT_LOGS'));
}
function getContent()
{
global $currentIndex, $cookie;
if (Tools::isSubmit('submitGoogleCheckout'))
{
$errors = array();
if (($merchant_id = Tools::getValue('gcheckout_merchant_id')) AND preg_match('/[0-9]{15}/', $merchant_id))
Configuration::updateValue('GCHECKOUT_MERCHANT_ID', $merchant_id);
else
$errors[] = '
'.$this->l('Merchant ID seems to be wrong').'
';
if (($merchant_key = Tools::getValue('gcheckout_merchant_key')) AND preg_match('/[a-zA-Z0-9_-]{22}/', $merchant_key))
Configuration::updateValue('GCHECKOUT_MERCHANT_KEY', $merchant_key);
else
$errors[] = '
'.$this->l('Merchant key seems to be wrong').'
';
if ($mode = (Tools::getValue('gcheckout_mode') == 'real' ? 'real' : 'sandbox'))
Configuration::updateValue('GCHECKOUT_MODE', $mode);
if (Tools::getValue('gcheckout_logs'))
Configuration::updateValue('GCHECKOUT_LOGS', 1);
else
Configuration::updateValue('GCHECKOUT_LOGS', 0);
if (!sizeof($errors))
Tools::redirectAdmin($currentIndex.'&configure=gcheckout&token='.Tools::getValue('token').'&conf=4');
foreach ($errors as $error)
echo $error;
}
$html = '
'.$this->displayName.'
';
return $html;
}
function hookPayment($params)
{
if (!$this->active)
return ;
global $smarty;
require_once('library/googlecart.php');
require_once('library/googleitem.php');
require_once('library/googleshipping.php');
$currency = $this->getCurrency();
$googleCart = new GoogleCart(Configuration::get('GCHECKOUT_MERCHANT_ID'), Configuration::get('GCHECKOUT_MERCHANT_KEY'), Configuration::get('GCHECKOUT_MODE'), $currency->iso_code);
foreach ($params['cart']->getProducts() as $product)
$googleCart->AddItem(new GoogleItem(utf8_decode($product['name']), utf8_decode($product['description_short']), intval($product['cart_quantity']), Tools::convertPrice($product['price_wt'], $currency)));
if ($wrapping = $params['cart']->getOrderTotal(true, 6))
$googleCart->AddItem(new GoogleItem(utf8_decode($this->l('Wrapping')), '', 1, Tools::convertPrice($wrapping, $currency)));
foreach ($params['cart']->getDiscounts() as $voucher)
$googleCart->AddItem(new GoogleItem(utf8_decode($voucher['name']), utf8_decode($voucher['description']), 1, '-'.Tools::convertPrice($voucher['value_real'], $currency)));
$googleCart->AddShipping(new GooglePickUp($this->l('Shipping costs'), Tools::convertPrice($params['cart']->getOrderShippingCost($params['cart']->id_carrier), $currency)));
$googleCart->SetEditCartUrl(Tools::getHttpHost(true, true).__PS_BASE_URI__.'order.php');
$googleCart->SetContinueShoppingUrl(Tools::getHttpHost(true, true).__PS_BASE_URI__.'order-confirmation.php');
$googleCart->SetRequestBuyerPhone(false);
$googleCart->SetMerchantPrivateData($params['cart']->id);
$buttonText = $this->l('Pay with GoogleCheckout');
$smarty->assign(array(
'googleCheckoutExtraForm' => $googleCart->CheckoutButtonCode($buttonText, 'LARGE'),
'buttonText' => $buttonText
));
return $this->display(__FILE__, 'payment.tpl');
}
function hookPaymentReturn($params)
{
if (!$this->active)
return ;
return $this->display(__FILE__, 'payment_return.tpl');
}
}
?>