public function indexAction() { $container = Mage::helper('SaferpayCw')->createContainer(); $packages = array(0 => 'Customweb_Saferpay', 1 => 'Customweb_Payment_Authorization'); $adapter = Mage::getModel('saferpaycw/endpointAdapter'); $dispatcher = new Customweb_Payment_Endpoint_Dispatcher($adapter, $container, $packages); $response = $dispatcher->dispatch(Customweb_Core_Http_ContextRequest::getInstance()); $wrapper = new Customweb_Core_Http_Response($response); $wrapper->send(); die; }
/** * Called when iframe/pp fails, as PSP does not send a notification * @Action("fail") */ public function fail(Customweb_Payment_Authorization_ITransaction $transaction, Customweb_Core_Http_IRequest $request) { if (!$transaction instanceof Customweb_Saferpay_Authorization_Transaction) { throw new Customweb_Core_Exception_CastException('Customweb_Saferpay_Authorization_Transaction'); } if (!$transaction->isAuthorizationFailed() && !$transaction->isAuthorized()) { $message = new Customweb_Payment_Authorization_ErrorMessage(Customweb_I18n_Translation::__("The payment could not be processed."), Customweb_I18n_Translation::__("The payment failed.")); $transaction->setAuthorizationFailed($message); } $url = $this->getAdapterFactory()->getAuthorizationAdapterByName($transaction->getAuthorizationMethod())->getFailedUrl($transaction); return Customweb_Core_Http_Response::redirect($url); }
/** * @Action("check") */ public function check(Customweb_Core_Http_IRequest $request) { $transaction = $this->loadTransaction($request); $parameters = $request->getParameters(); if (!isset($parameters[self::HASH_PARAMETER])) { throw new Exception('Security Hash not set'); } $transaction->checkSecuritySignature($this->getControllerName() . 'check', $parameters[self::HASH_PARAMETER]); $status = 'unkown'; $url = null; if ($transaction->isAuthorized()) { $status = 'complete'; $url = $transaction->getSuccessUrl(); } elseif ($transaction->isAuthorizationFailed()) { $status = 'complete'; $url = $transaction->getFailedUrl(); } $json = json_encode(array('status' => $status, 'redirect' => $url)); return Customweb_Core_Http_Response::_($json)->setContentType("application/json"); }
public function finalizeAuthorizationRequest(Customweb_Payment_Authorization_ITransaction $transaction) { $response = new Customweb_Core_Http_Response(); $response->setLocation($transaction->getNextRedirectUrl()); return $response; }
protected function handleException(Exception $e) { $response = new Customweb_Core_Http_Response(); $response->appendBody($e->getMessage())->appendBody('<br />')->appendBody('<pre>')->appendBody($e->getTraceAsString())->appendBody('</pre>'); return $response->setStatusCode(500)->setStatusMessage('Application Exception'); }
public function processAuthorization(Customweb_Payment_Authorization_ITransaction $transaction, array $parameters) { // Check if the CVC field is filled in in case of a alias transaction. if ($transaction->getTransactionState() == Customweb_Saferpay_Authorization_Transaction::STATE_INITIAL && $transaction->isUseExistingAlias() && !$this->isCardVerificationPossible($transaction->getTransactionContext()->getAlias(), $transaction->getTransactionContext()->getOrderContext(), $transaction->getPaymentCustomerContext(), $parameters)) { $message = Customweb_I18n_Translation::__("The CVC field is required."); $transaction->setAuthorizationFailed($message); } if (!$this->validateCustomParameters($transaction, $parameters)) { $reason = Customweb_I18n_Translation::__("Custom parameters have been altered. Fraud possible, aborting."); $transaction->setAuthorizationFailed($reason); } if ($transaction->isAuthorizationFailed()) { $this->redirect(null, $transaction, $this->getFailedUrl($transaction)); } elseif ($transaction->isAuthorized()) { $this->redirect(null, $transaction, $this->getSuccessUrl($transaction)); } else { switch ($transaction->getTransactionState()) { case Customweb_Saferpay_Authorization_Transaction::STATE_INITIAL: $this->processScdResponse($transaction, $parameters); break; case Customweb_Saferpay_Authorization_Transaction::STATE_3D_SECURE: if (!isset($parameters['DATA']) || empty($parameters['DATA'])) { return Customweb_Core_Http_Response::_("NO DATA parameter provided.")->setStatusCode(500); } $parameters = array_merge($parameters, $this->parseRequestParameters($parameters)); $this->process3DSecureResponse($transaction, $parameters); break; default: $this->redirect(null, $transaction, $this->getFailedUrl($transaction)); } } return $this->finalizeAuthorizationRequest($transaction); }
public function authenticate(Customweb_Payment_ExternalCheckout_IContext $context, $emailAddress, $successUrl) { if (!$context instanceof Customweb_SaferpayCw_Model_ExternalCheckoutContext) { throw new Customweb_Core_Exception_CastException('Customweb_SaferpayCw_Model_ExternalCheckoutContext'); } if ($context->getBillingAddress() === null) { throw new Exception("The authenticate method can not be called before the billing address is set on the context."); } $this->redirectOnEmptyBasket(); $quote = $context->getQuote(); if (Mage::getSingleton('customer/session')->isLoggedIn()) { $context->updateFromQuote($quote); $context->save(); return Customweb_Core_Http_Response::redirect($successUrl); } if ($quote->isAllowedGuestCheckout() && Mage::getStoreConfig('saferpaycw/general/external_checkout_account_creation') == 'skip_selection') { Mage::helper('SaferpayCw/externalCheckout')->validateCustomerData($quote, array('email' => $emailAddress, 'firstname' => $context->getBillingAddress()->getFirstName(), 'lastname' => $context->getBillingAddress()->getLastName()), 'guest'); $quote->collectTotals(); $quote->save(); $context->setRegisterMethod('guest'); $context->updateFromQuote($quote); $context->save(); return Customweb_Core_Http_Response::redirect($successUrl); } $context->setAuthenticationEmailAddress($emailAddress); $context->setAuthenticationSuccessUrl($successUrl); $context->save(); return Customweb_Core_Http_Response::redirect(Mage::getUrl('SaferpayCw/Externalcheckout/login', array('_secure' => true))); }
public function processAuthorization(Customweb_Payment_Authorization_ITransaction $transaction, array $parameters) { if (!$transaction instanceof Customweb_Saferpay_Authorization_Transaction) { throw new Customweb_Core_Exception_CastException('Customweb_Saferpay_Authorization_Transaction'); } if ($transaction->isUseExistingAlias()) { $hiddenAdapter = new Customweb_Saferpay_Authorization_Hidden_Adapter($this->getConfiguration()->getConfigurationAdapter(), $this->getContainer()); $result = $hiddenAdapter->processAuthorization($transaction, $parameters); if ($transaction->getAuthorizationMethod() == Customweb_Payment_Authorization_Iframe_IAdapter::AUTHORIZATION_METHOD_NAME) { if ($result == 'redirect:' . $transaction->getSuccessUrl() || $result == 'redirect:' . $transaction->getFailedUrl()) { return 'redirect:' . Customweb_Util_Url::appendParameters($transaction->getTransactionContext()->getIframeBreakOutUrl(), $transaction->getTransactionContext()->getCustomParameters()); } } return $result; } if (!isset($parameters['DATA']) || empty($parameters['DATA'])) { return Customweb_Core_Http_Response::_("NO DATA parameter provided.")->setStatusCode(500); } if (!$this->validateCustomParameters($transaction, $parameters)) { $reason = Customweb_I18n_Translation::__("Custom parameters have been altered. Fraud possible, aborting."); $transaction->setAuthorizationFailed($reason); return 'redirect:' . $this->getFailedUrl($transaction); } try { $parameters = $this->parseRequestParameters($parameters); } catch (Exception $e) { $transaction->setAuthorizationParameters($parameters); $transaction->setAuthorizationFailed($e->getMessage()); return 'redirect:' . $this->getFailedUrl($transaction); } $transaction->setPaymentInformation($this->getPaymentMethodWrapper($transaction->getTransactionContext()->getOrderContext())->extractPaymentInformation($parameters)); if ($this->validateParameters($transaction, $parameters)) { // Check transaction state $transaction->authorizeDry(); if (isset($parameters['PAYMENTMETHOD']) && !empty($parameters['PAYMENTMETHOD'])) { $paymentMachineName = Customweb_Saferpay_Method_PaymentMethodWrapper::getPaymentMethodMachineNameByPaymentMethodId($parameters['PAYMENTMETHOD']); $transaction->setEffectivePaymentMethodMachineName($paymentMachineName); } $transaction->setPaymentId($parameters['ID']); if (isset($parameters['ECI']) && $parameters['ECI'] != 0) { $transaction->setState3DSecure(Customweb_Payment_Authorization_DefaultTransaction::STATE_3D_SECURE_SUCCESS); } if ($this->getConfiguration()->isMarkLiabilityShiftTransactions()) { if ((!isset($parameters['ECI']) || $parameters['ECI'] == 0) && !$this->getPaymentMethodWrapper($transaction->getTransactionContext()->getOrderContext())->isEciMeaningless()) { $transaction->setAuthorizationUncertain(); } } if (isset($parameters['CARDREFID'])) { $transaction->setCardRefId($parameters['CARDREFID']); } if (isset($parameters['CARDMASK'])) { $transaction->setTruncatedPAN($parameters['CARDMASK']); $transaction->setAliasForDisplay($parameters['CARDMASK']); $this->setAliasAddress($transaction); $parameters['PAN'] = $parameters['CARDMASK']; } if (isset($parameters[Customweb_Saferpay_Method_PaymentMethodWrapper::FORM_KEY_OWNER_NAME])) { $transaction->setOwnerName($parameters[Customweb_Saferpay_Method_PaymentMethodWrapper::FORM_KEY_OWNER_NAME]); } // $transaction->setOwnerName($parameters[Customweb_Saferpay_Method_PaymentMethodWrapper::FORM_KEY_OWNER_NAME]); if (isset($parameters['EXPIRYMONTH']) && isset($parameters['EXPIRYYEAR'])) { $transaction->setCardExpiryDate($parameters['EXPIRYMONTH'], $parameters['EXPIRYYEAR']); } $transaction->authorize(Customweb_I18n_Translation::__('Customer sucessfully returned from the Saferpay payment page.')); if ($transaction->getTransactionContext()->getCapturingMode() == null) { $capturingMode = $this->getPaymentMethodWrapper($transaction->getTransactionContext()->getOrderContext())->getPaymentMethodConfigurationValue('capturing'); } else { $capturingMode = $transaction->getTransactionContext()->getCapturingMode(); } $transaction->setAuthorizationParameters($parameters); if (!$transaction->isAuthorizationUncertain() && $capturingMode == Customweb_Payment_Authorization_ITransactionContext::CAPTURING_MODE_DIRECT) { $this->captureTransaction($transaction); } } else { $transaction->setAuthorizationParameters($parameters); $transaction->setAuthorizationFailed(Customweb_I18n_Translation::__('Possible fraud detected. Parameters send from Saferpay were not correct.')); } return $this->finalizeAuthorizationRequest($transaction); }
/** * This method is called for all redirections to specific URL. * The user will get * redirected to this URL when the shop system calls self::processFurther(). * * @param string $state STATE_INITIAL | STATE_3D_SECURE * @param Customweb_Saferpay_Authorization_Transaction $transaction * @param string $url */ protected function redirect($state, Customweb_Saferpay_Authorization_Transaction $transaction, $url) { if ($state != null) { $transaction->setTransactionState($state); } $transaction->setNextRedirectUrl($url); $response = new Customweb_Core_Http_Response(); $response->setLocation($url); return $response; }
/** * This method creates a redirect which uses the HTML head for redirection. Most * HTTP client implementation will not follow this redirection. * * @param string $url * @return Customweb_Core_Http_Response */ public static function htmRedirect($url) { $body = '<html> <head> <meta http-equiv="refresh" content="0; url=' . $url . '" /> </head> <body>You will be redirected.</body> </html>'; $response = new Customweb_Core_Http_Response(); $response->setBody($body); return $response; }
public function authorizeAction() { $transaction = $this->getTransactionFromSession(); $response = $transaction->getOrder()->getPayment()->getMethodInstance()->processServerAuthorization($transaction, $_REQUEST); $transaction->save(); $wrapper = new Customweb_Core_Http_Response($response); $wrapper->send(); die; }