Exemple #1
0
 /**
  * Reserve order ID for specified quote and start checkout on PayPal
  * @return string
  */
 public function start($returnUrl, $cancelUrl)
 {
     $this->_quote->reserveOrderId()->save();
     // prepare API
     $this->_getApi();
     $this->_api->setAmount($this->_quote->getBaseGrandTotal())->setCurrencyCode($this->_quote->getBaseCurrencyCode())->setInvNum($this->_quote->getReservedOrderId())->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl)->setSolutionType($this->_config->solutionType)->setPaymentAction($this->_config->paymentAction);
     // supress or export shipping address
     if ($this->_quote->getIsVirtual()) {
         $this->_api->setSuppressShipping(true);
     } else {
         $address = $this->_quote->getShippingAddress();
         $isOverriden = 0;
         if (true === $address->validate()) {
             $isOverriden = 1;
             $this->_api->setAddress($address);
         }
         $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden);
         $this->_quote->getPayment()->save();
     }
     // add line items
     if ($this->_config->lineItemsEnabled) {
         list($items, $totals) = Mage::helper('paypal')->prepareLineItems($this->_quote);
         $this->_api->setLineItems($items)->setLineItemTotals($totals);
     }
     $this->_config->exportExpressCheckoutStyleSettings($this->_api);
     // call API and redirect with token
     $this->_api->callSetExpressCheckout();
     $token = $this->_api->getToken();
     $this->_redirectUrl = $this->_config->getExpressCheckoutStartUrl($token);
     return $token;
 }
 /**
  * Call Transaction API (Authorized & Capture at the same time)
  *
  * @param Eway_Rapid31_Model_Response $response
  * @return Eway_Rapid31_Model_Response
  */
 public function doTransaction(Eway_Rapid31_Model_Response $response)
 {
     $this->unsetData();
     $this->_buildRequest();
     $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
     $items = $this->_quote->getAllVisibleItems();
     $lineItems = array();
     foreach ($items as $item) {
         /* @var Mage_Sales_Model_Order_Item $item */
         $lineItem = Mage::getModel('ewayrapid/field_lineItem');
         $lineItem->setSKU($item->getSku());
         $lineItem->setDescription(substr($item->getName(), 0, 26));
         $lineItem->setQuantity($item->getQty());
         $lineItem->setUnitCost(round($item->getBasePrice() * 100));
         $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
         $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
         $lineItems[] = $lineItem;
     }
     $this->setItems($lineItems);
     $this->setItems(false);
     // add Payment
     $amount = round($this->_quote->getBaseGrandTotal() * 100);
     $paymentParam = Mage::getModel('ewayrapid/field_payment');
     $paymentParam->setTotalAmount($amount);
     $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
     $this->setPayment($paymentParam);
     $customerParam = $this->getCustomer();
     $customerParam->setTokenCustomerID($response->getTokenCustomerID());
     $this->setCustomer($customerParam);
     $response = $this->_doRapidAPI('Transaction');
     return $response;
 }
