public function startTransaction(Order $order, UrlInterface $url) { $config = new Config($this->_scopeConfig); $config->configureSDK(); $total = $order->getGrandTotal(); $items = $order->getAllVisibleItems(); $orderId = $order->getIncrementId(); $quoteId = $order->getQuoteId(); $currency = $order->getOrderCurrencyCode(); $returnUrl = $url->getUrl('paynl/checkout/finish/'); $exchangeUrl = $url->getUrl('paynl/checkout/exchange/'); $paymentOptionId = $this->getPaymentOptionId(); $arrBillingAddress = $order->getBillingAddress()->toArray(); $arrShippingAddress = $order->getShippingAddress()->toArray(); $enduser = array('initials' => substr($arrBillingAddress['firstname'], 0, 1), 'lastName' => $arrBillingAddress['lastname'], 'phoneNumber' => $arrBillingAddress['telephone'], 'emailAddress' => $arrBillingAddress['email']); $address = array(); $arrAddress = \Paynl\Helper::splitAddress($arrBillingAddress['street']); $address['streetName'] = $arrAddress[0]; $address['houseNumber'] = $arrAddress[1]; $address['zipCode'] = $arrBillingAddress['postcode']; $address['city'] = $arrBillingAddress['city']; $address['country'] = $arrBillingAddress['country_id']; $shippingAddress = array(); $arrAddress2 = \Paynl\Helper::splitAddress($arrShippingAddress['street']); $shippingAddress['streetName'] = $arrAddress2[0]; $shippingAddress['houseNumber'] = $arrAddress2[1]; $shippingAddress['zipCode'] = $arrShippingAddress['postcode']; $shippingAddress['city'] = $arrShippingAddress['city']; $shippingAddress['country'] = $arrShippingAddress['country_id']; $data = array('amount' => $total, 'returnUrl' => $returnUrl, 'paymentMethod' => $paymentOptionId, 'description' => $orderId, 'extra1' => $orderId, 'extra2' => $quoteId, 'exchangeUrl' => $exchangeUrl, 'currency' => $currency); $data['address'] = $address; $data['shippingAddress'] = $shippingAddress; $data['enduser'] = $enduser; $arrProducts = array(); foreach ($items as $item) { $arrItem = $item->toArray(); if ($arrItem['price_incl_tax'] != null) { $product = array('id' => $arrItem['product_id'], 'name' => $arrItem['name'], 'price' => $arrItem['price_incl_tax'], 'qty' => $arrItem['qty_ordered'], 'tax' => $arrItem['tax_amount']); } $arrProducts[] = $product; } //shipping $shippingCost = $order->getShippingAddress()->getShippingInclTax(); $shippingTax = $order->getShippingAddress()->getShippingTaxAmount(); $shippingDescription = $order->getShippingAddress()->getShippingDescription(); $arrProducts[] = array('id' => 'shipping', 'name' => $shippingDescription, 'price' => $shippingCost, 'qty' => 1, 'tax' => $shippingTax); // kortingen $discount = $order->getSubtotal() - $order->getSubtotalWithDiscount(); if ($discount > 0) { $arrProducts[] = array('id' => 'discount', 'name' => __('Discount'), 'price' => $discount * -1, 'qty' => 1, 'tax' => 0); } $data['products'] = $arrProducts; if ($config->isTestMode()) { $data['testmode'] = 1; } $data['ipaddress'] = $order->getRemoteIp(); $transaction = \Paynl\Transaction::start($data); return $transaction->getRedirectUrl(); }
/** * Returns billing address * * @return AddressAdapterInterface|null */ public function getBillingAddress() { if ($this->order->getBillingAddress()) { return $this->addressAdapterFactory->create(['address' => $this->order->getBillingAddress()]); } return null; }
/** * Send email to customer * * @param Order $order * @param bool $notify * @param string $comment * @return bool */ public function send(Order $order, $notify = true, $comment = '') { if ($order->getShippingAddress()) { $formattedShippingAddress = $this->addressRenderer->format($order->getShippingAddress(), 'html'); } else { $formattedShippingAddress = ''; } $formattedBillingAddress = $this->addressRenderer->format($order->getBillingAddress(), 'html'); $transport = new \Magento\Framework\Object(['template_vars' => ['order' => $order, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore(), 'formattedShippingAddress' => $formattedShippingAddress, 'formattedBillingAddress' => $formattedBillingAddress]]); $this->eventManager->dispatch('email_order_comment_set_template_vars_before', ['sender' => $this, 'transport' => $transport]); $this->templateContainer->setTemplateVars($transport->getTemplateVars()); return $this->checkAndSend($order, $notify); }
/** * Send email to customer * * @param Order $order * @param bool $notify * @param string $comment * @return bool */ public function send(Order $order, $notify = true, $comment = '') { $transport = ['order' => $order, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order)]; $this->eventManager->dispatch('email_order_comment_set_template_vars_before', ['sender' => $this, 'transport' => $transport]); $this->templateContainer->setTemplateVars($transport); return $this->checkAndSend($order, $notify); }
/** * @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; }
/** * Retrieve sales address (order or quote) on which tax calculation must be based * * @param \Magento\Sales\Model\Order $order * @param \Magento\Store\Model\Store|string|int|null $store * @return \Magento\Sales\Model\Order\Address|null */ protected function _getVatRequiredSalesAddress($order, $store = null) { $configAddressType = $this->customerAddressHelper->getTaxCalculationAddressType($store); $requiredAddress = null; switch ($configAddressType) { case \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING: $requiredAddress = $order->getShippingAddress(); break; default: $requiredAddress = $order->getBillingAddress(); break; } return $requiredAddress; }
/** * @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); }
/** * Set Billing Address data * * @param $formFields */ protected function setBillingAddressData($formFields) { $billingAddress = $this->_order->getBillingAddress(); if ($billingAddress) { $formFields['shopper.firstName'] = trim($billingAddress->getFirstname()); $middleName = trim($billingAddress->getMiddlename()); if ($middleName != "") { $formFields['shopper.infix'] = trim($middleName); } $formFields['shopper.lastName'] = trim($billingAddress->getLastname()); $formFields['shopper.telephoneNumber'] = trim($billingAddress->getTelephone()); $street = $this->_adyenHelper->getStreet($billingAddress); if (isset($street['name']) && $street['name'] != "") { $formFields['billingAddress.street'] = $street['name']; } if (isset($street['house_number']) && $street['house_number'] != "") { $formFields['billingAddress.houseNumberOrName'] = $street['house_number']; } else { $formFields['billingAddress.houseNumberOrName'] = "NA"; } if (trim($billingAddress->getCity()) == "") { $formFields['billingAddress.city'] = "NA"; } else { $formFields['billingAddress.city'] = trim($billingAddress->getCity()); } if (trim($billingAddress->getPostcode()) == "") { $formFields['billingAddress.postalCode'] = "NA"; } else { $formFields['billingAddress.postalCode'] = trim($billingAddress->getPostcode()); } if (trim($billingAddress->getRegionCode()) == "") { $formFields['billingAddress.stateOrProvince'] = "NA"; } else { $formFields['billingAddress.stateOrProvince'] = trim($billingAddress->getRegionCode()); } if (trim($billingAddress->getCountryId()) == "") { $formFields['billingAddress.country'] = "NA"; } else { $formFields['billingAddress.country'] = trim($billingAddress->getCountryId()); } } return $formFields; }
/** * Process addresses saving * * @param Order $order * @return $this * @throws \Exception */ public function process(Order $order) { if (null !== $order->getAddressesCollection()) { $order->getAddressesCollection()->save(); $billingAddress = $order->getBillingAddress(); $attributesForSave = []; if ($billingAddress && $order->getBillingAddressId() != $billingAddress->getId()) { $order->setBillingAddressId($billingAddress->getId()); $attributesForSave[] = 'billing_address_id'; } $shippingAddress = $order->getShippingAddress(); if ($shippingAddress && $order->getShippigAddressId() != $shippingAddress->getId()) { $order->setShippingAddressId($shippingAddress->getId()); $attributesForSave[] = 'shipping_address_id'; } if (!empty($attributesForSave)) { $this->attribute->saveAttribute($order, $attributesForSave); } } return $this; }
/** * 2016-03-09 * @param O $order * @return string */ function df_order_customer_name(O $order) { /** @var string $result */ $result = df_cc_s($order->getCustomerFirstname(), $order->getCustomerMiddlename(), $order->getCustomerLastname()); if (!$result) { /** @var C $customer */ $customer = $order->getCustomer(); if ($customer) { $result = $customer->getName(); } } if (!$result) { /** @var OA|null $ba */ $ba = $order->getBillingAddress(); if ($ba) { $result = $ba->getName(); } } if (!$result) { /** @var OA|null $ba */ $sa = $order->getShippingAddress(); if ($sa) { $result = $sa->getName(); } } if (!$result) { /** * 2016-08-24 * Имени в адресах может запросто не быть * (например, если покупатель заказывает цифровой товар и askForBillingAddress = false), * и вот тогда мы попадаем сюда. * В данном случае функция вернёт просто «Guest». */ $result = $this->o()->getCustomerName(); } return $result; }
/** * Prepare email template with variables * * @param Order $order * @return void */ protected function prepareTemplate(Order $order) { $transport = new \Magento\Framework\Object(['template_vars' => ['order' => $order, 'billing' => $order->getBillingAddress(), 'payment_html' => $this->getPaymentHtml($order), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->addressRenderer->format($order->getShippingAddress(), 'html'), 'formattedBillingAddress' => $this->addressRenderer->format($order->getBillingAddress(), 'html')]]); $this->eventManager->dispatch('email_order_set_template_vars_before', ['sender' => $this, 'transport' => $transport]); $this->templateContainer->setTemplateVars($transport->getTemplateVars()); parent::prepareTemplate($order); }
/** * Copy billing address from order * * @param \Magento\Sales\Model\Order $order * @return void */ protected function _initBillingAddressFromOrder(\Magento\Sales\Model\Order $order) { $this->getQuote()->getBillingAddress()->setCustomerAddressId(''); $this->_objectCopyService->copyFieldsetToTarget('sales_copy_order_billing_address', 'to_order', $order->getBillingAddress(), $this->getQuote()->getBillingAddress()); }
/** * 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; }
/** * @param Order $order * @return string|null */ protected function getFormattedBillingAddress($order) { return $this->addressRenderer->format($order->getBillingAddress(), 'html'); }
/** * Prepare email template with variables * * @param Order $order * @return void */ protected function prepareTemplate(Order $order) { $transport = ['order' => $order, 'billing' => $order->getBillingAddress(), 'payment_html' => $this->getPaymentHtml($order), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order)]; $this->eventManager->dispatch('email_order_set_template_vars_before', ['sender' => $this, 'transport' => $transport]); $this->templateContainer->setTemplateVars($transport); parent::prepareTemplate($order); }
/** * @param \Magento\Sales\Model\Order $order * @return array|null */ public function getBuyerData(\Magento\Sales\Model\Order $order) { /** * @var $billingAddress \Magento\Sales\Api\Data\OrderAddressInterface */ $billingAddress = $order->getBillingAddress(); if ($billingAddress) { $buyer = ['email' => $billingAddress->getEmail(), 'phone' => $billingAddress->getTelephone(), 'firstName' => $billingAddress->getFirstname(), 'lastName' => $billingAddress->getLastname()]; return $buyer; } return null; }
/** * Prepare email template with variables * * @param Order $order * @return void */ protected function prepareTemplate(Order $order) { $this->templateContainer->setTemplateVars(['order' => $order, 'billing' => $order->getBillingAddress(), 'payment_html' => $this->getPaymentHtml($order), 'store' => $order->getStore()]); parent::prepareTemplate($order); }
/** * Send email to customer * * @param Order $order * @param bool $notify * @param string $comment * @return bool */ public function send(Order $order, $notify = true, $comment = '') { $this->templateContainer->setTemplateVars(['order' => $order, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore()]); return $this->checkAndSend($order, $notify); }
/** 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; }
/** * @param Order $orderModel * @return int * @throws \Zend_Http_Client_Exception */ public function sendInfoToRejoiner(Order $orderModel) { $apiKey = $this->scopeConfig->getValue(self::XML_PATH_REJOINER_API_KEY); $apiSecret = utf8_encode($this->scopeConfig->getValue(self::XML_PATH_REJOINER_API_SECRET)); $siteId = $this->scopeConfig->getValue(self::XML_PATH_REJOINER_API_SITE_ID); $requestPath = sprintf(self::REJOINER_API_REQUEST_PATH, $siteId); $customerEmail = $orderModel->getBillingAddress()->getEmail(); $requestBody = utf8_encode(sprintf('{"email": "%s"}', $customerEmail)); $hmacData = utf8_encode(implode("\n", [\Zend_Http_Client::POST, $requestPath, $requestBody])); $codedApiSecret = base64_encode(hash_hmac('sha1', $hmacData, $apiSecret, true)); $authorization = sprintf('Rejoiner %s:%s', $apiKey, $codedApiSecret); $client = $this->_httpClient->create(['uri' => self::REJOINER_API_URL . $requestPath]); $client->setRawData($requestBody); $client->setHeaders(['Authorization' => $authorization, 'Content-type' => 'application/json;']); try { $response = $client->request(\Zend_Http_Client::POST); $responseCode = $response->getStatus(); } catch (\Exception $e) { $this->log($e->getMessage()); $responseCode = 00; } switch ($responseCode) { case '200': $this->log($responseCode . ': Everything is alright.'); break; case '400': $this->log($responseCode . ': required params were not specified and/or the body was malformed'); break; case '403': $this->log($responseCode . ': failed authentication and/or incorrect signature'); break; case '500': $this->log($responseCode . ': internal error, contact us for details'); break; default: $this->log($responseCode . ': unexpected response code'); break; } return $responseCode; }
/** * Getter for billing address of order by format * * @param \Magento\Sales\Model\Order $order * @return string */ public function getBillingAddressFormattedHtml($order) { $billingAddress = $order->getBillingAddress(); if (!$billingAddress instanceof \Magento\Sales\Model\Order\Address) { return ''; } return $billingAddress->format('html'); }
/** 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()); }
/** * 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; }
/** * Retrieve sales address (order or quote) on which tax calculation must be based * * @param Order $order * @param \Magento\Store\Model\Store|string|int|null $store * @return Address|null */ protected function _getVatRequiredSalesAddress($order, $store = null) { $configAddressType = $this->customerAddressHelper->getTaxCalculationAddressType($store); $requiredAddress = $configAddressType === AbstractAddress::TYPE_SHIPPING ? $order->getShippingAddress() : $order->getBillingAddress(); return $requiredAddress; }
/** * 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; }
/** * Return billing address * * @param \Magento\Sales\Model\Order $object * @return OrderAddress|null */ protected function getBillingAddress(\Magento\Sales\Model\Order $object) { $billingAddress = null; if ($object->getBillingAddress()) { $billingAddress = $this->orderAddressMapper->extractDto($object->getBillingAddress()); } return $billingAddress; }