craftcms / commerce-stripe

Stripe payment gateway for Craft Commerce
https://plugins.craftcms.com/commerce-stripe
MIT License
31 stars 48 forks source link

Incorrect Customer model validation rule for 'reference' attribute #97

Closed nateiler closed 3 years ago

nateiler commented 4 years ago

https://github.com/craftcms/commerce-stripe/blob/4e03574d188a279847b9943a78a8f5fd600332a1/src/models/Customer.php#L114

The 'reference' validation rule does not work properly across a model and record. When validating a model using the target as a record, it will never consider a record if it already exists. To clarify, try re-saving an existing customer; the result will be a validation error.

The class comparison here is the culprit: https://github.com/yiisoft/yii2/blob/2498a770403c27b0caef44f777ef0df4e74c7dc5/framework/validators/UniqueValidator.php#L184

Should probably use Craft's unique validator: https://github.com/craftcms/cms/blob/develop/src/validators/UniqueValidator.php

lukeholder commented 3 years ago

Thanks, fixed for the next release.