Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Braintree and Custom Payment Method Product 400 Bad Request on purchase #5409

Closed
stevewinni opened this issue Jul 1, 2016 · 19 comments
Closed

Comments

@stevewinni
Copy link

stevewinni commented Jul 1, 2016

Steps to reproduce

  1. Install Magento 2.1.0.
  2. Enable Braintree and /or build custom payment method
  3. Add product to cart
  4. Complete credit card details
  5. Submit

Expected result

  1. Puchase completed and Transaction recorded in PSP

Actual result

  1. Ajax 400 Bad Request, Unable to place order.
  2. Debug.log - [2016-07-01 16:07:41] main.DEBUG: cache_invalidate: {"method":"POST","url":"http://dev.domain.com/rest/default/V1/carts/mine/payment-information","invalidateInfo":{"tags":["catalog_product_14","FPC"],"mode":"matchingTag"},"is_exception":false} []
  3. [Screenshot, logs]
    screen shot 2016-07-01 at 17 40 52
  4. Trace:
    "#0 /var/www/vhosts/domain.com/dev.domain.com/vendor/magento/framework/Interception/Interceptor.php(146): Magento\Checkout\Model\PaymentInformationManagement->savePaymentInformationAndPlaceOrder(53, Object(Magento\Quote\Model\Quote\Payment), Object(Magento\Quote\Model\Quote\Address))
    Can you commit to repository a folder dev/tests/static ? #1 /var/www/vhosts/domain.com/dev.domain.com/var/generation/Magento/Checkout/Model/PaymentInformationManagement/Interceptor.php(26): Magento\Checkout\Model\PaymentInformationManagement\Interceptor->___callPlugins('savePaymentInfo...', Array, Array)
    BUG FIX - Uncaught exception when accessing admin with none existent use... #2 [internal function]: Magento\Checkout\Model\PaymentInformationManagement\Interceptor->savePaymentInformationAndPlaceOrder(53, Object(Magento\Quote\Model\Quote\Payment), Object(Magento\Quote\Model\Quote\Address))
    __DIR__ Typo fixed #3 /var/www/vhosts/domain.com/dev.domain.com/vendor/magento/module-webapi/Controller/Rest.php(307): call_user_func_array(Array, Array)
    Enable Magento_Profiler by SetEnv #4 /var/www/vhosts/domain.com/dev.domain.com/vendor/magento/module-webapi/Controller/Rest.php(216): Magento\Webapi\Controller\Rest->processApiRequest()
    Enable automated CRUD setup for Adminhtml Grids #5 /var/www/vhosts/domain.com/dev.domain.com/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(37): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
    Why use private for message ? #6 /var/www/vhosts/domain.com/dev.domain.com/vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
    Ability to provide configuration for different environments in app/etc/local.xml #7 /var/www/vhosts/domain.com/dev.domain.com/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
    Clear separation for Controller and controllers required with Full Controller path #8 /var/www/vhosts/domain.com/dev.domain.com/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
    Added: dispatchEvent to deleteAction(). Only existed in massDeleteAction(). #9 {main}"
@YevSent
Copy link
Contributor

YevSent commented Jul 3, 2016

What type of payment action (Authorization or Authorize and Capture) did you use? Also, you use fresh Magento installation or upgrade version from some previous release?

@stevewinni
Copy link
Author

stevewinni commented Jul 3, 2016

It's using Sandbox with Authorize and Capture. The install is originally a 2.0.6 that has been upgraded on each point step to 2.1.0. It is also using the demo data and Luma Theme.

Platform: CentOS7, PHP7.0.7, FastCGI

Any Ideas on were to start debugging this one? Apart from following the Interceptor Class back up the tree.... Hope you've got a solution as I only had three days left to solve this before Client drops the platform....
screen shot 2016-07-03 at 18 21 16

@YevSent
Copy link
Contributor

YevSent commented Jul 4, 2016

@stevewinni, this is known issue and related to incorrect upgrade scripts for Sales module. On the fresh install, it should work.
Closed as duplicate for #4785 .

@YevSent YevSent closed this as completed Jul 4, 2016
@stevewinni
Copy link
Author

stevewinni commented Jul 4, 2016

Opppss.... OK for those who come after the fix is;

ALTER TABLE sales_invoice_grid ADD base_grand_total decimal(12,4) AFTER grand_total;

@YevSent
Copy link
Contributor

YevSent commented Jul 4, 2016

For now, there is no workaround, because problem is related to db schema changes between upgrades.

@stevewinni
Copy link
Author

Thank Joni... Looks like the DB amend listed in #4785 works.... I have success payment posts via Braintree after I amend DB..

@Nerogee
Copy link

Nerogee commented Jul 5, 2016

@joni-jones On the fresh install, it still doesn't work.

@flecxie
Copy link

flecxie commented Jul 30, 2016

@Nerogee: are you using table prefixing?
If so see #5902.

@Nerogee
Copy link

Nerogee commented Aug 1, 2016

@flecxie. I don't use table prefixing

@flecxie
Copy link

flecxie commented Aug 1, 2016

@Nerogee: Do you have debugging enabled / do you see anything in var/report/debug.log?

I have tried setting up a Braintree account on a vanilla Magento CE 2.1.0 installation (without table prefixing) and it did work for me (see #5902). The "400 Bad Request" can be caused by a large variety of reasons, you will probably have to debug with Xdebug (see https://www.fontis.com.au/blog/debugging-magento-with-xdebug) to figure out where things go wrong exactly...

@Nerogee
Copy link

Nerogee commented Aug 9, 2016

@flecxie sorry for late reply. I don't use table prefixing. Magento2.1 is fresh installed. I got message like "can't place order, please try again later.". I did notice for the debug.log that the Invoice ID is not updated which result in paypal keep receiving the same Invoice ID and thus fail to pass through or this may even cause problem when try to save order in system due the duplicate order ID (duplicated key).

@romeof1980
Copy link

hi there,
We've been experiencing the same Braintree issue both with Sandbox and Production (using both 2.0.7 and 2.1.0) with credit card processing (works as expected with PayPal through Braintrere)
We can see that the transactions are carried out in Braintree "Transaction" as expected.

But we also always get the '400 Bad Request' in the console and the message "Unable to place order. Please try again later".

Nothing worth to be mentioned in debug.log (see attachment).
Nothing in exception.log

thanks a lot,
romeo

debug.log works on Braintree - not on Magento 2.1.0.txt

@YevSent
Copy link
Contributor

YevSent commented Aug 10, 2016

Hi, @romeof1980, you can use xdebug to find the reason of error. You need to set a breakpoint on this line and you will see original exception message.

@romeof1980
Copy link

hi @joni-jones , thanks a lot for your reply.
I can indeed use xdebug. I took a look at the suggested link
and set the breakpoint as you suggested.

No when trying to checkout I get the following message from the console:
"NetworkError: 400 Bad Request - http://www.xxxxxx.net/rest/default/V1/guest-carts/3092d4cd6cf9cbb7ae4ef68cd3782dd8/payment-information" and
{"message":"%fieldName is a required field.","parameters":{"fieldName":"paymentMethod"}}
(but then when retrying the checkout only the original message {"message":"Unable to place order. Please try again later."} appears in the console)

About xdebug.. still trying to figure it out the right procedure to debug this issue.
when we append ?XDEBUG_PROFILE=1 to checkout/ we get the cachegrind file, but in the following step (checkout/#payment) we can't append the ?XDEBUG_PROFILE=1 so no cachegrind file is generated.

any hint will be highly appreciated.

thanks a lot,
romeo

@Vinai
Copy link
Contributor

Vinai commented Aug 11, 2016

You should be able to set xdebug.profiler_enable to 1 in your php.ini configuration file to always enable profiling, even if a request does not include XDEBUG_PROFILE as part of the request data.
See the xdebug configuration settings for more information.

@romeof1980
Copy link

@gabriel-sf
Copy link

Just to add a note (since I just fixed it after 3 full days), renaming the tables and removing the table prefix also solved the 400 error for me using PayFlow Pro.

@romeof1980
Copy link

Issue was fixed for us following the solution suggested in #5902 (deleting table prefixing and updating table sales_sequence_meta)

@singh190
Copy link

singh190 commented Feb 27, 2017

Hi,
This issue is coming in Magento ver. 2.1.3 also, while placing order, getting error 404 Bad Request.
I debugged in file app/code/Corra/Quote/Model/QuoteManagement.php; The error is cached after code
$order = $this->orderManagement->place($order);
Customers are charged multiple times when they use payment method as BrainTree credit card.
The following information was logged:
2017-02-23T21:33:14+00:00 DEBUG (7): ===========PLACE ORDER START=========== {"data":"{"additional_data":{"device_data":"{\"correlation_id\":\"c80ae18c244c4d27a0b52cca03e24f72\",\"device_session_id\":\"73923DFD39BE4CFB9D97A74214CE6A68\",\"fraud_merchant_id\":\"600000\"}","payment_method_nonce":"96c5de0f-fd23-0f69-2c49-d62fdf6ba364"},"method":"braintree","checks":["checkout","country","currency","total","zero_total"]}"}

2017-02-23T21:33:14+00:00 DEBUG (7): Quote Before Quote Submit {"Reserved Order ID":null,"Quote ID":"324944","Customer Email":"[email protected]","Checkout Session":"{"shipper_global":{"dateFormat":"mm/dd/yyyy","currencyCode":"usd","weightUnit":"lb","dropshipShowMergedRates":true,"dropshipShowItemDesc":false,"dropshipDescription":"Multiple Warehouses","dropshipTitle":"Shipping","distanceUnit":"MI","carrierGroupDescription":"Origin","calendarConfirm":false,"shippingTooltipText":"","showPickupMulti":false,"cityRequired":false,"sortBasedPrice":true,"dropshipShowWeight":false,"preferredLocale":"en-US","transaction":"SHQ_REQUEST_20170223_2133_XXX.95881385"},"custom_method_code":"shqFDX_FDX_2DA"}"}

2017-02-23T21:33:17+00:00 DEBUG (7): Error on place order {"error":"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'braintree-923835-mf5krd2' for key 'UNQ_54DCE14AEAEA03B587F9EF723EB10A10', query was: INSERT INTO vault_payment_token (customer_id, public_hash, payment_method_code, type, expires_at, gateway_token, details, is_active) VALUES (?, ?, ?, ?, '2018-07-01 00:00:00', ?, ?, ?)"}

Given that the user get's many Magento order ids, it would appear that Magento is trying to charge the users many times.
We have tried every steps mentioned in this ticket as well as #5902, both.
Plz suggest any solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants