craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
215 stars 170 forks source link

[3.x]: Payment source not saved when using `savePaymentSource` and `registerUserOnOrderComplete` #2825

Closed iamkeir closed 1 year ago

iamkeir commented 2 years ago

What happened?

Description

During guest checkout, when adding a new payment source and presenting customer with checkboxes for both registerUserOnOrderComplete and savePaymentSource, the payment source is not saved.

Possibly intended behaviour? If so, some insight into why might be useful - other customer information is saved (e.g. addresses) so it seems odd to exclude the payment source. Was not able to find anything in the docs that indicates savePaymentSource only works if user logged in during checkout.

Steps to reproduce

  1. Checkout as guest
  2. Tick checkbox for registerUserOnOrderComplete
  3. Tick checkbox for savePaymentSource
  4. Submit order
  5. Notice payment source not saved

Craft CMS version

Craft Pro 3.7.43

Craft Commerce version

3.4.15

PHP version

8.0.8

Operating system and version

Darwin 21.1.0

Database type and version

MySQL 5.7.34

Image driver and version

No response

Installed plugins and versions

No response

pdaleramirez commented 2 years ago

@iamkeir This is not bug. The creating of user triggers after saving the paymentSource when checking out as guest. I'll mark it as enhancement.

iamkeir commented 2 years ago

@pdaleramirez thanks, but, if the creation of the user AFTER check out is the issue, how is it that all the other customer information is saved?

Either way, probably worth updating the docs to say savePaymentSource only works if customer logged in?

iamkeir commented 2 years ago

Got to the bottom of this - paymentSource is saved against User rather than Customer, which seems a little odd as all other data is against Customer. And, yes, it seems you currently require currentUser to use savePaymentSource. Referencing: https://github.com/craftcms/commerce/blob/9311f824ed24e303dfec46ab01b9b90823237410/src/controllers/PaymentsController.php#L252

So, yes, that enhancement would be very useful!

iamkeir commented 2 years ago

Created a Stack Exchange query for finding a workaround in the meantime: https://craftcms.stackexchange.com/questions/39598/commerce-3-register-user-and-save-payment-source-after-order-complete-for-gues

iamkeir commented 1 year ago

@lukeholder completed as in now supported, or completed as in not bug/won't fix? No worries either way.