/**
 * Calls a transaction request
 */
function ideal_payment_api_transreq_call($order)
{
    //Get user ID
    global $user;
    if ($user) {
        $user_id = $user->uid;
    }
    $path_module = drupal_get_path('module', 'ideal_payment_api');
    require_once $path_module . '/lib/iDEALConnector.php';
    $iDEALConnector = new iDEALConnector();
    $order['description'] = check_plain($order['description']);
    if (drupal_strlen($order['description']) > 32) {
        //@TODO: run this trough a general error handler.
        $order['description_orig'] = $order['description'];
        $order['description'] = drupal_substr($order['description'], 0, 32);
        watchdog('ideal_api', t('iDEAL decription too long. Changed from %orig to %shortened', array('%orig' => $order['description_orig'], '%shortened' => $order['description'])));
    }
    //issuerid is min. 4 chars, add leading 0's
    $order['issuer_id'] = str_pad($order['issuer_id'], 4, '0', STR_PAD_LEFT);
    //Send TransactionRequest
    $response = $iDEALConnector->RequestTransaction($order['issuer_id'], $order['order_id'], $order['amount'], $order['description'], $order['order_id'], $iDEALConnector->config['EXPIRATIONPERIOD'], $iDEALConnector->config['MERCHANTRETURNURL']);
    if (!$response->errCode) {
        return $response;
    } else {
        watchdog('ideal_api', $response->errCode . ': ' . $response->errMsg, NULL, WATCHDOG_ERROR);
        return $response;
    }
}
Exemple #2
0
	public function ProcessPaymentForm()
	{
		// any error that we need to show from a previous transaction attempt?
		if (isset($_SESSION['IdealError'])) {
			$this->SetError($_SESSION['IdealError']);
			unset($_SESSION['IdealError']);

			return false;
		}

		// check that an issuer was selected
		if (!isset($_POST['Ideal_issuer']) || empty($_POST['Ideal_issuer'])) {
			$this->SetError(GetLang('IdealIssuerNotSelected'));

			return false;
		}

		$issuer = $_POST['Ideal_issuer'];
		$orderID = $this->GetCombinedOrderId();
		$amount = round($this->GetGatewayAmount() * 100);
		$description = GetLang("IdealTransactionDescription", array("shopName" => GetConfig('StoreName'), "orderID" => $orderID));
		// used to authenticate the redirect
		$entranceCode = md5(GetConfig('EncryptionToken').$_COOKIE['SHOP_ORDER_TOKEN']);

		// instantiate the ideal connector
		$iDEALConnector = new iDEALConnector();

		// create transaction request and set data
		$request = $iDEALConnector->RequestTransaction(
			$issuer,
			$orderID,
			$amount,
			$description,
			$entranceCode
		);

		if ($request === false) {
			$request = $iDEALConnector->getError();
		}

		// bad transaction
		if ($request->IsResponseError()) {
			$error = GetLang('IdealErrorTransactionRequest', array('code' => $request->getErrorCode(), "message" => $request->getErrorMessage()));
			$GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('payment', $this->GetName()), $error, $request->getErrorDetail());

			$this->SetError($error);

			return false;
		}

		// ID of this transaction...we need to store this somewhere before redirecting
		$transactionID = $request->getTransactionID();
		$_SESSION['IdealTransactionID'] = $transactionID;

		//Get IssuerURL
		$acquirerID = $request->getAcquirerID();
		$issuerURL = $request->getIssuerAuthenticationURL();
		$issuerURL = html_entity_decode($issuerURL);

		//Redirect the issuer authentication site
		ob_end_clean();
		header("Location: " . $issuerURL);
		exit;
	}