#rowester_code

1 messages ¡ Page 1 of 1 (latest)

ripe wraithBOT
#

👋 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.

bronze narwhal
#

Yes that's the one

runic sage
#

Can you share with me the relevant code?

bronze narwhal
#
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

runic sage
#

Ok, and how do you pass AddCreditCardHostingController to Stripe SDK?

bronze narwhal
#

I think it's via the STPAuthenticationContext protocol, we then provide this to the SDK via:

STPPaymentHandler.shared().confirmSetupIntent(
   intentParameters,
   with: inputDetails.authenticationContext
) {
runic sage
#

Can you put some logs in your code to confirm inputDetails.authenticationContext is an instance of AddCreditCardHostingController ?

bronze narwhal
#
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

runic sage
#

OK, do you have any code that might change the value of inputDetails.authenticationContext ?

bronze narwhal
#

No, I don't think so, we provide the context straight to the SDK when we attempt to link a credit card funding source.

runic sage
#

I mean any code that might change the value of inputDetails.authenticationContext after calling STPPaymentHandler.shared().confirmSetupIntent ?

bronze narwhal
#

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
}
runic sage
#

Can you share with me a sample project that I can run and reproduce?

bronze narwhal
#

Unfortunately I work for a company & the codebase is private, I'm happy to provide you with any code snippets however