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

Update PaymentIntents support #1038

Merged
merged 16 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Changes to the object returned by `STPPaymentCardTextField.cardParams` no longer mutate the object held by the `STPPaymentCardTextField`
* This is a breaking change for code like: `paymentCardTextField.cardParams.name = @"Jane Doe";`
* `STPPaymentIntentParams.returnUrl` has been renamed to `STPPaymentIntentParams.returnURL`. Xcode should offer a deprecation warning & fix-it to help you migrate.
* `STPPaymentIntent.returnUrl` has been removed, because it's no longer a property of the PaymentIntent. When the PaymentIntent status is `.requiresSourceAction`, and the `nextSourceAction.type` is `.authorizeWithURL`, you can find the return URL at `nextSourceAction.authorizeWithURL.returnURL`.

### Migrating from versions < 13.1.0
* The SDK now supports PaymentIntents with `STPPaymentIntent`, which use `STPRedirectContext` in the same way that `STPSource` does
Expand Down
28 changes: 28 additions & 0 deletions Stripe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,15 @@
B3302F4C200700AB005DDBE9 /* STPLegalEntityParamsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B3302F4B200700AB005DDBE9 /* STPLegalEntityParamsTest.m */; };
B347DD481FE35423006B3BAC /* STPValidatedTextField.h in Headers */ = {isa = PBXBuildFile; fileRef = B347DD461FE35423006B3BAC /* STPValidatedTextField.h */; };
B347DD491FE35423006B3BAC /* STPValidatedTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = B347DD471FE35423006B3BAC /* STPValidatedTextField.m */; };
B36C6D6D2193671400D17575 /* STPPaymentIntentSourceAction.h in Headers */ = {isa = PBXBuildFile; fileRef = B36C6D6B2193671400D17575 /* STPPaymentIntentSourceAction.h */; settings = {ATTRIBUTES = (Public, ); }; };
B36C6D6E2193671400D17575 /* STPPaymentIntentSourceAction.h in Headers */ = {isa = PBXBuildFile; fileRef = B36C6D6B2193671400D17575 /* STPPaymentIntentSourceAction.h */; settings = {ATTRIBUTES = (Public, ); }; };
B36C6D6F2193671400D17575 /* STPPaymentIntentSourceAction.m in Sources */ = {isa = PBXBuildFile; fileRef = B36C6D6C2193671400D17575 /* STPPaymentIntentSourceAction.m */; };
B36C6D702193671400D17575 /* STPPaymentIntentSourceAction.m in Sources */ = {isa = PBXBuildFile; fileRef = B36C6D6C2193671400D17575 /* STPPaymentIntentSourceAction.m */; };
B36C6D732193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.h in Headers */ = {isa = PBXBuildFile; fileRef = B36C6D712193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.h */; settings = {ATTRIBUTES = (Public, ); }; };
B36C6D742193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.h in Headers */ = {isa = PBXBuildFile; fileRef = B36C6D712193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.h */; settings = {ATTRIBUTES = (Public, ); }; };
B36C6D752193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.m in Sources */ = {isa = PBXBuildFile; fileRef = B36C6D722193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.m */; };
B36C6D762193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.m in Sources */ = {isa = PBXBuildFile; fileRef = B36C6D722193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.m */; };
B36C6D782193A16F00D17575 /* STPPaymentIntentSourceActionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B36C6D772193A16F00D17575 /* STPPaymentIntentSourceActionTest.m */; };
B382D6611FE8BEA0009B56AB /* STPValidatedTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = B347DD471FE35423006B3BAC /* STPValidatedTextField.m */; };
B3A241391FFEB57400A2F00D /* STPConnectAccountParams.h in Headers */ = {isa = PBXBuildFile; fileRef = B3A241371FFEB57400A2F00D /* STPConnectAccountParams.h */; settings = {ATTRIBUTES = (Public, ); }; };
B3A2413A1FFEB57400A2F00D /* STPConnectAccountParams.h in Headers */ = {isa = PBXBuildFile; fileRef = B3A241371FFEB57400A2F00D /* STPConnectAccountParams.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -1101,6 +1110,11 @@
B3302F4B200700AB005DDBE9 /* STPLegalEntityParamsTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = STPLegalEntityParamsTest.m; sourceTree = "<group>"; };
B347DD461FE35423006B3BAC /* STPValidatedTextField.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = STPValidatedTextField.h; sourceTree = "<group>"; };
B347DD471FE35423006B3BAC /* STPValidatedTextField.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = STPValidatedTextField.m; sourceTree = "<group>"; };
B36C6D6B2193671400D17575 /* STPPaymentIntentSourceAction.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = STPPaymentIntentSourceAction.h; path = PublicHeaders/STPPaymentIntentSourceAction.h; sourceTree = "<group>"; };
B36C6D6C2193671400D17575 /* STPPaymentIntentSourceAction.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = STPPaymentIntentSourceAction.m; sourceTree = "<group>"; };
B36C6D712193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = STPPaymentIntentSourceActionAuthorizeWithURL.h; path = PublicHeaders/STPPaymentIntentSourceActionAuthorizeWithURL.h; sourceTree = "<group>"; };
B36C6D722193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = STPPaymentIntentSourceActionAuthorizeWithURL.m; sourceTree = "<group>"; };
B36C6D772193A16F00D17575 /* STPPaymentIntentSourceActionTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = STPPaymentIntentSourceActionTest.m; sourceTree = "<group>"; };
B3A241371FFEB57400A2F00D /* STPConnectAccountParams.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = STPConnectAccountParams.h; path = PublicHeaders/STPConnectAccountParams.h; sourceTree = "<group>"; };
B3A241381FFEB57400A2F00D /* STPConnectAccountParams.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = STPConnectAccountParams.m; sourceTree = "<group>"; };
B3A99BC11FEAF2CA003F6ED3 /* STPLegalEntityParams.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = STPLegalEntityParams.h; path = PublicHeaders/STPLegalEntityParams.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1695,6 +1709,7 @@
8B013C881F1E784A00DD831B /* STPPaymentConfigurationTest.m */,
F14C872E1D4FCDBA00C7CC6A /* STPPaymentContextApplePayTest.m */,
B3BDCAD020EEF5B90034F7F5 /* STPPaymentIntentParamsTest.m */,
B36C6D772193A16F00D17575 /* STPPaymentIntentSourceActionTest.m */,
B3BDCACC20EEF4540034F7F5 /* STPPaymentIntentTest.m */,
F1DE87FF1F8D410D00602F4C /* STPPaymentMethodsViewControllerTest.m */,
C1EEDCC91CA2186300A54582 /* STPPhoneNumberValidatorTest.m */,
Expand Down Expand Up @@ -2041,6 +2056,10 @@
B3BDCAC720EEF22D0034F7F5 /* STPPaymentIntentEnums.h */,
B3BDCAD520EEF5EC0034F7F5 /* STPPaymentIntentParams.h */,
B3BDCAD220EEF5E00034F7F5 /* STPPaymentIntentParams.m */,
B36C6D6B2193671400D17575 /* STPPaymentIntentSourceAction.h */,
B36C6D6C2193671400D17575 /* STPPaymentIntentSourceAction.m */,
B36C6D712193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.h */,
B36C6D722193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.m */,
C1D7B51E1E36C32F002181F5 /* STPSource.h */,
C1D7B51F1E36C32F002181F5 /* STPSource.m */,
F19491DD1E5F6B8C001E1FC2 /* STPSourceCardDetails.h */,
Expand Down Expand Up @@ -2198,6 +2217,7 @@
04F94DAB1D229F3F004FC826 /* UIBarButtonItem+Stripe.h in Headers */,
04F94DC91D22A20A004FC826 /* STPSwitchTableViewCell.h in Headers */,
0433EB4B1BD06313003912B4 /* NSDictionary+Stripe.h in Headers */,
B36C6D6E2193671400D17575 /* STPPaymentIntentSourceAction.h in Headers */,
04F94DCB1D22A229004FC826 /* UIView+Stripe_FirstResponder.h in Headers */,
04F94DD11D22A239004FC826 /* STPPromise.h in Headers */,
C1BD9B351E3940C400CEE925 /* STPSourceVerification.h in Headers */,
Expand Down Expand Up @@ -2231,6 +2251,7 @@
C124A17D1CCAA0C2007D42EE /* NSMutableURLRequest+Stripe.h in Headers */,
F1FA6F991E25970F00EB444D /* STPCoreTableViewController+Private.h in Headers */,
C1BD9B2F1E3940A200CEE925 /* STPSourceRedirect.h in Headers */,
B36C6D742193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.h in Headers */,
8B429AD91EF9D4B500F95F34 /* STPBankAccountParams+Private.h in Headers */,
F1BEB2FE1F3508BB0043F48C /* NSError+Stripe.h in Headers */,
04E32AA01B7A9490009C9E35 /* STPPaymentCardTextField.h in Headers */,
Expand Down Expand Up @@ -2317,6 +2338,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
B36C6D732193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.h in Headers */,
C15993361D8808680047950D /* STPShippingMethodsViewController.h in Headers */,
F1A2F92C1EEB6A70006B0456 /* NSCharacterSet+Stripe.h in Headers */,
F1D3A24E1EB012010095BFA9 /* STPMultipartFormDataPart.h in Headers */,
Expand Down Expand Up @@ -2399,6 +2421,7 @@
0426B9721CEAE3EB006AC8DD /* UITableViewCell+Stripe_Borders.h in Headers */,
04CDE5C91BC20B1D00548833 /* STPBankAccountParams.h in Headers */,
049A3F891CC73C7100F57DE7 /* STPPaymentContext.h in Headers */,
B36C6D6D2193671400D17575 /* STPPaymentIntentSourceAction.h in Headers */,
04E39F541CECF7A100AF3B96 /* STPPaymentMethodTuple.h in Headers */,
F15232241EA9303800D65C67 /* STPURLCallbackHandler.h in Headers */,
C18410761EC2529400178149 /* STPEphemeralKeyManager.h in Headers */,
Expand Down Expand Up @@ -2928,6 +2951,7 @@
C1EF044D1DD2397500FBF452 /* STPShippingAddressViewControllerLocalizationTests.m in Sources */,
C1080F4C1CBED48A007B2D89 /* STPAddressTests.m in Sources */,
C1C02CCE1ECCE92900DF5643 /* STPEphemeralKeyTest.m in Sources */,
B36C6D782193A16F00D17575 /* STPPaymentIntentSourceActionTest.m in Sources */,
C14C4DB11EC3B34500C2FDF6 /* STPAPIRequestTest.m in Sources */,
F1D96F9B1DC7DCDE00477E64 /* STPLocalizationUtils+STPTestAdditions.m in Sources */,
04415C6F1A6605B5001225ED /* STPCertTest.m in Sources */,
Expand All @@ -2944,6 +2968,7 @@
0438EF451B74170D00D506CC /* STPCardValidator.m in Sources */,
04F94DBB1D229F8D004FC826 /* PKPaymentAuthorizationViewController+Stripe_Blocks.m in Sources */,
C1271A3E1E3FA4E800F25DFE /* STPSectionHeaderView.m in Sources */,
B36C6D702193671400D17575 /* STPPaymentIntentSourceAction.m in Sources */,
F12829DD1D7747E4008B10D6 /* STPBundleLocator.m in Sources */,
04F94DA91D229F32004FC826 /* STPPaymentMethodTuple.m in Sources */,
C15608E01FE08F2E0032AE66 /* UIView+Stripe_SafeAreaBounds.m in Sources */,
Expand Down Expand Up @@ -2994,6 +3019,7 @@
C159933A1D8808880047950D /* STPShippingAddressViewController.m in Sources */,
04F94DA41D229F1C004FC826 /* STPAddressViewModel.m in Sources */,
049880FF1CED5A2300EA4FFD /* STPPaymentConfiguration.m in Sources */,
B36C6D762193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.m in Sources */,
B3A99BC61FEAF2CA003F6ED3 /* STPLegalEntityParams.m in Sources */,
C180211D1E3A58710089D712 /* STPSourcePoller.m in Sources */,
04F94DB91D229F86004FC826 /* STPApplePayPaymentMethod.m in Sources */,
Expand Down Expand Up @@ -3075,6 +3101,7 @@
04CDB5101A5F30A700B854EE /* STPCard.m in Sources */,
04CDB5001A5F30A700B854EE /* STPAPIClient.m in Sources */,
C18410781EC2529400178149 /* STPEphemeralKeyManager.m in Sources */,
B36C6D6F2193671400D17575 /* STPPaymentIntentSourceAction.m in Sources */,
04CDB50C1A5F30A700B854EE /* STPBankAccount.m in Sources */,
049A3F7F1CC1920A00F57DE7 /* UIViewController+Stripe_KeyboardAvoiding.m in Sources */,
04F416271CA3639500486FB5 /* STPAddCardViewController.m in Sources */,
Expand Down Expand Up @@ -3147,6 +3174,7 @@
049A3F961CC75B2E00F57DE7 /* STPPromise.m in Sources */,
B3BDCAD320EEF5E10034F7F5 /* STPPaymentIntentParams.m in Sources */,
04695AD41C77F9DB00E08063 /* NSString+Stripe.m in Sources */,
B36C6D752193676600D17575 /* STPPaymentIntentSourceActionAuthorizeWithURL.m in Sources */,
F15232261EA9303800D65C67 /* STPURLCallbackHandler.m in Sources */,
F1BEB2FF1F3508BB0043F48C /* NSError+Stripe.m in Sources */,
049952D01BCF13510088C703 /* STPAPIRequest.m in Sources */,
Expand Down
15 changes: 7 additions & 8 deletions Stripe/PublicHeaders/STPPaymentIntent.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

NS_ASSUME_NONNULL_BEGIN

@class STPPaymentIntentSourceAction;

/**
A PaymentIntent tracks the process of collecting a payment from your customer.

Expand Down Expand Up @@ -79,18 +81,15 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) BOOL livemode;

/**
Email address that the receipt for the resulting payment will be sent to.
If `status == STPPaymentIntentStatusRequiresSourceAction`, this
property contains the next action to take for this PaymentIntent.
*/
@property (nonatomic, nullable, readonly) NSString *receiptEmail;
@property (nonatomic, nullable, readonly) STPPaymentIntentSourceAction* nextSourceAction;

/**
The URL to redirect your customer back to after they authenticate or cancel their
payment on the payment method’s app or site.

This should be a URL that your app handles if the PaymentIntent is going to
be confirmed in your app, and it has a redirect authorization flow.
Email address that the receipt for the resulting payment will be sent to.
*/
@property (nonatomic, nullable, readonly) NSURL *returnUrl;
@property (nonatomic, nullable, readonly) NSString *receiptEmail;

/**
The Stripe ID of the Source used in this PaymentIntent.
Expand Down
20 changes: 20 additions & 0 deletions Stripe/PublicHeaders/STPPaymentIntentEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,23 @@ typedef NS_ENUM(NSInteger, STPPaymentIntentConfirmationMethod) {
*/
STPPaymentIntentConfirmationMethodSecret,
};

