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

Add dismiss to ApplePayContext #4470

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## X.Y.Z X-Y-Z
### ApplePay
* [Added] Added a `dismiss` method to `STPApplePayContext`.


## 24.4.0 2025-01-13
### PaymentSheet
* [Fixed] PaymentSheet using vertical payment method layout now defaults to Apple Pay when the customer doesn't have a default saved payment method.
20 changes: 20 additions & 0 deletions Stripe/StripeiOSTests/STPApplePayContextFunctionalTest.swift
Original file line number Diff line number Diff line change
@@ -188,6 +188,26 @@ class STPApplePayContextFunctionalTest: STPNetworkStubbingTestCase {
waitForExpectations(timeout: STPTestingNetworkRequestTimeout, handler: nil)
}

func testDismiss() {
// Dismissing before presenting...
context.dismiss()
// ...does nothing
XCTAssertNotNil(context.authorizationController)

// Dismissing after presentation...
context.presentApplePay()
context.dismiss()
// ...cleans up state
XCTAssertNil(context.authorizationController)
// ...and does not call the didComplete delegate method
let didCallCompletion = expectation(description: "applePayContext:didCompleteWithStatus: called")
didCallCompletion.isInverted = true
delegate?.didCompleteDelegateMethod = { _, _ in
didCallCompletion.fulfill()
}
waitForExpectations(timeout: 1)
}

// MARK: - Error tests

func testBadPaymentIntentClientSecretErrors() {
Original file line number Diff line number Diff line change
@@ -149,7 +149,7 @@ public class STPApplePayContext: NSObject, PKPaymentAuthorizationControllerDeleg
private var presentationWindow: UIWindow?

/// Presents the Apple Pay sheet from the key window, starting the payment process.
/// @note This method should only be called once; create a new instance of STPApplePayContext every time you present Apple Pay.
/// - Note: This method should only be called once; create a new instance of STPApplePayContext every time you present Apple Pay.
/// - Parameters:
/// - completion: Called after the Apple Pay sheet is presented
@available(iOSApplicationExtension, unavailable)
@@ -170,7 +170,7 @@ public class STPApplePayContext: NSObject, PKPaymentAuthorizationControllerDeleg
}

/// Presents the Apple Pay sheet from the specified window, starting the payment process.
/// @note This method should only be called once; create a new instance of STPApplePayContext every time you present Apple Pay.
/// - Note: This method should only be called once; create a new instance of STPApplePayContext every time you present Apple Pay.
/// - Parameters:
/// - window: The UIWindow to host the Apple Pay sheet
/// - completion: Called after the Apple Pay sheet is presented
@@ -223,6 +223,23 @@ public class STPApplePayContext: NSObject, PKPaymentAuthorizationControllerDeleg
presentApplePay(from: window, completion: completion)
}

/// Dismisses the Apple Pay sheet.
/// - Parameter completion: Called after the Apple Pay sheet is dismissed.
/// - Note: Does not call the `applePayContext:didCompleteWithStatus:` delegate method.
/// - Note: You must create a new instance of ApplePayContext after using this method.
@objc(dismissWithCompletion:)
public func dismiss(completion: STPVoidBlock? = nil) {
guard didPresentApplePay else {
return
}
authorizationController?.dismiss {
stpDispatchToMainThreadIfNecessary {
completion?()
self._end()
}
}
}

/// The API Client to use to make requests.
/// Defaults to `STPAPIClient.shared`
@objc public var apiClient: STPAPIClient = STPAPIClient.shared