<?php
require_once ROOT_PATH.'/zipmarket/apps/payments/models/payments_abstract.class.php';
class zarinpal extends payments_abstract
{
	public function generateForm($order_data = array())
	{
		global $langArray, $currency, $config, $languageURL;
		try
		{
			ini_set("soap.wsdl_cache_enabled", "0");
			$client = new SoapClient('http://www.zarinpal.com/WebserviceGateway/wsdl', array('encoding'=>'UTF-8'));
		} catch (SoapFault $ex) {die('System Error1: constructor error');}
		$merchant = $this->getMeta('zarinpal_merchant');
		$price    = intval($order_data['price']);
		$price   += ceil($price * 2 / 100);
		$callBack = 'http://' . $config['domain'] . '/' . $languageURL . 'payments/zarinpal/?oID='.(int)$order_data['id'].'&Price='.$price;
		$res = $client->PaymentRequest($merchant, $price, $callBack, 'www . Amir Market . biz -::- ZarinaPal Payment -::- '.$price);
		if (strlen($res) == 36)
		{
			$form  = '<form class="form-for-pay" action="https://www.zarinpal.com/users/pay_invoice/'.$res.'" method="post" id="zarinpal_form_submit">'."\n";
		}
		else
		{
			$form  = '<form class="form-for-pay" action="http://' . $config['domain'] . '/' . $languageURL . 'payments/msg/?zarin_error='.$res.'" method="post" id="zarinpal_form_submit">'."\n";
		}
		$form .= '<button id="zarinpal-purchase-button" class="btn-icon purchase" type="submit">Purchase</button>'."\n";
		$form .= '</form>'."\n";
		return $form;
	}
	public function generateDepositForm($order_data = array())
	{
	//require_once("../nusoap.php");
		global $langArray, $currency, $config, $languageURL;
		try
		{
			ini_set("soap.wsdl_cache_enabled", "0");
			$client = new SoapClient('http://www.zarinpal.com/WebserviceGateway/wsdl', array('encoding'=>'UTF-8'));
		} catch (SoapFault $ex) {die('System Error1: constructor error');}
		$merchant = $this->getMeta('zarinpal_merchant');
		$price    = intval($order_data['deposit']);
		$price   += ceil($price * 2 / 100);
		$callBack = 'http://' . $config['domain'] . '/' . $languageURL . 'payments/deposit_zarinpal/?oID='.(int)$order_data['id'].'&Price='.$price;
		$res = $client->PaymentRequest($merchant, $price, $callBack, '-::- ZarinaPal Payment -::-'.$price);
		if (strlen($res) == 36)
		{
			$form  = '<form class="form-for-pay" action="https://www.zarinpal.com/users/pay_invoice/'.$res.'" method="post" id="zarinpal_form_submit">'."\n";
		}
		else
		{
			$form  = '<form class="form-for-pay" action="http://' . $config['domain'] . '/' . $languageURL . 'payments/msg/?zarin_error='.$res.'" method="post" id="zarinpal_form_submit">'."\n";
		}
		$form .= '<button id="zarinpal-purchase-button" class="btn-icon purchase" type="submit">Purchase</button>'."\n";
		$form .= '</form>'."\n";
		return $form;
	}	
}
?>