<?php
/*
 * @version			$Id: index.php 10381 2008-06-01 03:35:53Z $
 * @package			Carteasy
 * @copyright		Copyright (C) 2005 - 2011 Wlanium
 * @license			proprietary
 * @author			Thomas Bartelt
 * Carteasy is a web shop system
 */


include_once('./core/shop_klarna.class.php');


class KlarnaPaymentMethod {


	private $base_object;
	private $layout_object;


	private $customer_data;
	private $shipping_address;
	private $billing_address;
	private $shoppingcart;
	private $payment_method;
	private $shipping_method;
	private $gift_certificate;
	private $order_id;


	function __construct($base_object, $layout_object) {
		$this->base_object = $base_object;
		$this->layout_object = $layout_object;

		$this->customer_data = false;
		$this->shipping_address = false;
		$this->billing_address = false;
		$this->shoppingcart = false;
		$this->payment_method = false;
		$this->shipping_method = false;
		$this->gift_certificate = false;
		$this->order_id = false;
	} // end __construct


	public function set_data($customer, $shipping, $billing, $shoppingcart, $delivery, $payment, $order_id = false) {
		$this->customer_data = $customer;
		$this->shipping_address = $shipping;
		$this->billing_address = $billing;
		$this->shoppingcart = $shoppingcart;
		$this->payment_method = $payment;
		$this->shipping_method = $delivery;
		$this->order_id = $order_id;
	} // end set_data


	public function set_gift_certificate($gift_certificate) {
		$this->gift_certificate = $gift_certificate;
	} // end set_gift_certificate


	public function set_order_id($order_id) {
		$this->order_id = $order_id;
	} // end set_order_id


	public function before_order($arg = false) {
		$klarna_object = new Shop_klarna($this->base_object);

		$klarna_object->set_shoppingcart($this->shoppingcart);
		$klarna_object->set_order_data($this->shipping_method->price_add, $this->payment_method->paymentAdd);
		$klarna_object->set_address($this->billing_address, $this->shipping_address);
		if ($arg) {
			$this->klarna_invoice_number = $klarna_object->transaction_test($arg);
		} else {
			$this->klarna_invoice_number = $klarna_object->transaction_test();
		}

		if (!$this->klarna_invoice_number) {
			return $klarna_object->get_error();
		}

		return false;
	} // end before_order


	public function during_order($arg = false) {
		/*
		$klarna_object = new Shop_klarna($this->base_object);
		$klarna_object->set_shoppingcart($this->shoppingcart);
		$klarna_object->set_order_data($this->shipping_method->price_add, $this->payment_method->paymentAdd);
		$klarna_object->set_address($this->billing_address, $this->shipping_address);

		if ($arg) {
			$return = $klarna_object->transaction($arg);
		} else {
			$return = $klarna_object->transaction();
		}*/

		if ($return) {
			return array('klarna_invoice_number' => $this->klarna_invoice_number);
		}

		return false;
	} // end during_order


	public function after_order($order_total = false) {
		return $this->layout_object->_fetch('content_cash_desk/completed.tpl');
	} // end after_order


	public function change_order() {

	} // end change_order


} // end KlarnaPaymentMethod

/* EOF */