OpenCart 🇺🇦

Схема

public mixed send ( )

Аргументы

Аргумент Возможный тип Описание
У метода нет аргументов

Описание

Метод пока еще не документирован.

Исходный код

$this->language->load('payment/google_checkout');

$json = array();

if ($this->cart->hasShipping() && !isset($this->session->data['shipping_method'])) {
	$json['error'] = $this->language->get('error_shipping');	
}

if (!$json) {
	$xml  = '<?xml version="1.0" encoding="UTF-8"?>';
	$xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">';
	$xml .= '	<shopping-cart>';
//	$xml .= '   	<merchant-private-data>';
//	$xml .= '			<order_id>' . $this->session->data['order_id'] . '</order_id>';
//	$xml .= '   	</merchant-private-data>'; 
	$xml .= '		<items>';

	$products = $this->cart->getProducts();

	foreach ($products as $product) { 
		$xml .= '			<item>';
		$xml .= '				<merchant-item-id>' . $product['key'] . '</merchant-item-id>';

		$option_data = array();

		foreach ($product['option'] as $option) {
			$option_data[] = $option['name'] . ': ' . $option['value'];
		}

		if ($option_data) {
			$xml .= '				<item-name>' . $product['name'] . ' ' . implode('; ', $option_data) . '</item-name>'; 
			$xml .= '				<item-description>' . $product['name'] . ' ' . implode('; ', $option_data) . '</item-description>';  
		} else {
			$xml .= '				<item-name>' . $product['name'] . '</item-name>'; 
			$xml .= '				<item-description>' . $product['name'] . '</item-description>';  
		}

		$xml .= '				<unit-price currency="' . $this->currency->getCode() . '">' . $this->currency->format($product['price'], $this->currency->getCode(), false, false) . '</unit-price>';
		$xml .= '				<quantity>' . $product['quantity'] . '</quantity>';
		$xml .= '			</item>'; 
	}

	$xml .= '		</items>';
	$xml .= '	</shopping-cart>';

	if ($this->cart->hasShipping()) {
		$xml .= '	<checkout-flow-support>';  
		$xml .= '		<merchant-checkout-flow-support>';
		$xml .= '			<shipping-methods>';
		$xml .= '				<flat-rate-shipping name="' . $this->session->data['shipping_method']['title'] . '">';
		$xml .= '					<price currency="' . $this->currency->getCode() . '">' . $this->currency->format($this->session->data['shipping_method']['cost'], $this->currency->getCode(), false, false) . '</price>';
		$xml .= '				</flat-rate-shipping>';
		$xml .= '			</shipping-methods>';
		$xml .= '		</merchant-checkout-flow-support>';
		$xml .= '	</checkout-flow-support>';
	}

	if ($this->cart->hasShipping()) {
		$xml .= '	<checkout-flow-support>';  
		$xml .= '		<merchant-checkout-flow-support>';
		$xml .= '			<shipping-methods>';
		$xml .= '				<flat-rate-shipping name="' . $this->session->data['shipping_method']['title'] . '">';
		$xml .= '					<price currency="' . $this->currency->getCode() . '">' . $this->currency->format($this->session->data['shipping_method']['cost'], $this->currency->getCode(), false, false) . '</price>';
		$xml .= '				</flat-rate-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;
	$hash = 'sha1';

	if (strlen($key) > $blocksize) {
		$key = pack('H*', $hash($key));
	}

	$key = str_pad($key, $blocksize, chr(0x00));
	$ipad = str_repeat(chr(0x36), $blocksize);
	$opad = str_repeat(chr(0x5c), $blocksize);
	$hmac = pack('H*', $hash(($key ^ $opad) . pack('H*', $hash(($key ^ $ipad) . $xml))));

	$json['cart'] = base64_encode($xml);
	$json['signature'] = base64_encode($hmac);	
}

$this->response->setOutput(json_encode($json));