<?php
	session_start();
	
	/**
	 * @author Jan Wehrs (jan.wehrs@billpay.de)
	 * @copyright Copyright 2010 Billpay GmbH
	 * @license commercial 
	 */
	require_once '../../api/ipl_xml_api.php';
	require_once '../../api/php5/ipl_invoice_created_request.php';
	
	// This is the order reference from the capture request
	$ref = $_GET["ref"];
	
	$req = new ipl_invoice_created_request($_SESSION['api-url-base']);
	$req->set_default_params($_SESSION['mid'], $_SESSION['pid'], $_SESSION['security-key']);
	$req->set_invoice_params(27455, "EUR", $ref, 5);
	$req->set_payment_info_params(true, true);
	
	try {
		$req->send();

		if (!$req->has_error()) {
			echo "Account holder: 	" . $req->get_account_holder() . "<br />";
			echo "Account number: 	" . $req->get_account_number() . "<br />";
			echo "Bank code: 		" . $req->get_bank_code() . "<br />";
			echo "Bank name: 		" . $req->get_bank_name() . "<br />";
			echo "Invoice reference: 	" . $req->get_invoice_reference() . "<br />";
			echo "Invoice due date: 	" . $req->get_invoice_duedate() . "<br />";
			echo "Activation performed: " . ($req->get_activation_performed() ? "Yes" : "No") . "<br />";
			
			if (count($req->get_dues()) > 0) {
				echo "Hire purchase payment:<br />";
				$pos = 0;
				foreach ($req->get_dues() as $due) {
					echo (++$pos).") date: ".$due['date'].", amount: ".$due['value']."<br />";
				}
			}
			
			echo "<input type=\"button\" value=\"Edit cart content\" onclick=\"window.location.href='edit.php?ref=" . $ref . "'\" />";
			echo "<input type=\"button\" value=\"Full cancel\" onclick=\"window.location.href='cancel.php?ref=" . $ref . "'\" />";
			
		}
		else {
			echo "Error occured!<br />";
			echo "Error code: " . $req->get_error_code() . "<br />";
			echo "Merchant msg: " . utf8_decode($req->get_merchant_error_message()) . "<br />";
			echo "Customer msg: " . utf8_decode($req->get_customer_error_message()) . "<br />";
		}
		
		echo "<br /><br />";
		echo "<strong>Request XML:</strong> " . htmlentities($req->get_request_xml());
		echo "<br /><br />";
		echo "<strong>Response XML:</strong> " . htmlentities($req->get_response_xml());
	}
	catch(Exception $e) {
		echo $e->getMessage();
	}
?>