PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/catalog/controller/payment/google_checkout.php

https://bitbucket.org/sandeepbhaskar/inspiredliving
PHP | 205 lines | 77 code | 20 blank | 108 comment | 9 complexity | 6136c45268b1930999a9b419b1fcb3e6 MD5 | raw file
  1. <?php
  2. class ControllerPaymentGoogleCheckout extends Controller {
  3. public function index() {
  4. $this->data['button_confirm'] = $this->language->get('button_confirm');
  5. if (!$this->config->get('google_checkout_test')) {
  6. $this->data['action'] = 'https://checkout.google.com/api/checkout/v2/checkout/Merchant/' . $this->config->get('google_checkout_merchant_id');
  7. } else {
  8. $this->data['action'] = 'https://sandbox.google.com/checkout/api/checkout/v2/checkout/Merchant/' . $this->config->get('google_checkout_merchant_id');
  9. }
  10. $this->load->model('checkout/order');
  11. $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
  12. if ($order_info) {
  13. $xml = '<?xml version="1.0" encoding="UTF-8"?>';
  14. $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">';
  15. $xml .= ' <shopping-cart>';
  16. $xml .= ' <merchant-private-data>';
  17. $xml .= ' <order_id>' . $this->session->data['order_id'] . '</order_id>';
  18. $xml .= ' </merchant-private-data>';
  19. $xml .= ' <items>';
  20. $products = $this->cart->getProducts();
  21. foreach ($products as $product) {
  22. $xml .= ' <item>';
  23. $xml .= ' <merchant-item-id>' . $product['product_id'] . '</merchant-item-id>';
  24. $option_data = array();
  25. foreach ($product['option'] as $option) {
  26. $option_data[] = $option['name'] . ': ' . $option['value'];
  27. }
  28. if ($option_data) {
  29. $xml .= ' <item-name>' . $product['name'] . ' ' . implode('; ', $option_data) . '</item-name>';
  30. $xml .= ' <item-description>' . $product['name'] . ' ' . implode('; ', $option_data) . '</item-description>';
  31. } else {
  32. $xml .= ' <item-name>' . $product['name'] . '</item-name>';
  33. $xml .= ' <item-description>' . $product['name'] . '</item-description>';
  34. }
  35. $xml .= ' <unit-price currency="' . $this->currency->getCode() . '">' . $this->currency->format($product['price'], $this->currency->getCode(), false, false) . '</unit-price>';
  36. $xml .= ' <quantity>' . $product['quantity'] . '</quantity>';
  37. $xml .= ' </item>';
  38. }
  39. $xml .= ' </items>';
  40. $xml .= ' </shopping-cart>';
  41. if ($this->cart->hasShipping()) {
  42. $xml .= ' <checkout-flow-support>';
  43. $xml .= ' <merchant-checkout-flow-support>';
  44. $xml .= ' <shipping-methods>';
  45. $xml .= ' <flat-rate-shipping name="' . $this->session->data['shipping_method']['title'] . '">';
  46. $xml .= ' <price currency="' . $this->currency->getCode() . '">' . $this->currency->format($this->session->data['shipping_method']['cost'], $this->currency->getCode(), false, false) . '</price>';
  47. $xml .= ' </flat-rate-shipping>';
  48. $xml .= ' </shipping-methods>';
  49. $xml .= ' </merchant-checkout-flow-support>';
  50. $xml .= ' </checkout-flow-support>';
  51. }
  52. $xml .= '</checkout-shopping-cart>';
  53. $key = $this->config->get('google_checkout_merchant_key');
  54. $blocksize = 64;
  55. $hash = 'sha1';
  56. if (strlen($key) > $blocksize) {
  57. $key = pack('H*', $hash($key));
  58. }
  59. $key = str_pad($key, $blocksize, chr(0x00));
  60. $ipad = str_repeat(chr(0x36), $blocksize);
  61. $opad = str_repeat(chr(0x5c), $blocksize);
  62. $hmac = pack('H*', $hash(($key ^ $opad) . pack('H*', $hash(($key ^ $ipad) . $xml))));
  63. $this->data['cart'] = base64_encode($xml);
  64. $this->data['signature'] = base64_encode($hmac);
  65. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/google_checkout.tpl')) {
  66. $this->template = $this->config->get('config_template') . '/template/payment/google_checkout.tpl';
  67. } else {
  68. $this->template = 'default/template/payment/google_checkout.tpl';
  69. }
  70. $this->render();
  71. }
  72. }
  73. public function callback() {
  74. $this->log->write($_SERVER['REQUEST_URI']);
  75. /*
  76. order-summary.google-order-number=923823874108605
  77. &order-summary.total-chargeback-amount.currency=USD
  78. &order-summary.total-chargeback-amount=0.0
  79. &order-summary.total-charge-amount=0.0
  80. &order-summary.total-charge-amount.currency=USD
  81. &order-summary.total-refund-amount.currency=USD
  82. &order-summary.total-refund-amount=0.0
  83. &order-summary.purchase-date=2010-04-21T14%3A09%3A40.000Z
  84. &order-summary.archived=false
  85. &order-summary.shopping-cart.items.item-1.item-name=Peanut+Butter
  86. &order-summary.shopping-cart.items.item-1.item-description=Crunchy+peanut+butter
  87. &order-summary.shopping-cart.items.item-1.unit-price.currency=USD
  88. &order-summary.shopping-cart.items.item-1.unit-price=2.95
  89. &order-summary.shopping-cart.items.item-1.quantity=1
  90. &order-summary.shopping-cart.items=order-summary.shopping-cart.items.item-1
  91. &order-summary.order-adjustment.total-tax=0.0
  92. &order-summary.order-adjustment.total-tax.currency=USD
  93. &order-summary.order-adjustment.adjustment-total.currency=USD
  94. &order-summary.order-adjustment.adjustment-total=0.0
  95. &order-summary.buyer-id=539251754962590
  96. &order-summary.buyer-marketing-preferences.email-allowed=false
  97. &order-summary.buyer-shipping-address.email=test%40sandbox.google.com
  98. &order-summary.buyer-shipping-address.company-name=
  99. &order-summary.buyer-shipping-address.contact-name=Jan+Test
  100. &order-summary.buyer-shipping-address.address1=123+Test+St
  101. &order-summary.buyer-shipping-address.address2=
  102. &order-summary.buyer-shipping-address.phone=111+222-3333
  103. &order-summary.buyer-shipping-address.fax=
  104. &order-summary.buyer-shipping-address.structured-name.first-name=Test%20First%20Name
  105. &order-summary.buyer-shipping-address.structured-name.last-name=Test%20Last%20Name
  106. &order-summary.buyer-shipping-address.country-code=US
  107. &order-summary.buyer-shipping-address.postal-code=10001
  108. &order-summary.buyer-shipping-address.city=Test+City
  109. &order-summary.buyer-shipping-address.region=NY
  110. &order-summary.order-total=2.95
  111. &order-summary.order-total.currency=USD
  112. &order-summary.fulfillment-order-state=NEW
  113. &order-summary.financial-order-state=REVIEWING
  114. _type=new-order-notification
  115. &serial-number=85f54628-538a-44fc-8605-ae62364f6c71
  116. &google-order-number=841171949013218
  117. &buyer-shipping-address.contact-name=Will%20Shipp-Toomey
  118. &buyer-shipping-address.email=willstoomey%40example.com
  119. &buyer-shipping-address.address1=10%20Example%20Road
  120. &buyer-shipping-address.city=Sampleville
  121. &buyer-shipping-address.region=CA
  122. &buyer-shipping-address.postal-code=94141
  123. &buyer-shipping-address.country-code=US
  124. &buyer-shipping-address.phone=5555551234
  125. &buyer-shipping-address.structured-name.first-name=Will
  126. &buyer-shipping-address.structured-name.last-name=Shipp-Toomey
  127. &buyer-billing-address.contact-name=Bill%20Hu
  128. &buyer-billing-address.email=billhu%40example.com
  129. &buyer-billing-address.address1=99%20Credit%20Lane
  130. &buyer-billing-address.city=Mountain%20View
  131. &buyer-billing-address.region=CA
  132. &buyer-billing-address.postal-code=94043
  133. &buyer-billing-address.country-code=US
  134. &buyer-billing-address.phone=5555557890
  135. &buyer-billing-address.structured-name.first-name=Bill
  136. &buyer-billing-address.structured-name.last-name=Hu
  137. &buyer-id=294873009217523
  138. &fulfillment-order-state=NEW
  139. &financial-order-state=REVIEWING
  140. &shopping-cart.cart-expiration.good-until-date=2007-12-31T23%3A59%3A59-05%3A00
  141. &shopping-cart.items.item-1.merchant-item-id=GGLAA1453
  142. &shopping-cart.items.item-1.item-name=Dry%20Food%20Pack
  143. &shopping-cart.items.item-1.item-description=One%20pack%20of%20nutritious%20dried%emergency%20food.
  144. &shopping-cart.items.item-1.quantity=1
  145. &shopping-cart.items.item-1.tax-table-selector=food
  146. &shopping-cart.items.item-1.unit-price=4.99
  147. &shopping-cart.items.item-1.unit-price.currency=USD
  148. &shopping-cart.items.item-2.merchant-item-id=GGLAA1453
  149. &shopping-cart.items.item-2.item-name=Megasound%202GB%20MP3%20Player
  150. &shopping-cart.items.item-2.item-description=Portable%20player%20holds%20500%20songs.
  151. &shopping-cart.items.item-2.quantity=1
  152. &shopping-cart.items.item-2.tax-table-selector=food
  153. &shopping-cart.items.item-2.unit-price=179.99
  154. &shopping-cart.items.item-2.unit-price.currency=USD
  155. &shopping-cart.items.item-2.merchant-private-item-data=merchant-product-id%3D1234567890
  156. &order-adjustment.total-tax=11.05
  157. &order-adjustment.total-tax.currency=USD
  158. &order-adjustment.shipping.flat-rate-shipping-adjustment.shipping-name=SuperShip
  159. &order-adjustment.shipping.flat-rate-shipping-adjustment.shipping-cost=9.95
  160. &order-adjustment.shipping.flat-rate-shipping-adjustment.shipping-cost.currency=USD
  161. &order-total=190.98
  162. &order-total.currency=USD
  163. &buyer-marketing-preferences.email-allowed=false
  164. ×tamp=2007-03-19T15%3A06%3A26.051Z
  165. &order-summary...
  166. ... [order-summary parameters]
  167. */
  168. }
  169. }
  170. ?>