-
Notifications
You must be signed in to change notification settings - Fork 997
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 STPPaymentIntent, and method to retrieve from the API given a clientSecret #985
Changes from 5 commits
1ed8e33
d03a0d4
2328380
96a3628
de5ce3c
628cb5e
532e9be
6136e70
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 |
---|---|---|
|
@@ -320,6 +320,23 @@ static NSString *const STPSDKVersion = @"13.0.3"; | |
|
||
@end | ||
|
||
#pragma mark Payment Intents | ||
|
||
/** | ||
Stripe extensions for working with PaymentIntent objects. | ||
*/ | ||
@interface STPAPIClient (PaymentIntents) | ||
|
||
/** | ||
Retrieves the PaymentIntent object using the given secret. @see https://stripe.com/docs/api#retrieve_payment_intent | ||
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. This link isn't working for me. Is it going to be soon? 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. found it :) |
||
|
||
@param secret The client secret of the payment intent to be retrieved. Cannot be nil. | ||
@param completion The callback to run with the returned PaymentIntent object, or an error. | ||
*/ | ||
- (void)retrievePaymentIntentWithClientSecret:(NSString *)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. I'm wondering if there's less ambiguous vocabulary we can use so it's not confused with Stripe client secret? Or is it? 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. looks like the rest of our documentation uses this ambiguous vocabulary so nevermind :) 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. if we're confident it's not going to change, maybe we can mention it starts with 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 still not sure what the right level of client-side protection is, vs encoding specifics about the current state of things. |
||
completion:(STPPaymentIntentCompletionBlock)completion; | ||
@end | ||
|
||
#pragma mark URL callbacks | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
@class STPSource; | ||
@class STPCustomer; | ||
@protocol STPSourceProtocol; | ||
@class STPPaymentIntent; | ||
|
||
/** | ||
These values control the labels used in the shipping info collection form. | ||
|
@@ -106,6 +107,14 @@ typedef void (^STPSourceCompletionBlock)(STPSource * __nullable source, NSError | |
*/ | ||
typedef void (^STPSourceProtocolCompletionBlock)(id<STPSourceProtocol> __nullable source, NSError * __nullable error); | ||
|
||
/** | ||
A callback to be run with a PaymentIntent response from the Stripe API. | ||
|
||
@param paymentIntent The Stripe PaymentIntent from the response. Will be nil if an error occurs. @see STPPaymentIntent | ||
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. do we need to specifically say 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. IDK? I was following the pattern of every other callback here. I think this is reasonable, because it's saying "see |
||
@param error The error returned from the response, or nil in one occurs. @see StripeError.h for possible values. | ||
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. if* none* occurs looks like similar typos elsewhere in this file |
||
*/ | ||
typedef void (^STPPaymentIntentCompletionBlock)(STPPaymentIntent * __nullable paymentIntent, NSError * __nullable error); | ||
|
||
/** | ||
A callback to be run with a validation result and shipping methods for a | ||
shipping address. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// | ||
// STPPaymentIntent.h | ||
// Stripe | ||
// | ||
// Created by Daniel Jackson on 6/27/18. | ||
// Copyright © 2018 Stripe, Inc. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "STPAPIResponseDecodable.h" | ||
#import "STPPaymentIntentEnums.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
A PaymentIntent tracks the process of collecting a payment from your customer. | ||
|
||
@see https://stripe.com/docs/api#payment_intents | ||
@see https://stripe.com/docs/payments/dynamic-authentication | ||
*/ | ||
@interface STPPaymentIntent : NSObject<STPAPIResponseDecodable> | ||
|
||
/** | ||
You cannot directly instantiate an `STPPaymentIntent`. You should only use one that | ||
has been returned from an `STPAPIClient` callback. | ||
*/ | ||
- (instancetype)init __attribute__((unavailable("You cannot directly instantiate an STPPaymentIntent. You should only use one that has been returned from an STPAPIClient callback."))); | ||
|
||
/** | ||
The Stripe ID of the PaymentIntent. | ||
*/ | ||
@property (nonatomic, readonly) NSString *stripeId; | ||
|
||
/** | ||
The client secret used to fetch this PaymentIntent | ||
*/ | ||
@property (nonatomic, readonly) NSString *clientSecret; | ||
|
||
/** | ||
The amount associated with the PaymentIntent | ||
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. Our doc has a better sounding description to me: "Amount intended to be collected by this PaymentIntent." |
||
*/ | ||
@property (nonatomic, readonly) NSNumber *amount; | ||
|
||
/** | ||
If status is canceled, when the PaymentIntent was canceled. | ||
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. "If status is STPPaymentIntentStatusCanceled, when the PaymentIntent was canceled."? |
||
*/ | ||
@property (nonatomic, nullable, readonly) NSDate *canceledAt; | ||
|
||
/** | ||
Capture method of this PaymentIntent | ||
*/ | ||
@property (nonatomic, readonly) STPPaymentIntentCaptureMethod captureMethod; | ||
|
||
/** | ||
Confirmation method of this PaymentIntent | ||
*/ | ||
@property (nonatomic, readonly) STPPaymentIntentConfirmationMethod confirmationMethod; | ||
|
||
/** | ||
When the PaymentIntent was created. | ||
*/ | ||
@property (nonatomic, nullable, readonly) NSDate *created; | ||
|
||
/** | ||
The currency associated with the PaymentIntent. | ||
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. Our docs nicely mention it's the ISO currency code, I wonder if we mention that elsewhere we reference "Three-letter ISO currency code, in lowercase. Must be a supported currency." https://www.iso.org/iso-4217-currency-codes.html 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. It looks mixed. Most headers that have a I think it's reasonable to elide this |
||
*/ | ||
@property (nonatomic, readonly) NSString *currency; | ||
|
||
/** | ||
The `description` field of the PaymentIntent. | ||
An arbitrary string attached to the object. Often useful for displaying to users. | ||
*/ | ||
@property (nonatomic, nullable, readonly) NSString *stripeDescription; | ||
|
||
/** | ||
Whether or not this PaymentIntent was created in livemode. | ||
*/ | ||
@property (nonatomic, readonly) BOOL livemode; | ||
|
||
/** | ||
Email address that the receipt for the resulting payment will be sent to. | ||
*/ | ||
@property (nonatomic, nullable, readonly) NSString *receiptEmail; | ||
|
||
/** | ||
The Stripe ID of the Source used in this PaymentIntent. | ||
*/ | ||
@property (nonatomic, nullable, readonly) NSString *sourceId; | ||
|
||
/** | ||
Status of the PaymentIntent | ||
*/ | ||
@property (nonatomic, readonly) STPPaymentIntentStatus status; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// | ||
// STPPaymentIntentEnums.h | ||
// Stripe | ||
// | ||
// Created by Daniel Jackson on 6/27/18. | ||
// Copyright © 2018 Stripe, Inc. All rights reserved. | ||
// | ||
|
||
/** | ||
Status types for an STPPaymentIntent | ||
*/ | ||
typedef NS_ENUM(NSInteger, STPPaymentIntentStatus) { | ||
/** | ||
Unknown status | ||
*/ | ||
STPPaymentIntentStatusUnknown, | ||
|
||
/** | ||
This PaymentIntent requires a Source | ||
*/ | ||
STPPaymentIntentStatusRequiresSource, | ||
|
||
/** | ||
This PaymentIntent needs to be confirmed | ||
*/ | ||
STPPaymentIntentStatusRequiresConfirmation, | ||
|
||
/** | ||
The selected Source requires additional authentication steps. | ||
Additional actions found via `next_source_action` | ||
*/ | ||
STPPaymentIntentStatusRequiresSourceAction, | ||
|
||
/** | ||
Stripe is processing this PaymentIntent | ||
*/ | ||
STPPaymentIntentStatusProcessing, | ||
|
||
/** | ||
The payment has succeeded | ||
*/ | ||
STPPaymentIntentStatusSucceeded, | ||
|
||
/** | ||
Indicates the payment must be captured, for STPPaymentIntentCaptureMethodManual | ||
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. "Indicates the payment must be captured. The 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 guess what you have is fine, I'm just wondering what's the intention behind having a separate 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.
|
||
*/ | ||
STPPaymentIntentStatusRequiresCapture, | ||
|
||
/** | ||
This PaymentIntent was canceled and cannot be changed. | ||
*/ | ||
STPPaymentIntentStatusCanceled, | ||
}; | ||
|
||
/** | ||
Capture methods for a STPPaymentIntent | ||
*/ | ||
typedef NS_ENUM(NSInteger, STPPaymentIntentCaptureMethod) { | ||
/** | ||
Unknown capture method | ||
*/ | ||
STPPaymentIntentCaptureMethodUnknown, | ||
|
||
/** | ||
The PaymentIntent will be automatically captured | ||
*/ | ||
STPPaymentIntentCaptureMethodAutomatic, | ||
|
||
/** | ||
The PaymentIntent must be manually captured once it has the status | ||
`STPPaymentIntentStatusRequiresCapture` | ||
*/ | ||
STPPaymentIntentCaptureMethodManual, | ||
}; | ||
|
||
/** | ||
Confirmation methods for a STPPaymentIntent | ||
*/ | ||
typedef NS_ENUM(NSInteger, STPPaymentIntentConfirmationMethod) { | ||
/** | ||
Unknown confirmation method | ||
*/ | ||
STPPaymentIntentConfirmationMethodUnknown, | ||
|
||
/** | ||
Confirmed via publishable key | ||
*/ | ||
STPPaymentIntentConfirmationMethodPublishable, | ||
|
||
/** | ||
Confirmed via secret key | ||
*/ | ||
STPPaymentIntentConfirmationMethodSecret, | ||
}; |
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.
Looks like the docs for the other extension interface definitions in this file say "STPAPIClient extensions..."
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.
There's actually a mix of extensions on
STPAPIClient
and onStripe
, which I didn't realize at first. Great catch, thanks!