opencart_serbian /catalog/controller/payment/google_checkout.php

Language PHP Lines 173
MD5 Hash 1d0b46bea149d816648efcb5390135b2 Estimated Cost $2,383 (why?)
Repository https://bitbucket.org/jjasko/opencart_serbian View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
class ControllerPaymentGoogleCheckout extends Controller {
	public function index() {
		if (!$this->config->get('google_checkout_test')) {
			$this->data['action'] = 'https://checkout.google.com/api/checkout/v2/checkout/Merchant/' . $this->config->get('google_checkout_merchant_id');	
		} else {
			$this->data['action'] = 'https://sandbox.google.com/checkout/api/checkout/v2/checkout/Merchant/' . $this->config->get('google_checkout_merchant_id');
		}
		
		$xml  = '<?xml version="1.0" encoding="UTF-8"?>';
		$xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">';
		$xml .= '	<shopping-cart>';
		$xml .= '		<items>';
		
		$products = $this->cart->getProducts();
		
		foreach ($products as $product) { 
			$option_data = array();
			
			foreach ($product['option'] as $option) {
				$option_data[] = $option['name'] . ': ' . $option['value'];
			}
		
			if ($option_data) {
				$name = $product['name'] . ' ' . implode('; ', $option_data);
			} else {
				$name = $product['name'];
			}
			
			$xml .= '			<item>';
			$xml .= '				<merchant-item-id>' . $product['product_id'] . '</merchant-item-id>';
			$xml .= '				<item-name>' . $name . '</item-name>'; 
			$xml .= '				<item-description>' . substr(strip_tags($product['description']), 0, 299) . '</item-description>';   
			$xml .= '				<unit-price currency="' . $this->currency->getCode() . '">' . $product['price'] . '</unit-price>';
			$xml .= '				<quantity>' . $product['quantity'] . '</quantity>';
			$xml .= '			</item>'; 
		}
		
		$xml .= '		</items>';
		$xml .= '	</shopping-cart>';
		$xml .= '	<checkout-flow-support>';  
		$xml .= '		<merchant-checkout-flow-support>';
		$xml .= '			<merchant-calculations>'; 
		$xml .= '				<merchant-calculations-url>' . $this->url->link('payment/google_checkout/shipping', '', 'SSL') . '</merchant-calculations-url>';
		$xml .= '			</merchant-calculations>';
		$xml .= '			<shipping-methods>';
		$xml .= '				<merchant-calculated-shipping name="SuperShip International">';
		$xml .= '					<price currency="' . $this->currency->getCode() . '">11.00</price>';
		$xml .= '					<address-filters>';
		$xml .= '						<allowed-areas>';
		$xml .= '							<us-country-area country-area="ALL" />';
		$xml .= '						</allowed-areas>';
		$xml .= '						<allow-us-po-box>false</allow-us-po-box>';
		$xml .= '					</address-filters>';
		$xml .= '				</merchant-calculated-shipping>';
		$xml .= '			</shipping-methods>';
		$xml .= '		</merchant-checkout-flow-support>';

		$xml .= '	</checkout-flow-support>';
		$xml .= '</checkout-shopping-cart>';

		$key = $this->config->get('google_checkout_merchant_key');

		$blocksize = 64;
		$hashfunc = 'sha1';
		
		if (strlen($key) > $blocksize) {
			$key = pack('H*', $hashfunc($key));
		}
		
		$key = str_pad($key, $blocksize, chr(0x00));
		$ipad = str_repeat(chr(0x36), $blocksize);
		$opad = str_repeat(chr(0x5c), $blocksize);
		$hmac = pack('H*', $hashfunc(($key ^ $opad) . pack('H*', $hashfunc(($key ^ $ipad) . $xml))));

		$this->data['cart'] = base64_encode($xml);
		$this->data['signature'] = base64_encode($hmac);
		
		if (!$this->config->get('google_checkout_test')) {
			$this->data['button'] = 'http://checkout.google.com/checkout/buttons/checkout.gif?merchant_id=' . $this->config->get('google_checkout_merchant_id') . '&w=180&h=46&style=white&variant=text&loc=en_US';	
		} else {
			$this->data['button'] = 'http://sandbox.google.com/checkout/buttons/checkout.gif?merchant_id=' . $this->config->get('google_checkout_merchant_id') . '&w=180&h=46&style=white&variant=text&loc=en_US';
		}
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/google_checkout.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/payment/google_checkout.tpl';
		} else {
			$this->template = 'default/template/payment/google_checkout.tpl';
		}	
		
		$this->render();
	}

	public function shipping() {
		ob_start();
		
		print_r($this->request->get);
		print_r($this->request->post);

		$content = ob_get_contents();
		
		ob_end_clean();
		
		$log = new Logger('error.txt');
		$log->write($content);
		
/*
<calculate>
    <addresses>
        <anonymous-address>
            <country-code>US</country-code>
            <city>Mountain View</city>
            <region>CA</region>
            <postal-code>94043</postal-code>
        </anonymous-address>
    </addresses>
    <shipping>
        <method name="FedEx Overnight Shipping"/>
        <method name="UPS Ground"/>
    </shipping>
</calculate>



		$this->load->model('setting/extension');
		
		$quote_data = array();
		
		$results = $this->model_setting_extension->getExtensions('shipping');
		
		foreach ($results as $result) {
			$this->load->model('shipping/' . $result['code']);
			
			$quote = $this->{'model_shipping_' . $result['code']}->getQuote(); 

			if ($quote) {
				$quote_data[$result['code']] = array(
					'title'      => $quote['title'],
					'quote'      => $quote['quote'], 
					'sort_order' => $quote['sort_order'],
					'error'      => $quote['error']
				);
			}
		}

		$sort_order = array();
	  
		foreach ($quote_data as $key => $value) {
      		$sort_order[$key] = $value['sort_order'];
    	}

    	array_multisort($sort_order, SORT_ASC, $quote_data);
*/
		$xml = '<shipping-methods>';
		
		foreach ($quote_data as $shipping) {
			$xml .= '<merchant-calculated-shipping name="UPS Next Day Air">';
			$xml .= '	<price currency="' . $this->currency->getCode() . '">20.00</price>';
			$xml .= '		<address-filters>';
			$xml .= '			<allow-us-po-box>false<allow-us-po-box>';
			$xml .= '		</address-filters>';
			$xml .= '</merchant-calculated-shipping>';
			$xml .= '<merchant-calculated-shipping name="UPS Ground">';
			$xml .= '	<price currency="' . $this->currency->getCode() . '">15.00</price>';
			$xml .= '</merchant-calculated-shipping>';
		}
		
		$xml .= '</shipping-methods>';
		
		$this->response->setOutput($xml);
	}
}
?>
Back to Top