#rowester_code
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1270920418794147892
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there, is this is the method that you refer to https://stripe.dev/stripe-ios/stripepayments/documentation/stripepayments/stpauthenticationcontext/authenticationcontextwilldismiss(_:) ?
Yes that's the one
Can you share with me the relevant code?
Are you using the latest version of stripe ios SDK? https://github.com/stripe/stripe-ios/blob/master/CHANGELOG.md#23290-2024-08-05
class AddCreditCardHostingController:
UIHostingController<AddCreditCardView<DefaultAddCreditCardViewModel>>,
STPAuthenticationContext
{
...
// MARK: - Conformance: STPAuthenticationContext
func prepare(forPresentation completion: @escaping STPVoidBlock) {
loadingDelegate?.setLoadingIndicatorState(.hidden, in: self)
DispatchQueue.main.async {
completion()
}
}
func authenticationPresentingViewController() -> UIViewController {
return self
}
func authenticationContextWillDismiss(_ viewController: UIViewController) {
loadingDelegate?.setLoadingIndicatorState(.loading(), in: self)
}
Yep, using the latest version. I've tried with a UIViewController and UIHostingController but have had no luck
Ok, and how do you pass AddCreditCardHostingController to Stripe SDK?
I think it's via the STPAuthenticationContext protocol, we then provide this to the SDK via:
STPPaymentHandler.shared().confirmSetupIntent(
intentParameters,
with: inputDetails.authenticationContext
) {
Can you put some logs in your code to confirm inputDetails.authenticationContext is an instance of AddCreditCardHostingController ?
if let hostingController = inputDetails.authenticationContext as? AddCreditCardHostingController {
// This is hit
print("Is hosting controller")
}
STPPaymentHandler.shared().confirmSetupIntent(
intentParameters,
with: inputDetails.authenticationContext
) { status, intent, _ in
...
}
I added a check to ensure the context was the hosting controller, the print statement seems to be hit
OK, do you have any code that might change the value of inputDetails.authenticationContext ?
No, I don't think so, we provide the context straight to the SDK when we attempt to link a credit card funding source.
I mean any code that might change the value of inputDetails.authenticationContext after calling STPPaymentHandler.shared().confirmSetupIntent ?
No, not that I can see. This is our implementation:
func authorizePaymentMethod() async throws -> String {
guard let inputDetails, let intentParameters else {
throw FundingSourceServiceError.invalidConfig
}
let setupIntent: STPSetupIntent = try await withCheckedThrowingContinuation { continuation in
DispatchQueue.main.async {
STPPaymentHandler.shared().confirmSetupIntent(
intentParameters,
with: inputDetails.authenticationContext
) { status, intent, _ in
switch status {
case .succeeded:
guard let intent = intent else {
let error = FundingSourceServiceError.internalError(cause: "Intent is nil on success")
return continuation.resume(throwing: error)
}
return continuation.resume(returning: intent)
case .failed:
let error = FundingSourceServiceError.internalError(cause: "Extra Authorization failed")
return continuation.resume(throwing: error)
case .canceled:
let error = FundingSourceServiceError.internalError(cause: "Authorization cancelled")
return continuation.resume(throwing: error)
}
}
}
}
guard let paymentMethodId = setupIntent.paymentMethodID else {
throw FundingSourceServiceError.internalError(cause: "Invalid intent, no payment method found")
}
return paymentMethodId
}
Can you share with me a sample project that I can run and reproduce?
Unfortunately I work for a company & the codebase is private, I'm happy to provide you with any code snippets however