PAYCOMET BankStore API (PHP)

The immediate benefit of using the Bankstore system in your business is providing the client with a fast way of accepting purchases without needing to enter your bank information in each operation. This method is ideal for On Demand Videos, subscriptions, and the purchase of redeemable points, etc.

  1. Download Link
  2. Installation
  3. Support
  4. Code
    1. bankstore_examples.php
    2. class/Paytpv_bankstore.php

This is the connection API with all PAYCOMET BankStore services through XML, IFRAME, FULLSCREEN and JET.

Download Link

Download Link: PAYCOMET-XML-Bankstore

Installation

  • Download the directory with the connection type and methods aquí
  • Include the type class/Paytpv_bankstore.php in your code
  • Recover the $merchantCode, $password, and $terminal information from your control panel and generate the JETID if you are going to use the BankStore JET integration

Support

If you have any questions or queries, just email us at tecnico@paycomet.com

Code

bankstore_examples.php


<?php
/**
* To include the necessary information of your product, it is necessary to consult the control panel and include:
*
*  $merchantCode    = Client code
*  $password        = Password
*  $terminal        = Terminal number
*
*/
include("class/Paytpv_bankstore.php");
$merchantCode   = "";
$password       = "";
$terminal       = "";
$jetid          = NULL; // Optional if BankStore JET is not used
$paycomet = new Paytpv_Bankstore($merchantCode, $terminal, $password, $jetid);
//------------------------------------------------  métodos por XML  --------------------------------------------------->
$response = $paycomet->AddUserToken("jettoken");
$response = $paycomet->AddUser("credit_card_pan", "credit_card_expdate", "credit_card_cvv");
$response = $paycomet->InfoUser("iduser", "tokenuser");
$response = $paycomet->ExecutePurchase("iduser", "tokenuser", "amount", "operation_reference", "currency");
$response = $paycomet->ExecutePurchaseDcc("iduser", "tokenuser", "amount", "operation_reference");
$response = $paycomet->ConfirmPurchaseDcc("iduser", "dcccurrency", "dccsession");
$response = $paycomet->ExecuteRefund("iduser", "tokenuser", "operation_reference", "currency", "authcode", "amount");
$response = $paycomet->CreateSubscription("credit_card_pan", "credit_card_expdate", "credit_card_cvv", date("Y-m-d"), date("Y-m-d", strtotime("+15 day")), "operation_reference", "periodicity", "amount", "currency");
$response = $paycomet->EditSubscription("iduser", "tokenuser", date("Y-m-d"), date("Y-m-d", strtotime("+15 day")), "periodicity", "amount", "currency", "execute");
$response = $paycomet->RemoveSubscription("iduser", "tokenuser");
$response = $paycomet->CreateSubscriptionToken("iduser", "tokenuser", date("Y-m-d"), date("Y-m-d", strtotime("+15 day")), "operation_reference", "periodicity", "amount", "currency");
$response = $paycomet->CreatePreauthorization("iduser", "tokenuser", "amount", "operation_reference", "currency");
$response = $paycomet->PreauthorizationConfirm("iduser", "tokenuser", "amount", "operation_reference");
$response = $paycomet->PreauthorizationCancel("iduser", "tokenuser", "amount", "operation_reference");
$response = $paycomet->DeferredPreauthorizationConfirm("iduser", "tokenuser", "amount", "operation_reference");
$response = $paycomet->DeferredPreauthorizationCancel("iduser", "tokenuser", "amount", "operation_reference");
$response = $paycomet->ExecutePurchaseRToken("amount", "operation_reference", "reference_token", "currency");
//------------------------------------------------  métodos por IFRAME/Fullscreen  ------------------------------------->
$response = $paycomet->ExecutePurchaseUrl("operation_reference", "amount", "currency", "language");
$response = $paycomet->AddUserUrl("operation_reference", "language");
$response = $paycomet->CreateSubscriptionUrl("operation_reference", "amount", "currency", date("Ymd"), date("Ymd", strtotime("+15 day")), "periodicity", "language");
$response = $paycomet->ExecutePurchaseTokenUrl("operation_reference", "amount", "currency", "iduser", "tokenuser", "language");
$response = $paycomet->CreateSubscriptionTokenUrl("operation_reference", "amount", "currency", date("Ymd"), date("Ymd", strtotime("+15 day")), "periodicity", "iduser", "tokenuser", "language");
$response = $paycomet->CreatePreauthorizationUrl("operation_reference", "amount", "currency", "language");
$response = $paycomet->PreauthorizationConfirmUrl("operation_reference", "amount", "currency", "iduser", "tokenuser");
$response = $paycomet->PreauthorizationCancelUrl("operation_reference", "amount", "currency", "iduser", "tokenuser");
$response = $paycomet->ExecutePreauthorizationTokenUrl("operation_reference", "amount", "currency", "iduser", "tokenuser");
$response = $paycomet->DeferredPreauthorizationUrl("operation_reference", "amount", "currency");
$response = $paycomet->DeferredPreauthorizationConfirmUrl("operation_reference", "amount", "currency", "iduser", "tokenuser");
$response = $paycomet->DeferredPreauthorizationCancelUrl("operation_reference", "amount", "currency", "iduser", "tokenuser");
if ($response->RESULT == "KO") {
	var_dump($response);
} else {
	if (isset($response->URL_REDIRECT)) {
		header("Location: ".$response->URL_REDIRECT);
		die();
	}
	var_dump($response);
}
?>
		

class/Paytpv_bankstore.php


