/* Show XML or HTML Form */ /** * Include phpGCheckout configuration file * */ require_once '../config.php'; /** * Your Merchant IDs and Keys here */ $merchant_id = ''; $mercant_key = ''; /** * Create a new Cart */ $xml_merchant_private_data = "<item-note>Popular item: Check inventory and order more if needed</item-note>"; $GCheckout = new gCart($merchant_id, $mercant_key, '2006-12-31T23:59:59', $xml_merchant_private_data); /** * Add Merchant Checkout Flow Support */ $GCheckout->setMerchantCheckoutFlowSupport("http://www.example.com/edit", "http://www.example.com/shopping"); /** * Create Item */ $AARechargeableBatteryPack = new gItem('Dry Food Pack AA1453', 'A pack of highly nutritious dried food for emergency - store in your garage for up to one year!!', 1, 35.0); $AARechargeableBatteryPack_SKU = "<item-sku>SK00000001</item-sku>"; $AARechargeableBatteryPack->setPrivateItemData($AARechargeableBatteryPack_SKU); $AARechargeableBatteryPack->setTaxTableSelector("food"); $MegaSoundPlayer = new gItem('HelloWorld 2GB MP3 Player', 'HelloWorld, the simple MP3 player', 1, 178.99); /** * Add Item to Cart */
$OUTPUT_XML = false; /* Show XML or HTML Form */ /** * Include phpGCheckout configuration file * */ require_once '../config.php'; /** * Your Merchant IDs and Keys here */ $merchant_id = ''; $mercant_key = ''; /** * Create a new Cart */ $GCheckout = new gCart($merchant_id, $mercant_key); /** * Create Item */ $MegaSoundPlayer = new gItem('HelloWorld 2GB MP3 Player', 'HelloWorld, the simple MP3 player', 1, 159.99); /** * Add Item to Cart */ $GCheckout->addItems(array($MegaSoundPlayer)); if ($OUTPUT_XML) { header('Content-type: text/xml'); echo $GCheckout->getCart(); } else { ?> <form action="https://sandbox.google.com/cws/v2/Merchant/<?php echo $merchant_id;
/** * Posts Data to URL * * @param unknown_type $data * @param unknown_type $url * @return unknown */ function postData($data, $url, $merchant_id, $merchant_key) { $gcart = new gCart($merchant_id, $merchant_key); return $gcart->_getCurlResponse($data, $url); }
public function getHandler($returnUrl = '', $cancelUrl = '') { $application = ActiveRecordModel::getApplication(); $GLOBALS['merchant_id'] = $this->getConfigValue('merchant_id'); if ($this->getConfigValue('sandbox') && !defined('PHPGCHECKOUT_USE_SANDBOX')) { define('PHPGCHECKOUT_USE_SANDBOX', true); } include_once dirname(dirname(__FILE__)) . '/library/google/config.php'; if ($this->order) { $GLOBALS['GCheckout_currency'] = $this->getValidCurrency($this->order->getCurrency()->getID()); } $handler = new gCart($this->getConfigValue('merchant_id'), $this->getConfigValue('merchant_key')); $handler->setMerchantCheckoutFlowSupport($returnUrl, $cancelUrl, $this->application->getConfig()->get('REQUIRE_PHONE')); // add cart items if ($this->order) { $items = array(); foreach ($this->order->getOrderedItems() as $item) { if (!$item->isSavedForLater->get()) { $gItem = new gItem(htmlspecialchars($item->product->get()->getValueByLang('name')), htmlspecialchars($item->product->get()->getValueByLang('shortDescription')), $item->count->get(), $item->price->get()); $gItem->setPrivateItemData('<item-id>' . $item->getID() . '</item-id><order-id>' . $this->order->getID() . '</order-id>'); $items[] = $gItem; } // add discounts if ($discounts = $this->order->getFixedDiscountAmount()) { $items[] = new gItem($application->translate('_discount'), '', 1, $discounts * -1); } $handler->addItems($items); } // get shipping rates for all zones - silly, eh? if ($this->order->isShippingRequired()) { $shipment = $this->order->getShipments()->get(0); $zoneCountries = $zoneStates = $zoneZips = array(); foreach (DeliveryZone::getAll() as $zone) { $countries = $zone->getCountries()->extractField('countryCode'); $states = array(); foreach ($zone->getStates()->extractReferencedItemSet('state') as $state) { if ($state->countryID == 'US') { $states[] = $state->code->get(); } else { $countries[] = $state->countryID->get(); } } $countries = array_intersect(array_unique($countries), $this->getSupportedCountries()); $zipMasks = $zone->getZipMasks()->extractField('mask'); foreach ($zone->getShippingRates($shipment)->toArray() as $rate) { $name = $rate['serviceName'] ? $rate['serviceName'] : $rate['ShippingService']['name_lang']; $gRate = new gShipping($name, round($rate['costAmount'], 2), 'merchant-calculated-shipping'); // @todo: remove this. chokes up on non-US postal codes $zipMasks = array(); $gRate->addAllowedAreas($countries, $states, $zipMasks); $shipping[$name] = $gRate; } $zoneCountries = array_merge($zoneCountries, $countries); $zoneStates = array_merge($zoneStates, $states); $zoneZips = array_merge($zoneZips, $zipMasks); } // default zone $enabledCountries = array_keys($application->getConfig()->get('ENABLED_COUNTRIES')); $defCountries = array_intersect($enabledCountries, $zoneCountries, $this->getSupportedCountries()); foreach (DeliveryZone::getDefaultZoneInstance()->getShippingRates($shipment)->toArray() as $rate) { $gRate = new gShipping($rate['serviceName'] ? $rate['serviceName'] : $rate['ShippingService']['name_lang'], round($rate['costAmount'], 2), 'merchant-calculated-shipping'); $gRate->addAllowedAreas($defCountries, array(), array()); $shipping[] = $gRate; } $handler->_setShipping($shipping); } } // set merchant calculations $router = CustomerOrder::getApplication()->getRouter(); $calcUrl = $router->createFullUrl($router->createUrl(array('controller' => 'googleCheckout', 'action' => 'index')), !$this->getConfigValue('sandbox')); $handler->setMerchantCalculations(new gMerchantCalculations($calcUrl, $this->getConfigValue('coupons'))); $handler->setDefaultTaxTable(new gTaxTable('Tax', array(new gTaxRule(0)))); return $handler; }