Exemple #3
0
 /**
  * Reserve order ID for specified quote and start checkout on PayPal
  * @return string
  */
 public function start($returnUrl, $cancelUrl)
 {
     $this->_quote->collectTotals();
     if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) {
         Mage::throwException(Mage::helper('paypal')->__('PayPal does not support processing orders with zero amount. To complete your purchase, proceed to the standard checkout process.'));
     }
     $this->_quote->reserveOrderId()->save();
     // prepare API
     $this->_getApi();
     $this->_api->setAmount($this->_quote->getBaseGrandTotal())->setCurrencyCode($this->_quote->getBaseCurrencyCode())->setInvNum($this->_quote->getReservedOrderId())->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl)->setSolutionType($this->_config->solutionType)->setPaymentAction($this->_config->paymentAction);
     if ($this->_giropayUrls) {
         list($successUrl, $cancelUrl, $pendingUrl) = $this->_giropayUrls;
         $this->_api->addData(array('giropay_cancel_url' => $cancelUrl, 'giropay_success_url' => $successUrl, 'giropay_bank_txn_pending_url' => $pendingUrl));
     }
     $this->_setBillingAgreementRequest();
     // supress or export shipping address
     if ($this->_quote->getIsVirtual()) {
         $this->_api->setSuppressShipping(true);
     } else {
         $address = $this->_quote->getShippingAddress();
         $isOverriden = 0;
         if (true === $address->validate()) {
             $isOverriden = 1;
             $this->_api->setAddress($address);
         }
         $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden);
         $this->_quote->getPayment()->save();
     }
     // add line items
     $paypalCart = Mage::getModel('paypal/cart', array($this->_quote));
     $this->_api->setPaypalCart($paypalCart)->setIsLineItemsEnabled($this->_config->lineItemsEnabled);
     // add shipping options if needed and line items are available
     if ($this->_config->lineItemsEnabled && $this->_config->transferShippingOptions && $paypalCart->getItems()) {
         if (!$this->_quote->getIsVirtual() && !$this->_quote->hasNominalItems()) {
             if ($options = $this->_prepareShippingOptions($address, true)) {
                 $this->_api->setShippingOptionsCallbackUrl(Mage::getUrl('*/*/shippingOptionsCallback', array('quote_id' => $this->_quote->getId())))->setShippingOptions($options);
             }
         }
     }
     // add recurring payment profiles information
     if ($profiles = $this->_quote->prepareRecurringPaymentProfiles()) {
         foreach ($profiles as $profile) {
             $profile->setMethodCode(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS);
             if (!$profile->isValid()) {
                 Mage::throwException($profile->getValidationErrors(true, true));
             }
         }
         $this->_api->addRecurringPaymentProfiles($profiles);
     }
     $this->_config->exportExpressCheckoutStyleSettings($this->_api);
     // call API and redirect with token
     $this->_api->callSetExpressCheckout();
     $token = $this->_api->getToken();
     $this->_redirectUrl = $this->_config->getExpressCheckoutStartUrl($token);
     $this->_quote->getPayment()->unsAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
     $this->_quote->getPayment()->save();
     return $token;
 }
