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(); } }
private function getFormActionUrl(Customweb_Payment_Authorization_ITransaction $transaction) { $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); }
/** * 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); } }