Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
87 stars 33 forks source link

Customer cannot add a saved card to a subscription when using Square #380

Open sitetherapy opened 1 year ago

sitetherapy commented 1 year ago

Describe the bug

I created a subscription in Woocommerce Subscriptions but did not attach a payment method. This meant it was set to Manual Renewal. When logging in to the My Account area and trying to add a saved credit card, the card is not added and an error is given.

To Reproduce

1) Create (in the admin screen) a subscription without any payment method. Ensure that this is set to Active. 2) login as that subscriber and go to the My Account page. 3) Click on Payment Methods and then on Add Payment Method. Add valid credit card, CVC, etc, and click Add Payment Method button

Actual behavior

Status code CUSTOMER_NOT_FOUND: Customer with ID [some hex value] not found.`

where some hex value is a hashed value.

Expected behavior

Card saved and attached to subscription.

Desktop (please complete the following information):

Not really relevant but I'm using Safari Version 16.2 (18614.3.7.1.5)

Additional context

1) Note that before doing this I purchased a test product on this site so that my information was in Square and associated with this website.

2) I turned on debug logging and Square is rejecting this because Woo Subs is not passing required information: ( [0] => Square\Models\Error Object ( [category:Square\Models\Error:private] => INVALID_REQUEST_ERROR [code:Square\Models\Error:private] => BAD_REQUEST [detail:Square\Models\Error:private] => At least one ofgiven_name,family_name,company_name,email_address, orphone_number` is required for a customer. [field:Square\Models\Error:private] => )

) ` Apparently Woo Subs is not passing any of the above information to Square when trying to add a new card.

sitetherapy commented 1 year ago

MORE INFO:

This seems to only occur when logged in as a user with admin rights. A regular user with the Subscriber role does not see this.

Proposed Solution: Add text to the error message indicating this so that developers aren't misled to believe that this is a general issue.

csmcneill commented 1 year ago

I'm unable to reproduce this as far as I can tell. When I...

  1. Manually create a subscription for an admin user.
  2. Set it to active.
  3. Do not add a payment method (i.e. set it to Manual Renewal) Markup on 2023-01-22 at 11:11:05
  4. Navigate to My Account > Subscriptions Markup on 2023-01-22 at 11:12:16
  5. Add a payment method to the subscription in question. Markup on 2023-01-22 at 11:12:43

...I am able to without any errors: vCe6vB.png

Here is the API request:

Request
method:
uri: createCard
user-agent: WooCommerce-Square/3.4.2 (WooCommerce/7.3.0; WordPress/6.1.1)
headers: Array
(
)
body:
duration: 0.77242s

And here is the API response:

Response
code: 200
message:
headers: Array
(
[0] => HTTP/1.1 200 OK
[Date] => Sun, 22 Jan 2023 17:13:16 GMT
[Content-Type] => application/json
[Content-Length] => 443
[Connection] => keep-alive
[Content-Encoding] => gzip
[Square-Version] => 2022-05-12
[Vary] => Origin, Accept-Encoding
[X-Content-Type-Options] => nosniff
[X-Download-Options] => noopen
[X-Frame-Options] => SAMEORIGIN
[X-Permitted-Cross-Domain-Policies] => none
[X-Speleo-Traceid] => [redacted]
[X-Xss-Protection] => 1; mode=block
[X-Sq-Dc] => sjc2b
[X-Sq-Region] => sjc2b
[Strict-Transport-Security] => max-age=631152000; includeSubDomains; preload
)
body: {
"card": {
"id": "[redacted]",
"card_brand": "VISA",
"last_4": "1111",
"exp_month": 10,
"exp_year": 2023,
"cardholder_name": "John Doe",
"billing_address": {
"address_line_1": "123 Main Street",
"address_line_2": "",
"locality": "Sacramento",
"administrative_district_level_1": "CA",
"postal_code": "12345",
"country": "US"
},
"fingerprint": "[redacted]",
"customer_id": "[redacted]",
"merchant_id": "[redacted]",
"enabled": true,
"card_type": "CREDIT",
"prepaid_type": "NOT_PREPAID",
"bin": "411111"
}
}

@sitetherapy can you confirm if I am taking the appropriate steps to replicate the issue?

sitetherapy commented 1 year ago

Hmm. Those steps are correct, but give me an error. I'll investigate more, but note that I'm testing with a live card on a live Square connection (not in test mode) and just set the next payment date in the future. From looking at the screenshots, it seems you're in test mode with a test card.

More later this week