Example #1
0
 /**
  * @param \Magento\Sales\Model\Order $order
  * @return array
  */
 public function getBasicData(\Magento\Sales\Model\Order $order)
 {
     $incrementId = $order->getIncrementId();
     $billingAddress = $order->getBillingAddress();
     $data = ['amount' => $order->getGrandTotal() * 100, 'desc' => __('Order # %1', [$incrementId]), 'first_name' => $billingAddress->getFirstname(), 'last_name' => $billingAddress->getLastname(), 'email' => $order->getCustomerEmail(), 'session_id' => $this->extOrderIdHelper->generate($order), 'order_id' => $incrementId];
     $paytype = $this->session->getPaytype();
     if ($paytype) {
         $data['pay_type'] = $paytype;
         $this->session->setPaytype(null);
     }
     return $data;
 }
Example #2
0
 /**
  * @param Order $order
  * @return void
  */
 protected function prepareTemplate(Order $order)
 {
     $this->templateContainer->setTemplateOptions($this->getTemplateOptions());
     if ($order->getCustomerIsGuest()) {
         $templateId = $this->identityContainer->getGuestTemplateId();
         $customerName = $order->getBillingAddress()->getName();
     } else {
         $templateId = $this->identityContainer->getTemplateId();
         $customerName = $order->getCustomerName();
     }
     $this->identityContainer->setCustomerName($customerName);
     $this->identityContainer->setCustomerEmail($order->getCustomerEmail());
     $this->templateContainer->setTemplateId($templateId);
 }
Example #3
0
 /**
  * Get order request data as array
  *
  * @param \Magento\Sales\Model\Order $order
  * @return array
  */
 protected function _getOrderData(\Magento\Sales\Model\Order $order)
 {
     $request = array('subtotal' => $this->_formatPrice($this->_formatPrice($order->getPayment()->getBaseAmountAuthorized()) - $this->_formatPrice($order->getBaseTaxAmount()) - $this->_formatPrice($order->getBaseShippingAmount())), 'tax' => $this->_formatPrice($order->getBaseTaxAmount()), 'shipping' => $this->_formatPrice($order->getBaseShippingAmount()), 'invoice' => $order->getIncrementId(), 'address_override' => 'true', 'currency_code' => $order->getBaseCurrencyCode(), 'buyer_email' => $order->getCustomerEmail());
     // append to request billing address data
     if ($billingAddress = $order->getBillingAddress()) {
         $request = array_merge($request, $this->_getBillingAddress($billingAddress));
     }
     // append to request shipping address data
     if ($shippingAddress = $order->getShippingAddress()) {
         $request = array_merge($request, $this->_getShippingAddress($shippingAddress));
     }
     return $request;
 }
Example #4
0
 /**
  * Get order request data as array
  *
  * @param \Magento\Sales\Model\Order $order
  * @return array
  */
 protected function _getOrderData(\Magento\Sales\Model\Order $order)
 {
     $request = ['invoice' => $order->getIncrementId(), 'address_override' => 'true', 'currency_code' => $order->getBaseCurrencyCode(), 'buyer_email' => $order->getCustomerEmail()];
     // append to request billing address data
     if ($billingAddress = $order->getBillingAddress()) {
         $request = array_merge($request, $this->_getBillingAddress($billingAddress));
     }
     // append to request shipping address data
     if ($shippingAddress = $order->getShippingAddress()) {
         $request = array_merge($request, $this->_getShippingAddress($shippingAddress));
     }
     return $request;
 }
Example #5
0
 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;
 }
