Skip to content

Commit

Permalink
Merge pull request #14 from stripe-ios/davidme/fix-STPPaymentIntentSe…
Browse files Browse the repository at this point in the history
…tupFutureUsage

Fix STPPaymentIntentSetupFutureUsage, add test
  • Loading branch information
yuki-stripe authored Nov 14, 2020
2 parents a05b307 + 8747f11 commit 872e49a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
15 changes: 14 additions & 1 deletion Stripe/STPPaymentIntentParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,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.
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.
@objc public var setupFutureUsage: NSNumber?
@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.
Expand Down
8 changes: 8 additions & 0 deletions Tests/Tests/STPPaymentIntentFunctionalTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion Tests/Tests/STPPaymentIntentParamsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)!)
Expand All @@ -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)
Expand Down

0 comments on commit 872e49a

Please sign in to comment.