I have a site about to launch and I've tested ecommerce with Braintree in Drupal 8 and all was well. Testing in live mode with my Braintree account looked good. I then made a new Payment Gateway at admin/commerce/config/payment-gateways/add for the client's Braintree account.
I go to test for the client and get errors in the logs like "Payment method token is invalid." and "Customer ID is invalid." I called Braintree support (who seem very helpful) and they tell me my requests are not sending valid tokens.
I tell them I'm seeing saved cards (from the vault) from my original testing with the now phantom Braintree payment gateway account which has been deleted. They tell me I should NOT be seeing saved cards on the new BT account because no cards have been run on that account.
So it appears there is a phantom BT account saved from my first testing. This original BT payment gateway appears to be saved into the system somewhere, even though that payment gateway has been deleted.
How do I flush the Payment Gateway memory and forget the old one and put the new in place?
| Comment | File | Size | Author |
|---|---|---|---|
| phantom-payment-gateway.png | 180.04 KB | joegml |
Comments
Comment #2
bojanz commentedConfirmed.
The problem is this:
Old customer IDs are not cleared when the Braintree credentials are changed from testing to live.
A workaround is to programatically update all users and clear their commerce_remote_id fields.
Code-wise we need to key the IDs by gateway ID and environment (dev/live).
Comment #3
joegml commented@bojanz that sounds similar to the issue I'm seeing. But, I was testing smoothly with my own account in live mode. Funds hit my bank account smoothly.
I then switched to a new BT payment gateway with the client creds in live mode and authentication failed at that point. Don't even think I ran the client creds in testing mode. I usually test with small amounts initially.
I think it would be helpful to have a "Clear all BT tokens/info" button in the config. How do I accomplish this by hand? I'm an old troglodyte who likes to issue mysql commands to solve things like this, but I don't think that's the Drupal 8 Way ;-)
Got a snippet I can run (in Drush if that's not too old fashioned or Drupal Console)?
Thanx and keep up the great work on the cutting edge.
Comment #4
bojanz commenteda "TRUNCATE TABLE user__commerce_remote_id" should do it (or a matching DELETE query).
Comment #5
joegml commentedYou rock. I will try this on a dev site first, then report back success or failure.
Comment #6
vasikeOpen core issue with a PR, that could help here: #2861181: Rework the handling of customer remote IDs for payments
Comment #7
joegml commentedI'd love to resolve this, but should follow best practices and run the test fix on the dev site.
Any special new things to do to take the live install to dev? I've synched git on both and copied over the DB to the dev location. Are there other things that need to be done in composer? See list of errors I'm getting below. My .gitignore contains "vendor" but no *.composer.*
Versions: Drupal: 8.2.5, commerce: detached:composer/8.x-2.x
I've also got two commerce_braintree dirs (which prob isn't good): one at www/modules/contrib/commerce_braintree (8.x-1.x-dev) and one at www/modules/commerce_braintree (detached:composer/8.x-1.x). Which of these is the real deal and which should get toasted?
Before drush cr ----------------------
Site renders OK and is generally up and running.
error_log:
Fatal error: Class 'Drupal\commerce\Plugin\Field\FieldType\RemoteIdItem' not found in /home/lciderby/dev/core/modules/field/src/FieldStorageConfigStorage.php on line 159
Drupal log messages:
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "commerce_payment_gateway" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 133 of /home/lciderby/dev/core/lib/Drupal/Core/Entity/EntityTypeManager.php).
Post drush cr on command line ----------------------
exception 'RuntimeException' with message 'Unable to determine class for field type 'commerce_remote_id' found[error]
in the 'field.storage.user.commerce_remote_id' configuration' in
/home/lciderby/dev/core/modules/field/src/FieldStorageConfigStorage.php:157
Stack trace:
#0 /home/lciderby/dev/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(189):
Drupal\field\FieldStorageConfigStorage->mapFromStorageRecords(Array, Array)
#1 /home/lciderby/dev/core/lib/Drupal/Core/Entity/EntityStorageBase.php(242):
Drupal\Core\Config\Entity\ConfigEntityStorage->doLoadMultiple(Array)
WSOD on all pages with message: The website encountered an unexpected error. Please try again later.
± |up ✓| → drush ws
RuntimeException: Unable to determine class for field type 'commerce_remote_id' found in the [error]
'field.storage.user.commerce_remote_id' configuration in
Drupal\field\FieldStorageConfigStorage->mapFromStorageRecords() (line 157 of
/home/lciderby/dev/core/modules/field/src/FieldStorageConfigStorage.php) #0
/home/lciderby/dev/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(189):
Drupal\field\FieldStorageConfigStorage->mapFromStorageRecords(Array, Array)
Sorry if this should be a new issue. I can post a new issue for this if that's appropriate.
Comment #8
joegml commentedOK so at this point it appears I have a double install of commerce_braintree: one via drush and one via composer each in different directories. This might explain the phantom account behavior I'm seeing.
Could someone outline the correct way to unwind this? At this point I'm happy to uninstall and then reinstall commerce_braintree, but I'd like to do that correctly with drush and composer and D8 in mind. There are also commerce and core versions to consider.
Thanx for any guidance!
Comment #9
jp.stacey commented@joegml you should be able to delete (well, maybe move it outside Drupal so you can always move it back) either copy of the module and run `drush cr`, I think.
But are we still saying (@bojanz?) that this is confirmed by others and so not an issue of this double install of the module? It would be useful if anyone who can duplicate it could put really granular steps to repeat in the ticket description, something like:
1. (Set up Drupal Commerce with a BT payment gateway)
2. Configure the gateway with one (test) BT account
3. Complete a checkout with BT payment (as guest? As a customer account?)
4. Reconfigure the gateway with another (live) BT account
5. Attempt to complete a checkout with BT payment (as guest? As a different customer? As the same one as #3 above?)
6. See errors as per etc. etc.
Something really "dumb" that looks like the steps for a Behat scenario, so anyone can follow it.
Comment #11
bojanz commented#2861181: Rework the handling of customer remote IDs for payments has landed, and Braintree has been updated to use the new API. Problem solved.
Comment #13
shaalI received the same error message from Braintree, because of an issue with config override.
It was charging customers successfully but for recurring-orders, it was sending transactions to braintree's sandbox instead of production.