public function execute() { $response = $this->getRequest()->getParams(); $this->_adyenLogger->info(print_r($response, true)); $result = $this->validateResponse($response); if ($result) { $session = $this->_session; $session->getQuote()->setIsActive(false)->save(); $this->_redirect('checkout/onepage/success'); } else { $this->_cancel($response); $this->_redirect('checkout/cart'); } }
protected function _apiRequest($request) { // log the request $this->_adyenLogger->info('The request to adyen: ' . print_r($request, true)); $webserviceUsername = $this->_adyenHelper->getWsUsername(); $webservicePassword = $this->_adyenHelper->getWsPassword(); $url = $this->_adyenHelper->getWsUrl(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $webserviceUsername . ":" . $webservicePassword); curl_setopt($ch, CURLOPT_POST, count($request)); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $results = curl_exec($ch); $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpStatus != 200) { throw new \Magento\Framework\Exception\LocalizedException(__('HTTP Status code' . $httpStatus . " " . $webserviceUsername . ":" . $webservicePassword)); } if ($results === false) { throw new \Magento\Framework\Exception\LocalizedException(__('HTTP Status code' . $results)); } parse_str($results, $resultArr); curl_close($ch); // log the result $this->_adyenLogger->info('The response to adyen: ' . print_r($resultArr, true)); return $resultArr; }
public function getFormFields() { $paymentInfo = $this->getInfoInstance(); $order = $paymentInfo->getOrder(); $realOrderId = $order->getRealOrderId(); $orderCurrencyCode = $order->getOrderCurrencyCode(); $skinCode = trim($this->getConfigData('skin_code')); $amount = $this->_adyenHelper->formatAmount($order->getGrandTotal(), $orderCurrencyCode); $merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account')); $shopperEmail = $order->getCustomerEmail(); $customerId = $order->getCustomerId(); $shopperIP = $order->getRemoteIp(); $browserInfo = $_SERVER['HTTP_USER_AGENT']; $deliveryDays = $this->getConfigData('delivery_days'); $shopperLocale = trim($this->getConfigData('shopper_locale')); $shopperLocale = !empty($shopperLocale) ? $shopperLocale : $this->resolver->getLocale(); $countryCode = trim($this->getConfigData('country_code')); $countryCode = !empty($countryCode) ? $countryCode : false; // if directory lookup is enabled use the billingadress as countrycode if ($countryCode == false) { if ($order->getBillingAddress() && $order->getBillingAddress()->getCountryId() != "") { $countryCode = $order->getBillingAddress()->getCountryId(); } } $formFields = array(); $formFields['merchantAccount'] = $merchantAccount; $formFields['merchantReference'] = $realOrderId; $formFields['paymentAmount'] = (int) $amount; $formFields['currencyCode'] = $orderCurrencyCode; $formFields['shipBeforeDate'] = date("Y-m-d", mktime(date("H"), date("i"), date("s"), date("m"), date("j") + $deliveryDays, date("Y"))); $formFields['skinCode'] = $skinCode; $formFields['shopperLocale'] = $shopperLocale; $formFields['countryCode'] = $countryCode; $formFields['shopperIP'] = $shopperIP; $formFields['browserInfo'] = $browserInfo; $formFields['sessionValidity'] = date(DATE_ATOM, mktime(date("H") + 1, date("i"), date("s"), date("m"), date("j"), date("Y"))); $formFields['shopperEmail'] = $shopperEmail; // recurring $recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData('recurring_type')); $formFields['recurringContract'] = $recurringType; $formFields['shopperReference'] = !empty($customerId) ? $customerId : self::GUEST_ID . $realOrderId; //blocked methods $formFields['blockedMethods'] = ""; $baseUrl = $this->storeManager->getStore($this->getStore())->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK); $formFields['resURL'] = $baseUrl . 'adyen/process/result'; $hmacKey = $this->_adyenHelper->getHmac(); $brandCode = $this->getInfoInstance()->getCcType(); if ($brandCode) { $formFields['brandCode'] = $brandCode; } // Sort the array by key using SORT_STRING order ksort($formFields, SORT_STRING); // Generate the signing data string $signData = implode(":", array_map(array($this, 'escapeString'), array_merge(array_keys($formFields), array_values($formFields)))); $merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true)); $formFields['merchantSig'] = $merchantSig; $this->_adyenLogger->info(print_r($formFields, true)); return $formFields; }
public function execute() { // check if 3d is active $order = $this->_getOrder(); $active = $order->getPayment()->getAdditionalInformation('3dActive'); $md = $order->getPayment()->getAdditionalInformation('md'); // check if 3D secure is active. If not just go to success page if ($active) { $this->_adyenLogger->info("3D secure is active"); // check if it is already processed if ($this->getRequest()->isPost()) { $this->_adyenLogger->info("Process 3D secure payment"); $requestMD = $this->getRequest()->getPost('MD'); $requestPaRes = $this->getRequest()->getPost('PaRes'); if ($requestMD == $md) { $order->getPayment()->setAdditionalInformation('paResponse', $requestPaRes); try { $result = $order->getPayment()->getMethodInstance()->authorise3d($order->getPayment()); } catch (Exception $e) { $result = 'Refused'; } // check if authorise3d was successful if ($result == 'Authorised') { $order->addStatusHistoryComment(__('3D-secure validation was successful'))->save(); $this->_redirect('checkout/onepage/success'); } else { $order->addStatusHistoryComment(__('3D-secure validation was unsuccessful.'))->save(); $this->_adyenHelper->cancelOrder($order); } } } else { $this->_adyenLogger->info("Customer was redirected to bank for 3D-secure validation."); $order->addStatusHistoryComment(__('Customer was redirected to bank for 3D-secure validation.'))->save(); $this->_view->loadLayout(); $this->_view->getLayout()->initMessages(); $this->_view->renderLayout(); } } else { $this->_redirect('checkout/onepage/success/'); } }
/** * Disable a recurring contract * * @param $recurringDetailReference * @param $shopperReference * @param $storeId * @return bool * @throws \Magento\Framework\Exception\LocalizedException */ public function disableRecurringContract($recurringDetailReference, $shopperReference, $storeId) { $merchantAccount = $this->_adyenHelper->getAdyenAbstractConfigData("merchant_account", $storeId); $request = ["merchantAccount" => $merchantAccount, "shopperReference" => $shopperReference, "recurringDetailReference" => $recurringDetailReference]; // call lib $service = new \Adyen\Service\Recurring($this->_client); try { $result = $service->disable($request); } catch (\Exception $e) { $this->_adyenLogger->info($e->getMessage()); } if (isset($result['response']) && $result['response'] == '[detail-successfully-disabled]') { return true; } else { throw new \Magento\Framework\Exception\LocalizedException(__('Failed to disable this contract')); } }
public function processNotification() { $this->_order = null; $this->_logger->info("START OF THE CRONJOB"); //fixme somehow the created_at is saved in my timzone $dateStart = new \DateTime(); // loop over notifications that are not processed and from 1 minute ago $dateStart = new \DateTime(); $dateStart->modify('-1 day'); // excecute notifications from 2 minute or earlier because order could not yet been created by mangento $dateEnd = new \DateTime(); $dateEnd->modify('-2 minute'); $dateRange = ['from' => $dateStart, 'to' => $dateEnd, 'datetime' => true]; $notifications = $this->_notificationFactory->create(); $notifications->addFieldToFilter('done', 0); $notifications->addFieldToFilter('created_at', $dateRange); foreach ($notifications as $notification) { // get order $incrementId = $notification->getMerchantReference(); $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId); if (!$this->_order->getId()) { throw new Exception(sprintf('Wrong order ID: "%1".', $incrementId)); } // declare all variables that are needed $this->_declareVariables($notification); // add notification to comment history status is current status $this->_addStatusHistoryComment(); // $previousAdyenEventCode = $this->order->getAdyenNotificationEventCode(); $previousAdyenEventCode = $this->_order->getData('adyen_notification_event_code'); // set pspReference on payment object $this->_order->getPayment()->setAdditionalInformation('pspReference', $this->_pspReference); // check if success is true of false if (strcmp($this->_success, 'false') == 0 || strcmp($this->_success, '0') == 0) { // Only cancel the order when it is in state pending, payment review or if the ORDER_CLOSED is failed (means split payment has not be successful) if ($this->_order->getState() === \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT || $this->_order->getState() === \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW || $this->_eventCode == \Magento\Sales\Model\Order::ADYEN_EVENT_ORDER_CLOSED) { $this->_debugData['_updateOrder info'] = 'Going to cancel the order'; // if payment is API check, check if API result pspreference is the same as reference if ($this->_eventCode == Adyen_Payment_Model_Event::ADYEN_EVENT_AUTHORISATION && $this->_getPaymentMethodType() == 'api') { if ($this->_pspReference == $this->_order->getPayment()->getAdditionalInformation('pspReference')) { // don't cancel the order if previous state is authorisation with success=true if ($previousAdyenEventCode != "AUTHORISATION : TRUE") { $this->_holdCancelOrder(false); } else { //$this->_order->setAdyenEventCode($previousAdyenEventCode); // do not update the adyenEventCode $this->_order->setData('adyen_notification_event_code', $previousAdyenEventCode); $this->_debugData['_updateOrder warning'] = 'order is not cancelled because previous notification was a authorisation that succeeded'; } } else { $this->_debugData['_updateOrder warning'] = 'order is not cancelled because pspReference does not match with the order'; } } else { // don't cancel the order if previous state is authorisation with success=true if ($previousAdyenEventCode != "AUTHORISATION : TRUE") { $this->_holdCancelOrder(false); } else { // $this->_order->setAdyenEventCode($previousAdyenEventCode); // do not update the adyenEventCode $this->_order->setData('adyen_notification_event_code', $previousAdyenEventCode); $this->_debugData['_updateOrder warning'] = 'order is not cancelled because previous notification was a authorisation that succeeded'; } } } else { $this->_debugData['_updateOrder info'] = 'Order is already processed so ignore this notification state is:' . $this->_order->getState(); } } else { // Notification is successful $this->_processNotification(); } $this->_order->save(); foreach ($this->_debugData as $debug) { $this->_logger->info($debug); } // set done to true $dateEnd = new \DateTime(); $notification->setDone(true); $notification->setUpdatedAt($dateEnd); $notification->save(); } $this->_logger->info("END OF THE CRONJOB"); }