Example #6
0
 /** Construct a user account blob
  * @param $order Order
  * @return UserAccount
  */
 protected function makeUserAccount(Order $order)
 {
     /* @var $user \Signifyd\Models\UserAccount */
     $user = SignifydModel::Make("\\Signifyd\\Models\\UserAccount");
     $user->emailAddress = $order->getCustomerEmail();
     $user->username = $order->getCustomerEmail();
     $user->accountNumber = $order->getCustomerId();
     $user->phone = $order->getBillingAddress()->getTelephone();
     /* @var $customer \Magento\Customer\Model\Customer */
     $customer = $this->_objectManager->get('Magento\\Customer\\Model\\Customer')->load($order->getCustomerId());
     $this->_logger->debug("Customer data: " . json_encode($customer));
     if (!is_null($customer) && !$customer->isEmpty()) {
         $user->createdDate = date('c', strtotime($customer->getCreatedAt()));
     }
     /** @var $orderFactory \Magento\Sales\Model\ResourceModel\Order\Collection */
     $orders = $this->_objectManager->get('\\Magento\\Sales\\Model\\ResourceModel\\Order\\Collection');
     $orders->addFieldToFilter('customer_id', $order->getCustomerId());
     $orders->load();
     $orderCount = 0;
     $orderTotal = 0.0;
     /** @var $o \Magento\Sales\Model\Order*/
     foreach ($orders as $o) {
         $orderCount++;
         $orderTotal += floatval($o->getGrandTotal());
     }
     $user->aggregateOrderCount = $orderCount;
     $user->aggregateOrderDollars = $orderTotal;
     return $user;
 }
Example #7
0
 /**
  * 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;
 }
Example #8
0
 /** Construct a user account blob
  * @param $order Order
  * @return array An array formatted for Signifyd
  */
 private function makeUserAccount(Order $order)
 {
     return array("emailAddress" => $order->getCustomerEmail(), "accountNumber" => $order->getCustomerId(), "phone" => $order->getBillingAddress()->getTelephone());
 }
Example #9
0
 /**
  * Set entity data to request
  *
  * @param \Magento\Sales\Model\Order $order
  * @param \Magento\Authorizenet\Model\Directpost $paymentMethod
  * @return $this
  */
 public function setDataFromOrder(\Magento\Sales\Model\Order $order, \Magento\Authorizenet\Model\Directpost $paymentMethod)
 {
     $payment = $order->getPayment();
     $this->setXType($payment->getAnetTransType());
     $this->setXFpSequence($order->getQuoteId());
     $this->setXInvoiceNum($order->getIncrementId());
     $this->setXAmount($payment->getBaseAmountAuthorized());
     $this->setXCurrencyCode($order->getBaseCurrencyCode());
     $this->setXTax(sprintf('%.2F', $order->getBaseTaxAmount()))->setXFreight(sprintf('%.2F', $order->getBaseShippingAmount()));
     //need to use strval() because NULL values IE6-8 decodes as "null" in JSON in JavaScript,
     //but we need "" for null values.
     $billing = $order->getBillingAddress();
     if (!empty($billing)) {
         $this->setXFirstName(strval($billing->getFirstname()))->setXLastName(strval($billing->getLastname()))->setXCompany(strval($billing->getCompany()))->setXAddress(strval($billing->getStreetLine(1)))->setXCity(strval($billing->getCity()))->setXState(strval($billing->getRegion()))->setXZip(strval($billing->getPostcode()))->setXCountry(strval($billing->getCountry()))->setXPhone(strval($billing->getTelephone()))->setXFax(strval($billing->getFax()))->setXCustId(strval($billing->getCustomerId()))->setXCustomerIp(strval($order->getRemoteIp()))->setXCustomerTaxId(strval($billing->getTaxId()))->setXEmail(strval($order->getCustomerEmail()))->setXEmailCustomer(strval($paymentMethod->getConfigData('email_customer')))->setXMerchantEmail(strval($paymentMethod->getConfigData('merchant_email')));
     }
     $shipping = $order->getShippingAddress();
     if (!empty($shipping)) {
         $this->setXShipToFirstName(strval($shipping->getFirstname()))->setXShipToLastName(strval($shipping->getLastname()))->setXShipToCompany(strval($shipping->getCompany()))->setXShipToAddress(strval($shipping->getStreetLine(1)))->setXShipToCity(strval($shipping->getCity()))->setXShipToState(strval($shipping->getRegion()))->setXShipToZip(strval($shipping->getPostcode()))->setXShipToCountry(strval($shipping->getCountry()));
     }
     $this->setXPoNum(strval($payment->getPoNumber()));
     return $this;
 }
Example #10
0
 /**
  * @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;
 }