/** * Prepare quote, reserve order ID for specified quote * * @return string */ public function initCheckout() { $this->_quote->reserveOrderId()->save(); /** * Reset multishipping flag before any manipulations with quote address * addAddress method for quote object related on this flag */ if ($this->_quote->getIsMultiShipping()) { $this->_quote->setIsMultiShipping(false); $this->_quote->save(); } /* * want to load the correct customer information by assigning to address * instead of just loading from sales/quote_address */ $customer = Mage::getSingleton('Mage_Customer_Model_Session')->getCustomer(); if ($customer) { $this->_quote->assignCustomer($customer); } $quote = Mage::getSingleton('Mage_Checkout_Model_Session')->getQuote(); if (!Mage::getSingleton('Mage_Customer_Model_Session')->isLoggedIn() && Mage::helper('Mage_Checkout_Helper_Data')->isAllowedGuestCheckout($quote)) { $this->_prepareGuestQuote(); } return $this->_quote->getReservedOrderId(); }
/** * 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; }
protected function _placeOrder($checkoutMessage, $orderStatus = 'pending', $notifyCreateOrder = false) { $this->_quote->collectTotals(); $this->_quote->reserveOrderId(); error_reporting(E_ERROR); $service = Mage::getModel('sales/service_quote', $this->_quote); // If file not exist may catch warring error_reporting(E_ALL); if ($service != false && method_exists($service, 'submitAll')) { // Magento version 1.4.1.x // $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $orderObj = $service->getOrder(); } else { // Magento version 1.4.0.x , 1.3.x $convertQuoteObj = Mage::getSingleton('sales/convert_quote'); $orderObj = $convertQuoteObj->addressToOrder($this->_quote->getShippingAddress()); $orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($this->_quote->getBillingAddress())); $orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($this->_quote->getShippingAddress())); $orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($this->_quote->getPayment())); $items = $this->_quote->getShippingAddress()->getAllItems(); foreach ($items as $item) { //@var $item Mage_Sales_Model_Quote_Item $orderItem = $convertQuoteObj->itemToOrderItem($item); if ($item->getParentItem()) { $orderItem->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId())); } $orderObj->addItem($orderItem); } $orderObj->setCanShipPartiallyItem(false); $orderObj->place(); } $orderMessages = ''; $notifyMessages = $this->_processNotifyMessage(); if ($checkoutMessage || $notifyMessages) { $orderMessages .= '<br /><b><u>' . Mage::helper('M2ePro')->__('M2E Pro Notes') . ':</u></b><br /><br />'; if ($checkoutMessage) { $orderMessages .= '<b>' . Mage::helper('M2ePro')->__('Checkout Message From Buyer') . ':</b>'; $orderMessages .= $checkoutMessage . '<br />'; } if ($notifyMessages) { $orderMessages .= $notifyMessages; } } // Adding notification to order $orderObj->addStatusToHistory($orderStatus, $orderMessages, false); $orderObj->save(); // -------------------- Mage::helper('M2ePro/Module')->getConfig()->setGroupValue('/synchronization/orders/', 'current_magento_order_id', $orderObj->getId()); $this->setFatalErrorHandler(); // -------------------- // Send Notification to customer after create order if ($notifyCreateOrder) { // Send new order E-mail only if select such mode $orderObj->sendNewOrderEmail(); } return $orderObj; }
/** * 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; }
/** * Build quote object * * @throws Exception */ public function buildQuote() { try { // do not change invoke order // -------------------- $this->initializeQuote(); $this->initializeCustomer(); $this->initializeAddresses(); $this->configureStore(); $this->initializeCurrency(); $this->initializeShippingMethodData(); $this->initializeQuoteItems(); $this->initializePaymentMethodData(); //$this->quote->setTotalsCollectedFlag(false); $this->quote->collectTotals()->save(); $this->quote->reserveOrderId(); // -------------------- } catch (Exception $e) { $this->quote->setIsActive(false)->save(); throw $e; } }
/** * Reserve order ID for specified quote and start checkout on PayPal * @return string */ public function start() { $this->_quote->collectTotals(); $this->_quote->reserveOrderId()->save(); // supress or export shipping address $this->_quote->getPayment()->save(); // call API and redirect with token $rs = Mage::getModel('sagepaysuite/sagePayDirectPro')->registerPayPalTransaction(); if ($rs->getPayPalRedirectUrl()) { return $rs->getPayPalRedirectUrl(); } else { return $rs; } }
/** * Reserve order ID for specified quote and start checkout on PayPal * * @return mixed */ public function start() { $this->_quote->collectTotals(); if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) { Mage::throwException(Mage::helper('payone_core')->__('PayPal does not support processing orders with zero amount. To complete your purchase, proceed to the standard checkout process.')); } $this->_quote->reserveOrderId()->save(); $service = $this->getFactory()->getServicePaymentGenericpayment($this->_config); $mapper = $service->getMapper(); $request = $mapper->mapExpressCheckoutParameters($this->_quote); $response = $this->getFactory()->getServiceApiPaymentGenericpayment()->request($request); if ($response instanceof Payone_Api_Response_Genericpayment_Redirect) { $this->_redirectUrl = $response->getRedirecturl(); $this->_workorderid = $response->getWorkorderId(); } }
/** * Reserve order ID for specified quote and start checkout on PayPal * * @param string * @param string * @param bool|null $button specifies if we came from Checkout Stream or from Product/Cart directly * @return mixed */ public function start($returnUrl, $cancelUrl, $button = null) { $this->_quote->collectTotals(); if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) { Mage::throwException($this->_helper->__(self::EBAYENTERPRISE_PAYPAL_ZERO_CHECKOUT_NOT_SUPPORTED)); } $this->_quote->reserveOrderId()->save(); $this->_getApi(); $setExpressCheckoutReply = $this->_api->setExpressCheckout($returnUrl, $cancelUrl, $this->_quote); if ($button) { // mark the payment to indicate express checkout was initiated from // outside the normal checkout flow // (e.g. clicked paypal checkout button from product page) $setExpressCheckoutReply[self::PAYMENT_INFO_BUTTON] = 1; } $this->_quote->getPayment()->importData($setExpressCheckoutReply); $this->_quote->getPayment()->save(); return $setExpressCheckoutReply; }
/** * 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; }
/** * Void the payment auth made for a quote. * * @param Mage_Sales_Model_Quote * @return array * @throws EbayEnterprise_PayPal_Exception when the operation cannot be completed or fails. */ public function doVoidQuote(Mage_Sales_Model_Quote $quote) { return $this->doVoid($quote->reserveOrderId()->getReservedOrderId(), $quote->getQuoteCurrencyCode()); }
/** * Do Authorization Request/ Response * * @param Mage_Sales_Model_Quote * @return array * * @throws EbayEnterprise_PayPal_Exception when the operation cannot be completed or fails. */ public function doAuthorization(Mage_Sales_Model_Quote $quote) { $sdk = $this->getSdk($this->config->apiOperationDoAuthorization); $payload = $sdk->getRequestBody(); $payload->setRequestId($this->coreHelper->generateRequestId(self::PAYPAL_DOAUTHORIZATION_REQUEST_ID_PREFIX))->setOrderId($quote->reserveOrderId()->getReservedOrderId())->setCurrencyCode($quote->getQuoteCurrencyCode())->setAmount($this->getTotal('grand_total', $quote)); $sdk->setRequestBody($payload); $this->logApiCall('do authorization', $sdk->getRequestBody()->serialize(), 'request'); $reply = $this->sendRequest($sdk); $isSuccess = $reply->isSuccess(); if (!$isSuccess) { $logMessage = 'PayPal request failed.'; $this->logger->warning($logMessage, $this->logContext->getMetaData(__CLASS__)); $e = Mage::exception('EbayEnterprise_PayPal', $this->helper->__(static::EBAYENTERPRISE_PAYPAL_API_FAILED)); $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e)); throw $e; } $this->logApiCall('do authorization', $reply->serialize(), 'response'); return ['method' => EbayEnterprise_PayPal_Model_Method_Express::CODE, 'order_id' => $reply->getOrderId(), 'payment_status' => $reply->getPaymentStatus(), 'pending_reason' => $reply->getPendingReason(), 'reason_code' => $reply->getReasonCode(), 'is_authorized' => $isSuccess]; }