/** * Handle Creditrating by Payone API response: * * @param Payone_Api_Response_Interface $response * @return string|bool will return true if all methods are available * @throws Exception|Mage_Payment_Exception */ public function handle(Payone_Api_Response_Interface $response) { $address = $this->getAddress(); $creditRatingScore = array(); if ($response instanceof Payone_Api_Response_Consumerscore_Valid) { /** @var $response Payone_Api_Response_Consumerscore_Valid */ $creditRatingScore = $response->getScore(); $address->setPayoneProtectScore($creditRatingScore); $address->setPayoneProtectDate(now()); $address->setPayoneProtectHash($this->helper()->createAddressHash($address)); $this->saveCustomerAddress($address); } elseif ($response instanceof Payone_Api_Response_Consumerscore_Invalid) { /** @var $response Payone_Api_Response_Consumerscore_Invalid*/ $creditRatingScore = Payone_Api_Enum_ConsumerscoreScore::RED; $address->setPayoneProtectScore($creditRatingScore); $address->setPayoneProtectDate(now()); $address->setPayoneProtectHash($this->helper()->createAddressHash($address)); $this->saveCustomerAddress($address); } elseif ($response instanceof Payone_Api_Response_Error) { /** @var $response Payone_Api_Response_Error */ $creditRatingScore = $this->handleError(null, $response); } //address shoult be saved to prevent to much creditratings $address->save(); return $creditRatingScore; }
/** * @param Payone_Api_Response_Interface $response * @return Payone_Core_Model_Domain_Transaction */ public function updateByApiResponse(Payone_Api_Response_Interface $response) { $transaction = $this->getFactory()->getModelTransaction(); $transaction->load($response->getTxid(), 'txid'); // should not exist but to be sure load by txid $transaction->setLastTxaction($response->getStatus()); $transaction->save(); return $transaction; }
/** * @param Payone_Api_Request_Interface $request * @param Payone_Api_Response_Interface $response * @return boolean */ public function save(Payone_Api_Request_Interface $request, Payone_Api_Response_Interface $response) { $domainObject = $this->getFactory()->getModelApi(); $domainObject->setData($request->toArray()); $domainObject->setRawRequest($request->__toString()); $domainObject->setRawResponse($response->__toString()); $domainObject->setResponse($response->getStatus()); $domainObject->save(); }
/** * @param Payone_Api_Request_Interface $request * @param null|Payone_Api_Response_Interface $response */ public function protocol(Payone_Api_Request_Interface $request, Payone_Api_Response_Interface $response = null) { $request->setApplyFilters($this->getServiceApplyFilters()); $response->setApplyFilters($this->getServiceApplyFilters()); $requestAsString = $request->__toString(); $responseAsString = $response->__toString(); foreach ($this->loggers as $key => $logger) { $logger->log($requestAsString); $logger->log($responseAsString); } foreach ($this->repositories as $key => $repository) { /** @var $repository Payone_Api_Persistence_Interface */ $repository->save($request, $response); } }
/** * @param Payone_Api_Response_Interface $response * @return Payone_Core_Model_Handler_Payment_Abstract|Payone_Core_Model_Handler_Payment_Debit */ public function handle(Payone_Api_Response_Interface $response) { $order = $this->getOrder(); $paymentMethod = $this->getPaymentMethod(); if ($response->isApproved()) { $this->getPayment()->setLastTransId($response->getTxid()); } elseif ($response->isError()) { return $this; } // Update Order Status $this->getServiceOrderStatus()->setConfigStore($this->getConfigStore()); $this->getServiceOrderStatus()->updateByApiResponse($order, $response); // Add Order Comment $this->getServiceOrderComment()->addByApiResponse($order, $response); return $this; }
/** * @param Mage_Sales_Model_Order $order * @param Payone_Api_Response_Interface $response * @param Payone_Api_Request_Interface $request * @throws Payone_Core_Exception_TransactionAlreadyExists * @return null|Payone_Core_Model_Domain_Transaction */ public function createByApiResponse(Mage_Sales_Model_Order $order, Payone_Api_Response_Interface $response, Payone_Api_Request_Interface $request) { $transaction = $this->getFactory()->getModelTransaction(); $transaction->load($response->getTxid(), 'txid'); // should not exist but to be sure load by txid if ($transaction->hasData()) { throw new Payone_Core_Exception_TransactionAlreadyExists($response->getTxid()); } $transaction->setTxid($response->getTxid()); $transaction->setLastTxaction($response->getStatus()); $transaction->setUserid($response->getUserid()); $transaction->setStoreId($order->getStoreId()); $transaction->setOrderId($order->getId()); $transaction->setReference($order->getIncrementId()); $transaction->setCurrency($order->getOrderCurrencyCode()); $transaction->setCustomerId($order->getCustomerId()); $transaction->setClearingtype($request->getClearingtype()); $transaction->setMode($request->getMode()); $transaction->setMid($request->getMid()); $transaction->setAid($request->getAid()); $transaction->setPortalid($request->getPortalid()); $transaction->setLastSequencenumber(0); $data = $response->toArray(); $transaction->addData($data); $transaction->save(); return $transaction; }
/** * @param Payone_Api_Response_Interface $response */ public function handle(Payone_Api_Response_Interface $response) { $address = $this->getAddress(); $errors = $this->getErrors(); $config = $this->getConfig(); $mapping = $config->getMappingPersonstatus(); if ($response instanceof Payone_Api_Response_AddressCheck_Valid) { /** @var $response Payone_Api_Response_AddressCheck_Valid */ if ($response->isCorrect()) { $this->handleCorrectAddress(); // Do nothing, best case, resume with personStatus mapping. } elseif ($response->isCorrectable()) { $correctedAddress = $this->prepareAddressCorrectionDataForCustomer($response); if ($correctedAddress['city'] == $address->getCity() && $correctedAddress['postcode'] == $address->getPostcode() && $correctedAddress['street'] == $address->getStreetFull()) { // PAYONE Api supports name correction, but it is not desired here, handle as a correct address. $this->handleCorrectAddress(); } elseif ($this->getConfig()->getConfirmAddressCorrection()) { // Address correction must be confirmed by customer, hand it up to controller/frontend $errors->setData('payone_address_corrected', $correctedAddress); } else { // Automatically correct address, allowing customer to resume checkout $this->correctAddress($response); } } $personStatus = $response->getPersonstatus(); if ($personStatus != 'NONE') { if (array_key_exists($personStatus, $mapping)) { $score = $mapping[$personStatus]; $address->setData('payone_addresscheck_score', $score); } } else { $score = 'G'; $address->setData('payone_addresscheck_score', $score); } $this->saveCustomerAddress($address); } elseif ($response instanceof Payone_Api_Response_AddressCheck_Invalid) { /** @var $response Payone_Api_Response_AddressCheck_Invalid */ $message = $this->getMessageForInvalidData($response->getCustomermessage()); $errors->setData('payone_address_invalid', $message); } elseif ($response instanceof Payone_Api_Response_Error) { /** @var $response Payone_Api_Response_Error */ $this->handleError(); } }
/** * @param Mage_Sales_Model_Order $order * @param Payone_Api_Response_Interface $response */ public function addByApiResponse(Mage_Sales_Model_Order $order, Payone_Api_Response_Interface $response) { // Preauthorization if ($response instanceof Payone_Api_Response_Preauthorization_Approved) { $comment = 'PAYONE successfully processed the payment-request.'; } elseif ($response instanceof Payone_Api_Response_Authorization_Approved) { $comment = 'PAYONE successfully processed and confirmed the payment-request.'; } elseif ($response instanceof Payone_Api_Response_Preauthorization_Redirect or $response instanceof Payone_Api_Response_Authorization_Redirect) { $comment = 'The payment-request has been forwarded.'; } elseif ($response instanceof Payone_Api_Response_Capture_Approved) { $comment = 'PAYONE successfully processed the capture-request.'; } elseif ($response instanceof Payone_Api_Response_Debit_Approved) { $comment = 'PAYONE successfully processed the debit-request.'; } elseif ($response instanceof Payone_Api_Response_Error) { $comment = 'The payment-request was incorrect. Please check the protocol.'; } else { $comment = $response->getStatus(); } $this->addCommentToOrder($order, $comment); }
/** * @param Mage_Sales_Model_Order $order * @param Payone_Api_Response_Interface $response */ public function updateByApiResponse(Mage_Sales_Model_Order $order, Payone_Api_Response_Interface $response) { $order->setPayoneTransactionStatus($response->getStatus()); }
/** * @param Payone_Api_Response_Authorization_Approved|Payone_Api_Response_Refund_Approved|Payone_Api_Response_Interface $response */ protected function sendAvsMail(Payone_Api_Response_Interface $response) { $storeId = $this->getOrder()->getStore()->getId(); $configMisc = $this->helperConfig()->getConfigMisc($storeId); $configEmailAvs = $configMisc->getEmailAvs(); if ($response instanceof Payone_Api_Response_Refund_Approved || $response instanceof Payone_Api_Response_Authorization_Approved || $response instanceof Payone_Api_Response_Preauthorization_Approved) { if ($configEmailAvs->isResultAvsInConfig($response->getProtectResultAvs())) { // Mailtemplates need an Varien_Object if we want to use Getter from the Object $responseMailObject = new Varien_Object($response->toArray()); $helperEmail = $this->helperEmail(); $helperEmail->setStoreId($storeId); $result = $helperEmail->send($configEmailAvs, array('response' => $responseMailObject)); } } }