/**
Types of Source Actions from a `STPPaymentIntent`, when the payment intent
status is `STPPaymentIntentStatusRequiresSourceAction`.
*/
typedef NS_ENUM(NSUInteger, STPPaymentIntentSourceActionType) {
/**
This is an unknown source action, that's been added since the SDK
was last updated.
Update your SDK, or use the `nextSourceAction.allResponseFields`
for custom handling.
*/
STPPaymentIntentSourceActionTypeUnknown,

/**
The payment intent needs to be authorized by the user. We provide
`STPRedirectContext` to handle the url redirections necessary.
*/
STPPaymentIntentSourceActionTypeAuthorizeWithURL,
};
44 changes: 44 additions & 0 deletions Stripe/PublicHeaders/STPPaymentIntentSourceAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// STPPaymentIntentSourceAction.h
// Stripe
//
// Created by Daniel Jackson on 11/7/18.
// Copyright © 2018 Stripe, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "STPAPIResponseDecodable.h"
#import "STPPaymentIntentEnums.h"

NS_ASSUME_NONNULL_BEGIN

@class STPPaymentIntentSourceActionAuthorizeWithURL;

/**
Source Action details for an STPPaymentIntent. This is a container for
the various types that are available. Check the `type` to see which one
it is, and then use the related property for the details necessary to handle
it.
*/
@interface STPPaymentIntentSourceAction: NSObject<STPAPIResponseDecodable>

