Example #1
0
	public function TransferToProvider()
	{
		$currency = GetDefaultCurrency();
		$currencyCode = $currency['currencycode'];

		$orders = $this->GetOrders();
		list(,$order) = each($orders);

		$amount = number_format($this->GetGatewayAmount(), '2');

		$billingDetails = $this->GetBillingDetails();

		$invoiceDescription = '';
		$quote = getCustomerQuote();
		foreach ($quote->getItems() as /** @var ISC_QUOTE_ITEM */$item){
			if ($invoiceDescription) {
				$invoiceDescription .= ", ";
			}

			$invoiceDescription .= $item->getQuantity() . 'x ' . $item->getName();
		}

		$data = array(
			'CustomerID'		=> $this->GetValue('customerid'),
			'UserName'			=> $this->GetValue('username'),
			'Currency'			=> $currencyCode,
			'Amount'			=> $amount,
			'ReturnURL'			=> $GLOBALS['ShopPath'] . '/finishorder.php',
			'CancelURL'			=> $GLOBALS['ShopPath'] . '/finishorder.php',
			'CompanyName'		=> GetConfig('CompanyName'),

			'CustomerFirstName'	=> $billingDetails['ordbillfirstname'],
			'CustomerLastName'	=> $billingDetails['ordbilllastname'],
			'CustomerAddress'	=> $billingDetails['ordbillstreet1'] . ' ' . $billingDetails['ordbillstreet2'],
			'CustomerCity'		=> $billingDetails['ordbillsuburb'],
			'CustomerState'		=> $billingDetails['ordbillstate'],
			'CustomerPostCode'	=> $billingDetails['ordbillzip'],
			'CustomerCountry'	=> $billingDetails['ordbillcountry'],
			'CustomerPhone'		=> $billingDetails['ordbillphone'],
			'CustomerEmail'		=> $billingDetails['ordbillemail'],

			'InvoiceDescription'=> $invoiceDescription,
			'MerchantReference' => $this->GetCombinedOrderId(),
		);

		$ewayUrl = $this->_ewayURL . 'Request?';
		$ewayUrl .= http_build_query($data);

		$response = PostToRemoteFileAndGetResponse($ewayUrl);

		if (empty($response)) {
			$this->logInvalidResponse($response, true);
		}

		try {
			$xml = new SimpleXMLElement($response);
		}
		catch (Exception $ex) {
			$this->logInvalidResponse($response, true);
		}

		if ((string)$xml->Result == 'True') {
			$transferUri = (string)$xml->URI;
			$this->RedirectToProvider($transferUri);
		}
		else {
			$this->logInvalidResponse((string)$xml->Error(), true);
		}
	}