magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Braintree doesn't work on Magento CE 2.1.0 when using table prefixing (HTTP/1.1 400 Bad Request)

Open flecxie opened this issue 10 years ago • 29 comments

The Magento CE 2.1.0 Braintree module seems to be broken when using table prefixing during installation. When setting up 2 stores (1 without table prefixing and 1 with table prefixing) then payments from the site with table prefixing fail.

Steps to reproduce

  1. Install Magento-CE-2.1.0_sample_data-2016-06-23-02-34-56 twice, once with sql table prefixing & once without
  2. Create a Braintree Sandbox account & enable Braintree on both sites (make sure you set merchant country)
  3. Purchase product on both sites

Expected result

  1. Purchase successful on both sites & transaction showing up on Braintree dashboard

Actual result

  1. Purchase successful on site which didn't use table prefixing
  2. Purchase fails on site which has table prefixing showing error "Unable to place Order. Please try again later." - the browser console also shows [HTTP/1.1 400 Bad Request] upon posting to payment-information
  3. Payment from both sites does show up on Braintree dashboard, even the payment which was marked as failed from the site with table prefixing

See screenshot below for error: braintree_bug

flecxie avatar Jul 30 '16 05:07 flecxie

Related to https://github.com/magento/magento2/issues/5714

flecxie avatar Jul 30 '16 08:07 flecxie

@asemenenko can you have the team check into this one?

pboisvert avatar Jul 31 '16 01:07 pboisvert

WAR for now is to get rid of table prefixing, to do this in an existing store:

  1. Rename all SQL tables
  2. Update table references in the sales_sequence_meta table (otherwise all orders will fail)

I used a simple bash script to rename all SQL tables. To update the tables references in sales_sequence_meta I ran the following SQL:

update sales_sequence_meta set sequence_table = replace(sequence_table,'YOURPREFIX_','');

flecxie avatar Jul 31 '16 05:07 flecxie

Hi @flecxie, please, attach debug and exception log. Created internal ticket to investigate this issue MAGETWO-56344. UPD: did you enable Vault for Braintree?

YevSent avatar Aug 03 '16 15:08 YevSent

Sorry, no longer have this environment but should be easy to replicate this issue locally.

Debug.log showed a successful Braintree transaction & the transaction did show up on the Braintree dashboard. Nothing in exception.log, but using Xdebug I could see an exception being triggered...

flecxie avatar Aug 04 '16 01:08 flecxie

Didn't enable Vault

flecxie avatar Aug 04 '16 01:08 flecxie

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 PayFlow Pro.

gabriel-sf avatar Aug 16 '16 11:08 gabriel-sf

Thanks @flecxie , deleting table prefixing fixed the issue for us too (both in 2.0.6 and 2.1.0). Vault enabled or not didn't make any difference for us, nor did "Authorize" or "Authorize and Capture".

rumbdev avatar Aug 17 '16 10:08 rumbdev

Hello I followed the suggestions in the the above post to remove the prefix from my magento database. I then did the table update update sales_sequence_meta set sequence_table = replace(sequence_table,'YOURPREFIX_',''); . However it seems that some tables are still referencing my old prefix mgxa_. When I try to add a new product I get the error

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'datbasename.mgxa_catalogrule_product_cl' doesn't exist, query was: INSERT INTO catalog_product_entity (entity_id, attribute_set_id, type_id, sku, has_options, required_options) VALUES (?, ?, ?, ?, ?, ?)

Any ideas on how to fix my db?

redline10000 avatar Aug 18 '16 22:08 redline10000

Hi @redline10000 , check this thread about the process on how to rename the tables.

http://magento.stackexchange.com/questions/103597/how-to-properly-remove-db-table-prefix-in-magento2/103599

gabriel-sf avatar Aug 18 '16 23:08 gabriel-sf

Hi @gabriel-sf

Thank you, the article makes sense but how do I figure out which table is looking for mgxa_catalogrule_product_cl?

redline10000 avatar Aug 18 '16 23:08 redline10000

Upon digging deeper into my database it appears that the triggers are still referencing the wrong table names. They all still have mgxa_ in them. But my tables no longer have mgxa_

redline10000 avatar Aug 19 '16 00:08 redline10000

@redline10000 to be honest, I removed the prefix of all the tables and then followed those instructions. Sorry I dont have more info. Have you cleared your cache and index?

gabriel-sf avatar Aug 19 '16 00:08 gabriel-sf

Hi @gabriel-sf

I have cleared the cache and indexes. I removed the triggers and everything seems fine now. Yet I am still getting the 400 error when making a braintree payment.

redline10000 avatar Aug 19 '16 01:08 redline10000

I would suggest using xdebug to see what errors you are getting and try to debug it from there. There might be a table or something missing.

gabriel-sf avatar Aug 19 '16 01:08 gabriel-sf

Hi @redline10000, have you enabled 3D secure in Magento 2 Braintree configuration section?

rumbdev avatar Aug 19 '16 17:08 rumbdev

@romeof1980 thank you for the suggestion but I ended up just making a new db. My install was a new install and was not really worth all of the effort to fix. Fresh install w/o table prefixes fixed everything.

redline10000 avatar Aug 19 '16 21:08 redline10000

Sounds very good. Personally, when editing dtb and ending with errors, I'd not just delete the cache but I'd also delete and redeploy static content

---- On Fri, 19 Aug 2016 23:00:51 +0200 [email protected] wrote ----

@romeof1980 thank you for the suggestion but I ended up just making a new db. My install was a new install and was not really worth all of the effort to fix. Fresh install w/o table prefixes fixed everything.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

rumbdev avatar Aug 19 '16 21:08 rumbdev

Any ETA on a fix?

davidaddison avatar Aug 29 '16 14:08 davidaddison

This fix already merged to develop branch ce1160f and will be available in some of 2.1.x releases.

YevSent avatar Aug 30 '16 07:08 YevSent