public function parseRecurringContractData($data) { /** @var Adyen_Payment_Model_Adyen_Oneclick $methodInstance */ $methodInstance = Mage::helper('payment')->getMethodInstance('adyen_oneclick'); if (!$methodInstance) { Adyen_Payment_Exception::throwException('Can not update billing agreement, incorrect payment method specified in recurring contract data'); } $methodInstance->parseRecurringContractData($this, $data); $this->setAgreementData($data); return $this; }
public function validate3dAction() { // get current order $session = $this->_getCheckout(); try { $order = $this->_getOrder(); $session->setAdyenQuoteId($session->getQuoteId()); $session->setAdyenRealOrderId($session->getLastRealOrderId()); $order->loadByIncrementId($session->getLastRealOrderId()); $adyenStatus = $order->getAdyenEventCode(); // get payment details $payment = $order->getPayment(); $paRequest = $payment->getAdditionalInformation('paRequest'); $md = $payment->getAdditionalInformation('md'); $issuerUrl = $payment->getAdditionalInformation('issuerUrl'); $infoAvailable = $payment && !empty($paRequest) && !empty($md) && !empty($issuerUrl); // check adyen status and check if all information is available if (!empty($adyenStatus) && $adyenStatus == 'RedirectShopper' && $infoAvailable) { $request = $this->getRequest(); $requestMD = $request->getPost('MD'); $requestPaRes = $request->getPost('PaRes'); // authorise the payment if the user is back from the external URL if ($request->isPost() && !empty($requestMD) && !empty($requestPaRes)) { if ($requestMD == $md) { $payment->setAdditionalInformation('paResponse', $requestPaRes); // send autorise3d request, catch exception in case of 'Refused' try { $result = $payment->getMethodInstance()->authorise3d($payment, $order->getGrandTotal()); } catch (Exception $e) { $result = 'Refused'; $order->setAdyenEventCode($result)->save(); } // check if authorise3d was successful if ($result == 'Authorised') { $order->addStatusHistoryComment(Mage::helper('adyen')->__('3D-secure validation was successful'), $order->getStatus())->save(); $session->unsAdyenRealOrderId(); $session->setQuoteId($session->getAdyenQuoteId(true)); $session->getQuote()->setIsActive(false)->save(); $this->_redirect('checkout/onepage/success'); } else { $order->addStatusHistoryComment(Mage::helper('adyen')->__('3D-secure validation was unsuccessful.'))->save(); $session->addException($e, Mage::helper('adyen')->__($e->getMessage())); $this->cancel(); } } else { $errorMsg = Mage::helper('adyen')->__('3D secure validation error'); Adyen_Payment_Exception::throwException($errorMsg); } } else { $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true, Mage::helper('adyen')->__('Customer was redirected to bank for 3D-secure validation.'))->save(); $this->getResponse()->setBody($this->getLayout()->createBlock($this->_redirectBlockType)->setOrder($order)->toHtml()); } } else { // log exception $errorMsg = Mage::helper('adyen')->__('3D secure went wrong'); if ($order) { $errorMsg .= " for orderId: " . $order->getId(); } if ($adyenStatus) { $errorMsg .= " adyenStatus is: " . $adyenStatus; } Adyen_Payment_Exception::throwException($errorMsg); } } catch (Exception $e) { Mage::logException($e); $session->addException($e, Mage::helper('adyen')->__($e->getMessage())); $this->cancel(); } }
/** * Retrieve billing agreement customer details by token * * @param Adyen_Payment_Model_Billing_Agreement|Mage_Payment_Model_Billing_AgreementAbstract $agreement * @return array */ public function getBillingAgreementTokenInfo(Mage_Payment_Model_Billing_AgreementAbstract $agreement) { $recurringContractDetail = $this->_api()->getRecurringContractDetail($agreement->getCustomerReference(), $agreement->getReferenceId()); if (!$recurringContractDetail) { Adyen_Payment_Exception::throwException(Mage::helper('adyen')->__('The recurring contract (%s) could not be retrieved', $agreement->getReferenceId())); } $agreement->parseRecurringContractData($recurringContractDetail); return $recurringContractDetail; }
/** * Do the actual API request * * @param array $request * @param int|Mage_Core_model_Store $storeId * * @throws Adyen_Payment_Exception * @return mixed */ protected function _doRequest(array $request, $storeId) { if ($storeId instanceof Mage_Core_model_Store) { $storeId = $storeId->getId(); } $requestUrl = $this->_helper()->getConfigDataDemoMode() ? "https://pal-test.adyen.com/pal/adapter/httppost" : "https://pal-live.adyen.com/pal/adapter/httppost"; $username = $this->_helper()->getConfigDataWsUserName($storeId); $password = $this->_helper()->getConfigDataWsPassword($storeId); Mage::log($request, null, 'adyen_api.log'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $requestUrl); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); curl_setopt($ch, CURLOPT_POST, count($request)); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); $error = curl_error($ch); if ($result === false) { Adyen_Payment_Exception::throwException($error); } $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpStatus != 200) { Adyen_Payment_Exception::throwException(Mage::helper('adyen')->__('HTTP Status code %s received, data %s', $httpStatus, $result)); } curl_close($ch); return $result; }
public function create(Varien_Object $payment, $amount, $paymentMethod = null, $merchantAccount = null, $recurringType = null, $recurringPaymentType = null, $enableMoto = null) { $order = $payment->getOrder(); $incrementId = $order->getIncrementId(); $orderCurrencyCode = $order->getOrderCurrencyCode(); // override amount because this amount uses the right currency $amount = $order->getGrandTotal(); $customerId = $order->getCustomerId(); if ($customerId) { $customer = Mage::getModel('customer/customer')->load($order->getCustomerId()); $customerId = $customer->getData('adyen_customer_ref') ?: $customer->getData('increment_id') ?: $customerId; } $realOrderId = $order->getRealOrderId(); $this->reference = $incrementId; $this->merchantAccount = $merchantAccount; $this->amount->currency = $orderCurrencyCode; $this->amount->value = Mage::helper('adyen')->formatAmount($amount, $orderCurrencyCode); //shopper data $customerEmail = $order->getCustomerEmail(); $this->shopperEmail = $customerEmail; $this->shopperIP = $order->getRemoteIp(); $this->shopperReference = !empty($customerId) ? $customerId : self::GUEST_ID . $realOrderId; // Set the recurring contract if ($recurringType) { if ($paymentMethod == "oneclick") { // For ONECLICK look at the recurringPaymentType that the merchant has selected in Adyen ONECLICK settings if ($payment->getAdditionalInformation('customer_interaction')) { $this->recurring = new Adyen_Payment_Model_Adyen_Data_Recurring(); $this->recurring->contract = "ONECLICK"; } else { $this->recurring = new Adyen_Payment_Model_Adyen_Data_Recurring(); $this->recurring->contract = "RECURRING"; } } elseif ($paymentMethod == "cc") { // if save card is disabled only shoot in as recurring if recurringType is set to ONECLICK,RECURRING if ($payment->getAdditionalInformation("store_cc") == "" && $recurringType == "ONECLICK,RECURRING") { $this->recurring = new Adyen_Payment_Model_Adyen_Data_Recurring(); $this->recurring->contract = "RECURRING"; } elseif ($payment->getAdditionalInformation("store_cc") == "1") { $this->recurring = new Adyen_Payment_Model_Adyen_Data_Recurring(); $this->recurring->contract = $recurringType; } elseif ($recurringType == "RECURRING") { // recurring permission is not needed from shopper so just save it as recurring $this->recurring = new Adyen_Payment_Model_Adyen_Data_Recurring(); $this->recurring->contract = "RECURRING"; } } else { $this->recurring = new Adyen_Payment_Model_Adyen_Data_Recurring(); $this->recurring->contract = $recurringType; } } /** * Browser info * @var unknown_type */ if (isset($_SERVER['HTTP_ACCEPT'])) { $this->browserInfo->acceptHeader = $_SERVER['HTTP_ACCEPT']; } if (isset($_SERVER['HTTP_USER_AGENT'])) { $this->browserInfo->userAgent = $_SERVER['HTTP_USER_AGENT']; } switch ($paymentMethod) { case "elv": $elv = unserialize($payment->getPoNumber()); $this->card = null; $this->shopperName = null; $this->bankAccount = null; $this->elv->accountHolderName = $elv['account_owner']; $this->elv->bankAccountNumber = $elv['account_number']; $this->elv->bankLocation = $elv['bank_location']; $this->elv->bankLocationId = $elv['bank_location']; $this->elv->bankName = $elv['bank_name']; break; case "cc": case "oneclick": $this->shopperName = null; $this->elv = null; $this->bankAccount = null; $billingAddress = $order->getBillingAddress(); $helper = Mage::helper('adyen'); if ($billingAddress) { $this->billingAddress = new Adyen_Payment_Model_Adyen_Data_BillingAddress(); $this->billingAddress->street = $helper->getStreet($billingAddress)->getName(); $this->billingAddress->houseNumberOrName = $helper->getStreet($billingAddress)->getHouseNumber(); $this->billingAddress->city = $billingAddress->getCity(); $this->billingAddress->postalCode = $billingAddress->getPostcode(); $this->billingAddress->stateOrProvince = $billingAddress->getRegionCode(); $this->billingAddress->country = $billingAddress->getCountryId(); } $deliveryAddress = $order->getShippingAddress(); if ($deliveryAddress) { $this->deliveryAddress = new Adyen_Payment_Model_Adyen_Data_DeliveryAddress(); $this->deliveryAddress->street = $helper->getStreet($deliveryAddress)->getName(); $this->deliveryAddress->houseNumberOrName = $helper->getStreet($deliveryAddress)->getHouseNumber(); $this->deliveryAddress->city = $deliveryAddress->getCity(); $this->deliveryAddress->postalCode = $deliveryAddress->getPostcode(); $this->deliveryAddress->stateOrProvince = $deliveryAddress->getRegionCode(); $this->deliveryAddress->country = $deliveryAddress->getCountryId(); } if ($paymentMethod == "oneclick") { $recurringDetailReference = $payment->getAdditionalInformation("recurring_detail_reference"); if ($payment->getAdditionalInformation('customer_interaction')) { $this->shopperInteraction = "Ecommerce"; } else { $this->shopperInteraction = "ContAuth"; } // For recurring Ideal and Sofort needs to be converted to SEPA for this it is mandatory to set selectBrand to sepadirectdebit if (!$payment->getAdditionalInformation('customer_interaction')) { if ($payment->getCcType() == "directEbanking" || $payment->getCcType() == "ideal") { $this->selectedBrand = "sepadirectdebit"; } } } else { $recurringDetailReference = null; $this->shopperInteraction = "Ecommerce"; } if ($paymentMethod == "cc" && Mage::app()->getStore()->isAdmin() && $enableMoto != null && $enableMoto == 1) { $this->shopperInteraction = "Moto"; } // if it is a sepadirectdebit set selectedBrand to sepadirectdebit if ($payment->getCcType() == "sepadirectdebit") { $this->selectedBrand = "sepadirectdebit"; } if ($recurringDetailReference && $recurringDetailReference != "") { $this->selectedRecurringDetailReference = $recurringDetailReference; } if (Mage::getModel('adyen/adyen_cc')->isCseEnabled()) { $this->card = null; // this is only needed for creditcards if ($payment->getAdditionalInformation("encrypted_data") != "") { $kv = new Adyen_Payment_Model_Adyen_Data_AdditionalDataKVPair(); $kv->key = new SoapVar("card.encrypted.json", XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema"); $kv->value = new SoapVar($payment->getAdditionalInformation("encrypted_data"), XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema"); $this->additionalData->entry = $kv; } else { if ($paymentMethod == 'cc') { // log the browser data to see why it is failing Mage::log($_SERVER['HTTP_USER_AGENT'], Zend_Log::ERR, "adyen_exception.log", true); // For CC encrypted data is needed if you use CSE Adyen_Payment_Exception::throwException(Mage::helper('adyen')->__('Missing the encrypted data value. Make sure the Client Side Encryption(CSE) script did encrypt the Credit Card details')); } } } else { if ($recurringDetailReference && $recurringDetailReference != "") { // this is only needed for creditcards if ($payment->getCcCid() != "" && $payment->getCcExpMonth() != "" && $payment->getCcExpYear() != "") { if ($recurringType != "RECURRING") { $this->card->cvc = $payment->getCcCid(); } $this->card->expiryMonth = $payment->getCcExpMonth(); $this->card->expiryYear = $payment->getCcExpYear(); } else { $this->card = null; } } else { // this is only the case for adyen_cc payments $this->card->cvc = $payment->getCcCid(); $this->card->expiryMonth = $payment->getCcExpMonth(); $this->card->expiryYear = $payment->getCcExpYear(); $this->card->holderName = $payment->getCcOwner(); $this->card->number = $payment->getCcNumber(); } } // installments if (Mage::helper('adyen/installments')->isInstallmentsEnabled() && $payment->getAdditionalInformation('number_of_installments') > 0) { $this->installments = new Adyen_Payment_Model_Adyen_Data_Installments(); $this->installments->value = $payment->getAdditionalInformation('number_of_installments'); } // add observer to have option to overrule and or add request data Mage::dispatchEvent('adyen_payment_card_payment_request', array('order' => $order, 'paymentMethod' => $paymentMethod, 'paymentRequest' => $this)); break; case "boleto": $boleto = unserialize($payment->getPoNumber()); $this->card = null; $this->elv = null; $this->bankAccount = null; $this->socialSecurityNumber = $boleto['social_security_number']; $this->selectedBrand = $boleto['selected_brand']; $this->shopperName->firstName = $boleto['firstname']; $this->shopperName->lastName = $boleto['lastname']; $this->deliveryDate = $boleto['delivery_date']; break; case "sepa": $sepa = unserialize($payment->getPoNumber()); $this->card = null; $this->elv = null; $this->shopperName = null; $this->bankAccount->iban = $sepa['iban']; $this->bankAccount->ownerName = $sepa['account_name']; $this->bankAccount->countryCode = $sepa['country']; $this->selectedBrand = "sepadirectdebit"; break; } return $this; }