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; }
/** * Event queue ajax grid */ public function gridAction() { try { $this->loadLayout()->renderLayout(); return; } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); } catch (Exception $e) { Adyen_Payment_Exception::logException($e); } $this->_redirect('*/*/'); }
/** * @event controller_action_predispatch * @param Varien_Event_Observer $observer */ public function addMethodsToConfig(Varien_Event_Observer $observer) { if (Mage::app()->getStore()->isAdmin()) { $store = Mage::getSingleton('adminhtml/session_quote')->getStore(); } else { $store = Mage::app()->getStore(); } if (Mage::getStoreConfigFlag('payment/adyen_oneclick/active', $store)) { try { $this->_addOneClickMethodsToConfig($store); $store->setConfig('payment/adyen_oneclick/active', 0); } catch (Exception $e) { Adyen_Payment_Exception::logException($e); } } }
/** * @event controller_action_predispatch * @param Varien_Event_Observer $observer */ public function addMethodsToConfig(Varien_Event_Observer $observer) { if (Mage::app()->getStore()->isAdmin()) { $store = Mage::getSingleton('adminhtml/session_quote')->getStore(); } else { $store = Mage::app()->getStore(); } // by default disable adyen_ideal only if IDeal is in directoryLookup result show this payment method $store->setConfig('payment/adyen_ideal/active', 0); if (Mage::getStoreConfigFlag('payment/adyen_hpp/active', $store)) { try { $this->_addHppMethodsToConfig($store); } catch (Exception $e) { $store->setConfig('payment/adyen_hpp/active', 0); Adyen_Payment_Exception::logException($e); } } }
public function insAction() { try { // if version is in the notification string show the module version $response = $this->getRequest()->getParams(); if (isset($response['version'])) { $helper = Mage::helper('adyen'); $this->getResponse()->setBody($helper->getExtensionVersion()); return $this; } if (isset($response['magento_version'])) { $version = Mage::getVersion(); $this->getResponse()->setBody($version); return $this; } $notificationMode = isset($response['live']) ? $response['live'] : ""; if ($notificationMode != "" && $this->_validateNotificationMode($notificationMode)) { // add HTTP POST attributes as an array so it is the same as JSON and SOAP result foreach ($response as $key => $value) { if (strpos($key, '_') !== false) { $results = explode('_', $key); $size = count($results); if ($size == 2) { $response[$results[0]][$results[1]] = $value; } elseif ($size == 3) { $response[$results[0]][$results[1]][$results[2]] = $value; } } } // create amount array so it is the same as JSON SOAP response $response['amount'] = array('value' => $response['value'], 'currency' => $response['currency']); $status = $this->processNotification($response); if ($status == "401") { $this->_return401(); return; } else { $this->getResponse()->clearHeader('Content-Type')->setHeader('Content-Type', 'text/html')->setBody("[accepted]"); return; } } else { if ($notificationMode == "") { $this->_return401(); return; } Mage::throwException(Mage::helper('adyen')->__('Mismatch between Live/Test modes of Magento store and the Adyen platform.')); return; } } catch (Exception $e) { Adyen_Payment_Exception::logException($e); } return $this; }
/** * @param Adyen_Payment_Model_Billing_Agreement $billingAgreement * @param Mage_Sales_Model_Quote_Payment $paymentInfo * * @return $this */ public function initBillingAgreementPaymentInfo(Adyen_Payment_Model_Billing_Agreement $billingAgreement, Mage_Sales_Model_Quote_Payment $paymentInfo) { try { $recurringDetailReference = $billingAgreement->getReferenceId(); $paymentInfo->setMethod('adyen_oneclick_' . $recurringDetailReference); $paymentInfo->setAdditionalInformation('recurring_detail_reference', $recurringDetailReference); // set the ccType needed for Sepa, Sofort and Ideal $agreementData = $billingAgreement->getAgreementData(); if (isset($agreementData['variant'])) { $paymentInfo->setCcType($agreementData['variant']); } } catch (Exception $e) { Adyen_Payment_Exception::logException($e); } return $this; }
/** * 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; }