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 shipping address
  *
  * @return AddressAdapterInterface|null
  */
 public function getShippingAddress()
 {
     if ($this->order->getShippingAddress()) {
         return $this->addressAdapterFactory->create(['address' => $this->order->getShippingAddress()]);
     }
     return null;
 }
Example #3
0
 /**
  * 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);
 }
 /**
  * @return ShippingInterface|null
  */
 public function create()
 {
     $shipping = null;
     if ($this->getOrderId()) {
         $this->order = $this->orderFactory->create()->load($this->getOrderId());
         if ($this->order->getEntityId()) {
             /** @var ShippingInterface $shipping */
             $shipping = $this->shippingFactory->create();
             $shippingAddress = $this->order->getShippingAddress();
             if ($shippingAddress) {
                 $shipping->setAddress($shippingAddress);
             }
             $shipping->setMethod($this->order->getShippingMethod());
             $shipping->setTotal($this->getTotal());
         }
     }
     return $shipping;
 }
 /**
  * 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;
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
/**
 * 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;
}
Example #8
0
 /**
  * Set Shipping Address data
  *
  * @param $formFields
  */
 protected function setShippingAddressData($formFields)
 {
     $shippingAddress = $this->_order->getShippingAddress();
     if ($shippingAddress) {
         $street = $this->_adyenHelper->getStreet($shippingAddress);
         if (isset($street['name']) && $street['name'] != "") {
             $formFields['deliveryAddress.street'] = $street['name'];
         }
         if (isset($street['house_number']) && $street['house_number'] != "") {
             $formFields['deliveryAddress.houseNumberOrName'] = $street['house_number'];
         } else {
             $formFields['deliveryAddress.houseNumberOrName'] = "NA";
         }
         if (trim($shippingAddress->getCity()) == "") {
             $formFields['deliveryAddress.city'] = "NA";
         } else {
             $formFields['deliveryAddress.city'] = trim($shippingAddress->getCity());
         }
         if (trim($shippingAddress->getPostcode()) == "") {
             $formFields['deliveryAddress.postalCode'] = "NA";
         } else {
             $formFields['deliveryAddress.postalCode'] = trim($shippingAddress->getPostcode());
         }
         if (trim($shippingAddress->getRegionCode()) == "") {
             $formFields['deliveryAddress.stateOrProvince'] = "NA";
         } else {
             $formFields['deliveryAddress.stateOrProvince'] = trim($shippingAddress->getRegionCode());
         }
         if (trim($shippingAddress->getCountryId()) == "") {
             $formFields['deliveryAddress.country'] = "NA";
         } else {
             $formFields['deliveryAddress.country'] = trim($shippingAddress->getCountryId());
         }
     }
     return $formFields;
 }
Example #9
0
 /**
  * @param Order $order
  * @return string|null
  */
 protected function getFormattedShippingAddress($order)
 {
     return $order->getIsVirtual() ? null : $this->addressRenderer->format($order->getShippingAddress(), 'html');
 }
Example #10
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 #11
0
 /**
  * @param $order Order
  * @return Recipient|null
  */
 protected function makeRecipient(Order $order)
 {
     $address = $order->getShippingAddress();
     if ($address == null) {
         return null;
     }
     $recipient = SignifydModel::Make("\\Signifyd\\Models\\Recipient");
     $recipient->deliveryAddress = $this->formatSignifydAddress($address);
     $recipient->fullName = $address->getName();
     $recipient->confirmationPhone = $address->getTelephone();
     $recipient->confirmationEmail = $address->getEmail();
     return $recipient;
 }
Example #12
0
 /**
  * Retrieve order item value by key
  *
  * @param \Magento\Sales\Model\Order $order
  * @param string $key
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getOrderItemValue(\Magento\Sales\Model\Order $order, $key)
 {
     $escape = true;
     switch ($key) {
         case 'order_increment_id':
             $value = $order->getIncrementId();
             break;
         case 'created_at':
             $value = $this->formatDate($order->getCreatedAt(), \IntlDateFormatter::SHORT, true);
             break;
         case 'shipping_address':
             $value = $order->getShippingAddress() ? $this->escapeHtml($order->getShippingAddress()->getName()) : __('N/A');
             break;
         case 'order_total':
             $value = $order->formatPrice($order->getGrandTotal());
             $escape = false;
             break;
         case 'status_label':
             $value = $order->getStatusLabel();
             break;
         case 'view_url':
             $value = $this->getUrl('sales/order/view', ['order_id' => $order->getId()]);
             break;
         default:
             $value = $order->getData($key) ? $order->getData($key) : __('N/A');
             break;
     }
     return $escape ? $this->escapeHtml($value) : $value;
 }
Example #13
0
 /**
  * Convert order to shipping address
  *
  * @param   \Magento\Sales\Model\Order $order
  * @return  \Magento\Sales\Model\Quote\Address
  */
 public function toQuoteShippingAddress(\Magento\Sales\Model\Order $order)
 {
     $address = $this->addressToQuoteAddress($order->getShippingAddress());
     $this->_objectCopyService->copyFieldsetToTarget('sales_convert_order', 'to_quote_address', $order, $address);
     return $address;
 }
Example #14
0
 /**
  * Returns shipping address
  *
  * @param \Magento\Sales\Model\Order $object
  * @return OrderAddress|null
  */
 protected function getShippingAddress(\Magento\Sales\Model\Order $object)
 {
     $shippingAddress = null;
     if ($object->getShippingAddress()) {
         $shippingAddress = $this->orderAddressMapper->extractDto($object->getShippingAddress());
     }
     return $shippingAddress;
 }
Example #15
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;
 }
 /**
  * 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;
 }
Example #17
0
 /**
  * Copy shipping address from order
  *
  * @param \Magento\Sales\Model\Order $order
  * @return void
  */
 protected function _initShippingAddressFromOrder(\Magento\Sales\Model\Order $order)
 {
     $orderShippingAddress = $order->getShippingAddress();
     $quoteShippingAddress = $this->getQuote()->getShippingAddress()->setCustomerAddressId('')->setSameAsBilling($orderShippingAddress && $orderShippingAddress->getSameAsBilling());
     $this->_objectCopyService->copyFieldsetToTarget('sales_copy_order_shipping_address', 'to_order', $orderShippingAddress, $quoteShippingAddress);
 }
Example #18
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 #19
0
 /**
  * @param $order Order
  * @return array
  */
 private function makeRecipient(Order $order)
 {
     $address = $order->getShippingAddress();
     return array("deliveryAddress" => $this->formatSignifydAddress($address), "fullName" => $address->getFirstname() . " " . $address->getLastname(), "confirmationPhone" => $address->getTelephone(), "confirmationEmail" => $address->getEmail());
 }