/** * @magentoDataFixture Magento/Sales/_files/order.php */ public function testRedirectActionIsContentGenerated() { $this->_order->load('100000001', 'increment_id'); $this->_order->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS); $this->_order->save(); $this->_order->load('100000001', 'increment_id'); $this->_session->setLastRealOrderId($this->_order->getRealOrderId())->setLastQuoteId($this->_order->getQuoteId()); $this->dispatch('paypal/standard/redirect'); $this->assertContains('<form action="https://www.paypal.com/cgi-bin/webscr" id="paypal_standard_checkout"' . ' name="paypal_standard_checkout" method="POST">', $this->getResponse()->getBody()); }
public function informCustomer(\Magento\Sales\Model\Order $order, $amount, $currency) { try { if (!($order_increment_id = $order->getRealOrderId()) or !($method_config = $this->_s2pModel->getFullConfigArray())) { return false; } $siteUrl = $order->getStore()->getBaseUrl(); $siteName = $this->_helper->getStoreName(); $supportEmail = $this->_helper->getStoreConfig('trans_email/ident_support/email'); $supportName = $this->_helper->getStoreConfig('trans_email/ident_support/name'); $payment_details_arr['site_url'] = $siteUrl; $payment_details_arr['order_increment_id'] = $order_increment_id; $payment_details_arr['site_name'] = $siteName; $payment_details_arr['customer_name'] = $order->getCustomerName(); $payment_details_arr['order_date'] = $order->getCreatedAtFormatted(\IntlDateFormatter::LONG); $payment_details_arr['support_email'] = $supportEmail; $payment_details_arr['total_paid'] = number_format($amount / 100, 2); $payment_details_arr['currency'] = $currency; $transport = $this->_transportBuilder->setTemplateIdentifier($method_config['smart2pay_email_payment_confirmation'])->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_ADMINHTML, 'store' => $order->getStore()->getId()])->setTemplateVars($payment_details_arr)->setFrom(['name' => $supportName, 'email' => $supportEmail])->addTo($order->getCustomerEmail())->getTransport(); $transport->sendMessage(); } catch (\Magento\Framework\Exception\MailException $e) { $this->_s2pLogger->write('Error sending customer informational email to [' . $order->getCustomerEmail() . ']', 'email_template'); $this->_s2pLogger->write($e->getMessage(), 'email_exception'); } catch (\Exception $e) { $this->_s2pLogger->write($e->getMessage(), 'exception'); } return true; }
/** * Loads the order info from a Magento order model. * * @param Order $order the order model. * @return \NostoOrder */ public function build(Order $order) { $nostoOrder = new \NostoOrder(); try { $nostoCurrency = new NostoCurrencyCode($order->getOrderCurrencyCode()); $nostoOrder->setOrderNumber($order->getId()); $nostoOrder->setExternalRef($order->getRealOrderId()); $nostoOrder->setCreatedDate(new NostoDate(strtotime($order->getCreatedAt()))); $nostoOrder->setPaymentProvider(new NostoOrderPaymentProvider($order->getPayment()->getMethod())); if ($order->getStatus()) { $nostoStatus = new NostoOrderStatus(); $nostoStatus->setCode($order->getStatus()); $nostoStatus->setLabel($order->getStatusLabel()); $nostoOrder->setStatus($nostoStatus); } foreach ($order->getAllStatusHistory() as $item) { if ($item->getStatus()) { $nostoStatus = new NostoOrderStatus(); $nostoStatus->setCode($item->getStatus()); $nostoStatus->setLabel($item->getStatusLabel()); $nostoStatus->setCreatedAt(new NostoDate(strtotime($item->getCreatedAt()))); $nostoOrder->addHistoryStatus($nostoStatus); } } // Set the buyer information $nostoBuyer = new NostoOrderBuyer(); $nostoBuyer->setFirstName($order->getCustomerFirstname()); $nostoBuyer->setLastName($order->getCustomerLastname()); $nostoBuyer->setEmail($order->getCustomerEmail()); $nostoOrder->setBuyer($nostoBuyer); // Add each ordered item as a line item /** @var Item $item */ foreach ($order->getAllVisibleItems() as $item) { $nostoItem = new NostoOrderItem(); $nostoItem->setItemId((int) $this->buildItemProductId($item)); $nostoItem->setQuantity((int) $item->getQtyOrdered()); $nostoItem->setName($this->buildItemName($item)); try { $nostoItem->setUnitPrice(new NostoPrice($this->_priceHelper->getItemFinalPriceInclTax($item))); } catch (\NostoInvalidArgumentException $E) { $nostoItem->setUnitPrice(new NostoPrice(0)); } $nostoItem->setCurrency($nostoCurrency); $nostoOrder->addItem($nostoItem); } // Add discounts as a pseudo line item if (($discount = $order->getDiscountAmount()) < 0) { $nostoItem = new NostoOrderItem(); $nostoItem->setItemId(-1); $nostoItem->setQuantity(1); $nostoItem->setName($this->buildDiscountRuleDescription($order)); $nostoItem->setUnitPrice(new NostoPrice($discount)); $nostoItem->setCurrency($nostoCurrency); $nostoOrder->addItem($nostoItem); } // Add shipping and handling as a pseudo line item if (($shippingInclTax = $order->getShippingInclTax()) > 0) { $nostoItem = new NostoOrderItem(); $nostoItem->setItemId(-1); $nostoItem->setQuantity(1); $nostoItem->setName('Shipping and handling'); $nostoItem->setUnitPrice(new NostoPrice($shippingInclTax)); $nostoItem->setCurrency($nostoCurrency); $nostoOrder->addItem($nostoItem); } } catch (Exception $e) { $this->_logger->error($e, ['exception' => $e]); } return $nostoOrder; }
protected function _checkIpnRequest() { $request = $this->getRequest()->getPost(); $this->_order = $this->_getOrder($request['ordernumber']); // check order ID $orderId = $this->_order->getRealOrderId(); if ($orderId != $request['ordernumber']) { throw new \Magento\Framework\Exception\LocalizedException(__('Order not found')); } $this->_paymentInst = $this->_order->getPayment()->getMethodInstance(); // check merchant ID if ($this->_paymentInst->getConfigData('merchant') != $request['merchant_id']) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid merchant ID: ' . $request['merchant_id'])); } // failed operation if ('AS000' != $request['responsecode']) { throw new \Magento\Framework\Exception\LocalizedException($this->_paymentInst->getAssistErrors($request['responsecode'])); } // wrong test mode if ($this->_paymentInst->getConfigData('mode') != $request['testmode']) { throw new \Magento\Framework\Exception\LocalizedException(__('Wrong Test Mode.')); } // accept only Approve operations, cancel and capture are processed real time if ('100' != $request['operationtype']) { throw new \Magento\Framework\Exception\LocalizedException(__('Wrong Operation Type. Only Approve is supported by IPN.')); } // check currency if ($this->_order->getBaseCurrencyCode() != $request['ordercurrency']) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid currency: ' . $request['ordercurrency'])); } // check amount $orderAmount = number_format($this->_order->getGrandTotal(), 2, '.', ''); if ($orderAmount != $request['orderamount']) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid amount: ' . $request['orderamount'])); } /* if (Mage::helper('assist')->isResponseSecuredMd5()) { $x = array( $this->_paymentInst->getConfigData('merchant'), $request['ordernumber'], $request['amount'], $request['currency'], $request['orderstate'] ); if ($this->_paymentInst->secreyKey(implode("", $x)) != $request['checkvalue']) { Mage::throwException('Incorrect Checkvalue: ' . $request['checkvalue']); } } if (Mage::helper('assist')->isResponseSecuredPgp()) { $y = implode("", array( $this->_paymentInst->getConfigData('merchant'), $request['ordernumber'], $request['amount'], $request['currency'], $request['orderstate'] )); $keyFile = Mage::getBaseDir('var') . DS . 'assist' . DS . $this->_paymentInst->getConfigData('assist_key'); if ($this->_paymentInst->sign($y, $keyFile) != $request['signature']) { Mage::throwException('Incorrect Signature.'); } } */ return $request; }
/** * @return array */ public function getFormFields() { $formFields = []; try { if ($this->_order->getPayment()) { $realOrderId = $this->_order->getRealOrderId(); $orderCurrencyCode = $this->_order->getOrderCurrencyCode(); $skinCode = trim($this->_adyenHelper->getAdyenHppConfigData('skin_code')); $amount = $this->_adyenHelper->formatAmount($this->_order->getGrandTotal(), $orderCurrencyCode); $merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account')); $shopperEmail = $this->_order->getCustomerEmail(); $customerId = $this->_order->getCustomerId(); $shopperIP = $this->_order->getRemoteIp(); $browserInfo = $_SERVER['HTTP_USER_AGENT']; $deliveryDays = $this->_adyenHelper->getAdyenHppConfigData('delivery_days'); $shopperLocale = trim($this->_adyenHelper->getAdyenHppConfigData('shopper_locale')); $shopperLocale = !empty($shopperLocale) ? $shopperLocale : $this->_resolver->getLocale(); $countryCode = trim($this->_adyenHelper->getAdyenHppConfigData('country_code')); $countryCode = !empty($countryCode) ? $countryCode : false; // if directory lookup is enabled use the billingadress as countrycode if ($countryCode == false) { if ($this->_order->getBillingAddress() && $this->_order->getBillingAddress()->getCountryId() != "") { $countryCode = $this->_order->getBillingAddress()->getCountryId(); } } $formFields = []; $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')); $brandCode = $this->_order->getPayment()->getAdditionalInformation("brand_code"); // Paypal does not allow ONECLICK,RECURRING only RECURRING if ($brandCode == "paypal" && $recurringType == 'ONECLICK,RECURRING') { $recurringType = "RECURRING"; } $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(); if ($brandCode) { $formFields['brandCode'] = $brandCode; } $issuerId = $this->_order->getPayment()->getAdditionalInformation("issuer_id"); if ($issuerId) { $formFields['issuerId'] = $issuerId; } $formFields = $this->setBillingAddressData($formFields); $formFields = $this->setShippingAddressData($formFields); $formFields = $this->setOpenInvoiceData($formFields); $formFields['shopper.gender'] = $this->getGenderText($this->_order->getCustomerGender()); $dob = $this->_order->getCustomerDob(); if ($dob) { $formFields['shopper.dateOfBirthDayOfMonth'] = trim($this->_getDate($dob, 'd')); $formFields['shopper.dateOfBirthMonth'] = trim($this->_getDate($dob, 'm')); $formFields['shopper.dateOfBirthYear'] = trim($this->_getDate($dob, 'Y')); } if ($this->_order->getPayment()->getAdditionalInformation(\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE) == "klarna") { // // needed for DE and AT $formFields['klarna.acceptPrivacyPolicy'] = 'true'; // don't allow editable shipping/delivery address $formFields['billingAddressType'] = "1"; $formFields['deliveryAddressType'] = "1"; // make setting to make this optional $adyFields['shopperType'] = "1"; } // Sort the array by key using SORT_STRING order ksort($formFields, SORT_STRING); // Generate the signing data string $signData = implode(":", array_map([$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->addAdyenDebug(print_r($formFields, true)); } } catch (Exception $e) { // do nothing for now } return $formFields; }