From 9b0c1b01d6cba4b19d154cb7d12c851535c2edc7 Mon Sep 17 00:00:00 2001 From: David Estes Date: Thu, 12 Nov 2020 10:11:03 -0800 Subject: [PATCH 1/3] Fix STPPaymentIntentSetupFutureUsage, add test --- Stripe/STPPaymentIntentParams.swift | 16 +++++++++++++++- Tests/Tests/STPPaymentIntentFunctionalTest.m | 8 ++++++++ Tests/Tests/STPPaymentIntentParamsTest.swift | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Stripe/STPPaymentIntentParams.swift b/Stripe/STPPaymentIntentParams.swift index 32bc38eba23..d39a79944c7 100644 --- a/Stripe/STPPaymentIntentParams.swift +++ b/Stripe/STPPaymentIntentParams.swift @@ -72,7 +72,21 @@ public class STPPaymentIntentParams: NSObject { /// When provided, this property indicates how you intend to use the payment method that your customer provides after the current payment completes. /// If applicable, additional authentication may be performed to comply with regional legislation or network rules required to enable the usage of the same payment method for additional payments. /// - seealso: STPPaymentIntentSetupFutureUsage for more details on what values you can provide. - @objc public var setupFutureUsage: NSNumber? + public var setupFutureUsage: STPPaymentIntentSetupFutureUsage? + + /// When provided, this property indicates how you intend to use the payment method that your customer provides after the current payment completes. + /// If applicable, additional authentication may be performed to comply with regional legislation or network rules required to enable the usage of the same payment method for additional payments. + /// This property should only be used in Objective-C. In Swift, use `setupFutureUsage`. + /// - seealso: STPPaymentIntentSetupFutureUsage for more details on what values you can provide. + @available(swift, obsoleted: 1.0, renamed: "setupFutureUsage") + @objc(setupFutureUsage) public var setupFutureUsage_objc: NSNumber? { + get { + setupFutureUsage?.rawValue as NSNumber? + } + set { + setupFutureUsage = newValue.map { STPPaymentIntentSetupFutureUsage(rawValue: Int(truncating: $0)) } as? STPPaymentIntentSetupFutureUsage + } + } /// A boolean number to indicate whether you intend to use the Stripe SDK's functionality to handle any PaymentIntent next actions. /// If set to false, STPPaymentIntent.nextAction will only ever contain a redirect url that can be opened in a webview or mobile browser. diff --git a/Tests/Tests/STPPaymentIntentFunctionalTest.m b/Tests/Tests/STPPaymentIntentFunctionalTest.m index b155b98c294..47f25466160 100644 --- a/Tests/Tests/STPPaymentIntentFunctionalTest.m +++ b/Tests/Tests/STPPaymentIntentFunctionalTest.m @@ -917,6 +917,14 @@ - (void)testConfirmPaymentIntentWithPayPal { [self waitForExpectationsWithTimeout:STPTestingNetworkRequestTimeout handler:nil]; } +#pragma mark - Test Objective-C setupFutureUsage + +- (void)testObjectiveCSetupFutureUsage { + STPPaymentIntentParams *params = [[STPPaymentIntentParams alloc] init]; + params.setupFutureUsage = @(STPPaymentIntentSetupFutureUsageOnSession); + XCTAssertEqualObjects(params.setupFutureUsageRawString, @"on_session"); +} + #pragma mark - Helpers - (STPSourceParams *)cardSourceParams { diff --git a/Tests/Tests/STPPaymentIntentParamsTest.swift b/Tests/Tests/STPPaymentIntentParamsTest.swift index a2f6ccb504e..9c756200ca5 100644 --- a/Tests/Tests/STPPaymentIntentParamsTest.swift +++ b/Tests/Tests/STPPaymentIntentParamsTest.swift @@ -131,7 +131,7 @@ class STPPaymentIntentParamsTest: XCTestCase { params.paymentMethodId = "test_payment_method_id" params.savePaymentMethod = NSNumber(value: true) params.returnURL = "fake://testing_only" - params.setupFutureUsage = NSNumber(value: 1) + params.setupFutureUsage = STPPaymentIntentSetupFutureUsage(rawValue: Int(truncating: NSNumber(value: 1))) params.useStripeSDK = NSNumber(value: true) params.mandateData = STPMandateDataParams( customerAcceptance: STPMandateCustomerAcceptanceParams(type: .offline, onlineParams: nil)!) From 33efbcd8e638c32a1913b360071a5acdc571459c Mon Sep 17 00:00:00 2001 From: David Estes Date: Thu, 12 Nov 2020 10:14:13 -0800 Subject: [PATCH 2/3] Make test more explicit --- Tests/Tests/STPPaymentIntentParamsTest.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/Tests/STPPaymentIntentParamsTest.swift b/Tests/Tests/STPPaymentIntentParamsTest.swift index 9c756200ca5..c5275854636 100644 --- a/Tests/Tests/STPPaymentIntentParamsTest.swift +++ b/Tests/Tests/STPPaymentIntentParamsTest.swift @@ -151,6 +151,7 @@ class STPPaymentIntentParamsTest: XCTestCase { XCTAssertEqual(params.mandateData, paramsCopy.mandateData) XCTAssertEqual(params.shipping, paramsCopy.shipping) + XCTAssertEqual(params.setupFutureUsage, STPPaymentIntentSetupFutureUsage.none) XCTAssertEqual(params.savePaymentMethod, paramsCopy.savePaymentMethod) XCTAssertEqual(params.returnURL, paramsCopy.returnURL) XCTAssertEqual(params.useStripeSDK, paramsCopy.useStripeSDK) From 8747f114f023c1da29a168f1cac9787c2132703b Mon Sep 17 00:00:00 2001 From: David Estes Date: Thu, 12 Nov 2020 10:21:38 -0800 Subject: [PATCH 3/3] Update docstring --- Stripe/STPPaymentIntentParams.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Stripe/STPPaymentIntentParams.swift b/Stripe/STPPaymentIntentParams.swift index d39a79944c7..603dc2bc0dc 100644 --- a/Stripe/STPPaymentIntentParams.swift +++ b/Stripe/STPPaymentIntentParams.swift @@ -71,7 +71,6 @@ public class STPPaymentIntentParams: NSObject { /// When provided, this property indicates how you intend to use the payment method that your customer provides after the current payment completes. /// If applicable, additional authentication may be performed to comply with regional legislation or network rules required to enable the usage of the same payment method for additional payments. - /// - seealso: STPPaymentIntentSetupFutureUsage for more details on what values you can provide. public var setupFutureUsage: STPPaymentIntentSetupFutureUsage? /// When provided, this property indicates how you intend to use the payment method that your customer provides after the current payment completes.