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

Add API to create PaymentMethod #1141

Merged
merged 13 commits into from
Mar 13, 2019
Merged

Add API to create PaymentMethod #1141

merged 13 commits into from
Mar 13, 2019

Conversation

yuki-stripe
Copy link
Collaborator

Summary

Add createPaymentMethod... method to STPAPIClient

Motivation

We're adding support for PaymentMethods!

Testing

Added a unit test for STPPaymentMethodParams
Added a functional test that exercises createPaymentMethod

Copy link

@ln-stripe ln-stripe left a comment

Choose a reason for hiding this comment

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

just one quesiton, ptal @yuki-stripe

Stripe/PublicHeaders/STPPaymentMethodParams.h Outdated Show resolved Hide resolved
Stripe/STPAPIClient.m Show resolved Hide resolved
@stripe-ci stripe-ci assigned yuki-stripe and unassigned ln-stripe Mar 8, 2019
@yuki-stripe yuki-stripe force-pushed the yuki-create-paymentmethod branch 3 times, most recently from 57b532f to 0531de0 Compare March 8, 2019 22:40
@yuki-stripe yuki-stripe force-pushed the yuki-create-paymentmethod branch from 8a1d6c0 to 07de690 Compare March 11, 2019 19:13
Copy link

@ln-stripe ln-stripe left a comment

Choose a reason for hiding this comment

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

ptal @yuki-stripe
mostly pretty good!

Stripe/PublicHeaders/STPAPIClient.h Outdated Show resolved Hide resolved
Stripe/PublicHeaders/STPAPIClient.h Outdated Show resolved Hide resolved
Tests/Tests/STPPaymentMethodFunctionalTest.m Show resolved Hide resolved
Tests/Tests/STPPaymentMethodFunctionalTest.m Show resolved Hide resolved
Tests/Tests/STPPaymentMethodFunctionalTest.m Outdated Show resolved Hide resolved
Copy link
Contributor

@danj-stripe danj-stripe left a comment

Choose a reason for hiding this comment

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

Looks good! Main change I'd like to see is copy for string properties + strong/assign for the others, and sharing the PaymentMethod type enum between STPPaymentMethod and STPPaymentMethodParams

I've got a couple other comments/suggestions, and a tip about changing the base branch to get CI to run (I'm assuming that it's pointed at the branch from #1140, but didn't actually verify that).

Stripe/PublicHeaders/STPPaymentMethodCardParams.h Outdated Show resolved Hide resolved
Stripe/PublicHeaders/STPPaymentMethodParams.h Outdated Show resolved Hide resolved
Stripe/PublicHeaders/STPPaymentMethodParams.h Outdated Show resolved Hide resolved
Stripe/STPAPIClient.m Outdated Show resolved Hide resolved
Stripe/STPPaymentMethodParams.m Outdated Show resolved Hide resolved
Tests/Tests/STPPaymentMethodFunctionalTest.m Show resolved Hide resolved
@yuki-stripe yuki-stripe changed the base branch from yuki-add-paymentmethod-models to master March 12, 2019 17:01
@yuki-stripe yuki-stripe requested a review from danj-stripe March 12, 2019 17:06
@yuki-stripe
Copy link
Collaborator Author

Should have addressed all the feedback, ptal @danj-stripe

Copy link
Contributor

@csabol-stripe csabol-stripe left a comment

Choose a reason for hiding this comment

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

Looks good! Only thing is omitting default property values of readwrite, strong, and assign

Stripe/PublicHeaders/STPPaymentMethodBillingDetails.h Outdated Show resolved Hide resolved
Stripe/PublicHeaders/STPPaymentMethodCardParams.h Outdated Show resolved Hide resolved
Stripe/PublicHeaders/STPPaymentMethodParams.h Outdated Show resolved Hide resolved
Stripe/STPPaymentMethod+Private.h Show resolved Hide resolved
Tests/Tests/STPPaymentMethodFunctionalTest.m Show resolved Hide resolved
Stripe/PublicHeaders/STPPaymentMethodEnums.h Outdated Show resolved Hide resolved
- (void)setType:(STPPaymentMethodType)type {
// If setting unknown and we're already unknown, don't want to override raw value
if (type != self.type) {
self.rawTypeString = [STPPaymentMethod stringFromType:type];
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like setting type = .unknown will set rawTypeString = nil, but rawTypeString is not nullable

Should it be nullable? Do we want to add an assert, that they never set type = .unknown? Something else?

(It looks like this bug also exists in STPSourceParams, which I know I said would be a good model... sorry! Can you update that class too?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Setting type = .unknown seems like user error to me, an assertion against that sounds ok.

Come to think of it, why is type publicly writable anyways?

Copy link
Contributor

Choose a reason for hiding this comment

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

Great question! I suspect if it was readonly, that'd work.

It's possible to create a SourcesParam using just alloc/init, and then manually setting any fields needed. The static constructors make it really easy to do the right thing for the common case, for all the various types.

The combination of the rawTypeString and additionalAPIParameters property allow full control over the Source/PaymentMethod being created, since we don't necessarily keep up with every possible change to available sources/paymentmethods.

Plausibly there's a use case for building a type that the SDK knows about, but one where the static constructor interferes, in which case being able to set the type using an enum might be nice. I think that's a sufficiently rare case that readonly is 👍. It'd be a breaking change on SourceParams, but I think that's probably fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Always a fan of more readonlys :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like the case described actually happens in the SDK already for STPSourceParams:

            STPSourceParams *params = [STPSourceParams new];
            params.type = STPSourceTypeCard;
            params.token = token.tokenId;

I'm thinking I'll make type readonly for STPPaymentMethodParams but add an assertion for STPSourceParams.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looking at the tests, it really seems we intended to accommodate setting this value to Unknown. e.g. one test does XCTAssertNil(sourceParams.rawTypeString);. I'm inclined now to instead mark rawTypeString as nullable on STPSourceParams.

- Make STPPaymentMethodParams' type property readonly
@yuki-stripe yuki-stripe requested a review from danj-stripe March 12, 2019 23:57
Copy link
Contributor

@danj-stripe danj-stripe left a comment

Choose a reason for hiding this comment

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

🎉 Looks good to me!

Stripe/STPPaymentMethod+Private.h Outdated Show resolved Hide resolved
@yuki-stripe yuki-stripe merged commit f369503 into master Mar 13, 2019
@yuki-stripe yuki-stripe deleted the yuki-create-paymentmethod branch May 29, 2019 14:29
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.

6 participants