Exemple #4
0
 /**
  * Convert quote model to order model
  *
  * @param   Mage_Sales_Model_Quote $quote
  * @return  Mage_Sales_Model_Order
  */
 public function toOrder(Mage_Sales_Model_Quote $quote, $order = null)
 {
     if (!$order instanceof Mage_Sales_Model_Order) {
         $order = Mage::getModel('sales/order');
     }
     /* @var $order Mage_Sales_Model_Order */
     $order->setStoreId($quote->getStoreId())->setQuoteId($quote->getId())->setRemoteIp($quote->getRemoteIp())->setCustomerId($quote->getCustomerId())->setCustomerEmail($quote->getCustomerEmail())->setCustomerFirstname($quote->getCustomerFirstname())->setCustomerLastname($quote->getCustomerLastname())->setCustomerGroupId($quote->getCustomerGroupId())->setCustomerTaxClassId($quote->getCustomerTaxClassId())->setCustomerNote($quote->getCustomerNote())->setCustomerNoteNotify($quote->getCustomerNoteNotify())->setCustomerIsGuest($quote->getCustomerIsGuest())->setBaseCurrencyCode($quote->getBaseCurrencyCode())->setStoreCurrencyCode($quote->getStoreCurrencyCode())->setOrderCurrencyCode($quote->getQuoteCurrencyCode())->setStoreToBaseRate($quote->getStoreToBaseRate())->setStoreToOrderRate($quote->getStoreToQuoteRate())->setCouponCode($quote->getCouponCode())->setGiftcertCode($quote->getGiftcertCode())->setIsVirtual($quote->getIsVirtual())->setIsMultiPayment($quote->getIsMultiPayment())->setAppliedRuleIds($quote->getAppliedRuleIds());
     Mage::dispatchEvent('sales_convert_quote_to_order', array('order' => $order, 'quote' => $quote));
     return $order;
 }
 /**
  * Returns the currency compliant to ISO 4217 (3 char code)
  * @return string 3 Character long currency code
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
  * @return string
  */
 public function getCurrency($object)
 {
     $currency = $object->getBaseCurrencyCode();
     if (!Mage::helper('paymill/optionHelper')->isBaseCurrency()) {
         if ($object instanceof Mage_Sales_Model_Quote) {
             $currency = $object->getQuoteCurrencyCode();
         } else {
             $currency = $object->getOrderCurrencyCode();
         }
     }
     return $currency;
 }
 /**
  * Reserve order ID for specified quote and start checkout on PayPal
  * @return string
  */
 public function start($returnUrl, $cancelUrl)
 {
     $this->_quote->reserveOrderId()->save();
     // prepare API
     $this->_getApi();
     $this->_api->setAmount($this->_quote->getBaseGrandTotal())->setCurrencyCode($this->_quote->getBaseCurrencyCode())->setInvNum($this->_quote->getReservedOrderId())->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl)->setSolutionType($this->_config->solutionType)->setPaymentAction($this->_config->paymentAction);
     if ($this->_giropayUrls) {
         list($successUrl, $cancelUrl, $pendingUrl) = $this->_giropayUrls;
         $this->_api->addData(array('giropay_cancel_url' => $cancelUrl, 'giropay_success_url' => $successUrl, 'giropay_bank_txn_pending_url' => $pendingUrl));
     }
     // supress or export shipping address
     if ($this->_quote->getIsVirtual()) {
         $this->_api->setSuppressShipping(true);
     } else {
         $address = $this->_quote->getShippingAddress();
         $isOverriden = 0;
         if (true === $address->validate()) {
             $isOverriden = 1;
             $this->_api->setAddress($address);
         }
         $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden);
         $this->_quote->getPayment()->save();
     }
     // add line items
     if ($this->_config->lineItemsEnabled && Mage::helper('paypal')->doLineItemsMatchAmount($this->_quote, $this->_quote->getBaseGrandTotal())) {
         //For transfering line items order amount must be equal to cart total amount
         list($items, $totals) = Mage::helper('paypal')->prepareLineItems($this->_quote);
         $this->_api->setLineItems($items)->setLineItemTotals($totals);
     }
     $this->_config->exportExpressCheckoutStyleSettings($this->_api);
     // call API and redirect with token
     $this->_api->callSetExpressCheckout();
     $token = $this->_api->getToken();
     $this->_redirectUrl = $this->_config->getExpressCheckoutStartUrl($token);
     return $token;
 }
 /**
  * Recalculate amount to store currency
  *
  * @param float $amount
  * @param Mage_Sales_Model_Quote $quote
  * @return float
  */
 protected function _reCalculateToStoreCurrency($amount, $quote)
 {
     if ($quote->getQuoteCurrencyCode() != $quote->getBaseCurrencyCode()) {
         $amount = $amount * $quote->getStoreToQuoteRate();
         $amount = Mage::app()->getStore()->roundPrice($amount);
     }
     return $amount;
 }
 /**
  * Build the request with necessary parameters for doAuthorisation() and doTransaction()
  *
  * @param Mage_Sales_Model_Order_Payment $payment
  * @param $amount
  * @return Eway_Rapid31_Model_Request_Direct
  */
 protected function _buildRequest(Mage_Sales_Model_Quote $quote, $amount)
 {
     // Empty Varien_Object's data
     $this->unsetData();
     $billing = $quote->getBillingAddress();
     $shipping = $quote->getShippingAddress();
     $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
     if (Mage::helper('ewayrapid')->isBackendOrder()) {
         $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
     } else {
         $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
     }
     $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion());
     $this->setShippingMethod('Other');
     $paymentParam = Mage::getModel('ewayrapid/field_payment');
     $paymentParam->setTotalAmount($amount);
     $paymentParam->setCurrencyCode($quote->getBaseCurrencyCode());
     $this->setPayment($paymentParam);
     $customerParam = Mage::getModel('ewayrapid/field_customer');
     $customerParam->setTitle($billing->getPrefix())->setFirstName($billing->getFirstname())->setLastName($billing->getLastname())->setCompanyName($billing->getCompany())->setJobDescription('')->setStreet1($billing->getStreet1())->setStreet2($billing->getStreet2())->setCity($billing->getCity())->setState($billing->getRegion())->setPostalCode($billing->getPostcode())->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))->setEmail($billing->getEmail())->setPhone($billing->getTelephone())->setMobile('')->setComments('')->setFax($billing->getFax())->setUrl('');
     $infoCard = Mage::getSingleton('core/session')->getInfoCard();
     if ($infoCard && $infoCard->getCard() && $infoCard->getOwner() && !$this->getTokenInfo()) {
         $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
         $cardDetails->setName($infoCard->getOwner())->setNumber($infoCard->getCard())->setExpiryMonth($infoCard->getExpMonth())->setExpiryYear($infoCard->getExpYear())->setCVN($infoCard->getCid());
         $customerParam->setCardDetails($cardDetails);
     }
     if ($quote->getTokenCustomerID()) {
         $customerParam->setTokenCustomerID($quote->getTokenCustomerID());
     } elseif ($token = $this->getTokenInfo()) {
         $customerParam->setTokenCustomerID($token->getToken() ? $token->getToken() : $token->getTokenCustomerID());
     }
     $this->setCustomer($customerParam);
     $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
     $shippingParam->setFirstName($shipping->getFirstname())->setLastName($shipping->getLastname())->setStreet1($shipping->getStreet1())->setStreet2($shipping->getStreet2())->setCity($shipping->getCity())->setState($shipping->getRegion())->setPostalCode($shipping->getPostcode())->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))->setEmail($shipping->getEmail())->setPhone($shipping->getTelephone())->setFax($shipping->getFax());
     $this->setShippingAddress($shippingParam);
     $orderItems = $quote->getAllVisibleItems();
     $lineItems = array();
     foreach ($orderItems as $orderItem) {
         /* @var Mage_Sales_Model_Order_Item $orderItem */
         $lineItem = Mage::getModel('ewayrapid/field_lineItem');
         $lineItem->setSKU($orderItem->getSku());
         $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
         $lineItem->setQuantity($orderItem->getQtyOrdered());
         $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
         $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
         $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
         $lineItems[] = $lineItem;
     }
     $this->setItems($lineItems);
     if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
         $this->setItems(false);
     }
     return $this;
 }
Exemple #9
0
 /**
  * Build XML-based Cart for Checkout by Amazon
  *
  * @param Mage_Sales_Model_Quote
  * @return string
  */
 public function getXmlCart(Mage_Sales_Model_Quote $quote)
 {
     $_xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<Order xmlns="http://payments.amazon.com/checkout/2008-11-30/">' . "\n";
     if (!$quote->hasItems()) {
         return false;
     }
     $_xml .= " <ClientRequestId>{$quote->getId()}</ClientRequestId>\n";
     // Returning parametr
     #        ."<ExpirationDate></ExpirationDate>";
     $_xml .= " <Cart>\n" . "   <Items>\n";
     foreach ($quote->getAllVisibleItems() as $_item) {
         $_xml .= "   <Item>\n" . "    <SKU>{$_item->getSku()}/{$_item->getId()}</SKU>\n" . "    <MerchantId>{$this->getMerchantId()}</MerchantId>\n" . "    <Title>{$_item->getName()}</Title>\n" . "    <Price>\n" . "     <Amount>{$this->formatAmount($_item->getPrice())}</Amount>\n" . "     <CurrencyCode>{$quote->getBaseCurrencyCode()}</CurrencyCode>\n" . "    </Price>\n" . "    <Quantity>{$_item->getQty()}</Quantity>\n" . "    <Weight>\n" . "      <Amount>{$this->formatAmount($_item->getWeight())}</Amount>\n" . "       <Unit>lb</Unit>\n" . "     </Weight>\n";
         $_xml .= "   </Item>\n";
     }
     $_xml .= "   </Items>\n" . "   <CartPromotionId>cart-total-discount</CartPromotionId>\n" . " </Cart>\n";
     $_xml .= " <IntegratorId>A2ZZYWSJ0WMID8MAGENTO</IntegratorId>\n" . " <IntegratorName>Varien</IntegratorName>\n";
     $_xml .= " <OrderCalculationCallbacks>\n" . "   <CalculateTaxRates>true</CalculateTaxRates>\n" . "   <CalculatePromotions>true</CalculatePromotions>\n" . "   <CalculateShippingRates>true</CalculateShippingRates>\n" . "   <OrderCallbackEndpoint>" . Mage::getUrl('amazonpayments/cba/callback', array('_secure' => true)) . "</OrderCallbackEndpoint>\n" . "   <ProcessOrderOnCallbackFailure>true</ProcessOrderOnCallbackFailure>\n" . " </OrderCalculationCallbacks>\n";
     $_xml .= "</Order>\n";
     return $_xml;
 }
 /**
  * Place the order
  *
  * @return bool
  */
 protected function _processOrder()
 {
     if (!$this->_auth()) {
         return false;
     }
     if (!$this->_validateQuote()) {
         return false;
     }
     // Push address to the quote, set totals,
     // Convert quote to the order,
     // Set rakuten_order attribute to "1"
     try {
         // To avoid duplicates look for order with the same Rakuten order no
         $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('ext_order_id', (string) $this->_request->order_no);
         if (count($orders)) {
             $this->_debugData['reason'] = 'The same order already placed';
             return false;
         }
         // Import addresses and other data to quote
         $this->_quote->setIsActive(true)->reserveOrderId();
         $storeId = $this->_quote->getStoreId();
         Mage::app()->setCurrentStore(Mage::app()->getStore($storeId));
         if ($this->_quote->getQuoteCurrencyCode() != $this->_quote->getBaseCurrencyCode()) {
             Mage::app()->getStore()->setCurrentCurrencyCode($this->_quote->getQuoteCurrencyCode());
         }
         $billing = $this->_convertAddress('client');
         $this->_quote->setBillingAddress($billing);
         $shipping = $this->_convertAddress('delivery_address');
         $this->_quote->setShippingAddress($shipping);
         $this->_convertTotals($this->_quote->getShippingAddress());
         $this->_quote->getPayment()->importData(array('method' => 'rakuten'));
         /**
          * Convert quote to order
          *
          * @var $convertQuote Mage_Sales_Model_Convert_Quote
          */
         $convertQuote = Mage::getSingleton('sales/convert_quote');
         /* @var $order Mage_Sales_Model_Order */
         $order = $convertQuote->toOrder($this->_quote);
         if ($this->_quote->isVirtual()) {
             $convertQuote->addressToOrder($this->_quote->getBillingAddress(), $order);
         } else {
             $convertQuote->addressToOrder($this->_quote->getShippingAddress(), $order);
         }
         $order->setExtOrderId((string) $this->_request->order_no);
         $order->setExtCustomerId((string) $this->_request->client->client_id);
         if (!$order->getCustomerEmail()) {
             $order->setCustomerEmail($billing->getEmail())->setCustomerPrefix($billing->getPrefix())->setCustomerFirstname($billing->getFirstname())->setCustomerMiddlename($billing->getMiddlename())->setCustomerLastname($billing->getLastname())->setCustomerSuffix($billing->getSuffix())->setCustomerIsGuest(1);
         }
         $order->setBillingAddress($convertQuote->addressToOrderAddress($this->_quote->getBillingAddress()));
         if (!$this->_quote->isVirtual()) {
             $order->setShippingAddress($convertQuote->addressToOrderAddress($this->_quote->getShippingAddress()));
         }
         /** @var $item Mage_Sales_Model_Quote_Item */
         foreach ($this->_quote->getAllItems() as $item) {
             $orderItem = $convertQuote->itemToOrderItem($item);
             if ($item->getParentItem()) {
                 $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
             }
             $order->addItem($orderItem);
         }
         /**
          * Adding transaction for correct transaction information displaying on the order view in the admin.
          * It has no influence on the API interaction logic.
          *
          * @var $payment Mage_Sales_Model_Order_Payment
          */
         $payment = Mage::getModel('sales/order_payment');
         $payment->setMethod('rakuten')->setTransactionId((string) $this->_request->order_no)->setIsTransactionClosed(false);
         $order->setPayment($payment);
         $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
         $order->setCanShipPartiallyItem(false);
         $message = '';
         if (trim((string) $this->_request->comment_client) != '') {
             $message .= $this->__('Customer\'s Comment: %s', '<strong>' . trim((string) $this->_request->comment_client) . '</strong><br />');
         }
         $message .= $this->__('Rakuten Order No: %s', '<strong>' . (string) $this->_request->order_no . '</strong><br />') . $this->__('Rakuten Client ID: %s', '<strong>' . (string) $this->_request->client->client_id . '</strong><br />');
         $order->addStatusHistoryComment($message);
         $order->setRakutenOrder(1);
         // Custom attribute for fast filtering of orders placed via Rakuten Checkout
         $order->place();
         $order->save();
         //            $order->sendNewOrderEmail();
         $this->_quote->setIsActive(false)->save();
         Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote));
     } catch (Exception $e) {
         $this->_debugData['exception'] = $e->getMessage();
         Mage::logException($e);
         return false;
     }
     return true;
 }
 /**
  * Build Amount
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return Amount
  */
 protected function buildAmount($quote)
 {
     $details = new Details();
     $details->setShipping($quote->getShippingAddress()->getBaseShippingAmount())->setTax($quote->getBillingAddress()->getBaseTaxAmount() + $quote->getBillingAddress()->getBaseHiddenTaxAmount() + $quote->getShippingAddress()->getBaseTaxAmount() + $quote->getShippingAddress()->getBaseHiddenTaxAmount())->setSubtotal($quote->getBaseSubtotal());
     $totals = $quote->getTotals();
     if (isset($totals['discount']) && $totals['discount']->getValue()) {
         $details->setShippingDiscount(-$totals['discount']->getValue());
     }
     $amount = new Amount();
     $amount->setCurrency($quote->getBaseCurrencyCode())->setDetails($details)->setTotal($quote->getBaseGrandTotal());
     return $amount;
 }
Exemple #12
0
 function CreateMagentoShopRequest(Mage_Sales_Model_Quote $quote)
 {
     $request = new Byjuno_Cdp_Helper_Api_Classes_ByjunoRequest();
     $request->setClientId(Mage::getStoreConfig('byjuno/api/clientid', Mage::app()->getStore()));
     $request->setUserID(Mage::getStoreConfig('byjuno/api/userid', Mage::app()->getStore()));
     $request->setPassword(Mage::getStoreConfig('byjuno/api/password', Mage::app()->getStore()));
     $request->setVersion("1.00");
     try {
         $request->setRequestEmail(Mage::getStoreConfig('byjuno/api/mail', Mage::app()->getStore()));
     } catch (Exception $e) {
     }
     $b = $quote->getCustomerDob();
     if (!empty($b)) {
         $request->setDateOfBirth(Mage::getModel('core/date')->date('Y-m-d', strtotime($b)));
     }
     Mage::getSingleton('checkout/session')->setData('dob_amasty', '');
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["dob"])) {
         $request->setDateOfBirth(Mage::getModel('core/date')->date('Y-m-d', strtotime($_POST["billing"]["dob"])));
         Mage::getSingleton('checkout/session')->setData('dob_amasty', $_POST["billing"]["dob"]);
     }
     $g = $quote->getCustomerGender();
     if (!empty($g)) {
         if ($g == '1') {
             $request->setGender('1');
         } else {
             if ($g == '2') {
                 $request->setGender('2');
             }
         }
     }
     $request->setRequestId(uniqid((string) $quote->getBillingAddress()->getId() . "_"));
     $reference = $quote->getCustomer()->getId();
     if (empty($reference)) {
         $request->setCustomerReference("guest_" . $quote->getBillingAddress()->getId());
     } else {
         $request->setCustomerReference($quote->getCustomer()->getId());
     }
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["method"]) && $_POST["method"] == 'guest') {
         $request->setCustomerReference(uniqid("guest_"));
     }
     $request->setFirstName((string) $quote->getBillingAddress()->getFirstname());
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["firstname"])) {
         $request->setFirstName((string) $_POST["billing"]["firstname"]);
     }
     $request->setLastName((string) $quote->getBillingAddress()->getLastname());
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["lastname"])) {
         $request->setLastName((string) $_POST["billing"]["lastname"]);
     }
     $request->setFirstLine(trim((string) $quote->getBillingAddress()->getStreetFull()));
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["street"])) {
         $street = '';
         if (!empty($_POST["billing"]["street"][0])) {
             $street .= $_POST["billing"]["street"][0];
         }
         if (!empty($_POST["billing"]["street"][1])) {
             $street .= $_POST["billing"]["street"][1];
         }
         $request->setFirstLine((string) trim($street));
     }
     $request->setCountryCode(strtoupper((string) $quote->getBillingAddress()->getCountry()));
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["country_id"])) {
         $request->setCountryCode((string) $_POST["billing"]["country_id"]);
     }
     $request->setPostCode((string) $quote->getBillingAddress()->getPostcode());
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["postcode"])) {
         $request->setPostCode($_POST["billing"]["postcode"]);
     }
     $request->setTown((string) $quote->getBillingAddress()->getCity());
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["city"])) {
         $request->setTown($_POST["billing"]["city"]);
     }
     $request->setFax((string) trim($quote->getBillingAddress()->getFax(), '-'));
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["fax"])) {
         $request->setFax(trim($_POST["billing"]["fax"], '-'));
     }
     $request->setLanguage((string) substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2));
     if ($quote->getBillingAddress()->getCompany()) {
         $request->setCompanyName1($quote->getBillingAddress()->getCompany());
     }
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["company"])) {
         $request->setCompanyName1(trim($_POST["billing"]["company"], '-'));
     }
     $request->setTelephonePrivate((string) trim($quote->getBillingAddress()->getTelephone(), '-'));
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["telephone"])) {
         $request->setTelephonePrivate(trim($_POST["billing"]["telephone"], '-'));
     }
     $request->setEmail((string) $quote->getBillingAddress()->getEmail());
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["email"])) {
         $request->setEmail((string) $_POST["billing"]["email"]);
     }
     Mage::getSingleton('checkout/session')->setData('gender_amasty', '');
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty') {
         $g = isset($_POST["billing"]["gender"]) ? $_POST["billing"]["gender"] : '';
         $request->setGender($g);
         Mage::getSingleton('checkout/session')->setData('gender_amasty', $g);
     }
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["prefix"])) {
         if (strtolower($_POST["billing"]["prefix"]) == 'herr') {
             $request->setGender('1');
             Mage::getSingleton('checkout/session')->setData('gender_amasty', '1');
         } else {
             if (strtolower($_POST["billing"]["prefix"]) == 'frau') {
                 $request->setGender('2');
                 Mage::getSingleton('checkout/session')->setData('gender_amasty', '2');
             }
         }
     }
     $extraInfo["Name"] = 'ORDERCLOSED';
     $extraInfo["Value"] = 'NO';
     $request->setExtraInfo($extraInfo);
     $extraInfo["Name"] = 'ORDERAMOUNT';
     $extraInfo["Value"] = number_format($quote->getGrandTotal(), 2, '.', '');
     $request->setExtraInfo($extraInfo);
     $extraInfo["Name"] = 'ORDERCURRENCY';
     $extraInfo["Value"] = $quote->getBaseCurrencyCode();
     $request->setExtraInfo($extraInfo);
     $extraInfo["Name"] = 'IP';
     $extraInfo["Value"] = $this->getClientIp();
     $request->setExtraInfo($extraInfo);
     $sesId = Mage::getSingleton('checkout/session')->getData("byjuno_session_id");
     if (Mage::getStoreConfig('byjuno/api/tmxenabled', Mage::app()->getStore()) == 'enable' && !empty($sesId)) {
         $extraInfo["Name"] = 'DEVICE_FINGERPRINT_ID';
         $extraInfo["Value"] = Mage::getSingleton('checkout/session')->getData("byjuno_session_id");
         $request->setExtraInfo($extraInfo);
     }
     /* shipping information */
     if (!$quote->isVirtual()) {
         $extraInfo["Name"] = 'DELIVERY_FIRSTNAME';
         $extraInfo["Value"] = $quote->getShippingAddress()->getFirstname();
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && empty($_POST["shipping"]["same_as_billing"])) {
             if (!empty($_POST["shipping"]["firstname"])) {
                 $extraInfo["Value"] = $_POST["shipping"]["firstname"];
             }
         }
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_LASTNAME';
         $extraInfo["Value"] = $quote->getShippingAddress()->getLastname();
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && empty($_POST["shipping"]["same_as_billing"])) {
             if (!empty($_POST["shipping"]["lastname"])) {
                 $extraInfo["Value"] = $_POST["shipping"]["lastname"];
             }
         }
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_FIRSTLINE';
         $extraInfo["Value"] = trim($quote->getShippingAddress()->getStreetFull());
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && empty($_POST["shipping"]["same_as_billing"])) {
             $extraInfo["Value"] = '';
             if (!empty($_POST["shipping"]["street"][0])) {
                 $extraInfo["Value"] = $_POST["shipping"]["street"][0];
             }
             if (!empty($_POST["shipping"]["street"][1])) {
                 $extraInfo["Value"] .= ' ' . $_POST["shipping"]["street"][1];
             }
             $extraInfo["Value"] = trim($extraInfo["Value"]);
         }
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_HOUSENUMBER';
         $extraInfo["Value"] = '';
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_COUNTRYCODE';
         $extraInfo["Value"] = strtoupper($quote->getShippingAddress()->getCountry());
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && empty($_POST["shipping"]["same_as_billing"])) {
             if (!empty($_POST["shipping"]["country_id"])) {
                 $extraInfo["Value"] = $_POST["shipping"]["country_id"];
             }
         }
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_POSTCODE';
         $extraInfo["Value"] = $quote->getShippingAddress()->getPostcode();
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && empty($_POST["shipping"]["same_as_billing"])) {
             if (!empty($_POST["shipping"]["postcode"])) {
                 $extraInfo["Value"] = $_POST["shipping"]["postcode"];
             }
         }
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_TOWN';
         $extraInfo["Value"] = $quote->getShippingAddress()->getCity();
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty') {
             if (!empty($_POST["shipping"]["same_as_billing"]) && $_POST["shipping"]["same_as_billing"] == '1' && !empty($_POST["billing"]["city"])) {
                 $extraInfo["Value"] = $_POST["billing"]["city"];
             } else {
                 if (!empty($_POST["shipping"]["city"])) {
                     $extraInfo["Value"] = $_POST["shipping"]["city"];
                 }
             }
         }
         $request->setExtraInfo($extraInfo);
         if ($quote->getShippingAddress()->getCompany() != '' && Mage::getStoreConfig('byjuno/api/businesstobusiness', Mage::app()->getStore()) == 'enable') {
             $extraInfo["Name"] = 'DELIVERY_COMPANYNAME';
             $extraInfo["Value"] = $quote->getShippingAddress()->getCompany();
             $request->setExtraInfo($extraInfo);
         }
     }
     $extraInfo["Name"] = 'CONNECTIVTY_MODULE';
     $extraInfo["Value"] = 'Byjuno Magento module 4.0.0';
     $request->setExtraInfo($extraInfo);
     return $request;
 }