-
Notifications
You must be signed in to change notification settings - Fork 996
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
New type of ephemeral keys #1131
Changes from all commits
067c02f
1e6ae5b
c506067
f502724
3f54ab1
dae2f88
2e7709c
8c345e1
3d6773d
fc048d2
38e5a16
69d2bbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,21 +16,20 @@ NS_ASSUME_NONNULL_BEGIN | |
|
||
/** | ||
You should make your application's API client conform to this interface. | ||
It provides a way for `STPCustomerContext` to request a new ephemeral key from | ||
your backend, which it will use to retrieve and update a Stripe customer. | ||
It provides a way for Stripe utility classes to request a new ephemeral key from | ||
your backend, which it will use to retrieve and update Stripe API objects. | ||
*/ | ||
@protocol STPEphemeralKeyProvider <NSObject> | ||
|
||
@protocol STPCustomerEphemeralKeyProvider <NSObject> | ||
/** | ||
Creates a new ephemeral key for retrieving and updating a Stripe customer. | ||
On your backend, you should create a new ephemeral key for the Stripe customer | ||
associated with your user, and return the raw JSON response from the Stripe API. | ||
For an example Ruby implementation of this API, refer to our example backend: | ||
https://github.com/stripe/example-ios-backend/blob/v14.0.0/web.rb | ||
|
||
Back in your iOS app, once you have a response from this API, call the provided | ||
completion block with the JSON response, or an error if one occurred. | ||
|
||
@param apiVersion The Stripe API version to use when creating a key. | ||
You should pass this parameter to your backend, and use it to set the API version | ||
in your key creation request. Passing this version parameter ensures that the | ||
|
@@ -40,7 +39,44 @@ NS_ASSUME_NONNULL_BEGIN | |
or `completion(nil, error)` if an error is returned. | ||
*/ | ||
- (void)createCustomerKeyWithAPIVersion:(NSString *)apiVersion completion:(STPJSONResponseCompletionBlock)completion; | ||
@end | ||
|
||
/** | ||
You should make your application's API client conform to this interface. | ||
It provides a way for Stripe utility classes to request a new ephemeral key from | ||
your backend, which it will use to retrieve and update Stripe API objects. | ||
*/ | ||
@protocol STPIssuingCardEphemeralKeyProvider <NSObject> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure these need to be two separate protocols. The documentation says that the API client should conform to both of these, which means checking for It's not totally clear to me how or why we intend to differentiate between creating customer and card ephemeral keys? Is the intention for the integrator to create two instances of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the way I imagined it, yes. You might imagine one API that calls The other alternative, as you suggest, is to make a single API - You raise a good point, though, that this breaks if someone's API client conforms to both protocols. Sadly, I think we'll need to add a property to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, what about adding a new method to Similarly, what are your thoughts about keeping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd prefer to keep a property on I don't feel as strongly about whether or not to split There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts @csabol-stripe? Can also discuss in slack on monday : ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. closing the loop: @jack-stripe and I met to discuss this today and we are happy moving forward with the patch as is :) |
||
/** | ||
Creates a new ephemeral key for retrieving and updating a Stripe Issuing Card. | ||
On your backend, you should create a new ephemeral key for your logged-in user's | ||
primary Issuing Card, and return the raw JSON response from the Stripe API. | ||
For an example Ruby implementation of this API, refer to our example backend: | ||
https://github.com/stripe/example-ios-backend/blob/v14.0.0/web.rb | ||
|
||
Back in your iOS app, once you have a response from this API, call the provided | ||
completion block with the JSON response, or an error if one occurred. | ||
|
||
@param apiVersion The Stripe API version to use when creating a key. | ||
You should pass this parameter to your backend, and use it to set the API version | ||
in your key creation request. Passing this version parameter ensures that the | ||
Stripe SDK can always parse the ephemeral key response from your server. | ||
@param completion Call this callback when you're done fetching a new ephemeral | ||
key from your backend. For example, `completion(json, nil)` (if your call succeeds) | ||
or `completion(nil, error)` if an error is returned. | ||
*/ | ||
- (void)createIssuingCardKeyWithAPIVersion:(NSString *)apiVersion completion:(STPJSONResponseCompletionBlock)completion; | ||
@end | ||
|
||
/** | ||
You should make your application's API client conform to this interface. | ||
It provides a way for Stripe utility classes to request a new ephemeral key from | ||
your backend, which it will use to retrieve and update Stripe API objects. | ||
@deprecated use `STPCustomerEphemeralKeyProvider` or `STPIssuingCardEphemeralKeyProvider` | ||
depending on the type of key that will be fetched. | ||
*/ | ||
__attribute__ ((deprecated("STPEphemeralKeyProvider has been renamed to STPCustomerEphemeralKeyProvider", "STPCustomerEphemeralKeyProvider"))) | ||
@protocol STPEphemeralKeyProvider <STPCustomerEphemeralKeyProvider> | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ @interface STPEphemeralKey () | |
@property (nonatomic, readwrite) BOOL livemode; | ||
@property (nonatomic, readwrite) NSString *secret; | ||
@property (nonatomic, readwrite) NSDate *expires; | ||
@property (nonatomic, readwrite) NSString *customerID; | ||
@property (nonatomic, readwrite, nullable) NSString *customerID; | ||
@property (nonatomic, readwrite, nullable) NSString *issuingCardID; | ||
@property (nonatomic, readwrite, nonnull, copy) NSDictionary *allResponseFields; | ||
|
||
@end | ||
|
@@ -40,19 +41,24 @@ + (instancetype)decodedObjectFromAPIResponse:(NSDictionary *)response { | |
} | ||
|
||
NSString *customerID; | ||
NSString *issuingCardID; | ||
for (id obj in associatedObjects) { | ||
if ([obj isKindOfClass:[NSDictionary class]]) { | ||
NSString *type = [obj stp_stringForKey:@"type"]; | ||
if ([type isEqualToString:@"customer"]) { | ||
customerID = [obj stp_stringForKey:@"id"]; | ||
} | ||
if ([type isEqualToString:@"issuing.card"]) { | ||
issuingCardID = [obj stp_stringForKey:@"id"]; | ||
} | ||
} | ||
} | ||
if (!customerID) { | ||
if (!customerID && !issuingCardID) { | ||
return nil; | ||
} | ||
STPEphemeralKey *key = [self new]; | ||
key.customerID = customerID; | ||
key.issuingCardID = issuingCardID; | ||
key.stripeID = stripeId; | ||
key.livemode = [dict stp_boolForKey:@"livemode" or:YES]; | ||
key.created = created; | ||
|
@@ -73,14 +79,11 @@ - (BOOL)isEqual:(id)object { | |
if (!object || ![object isKindOfClass:self.class]) { | ||
return NO; | ||
} | ||
return [self isEqualToResourceKey:object]; | ||
return [self isEqualToEphemeralKey:object]; | ||
} | ||
|
||
- (BOOL)isEqualToResourceKey:(STPEphemeralKey *)other { | ||
return [self.stripeID isEqualToString:other.stripeID] | ||
&& [self.secret isEqualToString:other.secret] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why were these removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah sorry, I mean why was it changed so it only compares the stripeIDs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping on this @jack-stripe ? (not going to block patch because id equivalence makes sense as sufficient to me but would be useful to know the reasoning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sorry, missed your comment @csabol-stripe! |
||
&& [self.expires isEqual:other.expires] | ||
&& [self.customerID isEqual:other.customerID]; | ||
- (BOOL)isEqualToEphemeralKey:(STPEphemeralKey *)other { | ||
return [self.stripeID isEqualToString:other.stripeID]; | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming this class means:
I don't think any of this is a blocker, just thinking through the user-facing consequences here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jack-stripe Just to make sure: is it in line with what you expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I safely deprecated
STPEphemeralKeyProvider
by changing it to subclassSTPCustomerEphemeralKeyProvider
- this would trigger a deprecation warning in existing integrations but not a compiler error. Yes, this will mean a docs update though.