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

Fix syncing of local tokens with remote payment methods #2897

Merged
merged 8 commits into from
Feb 19, 2024

Conversation

a-danae
Copy link
Contributor

@a-danae a-danae commented Feb 13, 2024

Fixes #2896

Changes proposed in this Pull Request:

  • Reduce the amount of iteration when syncing local tokens with the payment methods in Stripe. We had four loops, two of them nested within each other. Now we're using two, not nested.
  • (Hopefully) Simplify the logic behind the syncing process.

Testing instructions

Pulling remote payment methods

  1. Log in as a shopper
  2. Go to My Account > Payment methods
  3. Take note of the payment methods displayed
image
  1. On the Stripe dashboard, go to the page for the customer associated with this shopper. It's in https://dashboard.stripe.com/test/customers/cus_xxxx
  2. Under Payment Methods, click on Add > Add card
  3. Enter a test card, like 4000056655665556
image
  1. Skip the stored transient. Either remove the transient in wp_options LIKE '%stripe_payment_methods_%', or assign false to this variable
  2. As the shopper, reload the My Account > Payment methods page
  3. Confirm that the card you just added to Stripe is listed
image

Deleting local payment methods when removed remotely

  1. Log in as a shopper
  2. Go to My Account > Payment methods
  3. Take note of the payment methods displayed there
image
  1. On the Stripe dashboard, go to the page for the customer associated with this shopper. It's in https://dashboard.stripe.com/test/customers/cus_xxxx
  2. Under Payment Methods, delete one of the payment methods
image
  1. Skip the stored transient. Either remove the transient in wp_options LIKE '%stripe_payment_methods_%', or assign false to this variable
  2. As the shopper, reload the My Account > Payment methods page
  3. Confirm that the payment method you deleted in Stripe is no longer listed
image

Regression tests

Listing of payment methods from other extensions

  1. Enable WooPayments
  2. Save some card and SEPA payment methods
  3. Visit the My Account > Payment methods page
  4. Confirm all the tokens are listed as expected: The tokens are listed, and they don't get duplicated or deleted

Listing saved APMs

  1. Purchase a subscription using iDEAL, SEPA, or Bancontact
  2. Go to the My Account > Payment Methods page
  3. Confirm all the tokens are listed as expected

Disabling specific payment method types with saved payment methods

  1. As a shopper, save a card and a SEPA payment method
  2. Go to the My Account > Payment Methods page and note the listed payment methods
  3. As a merchant, go to the Stripe settings page in the WP dashboard > Payment methods tab
  4. Disable SEPA
  5. As a shopper, go to the My Account > Payment Methods page
  6. Confirm no SEPA payment methods are listed

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Added changelog entry in both changelog.txt and readme.txt (or does not apply)
  • Tested on mobile (or does not apply)

Post merge

Base automatically changed from fix/2872-dPE-APM-subscription-support to add/deferred-intent February 15, 2024 06:45
@a-danae a-danae changed the title Fix syncing of local tokens with remote payment methods Refactor syncing of local tokens with remote payment methods Feb 15, 2024
@a-danae a-danae changed the title Refactor syncing of local tokens with remote payment methods Fix syncing of local tokens with remote payment methods Feb 15, 2024
@a-danae a-danae marked this pull request as ready for review February 15, 2024 18:54
@a-danae a-danae requested review from Mayisha and wjrosa and removed request for Mayisha February 15, 2024 18:54
Copy link
Contributor

@Mayisha Mayisha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had already half reviewed this PR last Friday so decided to finish my review. I have tested the scenarios mentioned in the description and got the following outcomes.

  • Pulling remote payment methods ✔️
  • Deleting local payment methods when removed remotely ✔️
  • Regression tests (tested with WooPayments by saving a card) ✔️
  • Listing saved APMs (tested by purchasing a subscription using SEPA) ✔️
  • Disabling specific payment method types with saved payment methods (for iDeal and Bancontact) ✔️

I found 2 problems.

  • When sepa is enabled, I see it on the checkout page and even save the method while purchasing a subscription but I don't see it on My Account page.

no sepa

  • I can not add a payment method from My Account page. I get the following error
Notice: Undefined index: return_url in /var/www/html/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-intent-controller.php on line 959 {"success":true,"data":{"status":"succeeded","id":"seti_1OkQJ2CBKj0yxC0ZfaFbFojV","client_secret":"seti_1OkQJ2CBKj0yxC0ZfaFbFojV_secret_PZZRODQG5VdX2jq6fUlByCTtxWcipL0"}}

The issues seem unrelated to this PR. Let me know your thoughts.

Note: This one is not important but thought I would add it discovered during testing. Adding/deleting a payment method works find both ways to/from Stripe Dashboard and My Account page. When I set a default method on My account page it's reflected on the Stripe Dashboard. But setting default from Stripe does not reflect on the My account page. It's a unlikely scenario though, as a merchant won't be setting a default for a shopper.

@a-danae
Copy link
Contributor Author

a-danae commented Feb 19, 2024

Thanks for the thorough review, @Mayisha !

I can not add a payment method from My Account page. I get the following error

There's a GH issue for this over here #2907

When sepa is enabled, I see it on the checkout page and even save the method while purchasing a subscription but I don't see it on My Account page.

Good catch. I can replicate in add/deferred-intent, so I'd say we check this in a separate issue. Creating it... GH issue created #2922

This one is not important but thought I would add it discovered during testing. Adding/deleting a payment method works find both ways to/from Stripe Dashboard and My Account page. When I set a default method on My account page it's reflected on the Stripe Dashboard. But setting default from Stripe does not reflect on the My account page. It's a unlikely scenario though, as a merchant won't be setting a default for a shopper.

I can replicate this in develop. I also don't see any code intended to keep this option in sync.
But it might not be an issue. Do you see any potential problems with keeping it as is? We could create a GH issue to spike whether we'd like to change this behavior.

@a-danae a-danae requested a review from Mayisha February 19, 2024 16:23
Copy link
Contributor

@Mayisha Mayisha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Danae for the fix. Addressing the two issues with their separate tickets sounds good.

Do you see any potential problems with keeping it as is?

Also I don't see any problems here as it is not anything that significaant.

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

Successfully merging this pull request may close these issues.

2 participants