magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

Unable to continue with payment of order when pressing "back" to payment selection #4474

Closed karl-ravn closed 8 years ago

karl-ravn commented 8 years ago

When an order

Steps to reproduce

  1. Install Magento from develop branch.
  2. Add Product to the cart.
  3. Install (for instance) SaferPay plugin from CustomWeb
  4. Go to Checkout
  5. Fill in shipment details
  6. Select payment method and click "Place order"
  7. Press back in button (not cancel in payment provider)
  8. Press "Place order" again

    Expected result

  9. You would go to the payment provider and continue on the already made order in the system

    Actual result

  10. You get an error due to that the database table sales_order already contains the increment number
  11. The order is now in "pending payment" state until the timeout occurs, and the user cannot proceed with checkout without clearing cookies or switching web browser.

    Stack trace

[2016-05-12 02:37:15] main.CRITICAL: Zend_Db_Statement_Exception: Report ID: webapi-5733ec5b3500f; Message: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3000000496-3' for key 'SALES_ORDER_INCREMENT_ID_STORE_ID', query was: INSERT INTO `sales_order` (`state`, `status`, `coupon_code`, `protect_code`, `is_virtual`, `store_id`, `customer_id`, `base_discount_amount`, `base_grand_total`, `base_shipping_amount`, `base_shipping_tax_amount`, `base_subtotal`, `base_tax_amount`, `base_to_global_rate`, `base_to_order_rate`, `discount_amount`, `grand_total`, `shipping_amount`, `shipping_tax_amount`, `store_to_base_rate`, `store_to_order_rate`, `subtotal`, `tax_amount`, `total_qty_ordered`, `customer_is_guest`, `customer_note_notify`, `customer_group_id`, `quote_id`, `base_shipping_discount_amount`, `base_subtotal_incl_tax`, `base_total_due`, `shipping_discount_amount`, `subtotal_incl_tax`, `total_due`, `weight`, `increment_id`, `applied_rule_ids`, `base_currency_code`, `customer_email`, `customer_firstname`, `customer_lastname`, `customer_middlename`, `discount_description`, `global_currency_code`, `order_currency_code`, `remote_ip`, `store_currency_code`, `store_name`, `x_forwarded_for`, `total_item_count`, `discount_tax_compensation_amount`, `base_discount_tax_compensation_amount`, `shipping_discount_tax_compensation_amount`, `base_shipping_discount_tax_compensation_amnt`, `discount_tax_compensation_invoiced`, `base_discount_tax_compensation_invoiced`, `discount_tax_compensation_refunded`, `base_discount_tax_compensation_refunded`, `shipping_incl_tax`, `base_shipping_incl_tax`, `coupon_rule_name`, `gift_message_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) in /opt/store.traxfamily.com/vendor/magento/framework/Webapi/ErrorProcessor.php:194
Stack trace:
#0 /opt/store.traxfamily.com/vendor/magento/framework/Webapi/ErrorProcessor.php(139): Magento\Framework\Webapi\ErrorProcessor->_critical(Object(Zend_Db_Statement_Exception))
#1 /opt/store.traxfamily.com/vendor/magento/module-webapi/Controller/Rest.php(163): Magento\Framework\Webapi\ErrorProcessor->maskException(Object(Zend_Db_Statement_Exception))
#2 /opt/store.traxfamily.com/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
#3 /opt/store.traxfamily.com/vendor/magento/framework/App/Http.php(115): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#4 [internal function]: Magento\Framework\App\Http->launch()
#5 /opt/store.traxfamily.com/vendor/magento/framework/Interception/Interceptor.php(144): call_user_func_array(Array, Array)
#6 /opt/store.traxfamily.com/var/generation/Magento/Framework/App/Http/Interceptor.php(26): Magento\Framework\App\Http\Interceptor->___callPlugins('launch', Array, Array)
#7 /opt/store.traxfamily.com/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http\Interceptor->launch()
#8 /opt/store.traxfamily.com/pub/index.php(73): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#9 {main} [] []
joni-jones commented 8 years ago

@karl-ravn , seems your problem not related to Magento functionality and relates to SaferPay plugin. If this behavior is reproducible with other Magento built-in payments, please, update details and reopen this issue.

In other case, please refer to the Community Forums or Magento Stack Exchange site for technical questions.

karl-ravn commented 8 years ago

Seems to be same problem as #4580

karl-ravn commented 8 years ago

The problem seems to be that the quote has been created with a reserved_order_id, but there already exists a row with the same increment_id in order_sales.

The error goes through: OrderManager#save(\Magento\Sales\Api\Data\OrderInterface $entity) OrderService#place(\Magento\Sales\Api\Data\OrderInterface $order) QuoteManagement#submitQuote(QuoteEntity $quote, $orderData = []) (line 478 Magento 2.0.5 $order = $this->orderManagement->place($order);)

This could be avoided if either QuoteManagement#submitQuote() or Quote#reserveOrderId() would do a sanity check that there are no order with a conflicting increment_id. If a conflict is found, just regenerate a new order id.

rbutler514 commented 8 years ago

We just had this exact issue on Magento 2.07 using Braintree as our payment provider. Same steps to replicate the issue and since it was for a registered user, we had to manually remove the quote in the DB in order to allow them to create a new cart for checkout.

bvboas commented 8 years ago

Anyone figured out a temp fix?

I'm having the same issue.

mimarcel commented 7 years ago

@bvboas as stated in https://github.com/magento/magento2/issues/4580 , commit https://github.com/magento/magento2/commit/fe97d9e4540741edb0abc876d169c1df60a06b70 should fix the issue. I didn't test it myself, but I'm looking into it as well.