commerce icon indicating copy to clipboard operation
commerce copied to clipboard

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

Open iamkeir opened this issue 3 years ago • 4 comments

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

iamkeir avatar May 24 '22 11:05 iamkeir

@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.

pdaleramirez avatar Jun 23 '22 11:06 pdaleramirez

@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 avatar Jun 23 '22 12:06 iamkeir

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 avatar Jun 25 '22 16:06 iamkeir

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 avatar Jun 28 '22 08:06 iamkeir

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

iamkeir avatar Dec 09 '22 09:12 iamkeir