/**
You cannot directly instantiate an `STPPaymentIntentSourceAction`.
*/
- (instancetype)init __attribute__((unavailable("You cannot directly instantiate an STPPaymentIntentSourceAction.")));

/**
The type of source action needed. The value of this field determines which
property of this object contains further details about the action.
*/
@property (nonatomic, readonly) STPPaymentIntentSourceActionType type;

/**
The details for authorizing via URL, when `type == STPPaymentIntentSourceActionTypeAuthorizeWithURL`
*/
@property (nonatomic, nullable, readonly) STPPaymentIntentSourceActionAuthorizeWithURL* authorizeWithURL;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// STPPaymentIntentSourceActionAuthorizeWithURL.h
// Stripe
//
// Created by Daniel Jackson on 11/7/18.
// Copyright © 2018 Stripe, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "STPAPIResponseDecodable.h"

NS_ASSUME_NONNULL_BEGIN

/**
The `STPPaymentIntentSourceAction` details when type is `STPPaymentIntentSourceActionTypeAuthorizeWithURL`.

These are created & owned by the containing `STPPaymentIntent`.
*/
@interface STPPaymentIntentSourceActionAuthorizeWithURL: NSObject<STPAPIResponseDecodable>
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of renaming this something like STPPaymentIntentSourceActionURLAuthorizationData? AuthorizeWithURL is a bit confusing to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I figured consistency with the API (where this shows up as authorize_with_url, plus the other stripe SDKs (which use essentially the same thing), was a good reason to go with this monstrosity of a name. It's my hope that users of the library never actually really interact with this class - I suspect they'll just access it's fields through the STPPaymentIntent object

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense


/**
You cannot directly instantiate an `STPPaymentIntentSourceActionAuthorizeWithURL`.
*/
- (instancetype)init __attribute__((unavailable("You cannot directly instantiate an STPPaymentIntentSourceActionAuthorizeWithURL.")));

/**
The URL where the user will authorize this charge.
*/
@property (nonatomic, readonly) NSURL *url;

/**
The return URL that'll be redirected back to when the user is done
authorizing the charge.
*/
@property (nonatomic, nullable, readonly) NSURL *returnURL;

@end

NS_ASSUME_NONNULL_END
2 changes: 2 additions & 0 deletions Stripe/PublicHeaders/Stripe.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#import "STPPaymentIntent.h"
#import "STPPaymentIntentEnums.h"
#import "STPPaymentIntentParams.h"
#import "STPPaymentIntentSourceAction.h"
#import "STPPaymentIntentSourceActionAuthorizeWithURL.h"
#import "STPPaymentMethod.h"
#import "STPPaymentMethodsViewController.h"
#import "STPPaymentResult.h"
Expand Down
16 changes: 16 additions & 0 deletions Stripe/STPPaymentIntent+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (STPPaymentIntentConfirmationMethod)confirmationMethodFromString:(NSString *)string;

/**
Parse the string and return the correct `STPPaymentIntentSourceActionType`,
or `STPPaymentIntentSourceActionTypeUnknown` if it's unrecognized by this version of the SDK.

@param string the NSString with the `next_source_action.type`
*/
+ (STPPaymentIntentSourceActionType)sourceActionTypeFromString:(NSString *)string;

/**
Return the string representing the provided `STPPaymentIntentSourceActionType`.

@param sourceActionType the enum value to convert to a string
@return the string, or @"unknown" if this was an unrecognized type
*/
+ (NSString *)stringFromSourceActionType:(STPPaymentIntentSourceActionType)sourceActionType;

@end

NS_ASSUME_NONNULL_END
Loading