Automattic / woocommerce-services

WooCommerce Services is a feature plugin that integrates hosted services into WooCommerce (3.0+), and currently includes automated tax rates and the ability to purchase and print USPS shipping labels.
GNU General Public License v2.0
107 stars 20 forks source link

Fetch "Add payment method" URL from WCS #2736

Closed kallehauge closed 4 months ago

kallehauge commented 4 months ago

Description

We want to have greater control over where we send merchants to add payment methods since it happens outside of WP Admin and the URL might change in the future - but it's a primary function that should always be supported.

Related issue(s)

Steps to reproduce

We have two location that are affected by this change: The settings page and the "purchase" button.

  1. Checkout branch locally and activate WCS&T
  2. Go to /wp-admin/admin.php?page=wc-settings&tab=shipping&section=woocommerce-services-settings
  3. Click Choose a different card (or directly add a payment method if you do not have one or more cards attached to your WPCOM account)
  4. Press the Add another credit card button
  5. Verify you were sent to https://wordpress.com/me/purchases/add-credit-card
  6. Edit an order that has a shippable product (/wp-admin/admin.php?page=wc-orders&action=edit&id={SOMETHING})
  7. Open the shipping label modal by clicking on the Create shipping label button
  8. (Situation A) If it's a fresh WPCOM user, then you should see a "Add credit card" button
  9. (Situation B) If you already have one or more payment methods attach to your WPCOM account, then you can force the "Add credit card" state by:
    • Open client/extensions/woocommerce/woocommerce-services/views/shipping-label/label-purchase-modal/purchase-section/index.js in your IDE
    • Change the return of <PurchaseSection> to just ignore the surrounding conditions and just render the "Add credit card" CreditCardButton component.
  10. Click either the "Add credit card" button or the "add a credit card to your account" link in the description below the button
    • Both the link and button uses the same function, so they're technically identical and one will validate the other.
  11. Verify you were sent to https://wordpress.com/me/purchases/add-credit-card

Screenshots/GIFs

Settings page

Screenshot 2024-05-22 at 01 43 02

Purchase modal

Screenshot 2024-05-22 at 01 42 30

Checklist

harriswong commented 4 months ago

👀