Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change STPPaymentCardTextField to copy the cardParams object when it's set or read. #1031

Merged
merged 14 commits into from Nov 6, 2018

Conversation

danj-stripe
Copy link
Contributor

Summary

Exposing the internal STPCardParams object led to weird interactions, like #1027. It
also doesn't match our desired information hiding. Setting some fields on the cardParams
would persist (name, address, etc), while setting others had no effect (card number, etc).

By copying in both setter & getter, the internal state of this view is protected, and
must be changed by setting a new object on the property.

We expect well-behaved code to be backwards compatible, but this is a breaking change
that'll require a major version bump because it changes the interface & behavior.

Motivation

#1027 and IOS-958

Testing

Tests were written that illustrate the problem & current behavior, and then updated as the
behavior changed.

Sample projects were inspected and tested to make sure they weren't using the payment text
field in an unsupported way.

Using the runtime to iterate through all the properties and make sure they're equal.
…orked.

Using the runtime to iterate through all the properties and make sure they're equal, or
not, as appropriate.
Also changed the `setName:`/`setAddress:` overrides slightly to avoid calling `setName:`
from `setAddress:`
There are a bunch of places where we have `STPAddress` properties, and none of them
copy the object. Instead of changing `STPCardParams.address` as a one-off to be `copy`,
keep this `strong`.

I think the right thing to do would be to add a `STPMutableAddress` subclass, and take
a pass through the codebase. There are places where the STPAddress *should* be mutable,
like `STPCardParams.address`, allowing caller to build up the params to send to Stripe.

There are other places, like objects returned from the API, where it should be immutable.
Ex: `STPCard.address`.

This also makes the migrating instructions a lot simpler to understand.
@@ -638,7 +638,7 @@ behaves identically to user entering text (and will have the same forwarding
*/
STPFormTextField *originalSubResponder = self.currentFirstResponderField;

self.internalCardParams = cardParams;
self.internalCardParams = [cardParams copy];
[self setText:cardParams.number inField:STPCardFieldTypeNumber];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth adding a comment here highlighting that it's important to use cardParams and not internalCardParams for the sets

…bout the need for it

Per comment in `setCardParams:`, `setText:inField` calls trigger `paymentCardTextFieldDidChange:`
and `UIControlEventValueChanged`. This passes control back to the application code.

If the app code calls the `STPPaymentCardTextField.cardParams` property
accessor, the `internalCardParams` object is mutated to match the UI's state, and
that breaks the behavior of this method (motivating reason for this patch)

Similarly, if the app code changes the `STPCardParams` object that they own & passed into
this method during the delegate or value changed event, those changes could unexpectedly
show up.

The `desiredCardParams` copy is used so that at the end of the method's execution,
its done what was expected.
@danj-stripe
Copy link
Contributor Author

re-review? @csabol-stripe

@danj-stripe
Copy link
Contributor Author

I'm investigating the failure of -[STPCertTest testExpired]

@danj-stripe danj-stripe merged commit 40f29e8 into master Nov 6, 2018
@danj-stripe danj-stripe deleted the danj/feature/copy-cardparams+address branch November 6, 2018 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants