public function addSpecificPaymentPageParameters(Customweb_Payment_Authorization_IOrderContext $orderContext, array $parameters)
 {
     $this->orderContext = $orderContext;
     $this->addIfValueNotNull($parameters, 'COMPANY', Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingCompanyName()));
     $this->addIfValueNotNull($parameters, 'LEGALFORM', $this->guessLegalForm());
     $this->addIfValueNotNull($parameters, 'GENDER', $this->getGender($orderContext->getBillingGender(), $orderContext->getBillingCompanyName()));
     $parameters['FIRSTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingFirstName());
     $parameters['LASTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingLastName());
     $parameters['STREET'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingStreet());
     $parameters['ZIP'] = $orderContext->getBillingPostCode();
     $parameters['CITY'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingCity());
     $parameters['COUNTRY'] = $orderContext->getBillingCountryIsoCode();
     $parameters['EMAIL'] = $orderContext->getCustomerEMailAddress();
     $this->addIfValueNotNull($parameters, 'PHONE', $orderContext->getBillingPhoneNumber());
     if ($orderContext->getBillingDateOfBirth() != null) {
         $this->addIfValueNotNull($parameters, 'DATEOFBIRTH', $orderContext->getBillingDateOfBirth()->format('Ymd'));
     }
     $this->addIfValueNotNull($parameters, 'DELIVERY_GENDER', $this->getGender($orderContext->getShippingGender(), ""));
     $parameters['DELIVERY_FIRSTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingFirstName());
     $parameters['DELIVERY_LASTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingLastName());
     $parameters['DELIVERY_STREET'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingStreet());
     $parameters['DELIVERY_ZIP'] = $orderContext->getShippingPostCode();
     $parameters['DELIVERY_CITY'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingCity());
     $parameters['DELIVERY_COUNTRY'] = $orderContext->getShippingCountryIsoCode();
     $this->addIfValueNotNull($parameters, 'DELIVERY_PHONE', $orderContext->getShippingPhoneNumber());
     $parameters['LANGID'] = substr($orderContext->getLanguage(), 0, 2);
     //$parameters['IP'] = Customweb_Saferpay_Util::getClientIpAddress();
     return $parameters;
 }
 public function partialRefund(Customweb_Payment_Authorization_ITransaction $transaction, $items, $close)
 {
     if (!$transaction instanceof Customweb_Saferpay_Authorization_Transaction) {
         throw new Exception("The given transaction is not instanceof Customweb_Saferpay_Authorization_Transaction.");
     }
     $amount = Customweb_Util_Invoice::getTotalAmountIncludingTax($items);
     // Check the transaction state
     $transaction->refundByLineItemsDry($items, $close);
     $builder = new Customweb_Saferpay_BackendOperation_Adapter_Refund_ParameterBuilder($transaction, $this->getConfiguration(), $this->container);
     $sendParameters = $builder->buildParameters($amount);
     $requestUrl = Customweb_Saferpay_Util::addParametersToUrl($this->getExecuteUrl(), $sendParameters);
     $response = Customweb_Saferpay_Util::sendRequest($requestUrl);
     $parameters = $this->getXmlParameters($response);
     if ($parameters['RESULT'] == 0) {
         $id = $parameters['ID'];
         $this->capture($transaction, $amount, $id);
         $refundItem = $transaction->refundByLineItems($items, $close, Customweb_I18n_Translation::__("The total amount of the transaction was refunded. Refund transaction ID: '!paymentId' .", array('!paymentId' => $id)));
         $refundItem->setRefundId($id);
     } else {
         if ($parameters['RESULT'] == '75') {
             throw new Exception(Customweb_I18n_Translation::__('Refund of !amount failed because no card reference id was provided. This most likely because you try to refund a transaction authorized over the payment page. (Code: !result).', array('!amount' => $amount, '!result' => $parameters['RESULT'])));
         } else {
             throw new Exception(Customweb_I18n_Translation::__('Refund of !amount failed with code: !result.', array('!amount' => $amount, '!result' => $parameters['RESULT'])));
         }
     }
 }
 public function getFormActionUrl(Customweb_Payment_Authorization_ITransaction $transaction)
 {
     if ($transaction->isUseExistingAlias()) {
         return $this->container->getBean('Customweb_Payment_Endpoint_IAdapter')->getUrl("process", 'index', array('cw_transaction_id' => $transaction->getExternalTransactionId()));
     } else {
         $builder = new Customweb_Saferpay_Authorization_Hidden_ParameterBuilder($transaction, $this->getConfiguration(), $this->container);
         $parameters = $builder->buildRegisterCardParameters();
         $requestUrl = Customweb_Saferpay_Util::addParametersToUrl($this->getCreatePayInitUrl(), $parameters);
         return Customweb_Saferpay_Util::sendRequest($requestUrl);
     }
 }
 public function getRedirectionUrl(Customweb_Payment_Authorization_ITransaction $transaction, array $formData)
 {
     try {
         if ($transaction->isUseExistingAlias()) {
             return $this->container->getBean('Customweb_Payment_Endpoint_IAdapter')->getUrl("process", 'index', array_merge($formData, array('cw_transaction_id' => $transaction->getExternalTransactionId())));
         } else {
             if ($transaction->getRedirectUrl() == null) {
                 $builder = $this->createParameterBuilder($transaction);
                 $parameters = $builder->buildParameters();
                 $parameters = array_merge($parameters, $this->getPaymentMethodWrapper($transaction->getTransactionContext()->getOrderContext())->getAdditionalPaymentPageParameters());
                 $requestUrl = Customweb_Saferpay_Util::addParametersToUrl($this->getCreatePayInitUrl(), $parameters);
                 $transaction->setRedirectUrl(Customweb_Saferpay_Util::sendRequest($requestUrl));
             }
             return $transaction->getRedirectUrl();
         }
     } catch (Exception $e) {
         $transaction->setAuthorizationFailed($e->getMessage());
         return $transaction->getFailedUrlWithCustomParameters();
     }
 }
 protected function createAlias($transaction, $parameters)
 {
     $url = $this->getFormActionUrl($transaction);
     $response = Customweb_Saferpay_Util::sendFormData($url, $parameters);
     if (isset($response['location'])) {
         $transaction->setTransactionState(Customweb_Saferpay_Authorization_Transaction::STATE_ALIAS_EXISTS);
         $transaction->setNextRedirectUrl($response['location']);
     } else {
         $reason = Customweb_I18n_Translation::__("Server responded with unexpected headers '!response'", array('!response' => print_r($response, true)));
         $transaction->setAuthorizationFailed($reason);
         $this->redirect(null, $transaction, $this->getFailedUrl($transaction));
     }
 }
 /**
  * This method issues an autorization request for the transaction.
  * If the capturing mode is "Direct" the transaction gets captured after
  * a sucessfull authorization.
  *
  * @param Customweb_Saferpay_Authorization_Transaction $transaction
  */
 protected function requestAuthorization(Customweb_Saferpay_Authorization_Transaction $transaction, array $additionalParameters = array())
 {
     if (!isset($additionalParameters['CVC'])) {
         $isAliasWithAddressCheck = $transaction->isUseExistingAlias() && $this->getConfiguration()->getCardVerificationMode() != 'cvc';
         $isCreditCard = $this->getPaymentMethodWrapperFromPaymentMethod($transaction->getPaymentMethod()) instanceof Customweb_Saferpay_Method_CreditCardWrapper;
         $isMoto = strtolower($transaction->getAuthorizationMethod()) == strtolower(Customweb_Payment_Authorization_Moto_IAdapter::AUTHORIZATION_METHOD_NAME);
         $isRecurring = strtolower($transaction->getAuthorizationMethod()) == strtolower(Customweb_Payment_Authorization_Recurring_IAdapter::AUTHORIZATION_METHOD_NAME);
         if (!$isAliasWithAddressCheck && !$isMoto && !$isRecurring && $isCreditCard) {
             $message = Customweb_I18n_Translation::__("No CVC provided.");
             $transaction->setAuthorizationFailed($message);
             $this->redirect(null, $transaction, $this->getFailedUrl($transaction));
             return;
         }
     }
     // 		&& !isset($additionalParameters['IBAN'])
     $builder = new Customweb_Saferpay_Authorization_Hidden_ParameterBuilder($transaction, $this->getConfiguration(), $this->container);
     $sendParameters = $builder->buildParameters($additionalParameters);
     $requestUrl = Customweb_Saferpay_Util::addParametersToUrl($this->getExecuteUrl(), $sendParameters);
     $response = Customweb_Saferpay_Util::sendRequest($requestUrl);
     $parameters = $this->getXmlParameters($response);
     $transaction->resetKey();
     if ($parameters['RESULT'] == 0 && $this->isTransactionValidState($transaction)) {
         $transaction->setPaymentId($parameters['ID']);
         $transaction->setAuthorizationParameters($parameters);
         $transaction->authorize();
         if (isset($parameters['ECI']) && $parameters['ECI'] != self::ECI_NO_LIABILITY_SHIFT) {
             $transaction->setState3DSecure(Customweb_Saferpay_Authorization_Transaction::STATE_3D_SECURE_SUCCESS);
         }
         if ($this->getConfiguration()->isMarkLiabilityShiftTransactions() && $transaction->getAuthorizationMethod() != Customweb_Payment_Authorization_Recurring_IAdapter::AUTHORIZATION_METHOD_NAME && !$transaction->isUseExistingAlias() && !$transaction->isMoto()) {
             if ((!isset($parameters['ECI']) || $parameters['ECI'] == self::ECI_NO_LIABILITY_SHIFT) && !$this->getPaymentMethodWrapper($transaction->getTransactionContext()->getOrderContext())->isEciMeaningless()) {
                 $transaction->setAuthorizationUncertain();
             }
         }
         // In case the shop system request a new alias, we mark this transaction as a alias source.
         $transactionContext = $transaction->getTransactionContext();
         if (!($transactionContext instanceof Customweb_Payment_Authorization_Recurring_ITransactionContext && $transactionContext->getInitialTransaction() != null)) {
             if ($transaction->getTransactionContext()->getAlias() !== null || $transaction->getTransactionContext()->createRecurringAlias()) {
                 if ($transaction->getTransactionContext()->getAlias() != 'new' && !isset($parameters['PAN'])) {
                     $transaction->setAliasForDisplay($transaction->getTransactionContext()->getAlias()->getAliasForDisplay());
                     $transaction->addAuthorizationParameters(array('PAN' => $transaction->getTransactionContext()->getAlias()->getAliasForDisplay()));
                 } else {
                     if (isset($parameters['PAN'])) {
                         $transaction->setAliasForDisplay($parameters['PAN']);
                     } else {
                         if (isset($parameters['IBAN'])) {
                             $transaction->setAliasForDisplay(Customweb_Saferpay_Util::maskIban($parameters['IBAN']));
                         } else {
                             throw new Exception('PAN or IBAN must be set, none given.');
                         }
                     }
                 }
                 $this->setAliasAddress($transaction);
             }
         }
         if ($transaction->getTransactionContext()->getCapturingMode() == null) {
             $capturingMode = $this->getPaymentMethodWrapper($transaction->getTransactionContext()->getOrderContext())->getPaymentMethodConfigurationValue('capturing');
         } else {
             $capturingMode = $transaction->getTransactionContext()->getCapturingMode();
         }
         if (!$transaction->isAuthorizationUncertain() && $capturingMode == Customweb_Payment_Authorization_ITransactionContext::CAPTURING_MODE_DIRECT) {
             $this->captureTransaction($transaction);
         }
         $this->redirect(null, $transaction, $this->getSuccessUrl($transaction));
     } else {
         $userMessage = Customweb_Saferpay_Util::getUserErrorMessage($parameters['AUTHMESSAGE']);
         $backendMessage = Customweb_I18n_Translation::__("Saferpay authorization responded with : !result '!authmessage'", array('!result' => $parameters['RESULT'], '!authmessage' => $parameters['AUTHMESSAGE']));
         $transaction->setAuthorizationFailed(new Customweb_Payment_Authorization_ErrorMessage($userMessage, $backendMessage));
         $this->redirect(null, $transaction, $this->getFailedUrl($transaction));
     }
 }
 protected function performPayCompleteAction($parameters, $failMessage)
 {
     $requestUrl = Customweb_Saferpay_Util::addParametersToUrl($this->getPayCompleteUrl(), $parameters);
     try {
         $response = Customweb_Saferpay_Util::sendRequest($requestUrl);
         return $this->parseServerResponse($response);
     } catch (Exception $e) {
         $message = $failMessage . "\n" . $e->getMessage();
         throw new Exception($message);
     }
 }
 protected function getAddressParameters()
 {
     $parameters = array();
     $orderContext = $this->getOrderContext();
     if (!$orderContext->getPaymentMethod()->existsPaymentMethodConfigurationValue('address_mode')) {
         return array();
     }
     $mode = $orderContext->getPaymentMethod()->getPaymentMethodConfigurationValue('address_mode');
     if ($mode === self::SEND_ADDRESS_MODE_DELIVERY) {
         $parameters['ADDRESS'] = strtoupper(self::SEND_ADDRESS_MODE_DELIVERY);
         $parameters['COMPANY'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingCompanyName());
         $parameters['FIRSTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingFirstName());
         $parameters['LASTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingLastName());
         $parameters['STREET'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingStreet());
         $parameters['ZIP'] = $orderContext->getShippingPostCode();
         $parameters['CITY'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getShippingCity());
         $parameters['COUNTRY'] = $orderContext->getShippingCountryIsoCode();
         $parameters['EMAIL'] = $orderContext->getCustomerEMailAddress();
     } else {
         if ($mode === self::SEND_ADDRESS_MODE_BILLING) {
             $parameters['ADDRESS'] = strtoupper(self::SEND_ADDRESS_MODE_BILLING);
             $parameters['COMPANY'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingCompanyName());
             $parameters['FIRSTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingFirstName());
             $parameters['LASTNAME'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingLastName());
             $parameters['STREET'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingStreet());
             $parameters['ZIP'] = $orderContext->getBillingPostCode();
             $parameters['CITY'] = Customweb_Saferpay_Util::removeWrongEscaptedChars($orderContext->getBillingCity());
             $parameters['COUNTRY'] = $orderContext->getBillingCountryIsoCode();
             $parameters['EMAIL'] = $orderContext->getCustomerEMailAddress();
         }
     }
     return $parameters;
 }