<?php
/**
 * API de PAYCOMET para PHP. Métodos BankStore IFRAME/FULLSCREEN/XML/JET
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the 3-clause BSD License.
 *
 * This source file is subject to the 3-clause BSD License that is
 * bundled with this package in the LICENSE file.
 *
 * @package    PAYCOMET
 * @version    1.1.0
 * @author     PAYCOMET
 * @license    BSD License (3-clause)
 * @copyright  (c) 2010-2016, PAYCOMET
 * @link       https://www.paycomet.com
 */

class Paytpv_bankstore
{
	private $merchantCode;
	private $terminal;
	private $password;
	private $endpoint;
	private $endpointurl;
	private $jetid;

	public function __construct($arg1, $arg2, $arg3, $arg4 = NULL)
	{
		$this->merchantCode = $arg1;
		$this->terminal = $arg2;
		$this->password = $arg3;
		$this->jetid = $arg4;
		$this->endpoint = 'https://api.paycomet.com/gateway/xml-bankstore?wsdl';
		$this->endpointurl = 'https://api.paycomet.com/gateway/ifr-bankstore?';
	}

	/**
	* INTEGRACIÓN BANKSTORE XML --------------------------------------------------->
	*/

	/**
    * Add a card to PAYCOMET. IMPORTANT!!! This direct entry must be activated by PAYCOMET.
    * In its absence, the card entry method for PCI-DSS compliance must be AddUserUrl or AddUserToken (method used by BankStore JET)
    * @param int $pan Card number, without spaces or dashes
    * @param string $expdate Card expiration date, expressed as “mmyy” (month in two figures and year in two figures)
    * @param string $cvv CVC2 code of the card
    * @return object Object of response of the operation
    * @version 2.0 2016-06-02
    */
	public function AddUser($pan, $expdate, $cvv)
	{
		$pan = preg_replace('/\s+/', '', $pan);
		$expdate = preg_replace('/\s+/', '', $expdate);
		$cvv = preg_replace('/\s+/', '', $cvv);
		$signature = hash('sha512',$this->merchantCode.$pan.$cvv.$this->terminal.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->add_user($this->merchantCode, $this->terminal, $pan, $expdate, $cvv, $signature, $ip);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}
	/**
    * Remove a user from PAYCOMET through soap call
    * @param int $idpayuser User ID on PAYCOMET
    * @param string $tokenpayuser Token of PAYCOMET user
    * @return object Object of response of the operation
    * @version 1.0 2016-06-02
    */
	public function RemoveUser($idpayuser, $tokenpayuser)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try {
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->remove_user($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $signature, $ip);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}
	/**
    * Return the information of a user store don PAYCOMET through soap call
    * @param int $idpayuser User ID on PAYCOMET
    * @param string $tokenpayuser Token of the user on PAYCOMET
    * @return object Object of response of the operation
    * @version 1.0 2016-06-02
    */
	public function InfoUser($idpayuser, $tokenpayuser)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->info_user($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $signature, $ip);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}

	/**
    * Make a payment by web service
    * @param int $idpayuser User ID on PAYCOMET
    * @param string $tokenpayuser Token of the user on PAYCOMET
    * @param string $amount Payment amount 1€ = 100
    * @param string $transreference Unique payment identifier
    * @param string $currency Operation Currency identifier
    * @param string $productdescription Product description
    * @param string $owner Cardholder
	* @param integer $scoring (optional) Risk scoring value of the transaction
    * @return object Object of response of the operation
    * @version 2.0 2016-06-02
    */
	public function ExecutePurchase($idpayuser, $tokenpayuser, $amount, $transreference, $currency, $productdescription, $owner, $scoring = null)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$amount.$transreference.$this->password);
		$ip	= $_SERVER['REMOTE_ADDR'];

		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->execute_purchase($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $amount, $transreference, $currency, $signature, $ip, $productdescription, $owner, $scoring);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}

		return $this->SendResponse($ans);
	}

	/**
    * Make a payment by web service with the DCC operation
    * @param int $idpayuser User ID on PAYCOMET
    * @param string $tokenpayuser Token of the user on PAYCOMET
    * @param string $amount Payment amount 1€ = 100
    * @param string $transreference Unique payment identifier
    * @param string $productdescription Product description
    * @param string $owner Cardholder
    * @return object Object of response of the operation
    * @version 1.0 2016-06-07
	*/
	public function ExecutePurchaseDcc($idpayuser, $tokenpayuser, $amount, $transreference, $productdescription = false, $owner = false)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$amount.$transreference.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->execute_purchase_dcc($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $amount, $transreference, $signature, $ip, $productdescription, $owner);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}

	/**
    * Confirm a payment by web service with the DCC operation
    * @param string $transreference Unique payment identifier
    * @param string $dcccurrency Transaction currency selected. Maybe that of the PAYCOMET product or that selected by the end user. The amount will be sent in execute_purchase_dcc if it is the same as the product and converted if different.
    * @param string $dccsession Same session sent in the process of execute_purchase_dcc.
    * @return object Object of response of the operation
    * @version 1.0 2016-06-07
    */
	public function ConfirmPurchaseDcc($transreference, $dcccurrency, $dccsession)
	{
		$signature = hash('sha512',$this->merchantCode.$this->terminal.$transreference.$dcccurrency.$dccsession.$this->password);
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->confirm_purchase_dcc($this->merchantCode, $this->terminal, $transreference, $dcccurrency, $dccsession, $signature);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}

	/**
    * Make a refund of a payment by web service
    * @param int $idpayuser User ID on PAYCOMET
    * @param string $tokenpayuser Token of the user on PAYCOMET
    * @param string $transreference Unique payment identifier
    * @param string $currency Operation currency identifier
    * @param string $authcode AuthCode of the original operation to refund
    * @param string $amount Payment amount 1€ = 100
    * @return object Object of response of the operation
    * @version 2.0 2016-06-02
    */
	public function ExecuteRefund($idpayuser, $tokenpayuser, $transreference, $currency, $authcode, $amount = NULL)
	{
		$signature = hash('sha512',$this->merchantCode.$payiduser.$tokenpayuser.$this->terminal.$authcode.$transreference.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
				$ans = $clientSOAP->execute_refund($this->merchantCode, $this->terminal, $payiduser, $tokenpayuser, $authcode, $transreference, $currency, $signature, $ip, $amount);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}

	/**
    * Create a subscription on PAYCOMET on a card. IMPORTANT! This direct entry must be activated by PAYCOMET.
    * In its absence, the card entry method for compliance with PCI-DSS must be CreateSubscriptionUrl or CreateSubscriptionToken
    * @param int $pan Card number, without spaces or dashes
    * @param string $expdate Card expiration date, expressed as “mmyy” (month in two figures and year in two figures)
    * @param string $cvv CVC2 code of the card
    * @param string $startdate Subscription start date yyyy-mm-dd
    * @param string $enddate Subscription end date yyyy-mm-dd
    * @param string $transreference Unique payment identifier
    * @param string $periodicity Subscription frequency. Expressed in days.
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
	* @param integer $scoring (optional) Risk scoring value of the transaction
    * @return object Object of response of the operation
    * @version 2.0 2016-06-07
    */
	public function CreateSubscription($pan, $expdate, $cvv, $startdate, $enddate, $transreference, $periodicity, $amount, $currency, $ownerName = null, $scoring = null)
	{
		$pan = preg_replace('/\s+/', '', $pan);
		$expdate = preg_replace('/\s+/', '', $expdate);
		$cvv = preg_replace('/\s+/', '', $cvv);
		$signature = hash('sha512',$this->merchantCode.$pan.$cvv.$this->terminal.$amount.$currency.$this->password);
		$ip	= $_SERVER['REMOTE_ADDR'];

		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->create_subscription($this->merchantCode, $this->terminal, $pan, $expdate, $cvv, $startdate, $enddate, $transreference, $periodicity, $amount, $currency, $signature, $ip, 1, $ownerName, $scoring);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}

		return $this->SendResponse($ans);
	}

	/**
    * Modify a subscription on PAYCOMET on a card.
    * @param string $idpayuser Unique identifier of the user registered on the system.
    * @param string $tokenpayuser Token code associated with the USER ID.
    * @param string $startdate Subscription start date yyyy-mm-dd
    * @param string $enddate Subscription end date yyyy-mm-dd
    * @param string $periodicity Subscription frequency. Expressed in days.
    * @param string $amount Payment amount 1€ = 100
    * @param string $execute If the registration process involves the payment of the first instalment, the DS_EXECUTE value must be 1. If it is only desired to register the subscription without paying the first instalment (executed with the sent parameters) its value must be 0.
    * @return object Object of response of the operation
    * @version 2.0 2016-06-07
    */
	public function EditSubscription($idpayuser, $tokenpayuser, $startdate, $enddate, $periodicity, $amount, $execute)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$amount.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->edit_subscription($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $startdate, $enddate, $periodicity, $amount, $signature, $execute, $ip);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}

	/**
    * Remove a subscription on PAYCOMET on a card.
    * @param string $idpayuser Unique identifier of the user registered on the system.
    * @param string $tokenpayuser Token code associated with the USER ID.
    * @return object Object of response of the operation
    * @version 2.0 2016-06-07
    */
	public function RemoveSubscription($idpayuser, $tokenpayuser)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->remove_subscription($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $signature, $ip);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}

	/**
    * Create a subscription on PAYCOMET on a previously tokenised card.
    * @param string $idpayuser Unique identifier of the user registered on the system.
    * @param string $tokenpayuser Token code associated with the USER ID.
    * @param string $startdate Subscripction start date yyyy-mm-dd
    * @param string $enddate Subscription end date yyyy-mm-dd
    * @param string $transreference Unique payment identifier
    * @param string $periodicity Frequency of the subscription. Expressed in days.
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
	* @param integer $scoring (optional) Risk scoring value for the transaction
    * @return object Object of response of the operation
    * @version 2.0 2016-06-07
    */
	public function CreateSubscriptionToken($idpayuser, $tokenpayuser, $startdate, $enddate, $transreference, $periodicity, $amount, $currency, $scoring = null)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$amount.$currency.$this->password);
		$ip	= $_SERVER['REMOTE_ADDR'];

		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->create_subscription_token($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $startdate, $enddate, $transreference, $periodicity, $amount, $currency, $signature, $ip, $scoring);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}

		return $this->SendResponse($ans);
	}

	/**
    * Create a pre-authorisation by web service
    * @param int $idpayuser User ID on PAYCOMET
    * @param string $tokenpayuser User token on PAYCOMET
    * @param string $amount Payment amount 1€ = 100
    * @param string $transreference Unique payment identifier
    * @param string $currency Operation currency identifier
    * @param string $productdescription Product description
    * @param string $owner Cardholder
	* @param integer $scoring (optional) Risk scoring value of the transaction
    * @return object Object of response of the operation
    * @version 2.0 2016-06-02
    */
	public function CreatePreauthorization($idpayuser, $tokenpayuser, $amount, $transreference, $currency, $productdescription = false, $owner = false, $scoring = null)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$amount.$transreference.$this->password);
		$ip	= $_SERVER['REMOTE_ADDR'];

		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->create_preauthorization($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $amount, $transreference, $currency, $signature, $ip, $productdescription, $owner, $scoring);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}

		return $this->SendResponse($ans);
	}

	/**
    * Confirm a previously sent pre-authorisation by web service
    * @param int $idpayuser User ID on PAYCOMET
    * @param string $tokenpayuser User token on PAYCOMET
    * @param string $amount Payment amount 1€ = 100
    * @param string $transreference Unique payment identifier
    * @return object Object of response of the operation
    * @version 2.0 2016-06-02
    */
	public function PreauthorizationConfirm($idpayuser, $tokenpayuser, $amount, $transreference)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$transreference.$amount.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->preauthorization_confirm($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $amount, $transreference, $signature, $ip);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}

	/**
    * Cancel a previously sent pre-authorisation by web service
    * @param int $idpayuser User ID on PAYCOMET
    * @param string $tokenpayuser User token on PAYCOMET
    * @param string $amount Payment amount 1€ = 100
    * @param string $transreference Unique payment identifier
    * @return object Object of response of the operation
    * @version 2.0 2016-06-02
    */
	public function PreauthorizationCancel($idpayuser, $tokenpayuser, $amount, $transreference)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$transreference.$amount.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->preauthorization_cancel($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $amount, $transreference, $signature, $ip);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}

	/**
    * Confirm a deferred pre-authorisation by web service. Once a deferred pre-authorisation operation carried out and authorised, it can be confirmed to make the effective payment with the following 72 hours; after this time, deferred pre-authorisations are no longer valid.
    * @param int $idpayuser User ID on PAYCOMET
    * @param string $tokenpayuser User token on PAYCOMET
    * @param string $amount Payment amount 1€ = 100
    * @param string $transreference Unique payment identifier
    * @return object Object of response of the operation
    * @version 2.0 2016-06-07
    */
	public function DeferredPreauthorizationConfirm($idpayuser, $tokenpayuser, $amount, $transreference)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$transreference.$amount.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->deferred_preauthorization_confirm($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $amount, $transreference, $signature, $ip);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}

	/**
    * Cancel a deferred pre-authorisation by web service.
    * @param int $idpayuser User ID on PAYCOMET
    * @param string $tokenpayuser User token on PAYCOMET
    * @param string $amount Payment amount 1€ = 100
    * @param string $transreference Unique payment identifier
    * @return object Object of response of the operation
    * @version 2.0 2016-06-07
    */
	public function DeferredPreauthorizationCancel($idpayuser, $tokenpayuser, $amount, $transreference)
	{
		$signature = hash('sha512',$this->merchantCode.$idpayuser.$tokenpayuser.$this->terminal.$transreference.$amount.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->deferred_preauthorization_cancel($this->merchantCode, $this->terminal, $idpayuser, $tokenpayuser, $amount, $transreference, $signature, $ip);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}

	/**
    * Make a payment by webservice with the “payment by reference” for PAYCOMET system migration.
    * @param string $amount Payment amount 1€ = 100
    * @param string $transreference Unique payment identifier
    * @param string $rtoken Original reference of the card saved on the old system.
    * @param string $currency Operation currency identifier
    * @param string $productdescription Product description
    * @return object Object of response of the operation
    * @version 1.0 2016-06-07
    */
	public function ExecutePurchaseRToken($amount, $transreference, $rtoken, $currency, $productdescription = false)
	{
		$signature = hash('sha512',$this->merchantCode.$this->terminal.$amount.$transreference.$rtoken.$this->password);
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->execute_purchase_rtoken($this->merchantCode, $this->terminal, $amount, $transreference, $rtoken, $currency, $signature, $productdescription);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}
	/**
	* INTEGRACIÓN BANKSTORE JET --------------------------------------------------->
	*/

	/**
    * Add a user by BankStore JET through web service
    * @param int $jettoken Temporary user token on PAYCOMET
    * @return object Object of response of the operation
    * @version 1.0 2016-06-02
    */
	public function AddUserToken($jettoken)
	{
		$signature = hash('sha512',$this->merchantCode.$jettoken.$this->jetid.$this->terminal.$this->password);
		$ip = $_SERVER['REMOTE_ADDR'];
		try{
			$clientSOAP = new SoapClient($this->endpoint);
			$ans = $clientSOAP->add_user_token($this->merchantCode, $this->terminal, $jettoken, $this->jetid, $signature, $ip);
		} catch(SoapFault $e){
			return $this->SendResponse();
		}
		return $this->SendResponse($ans);
	}
	/**
	* INTEGRACIÓN BANKSTORE IFRAME/Fullscreen --------------------------------------------------->
	*/

	/**
	* Return the URL to launch an execute_purchase under IFRAME/Fullscreen
	* @param string $transreference Unique payment identifier
	* @param string $amount Payment amount 1€ = 100
	* @param string $currency Operation currency identifier
	* @param string $lang Language of transaction wording
	* @param string $description Description of the operation
	* @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
	* @param integer $scoring (optional) Risk scoring value for the transaction
	* @return object Object of response of the operation
	* @version 1.0 2016-06-06
	*/
	public function ExecutePurchaseUrl($transreference, $amount, $currency, $lang = "ES", $description = false, $secure3d = false, $scoring = null)
	{
		$pretest = array();

		$operation = new stdClass();
		$operation->Type = 1;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->Language = $lang;
		$operation->Concept = $description;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		if ($scoring) {
			$operation->Scoring = (int)$scoring;
		}
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);

		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);

		return $this->SendResponse($pretest);
	}

	/**
    * Return the URL to launch an execute_purchase_token under IFRAME/Fullscreen
    * @param string $transreference Unique payment identifier
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
    * @param string $iduser Unique identifier of the user registered on the system.
    * @param string $tokenuser Token code associated with the USER ID.
    * @param string $lang Language of the transaction wording
    * @param string $description Description of the operation
    * @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
	* @param integer $scoring (optional) Risk scoring value of the transaction
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */
	public function ExecutePurchaseTokenUrl($transreference, $amount, $currency, $iduser, $tokenuser, $lang = "ES", $description = false, $secure3d = false, $scoring = null)
	{
		$pretest = array();

		$operation = new stdClass();
		$operation->Type = 109;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->IdUser = $iduser;
		$operation->TokenUser = $tokenuser;
		$operation->Language = $lang;
		$operation->Concept = $description;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		if ($scoring) {
			$operation->Scoring = (int)$scoring;
		}
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);

		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);

		return $this->SendResponse($pretest);
	}

	/**
    * Return the URL to launch an add_user under IFRAME/Fullscreen
    * @param string $transreference Unique transaction identifier
    * @param string $lang Language of the transaction wording
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */
	public function AddUserUrl($transreference, $lang = "ES")
	{
		$pretest = array();
		$operation = new stdClass();
		$operation->Type = 107;
		$operation->Reference = $transreference;
		$operation->Language = $lang;
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);
		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);
		return $this->SendResponse($pretest);
	}

	/**
    * Return the URL to launch a create_subscription under IFRAME/Fullscreen
    * @param string $transreference Unique payment identifier
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
    * @param string $startdate Subscription start date yyyymmdd
    * @param string $enddate Subscription end date yyyymmdd
    * @param string $periodicity Frequency of the subscription. Expressed in days.
    * @param string $lang Language of the transaction wording
    * @param string $description Description of the operation
    * @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
	* @param integer $scoring (optional) Risk scoring value of the transaction
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */
	public function CreateSubscriptionUrl($transreference, $amount, $currency, $startdate, $enddate, $periodicity, $lang = "ES", $secure3d = false, $scoring = null)
	{
		$pretest = array();

		$operation = new stdClass();
		$operation->Type = 9;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->Language = $lang;
		$operation->StartDate = $startdate;
		$operation->EndDate = $enddate;
		$operation->Periodicity = $periodicity;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		if ($scoring) {
			$operation->Scoring = (int)$scoring;
		}
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);

		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);

		return $this->SendResponse($pretest);
	}

	/**
    * Return the URL to launch a create_subscription_token under IFRAME/Fullscreen
    * @param string $transreference Unique payment identifier
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
    * @param string $startdate Subscription start date yyyymmdd
    * @param string $enddate Subscription end date yyyymmdd
    * @param string $periodicity Frequency of the subscription. Expressed in days.
    * @param string $iduser Unique identifier of the user registered on the system.
    * @param string $tokenuser Token code associated with the USER ID.
    * @param string $lang Language of the transaction wording
    * @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
	* @param integer $scoring (optional) Risk scoring value of the transaction
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */
	public function CreateSubscriptionTokenUrl($transreference, $amount, $currency, $startdate, $enddate, $periodicity, $iduser, $tokenuser, $lang = "ES", $secure3d = false, $scoring = null)
	{
		$pretest = array();

		$operation = new stdClass();
		$operation->Type = 110;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->Language = $lang;
		$operation->StartDate = $startdate;
		$operation->EndDate = $enddate;
		$operation->Periodicity = $periodicity;
		$operation->IdUser = $iduser;
		$operation->TokenUser = $tokenuser;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		if ($scoring) {
			$operation->Scoring = (int)$scoring;
		}
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);

		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);

		return $this->SendResponse($pretest);
	}

	/**
    * Return the URL to launch a create_preauthorization under IFRAME/Fullscreen
    * @param string $transreference Unique payment identifier
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
    * @param string $lang Language of transaction wording
    * @param string $description Description of the operation
    * @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
	* @param integer $scoring (optional) Risk scoring value of the transaction
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */1
	public function CreatePreauthorizationUrl($transreference, $amount, $currency, $lang = "ES", $description = false, $secure3d = false, $scoring = null)
	{
		$pretest = array();

		$operation = new stdClass();
		$operation->Type = 3;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->Language = $lang;
		$operation->Concept = $description;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		if ($scoring) {
			$operation->Scoring = (int)$scoring;
		}
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);

		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);

		return $this->SendResponse($pretest);
	}

	/**
    * Return the URL to launch a preauthorization_confirm under IFRAME/Fullscreen
    * @param string $transreference Unique payment identifier
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
    * @param string $iduser Unique identifier of the user registered on the system.
    * @param string $tokenuser Token code associated with the USER ID.
    * @param string $lang Language of the transaction wording
    * @param string $description Description of the operation
    * @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */
	public function PreauthorizationConfirmUrl($transreference, $amount, $currency, $iduser, $tokenuser, $lang = "ES", $description = false, $secure3d = false)
	{
		$pretest = array();
		$operation = new stdClass();
		$operation->Type = 6;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->Language = $lang;
		$operation->Concept = $description;
		$operation->IdUser = $iduser;
		$operation->TokenUser = $tokenuser;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		$check_user_exist = $this->InfoUser($operation->IdUser, $operation->TokenUser);
		if ($check_user_exist->DS_ERROR_ID != 0) {
			return $this->SendResponse(array("DS_ERROR_ID" => $check_user_exist->DS_ERROR_ID));
		}
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);
		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);
		return $this->SendResponse($pretest);
	}

	/**
    * Return the URL to launch a preauthorization_cancel under IFRAME/Fullscreen
    * @param string $transreference Unique payment identifier
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
    * @param string $iduser Unique identifier of the user registered on the system.
    * @param string $tokenuser Token code associated with the USER ID.
    * @param string $lang Language of transaction wording
    * @param string $description Description of the operation
    * @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */
	public function PreauthorizationCancelUrl($transreference, $amount, $currency, $iduser, $tokenuser, $lang = "ES", $description = false, $secure3d = false)
	{
		$pretest = array();
		$operation = new stdClass();
		$operation->Type = 4;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->Language = $lang;
		$operation->Concept = $description;
		$operation->IdUser = $iduser;
		$operation->TokenUser = $tokenuser;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		$check_user_exist = $this->InfoUser($operation->IdUser, $operation->TokenUser);
		if ($check_user_exist->DS_ERROR_ID != 0) {
			return $this->SendResponse(array("DS_ERROR_ID" => $check_user_exist->DS_ERROR_ID));
		}
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);
		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);
		return $this->SendResponse($pretest);
	}

	/**
    * Return the URL to launch an execute_preauthorization_token under IFRAME/Fullscreen
    * @param string $transreference Unique payment identifier
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
    * @param string $iduser Unique identifier of the user registered on the system.
    * @param string $tokenuser Token code associated with the USER ID.
    * @param string $lang Language of the transaction wording
    * @param string $description Description of the operation
    * @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
	* @param integer $scoring (optional) Risk scoring value of the transaction
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */
	public function ExecutePreauthorizationTokenUrl($transreference, $amount, $currency, $iduser, $tokenuser, $lang = "ES", $description = false, $secure3d = false, $scoring = null)
	{
		$pretest = array();

		$operation = new stdClass();
		$operation->Type = 111;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->Language = $lang;
		$operation->Concept = $description;
		$operation->IdUser = $iduser;
		$operation->TokenUser = $tokenuser;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		if ($scoring) {
			$operation->Scoring = (int)$scoring;
		}
		$check_user_exist = $this->InfoUser($operation->IdUser, $operation->TokenUser);
		if ($check_user_exist->DS_ERROR_ID != 0) {
			return $this->SendResponse(array("DS_ERROR_ID" => $check_user_exist->DS_ERROR_ID));
		}

		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);

		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);

		return $this->SendResponse($pretest);
	}

	/**
    * Return the URL to launch a deferred_preauthorization under IFRAME/Fullscreen
    * @param string $transreference Unique payment identifier
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
    * @param string $lang Language of the transaction wording
    * @param string $description Description of the operation
    * @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
	* @param integer $scoring (optional) Risk scoring vale of the transaction
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */
	public function DeferredPreauthorizationUrl($transreference, $amount, $currency, $lang = "ES", $description = false, $secure3d = false, $scoring = null)
	{
		$pretest = array();

		$operation = new stdClass();
		$operation->Type = 13;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->Language = $lang;
		$operation->Concept = $description;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		if ($scoring) {
			$operation->Scoring = (int)$scoring;
		}
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);

		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);

		return $this->SendResponse($pretest);
	}

	/**
    * Return the URL to launch a deferred_preauthorization_confirm under IFRAME/Fullscreen
    * @param string $transreference Unique payment identifier
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
    * @param string $iduser Unique identifier of the user registered on the system.
    * @param string $tokenuser Token code associated with the USER ID.
    * @param string $lang Language of the transaction wording
    * @param string $description Description of the operation
    * @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */
	public function DeferredPreauthorizationConfirmUrl($transreference, $amount, $currency, $iduser, $tokenuser, $lang = "ES", $description = false, $secure3d = false)
	{
		$pretest = array();
		$operation = new stdClass();
		$operation->Type = 16;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->Language = $lang;
		$operation->Concept = $description;
		$operation->IdUser = $iduser;
		$operation->TokenUser = $tokenuser;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		$check_user_exist = $this->InfoUser($operation->IdUser, $operation->TokenUser);
		if ($check_user_exist->DS_ERROR_ID != 0) {
			return $this->SendResponse(array("DS_ERROR_ID" => $check_user_exist->DS_ERROR_ID));
		}
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);
		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);
		return $this->SendResponse($pretest);
	}

	/**
    * Retunr the URL to launch a deferred_preauthorization_cancel under IFRAME/Fullscreen
    * @param string $transreference Unique payment identifier
    * @param string $amount Payment amount 1€ = 100
    * @param string $currency Operation currency identifier
    * @param string $iduser Unique identifier of the user registered on the system.
    * @param string $tokenuser Token code associated with the USER ID.
    * @param string $lang Language of the transaction wording
    * @param string $description Description of the operation
    * @param string $secure3d Force the operation for 0 = Non-secure and 1 = Secure through 3DSecure
    * @return object Object of response of the operation
    * @version 1.0 2016-06-06
    */
	public function DeferredPreauthorizationCancelUrl($transreference, $amount, $currency, $iduser, $tokenuser, $lang = "ES", $description = false, $secure3d = false)
	{
		$pretest = array();
		$operation = new stdClass();
		$operation->Type = 14;
		$operation->Reference = $transreference;
		$operation->Amount = $amount;
		$operation->Currency = $currency;
		$operation->Language = $lang;
		$operation->Concept = $description;
		$operation->IdUser = $iduser;
		$operation->TokenUser = $tokenuser;
		if ($secure3d != false) {
			$operation->Secure3D = $secure3d;
		}
		$check_user_exist = $this->InfoUser($operation->IdUser, $operation->TokenUser);
		if ($check_user_exist->DS_ERROR_ID != 0) {
			return $this->SendResponse(array("DS_ERROR_ID" => $check_user_exist->DS_ERROR_ID));
		}
		$operation->Hash = $this->GenerateHash($operation, $operation->Type);
		$lastrequest = $this->ComposeURLParams($operation, $operation->Type);
		$pretest = $this->CheckUrlError($lastrequest);
		$pretest["URL_REDIRECT"] = ($this->endpointurl.$lastrequest);
		return $this->SendResponse($pretest);
	}

	/**
    * Create a response from the PAYCOMET BankStore service in object
    * @param array $respuesta Array of the response to be converted to object
    * @return object Object of response. Includes the RESULT value (OK for correct and KO for incorrect)
    * @version 1.0 2016-06-03
    */
	private function SendResponse($respuesta = false)
	{
		$result = new stdClass();
		if (!is_array($respuesta)) {
			$result->RESULT = "KO";
			$result->DS_ERROR_ID = 1011; // No se pudo conectar con el host
		} else {
			$result = (object)$respuesta;
			if ($respuesta["DS_ERROR_ID"] != "" && $respuesta["DS_ERROR_ID"] != 0) {
				$result->RESULT = "KO";
			} else {
				$result->RESULT = "OK";
			}
		}
		return $result;
	}

	/**
    * Generate the signature based on the type of operation for BankStore IFRAME/Fullscreen
    * @param object $operationdata Object with information of the operation to calculate its signature
    * @param int $operationtype Type of operation to generate the signature
    * @return string Hash from the calculated signature
    * @version 1.0 2016-06-06
    */
	private function GenerateHash($operationdata, $operationtype)
	{
		$hash = false;
		$reference = $operationdata->Reference;
		$amount = $operationdata->Amount;
		$currency = $operationdata->Currency;
		$iduser = $operationdata->IdUser;
		$tokenuser = $operationdata->TokenUser;
		if ((int)$operationtype == 1) {             // Authorization (execute_purchase)
			$hash = hash('sha512',$this->merchantCode.$this->terminal.$operationtype.$reference.$amount.$currency.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 3) {       // Preauthorization
			$hash = hash('sha512',$this->merchantCode.$this->terminal.$operationtype.$reference.$amount.$currency.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 6) {       // Confirmación de Preauthorization
			$hash = hash('sha512',$this->merchantCode.$iduser.$tokenuser.$this->terminal.$operationtype.$reference.$amount.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 4) {       // Cancelación de Preauthorization
			$hash = hash('sha512',$this->merchantCode.$iduser.$tokenuser.$this->terminal.$operationtype.$reference.$amount.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 9) {       // Subscription
			$hash = hash('sha512',$this->merchantCode.$this->terminal.$operationtype.$reference.$amount.$currency.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 107) {     // Add_user
			$hash = hash('sha512',$this->merchantCode.$this->terminal.$operationtype.$reference.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 109) {     // execute_purchase_token
			$hash = hash('sha512',$this->merchantCode.$iduser.$tokenuser.$this->terminal.$operationtype.$reference.$amount.$currency.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 110) {     // create_subscription_token
			$hash = hash('sha512',$this->merchantCode.$iduser.$tokenuser.$this->terminal.$operationtype.$reference.$amount.$currency.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 111) {     // create_preauthorization_token
			$hash = hash('sha512',$this->merchantCode.$iduser.$tokenuser.$this->terminal.$operationtype.$reference.$amount.$currency.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 13) {      // Preauthorization Diferida
			$hash = hash('sha512',$this->merchantCode.$this->terminal.$operationtype.$reference.$amount.$currency.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 16) {      // Confirmación de Preauthorization Diferida
			$hash = hash('sha512',$this->merchantCode.$iduser.$tokenuser.$this->terminal.$operationtype.$reference.$amount.hash('sha512',$this->password));
		} elseif ((int)$operationtype == 14) {      // Cancelación de Preauthorization Diferida
			$hash = hash('sha512',$this->merchantCode.$iduser.$tokenuser.$this->terminal.$operationtype.$reference.$amount.hash('sha512',$this->password));
		}
		return $hash;
	}

	/**
    * Receive the full operation and generate it to arrive by GET at the ENDPOINTURL
    * @param object $operationdata Object with operation information to calculate and generate the URL
    * @param int $operationtype Type of operation to generate the request
    * @return string URL to send to the ENDPOINTURL
    * @version 1.0 2016-06-06
    */
	private function ComposeURLParams($operationdata, $operationtype)
	{
		$secureurlhash = false;
		$data = array();
		$data["MERCHANT_MERCHANTCODE"]              = $this->merchantCode;
		$data["MERCHANT_TERMINAL"]                  = $this->terminal;
		$data["OPERATION"]                          = $operationtype;
		$data["LANGUAGE"]                           = $operationdata->Language;
		$data["MERCHANT_MERCHANTSIGNATURE"]         = $operationdata->Hash;
		$data["URLOK"]                              = $operationdata->UrlOk;
		$data["URLKO"]                              = $operationdata->UrlKo;
		$data["MERCHANT_ORDER"]                     = $operationdata->Reference;
		if ($operationdata->Secure3D != false) {
			$data["3DSECURE"]                       = $operationdata->Secure3D;
		}
		$data["MERCHANT_AMOUNT"]                    = $operationdata->Amount;
		if ($operationdata->Concept != "") {
			$data["MERCHANT_PRODUCTDESCRIPTION"]    = $operationdata->Concept;
		}
		if ((int)$operationtype == 1) {                 // Authorization (execute_purchase)
			$data["MERCHANT_CURRENCY"]              = $operationdata->Currency;
			$data["MERCHANT_SCORING"]               = $operationdata->Scoring;
		} elseif ((int)$operationtype == 3) {           // Preauthorization
			$data["MERCHANT_CURRENCY"]              = $operationdata->Currency;
			$data["MERCHANT_SCORING"]               = $operationdata->Scoring;
		} elseif ((int)$operationtype == 6) {           // Confirmación de Preauthorization
			$data["IDUSER"]                         = $operationdata->IdUser;
			$data["TOKEN_USER"]                     = $operationdata->TokenUser;
		} elseif ((int)$operationtype == 4) {           // Cancelación de Preauthorization
			$data["IDUSER"]                         = $operationdata->IdUser;
			$data["TOKEN_USER"]                     = $operationdata->TokenUser;
		} elseif ((int)$operationtype == 9) {           // Subscription
			$data["MERCHANT_CURRENCY"]              = $operationdata->Currency;
			$data["SUBSCRIPTION_STARTDATE"]         = $operationdata->StartDate;
			$data["SUBSCRIPTION_ENDDATE"]           = $operationdata->EndDate;
			$data["SUBSCRIPTION_PERIODICITY"]       = $operationdata->Periodicity;
			$data["MERCHANT_SCORING"]               = $operationdata->Scoring;
		} elseif ((int)$operationtype == 109) {         // execute_purchase_token
			$data["IDUSER"]                         = $operationdata->IdUser;
			$data["TOKEN_USER"]                     = $operationdata->TokenUser;
			$data["MERCHANT_CURRENCY"]              = $operationdata->Currency;
			$data["MERCHANT_SCORING"]               = $operationdata->Scoring;
		} elseif ((int)$operationtype == 110) {         // create_subscription_token
			$data["IDUSER"]                         = $operationdata->IdUser;
			$data["TOKEN_USER"]                     = $operationdata->TokenUser;
			$data["MERCHANT_CURRENCY"]              = $operationdata->Currency;
			$data["SUBSCRIPTION_STARTDATE"]         = $operationdata->StartDate;
			$data["SUBSCRIPTION_ENDDATE"]           = $operationdata->EndDate;
			$data["SUBSCRIPTION_PERIODICITY"]       = $operationdata->Periodicity;
			$data["MERCHANT_SCORING"]               = $operationdata->Scoring;
		} elseif ((int)$operationtype == 111) {         // create_preauthorization_token
			$data["IDUSER"]                         = $operationdata->IdUser;
			$data["TOKEN_USER"]                     = $operationdata->TokenUser;
			$data["MERCHANT_SCORING"]               = $operationdata->Scoring;
			$data["MERCHANT_CURRENCY"]              = $operationdata->Currency;
		} elseif ((int)$operationtype == 13) {          // Deferred Preauthorization
			$data["MERCHANT_CURRENCY"]              = $operationdata->Currency;
			$data["MERCHANT_SCORING"]               = $operationdata->Scoring;
		} elseif ((int)$operationtype == 16) {          // Deferred Confirmación de Preauthorization
			$data["IDUSER"]                         = $operationdata->IdUser;
			$data["TOKEN_USER"]                     = $operationdata->TokenUser;
		} elseif ((int)$operationtype == 14) {          // Deferred  Cancelación de Preauthorization
			$data["IDUSER"]                         = $operationdata->IdUser;
			$data["TOKEN_USER"]                     = $operationdata->TokenUser;
		}
		$content = "";
		foreach($data as $key => $value)
		{
			if($content != "") $content.="&";
			$content .= urlencode($key)."=".urlencode($value);
		}
		$data["VHASH"] = hash('sha512', hash('sha512',$content.hash('sha512',$this->password)));
		krsort($data);
		$secureurlhash = "";
		foreach($data as $key => $value)
		{
			if($secureurlhash != "") $secureurlhash.="&";
			$secureurlhash .= urlencode($key)."=".urlencode($value);
		}
		return $secureurlhash;
	}

	/**
    * Check whether the URL generated with the desired operation generates an error
    * @param string $peticion The URL with the request to PAYCOMET.
    * @return array $response Array with the response. If there is an error it returns the error that has been generated, if it is OK the DS_ERROR_ID value will be 0.
    * @version 1.0 2016-06-06
    */
	private function CheckUrlError($urlgen)
	{
		$response = array("DS_ERROR_ID" => 1023);
		if ($urlgen != "") {
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $this->endpointurl.$urlgen);
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,5);
			curl_setopt($ch, CURLOPT_TIMEOUT, 5);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);
			if($errno = curl_errno($ch)) {
				$response = array("DS_ERROR_ID" => 1021);
			} else {
				if ((strpos($output, "Error: ") == 0 && strpos($output, "Error: ") !== false) || (strpos($output, ""), "", $output));
				} else {
					$response = array("DS_ERROR_ID" => 0);
				}
			}
		}
		return $response;
	}
}
?>