#jack_api

1 messages Β· Page 1 of 1 (latest)

stable shardBOT
#

πŸ‘‹ 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/1293025495595876374

πŸ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

lofty sail
#

What is the problem you’re facing?

digital flume
#

the screen hangs

#

the app crashes as shown above

#

Swift 5 / IOS 16

#

Here is the sanitized code - STPAPIClient.shared.publishableKey = self.stripe_publishable_api_key

         // MARK: Create a PaymentSheet instance
    var configuration = PaymentSheet.Configuration()
    configuration.merchantDisplayName = "BO, Inc."
    configuration.customer = .init(id: self.customer_id, ephemeralKeySecret: self.ephemeral_key)
         // Set `allowsDelayedPaymentMethods` to true if your business can handle payment methods
         // that complete payment after a delay, like SEPA Debit and Sofort.
         configuration.allowsDelayedPaymentMethods = true
    configuration.returnURL = "www.openbarn.com"
    
    // self.paymentSheet = PaymentSheet(paymentIntentClientSecret: self.payment_intent, configuration: configuration)
    self.paymentSheet = PaymentSheet(paymentIntentClientSecret: self.payment_intent, configuration: configuration)
   
    print(self.Tag, " after paymentsheet")
    
    // MARK: Start the checkout process
    let paymentHandler = STPPaymentHandler.shared()
    // ProgressHUD.present(view: self.view, mview: self)
    
    DispatchQueue.main.async {
        self.paymentSheet?.present(from: self) { paymentResult in
            
            print(self.Tag, " paymentResult :  " , paymentResult)
            switch paymentResult {
            case .completed:
                print("Your order is confirmed")
            case .canceled:
                print("Payment canceled!")
            case .failed(let error):
                print("Payment failed: \(error.localizedDescription)")
            }
        }
    }
#

podfile install - pod 'Stripe', '~> 23.31.0'
pod 'StripePaymentSheet', '~> 23.31.0'

#

@lofty sail πŸ‘†

lofty sail
#

Can you log payment intent client secret and ephemeral key to check those values are set correctly in the configuration?

digital flume
#

@lofty sail let me try

#

when you say payment intent secret do you mean stripe_publishable_api_key?

#

We are not creating any payment intent, only doing a paymentsheet @lofty sail

#

both ephemeral key and stripe_publishable_api_key are the same that is shown in the dashboard (stripe.com)

lofty sail
#

To present a Payment Sheet, a Payment Intent and ephemeral keys should be created first, then set in Payment Sheet configuration and its initialization

digital flume
#

Yes. We include it

lofty sail
#

This has been explained in https://docs.stripe.com/payments/accept-a-payment?platform=ios#ios-collect-payment-details:

// MARK: Fetch the PaymentIntent client secret, Ephemeral Key secret, Customer ID, and publishable key
var request = URLRequest(url: backendCheckoutUrl)
request.httpMethod = "POST"
let task = URLSession.shared.dataTask(with: request, completionHandler: { [weak self] (data, response, error) in
  guard let data = data,
        let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any],
        let customerId = json["customer"] as? String,
        let customerEphemeralKeySecret = json["ephemeralKey"] as? String,
        let paymentIntentClientSecret = json["paymentIntent"] as? String,
        let publishableKey = json["publishableKey"] as? String,
        let self = self else {
    // Handle error
    return
  }

Securely accept payments online.

digital flume
#

self.paymentSheet = PaymentSheet(paymentIntentClientSecret: self.payment_intent, configuration: configuration)

#

Yes. We include it already.

lofty sail
#

What are the values of customerEphemeralKeySecret and paymentIntentClientSecret?

digital flume
#

Please see code above

lofty sail
#

Can you log ephemeral key secret and payment intent secret? What are their values?

digital flume
#

Let me run it again and share them here

#

ephemeral_key ek_test_YWNjdF8xNkQxNFpHRmhIcUpINjc4LFAzVDFGRzgzekduclpOS2JwTUlrM0RZampxeHlCdWY_00f72QECy7 intent : pi_3Q7Sp7GFhHqJH6780ycgzS2V_secret_KeC2DpbknWUzXJNZng92GnKbN

#

Just checked the Stripe dashboad and they are the same.

#

I am getting this error in my Xcode simulator

#

Req ID -
req_kYwc8cGyfRQXJk

#

@lofty sail πŸ‘†

lofty sail
#

Thanks for waiting! Discord is busy now. Looking into them

#

The code and secrets look right to me. Is there any error in your iOS logs?

digital flume
#

None

#

This is where the app crashes

#

LOG ANALYTICS: mc_load_started - [(key: "pay_var", value: "legacy"), (key: "ocr_type", value: "none"), (key: "mpe_config", value: ["customer": true, "save_payment_method_opt_in_behavior": "automatic", "apple_pay_config": false, "appearance": ["colors": false, "usage": false, "shadow": false, "primary_button": false, "font": false, "corner_radius": false, "border_width": false], "style": 0, "payment_method_layout": "horizontal", "default_billing_details": false, "allows_delayed_payment_methods": true, "billing_details_collection_configuration": ["address": "automatic", "name": "automatic", "email": "automatic", "phone": "automatic", "attach_defaults": false], "customer_access_provider": "legacy", "return_url": true]), (key: "is_decoupled", value: false), (key: "apple_pay_enabled", value: 1), (key: "active_link_session", value: false)]

#

Error in StripeUICore

#

@lofty sail πŸ‘†

lofty sail
#

Please be patient. We are looking into your code

digital flume
#

πŸ‘

lofty sail
#

Could you share your decoder how to parse the response returned from the server? The common cause it that server respond client_secret but you are trying to parse clientSecret. This will cause the configuration Payment Sheet fails to load due to null client secret reading from the different parameter name

digital flume
#

My backend sends the client secret. Same function call for Android and IOS

#

The stripe payment sheet works for android

#

Client secret is fetched by the same backend for Android and iOS

lofty sail
#

The issue is not with the backend. It's the parser at client side

#

How did you parse the response in iOS? Did you fetch the client secret from the correct parameter name?

digital flume
#

I fetch the client secret from backend and pass it to the IOS app

lofty sail
#

Could you share the decoder at you iOS app on you get the response from the server?

#

The issue is likely that you get the information from incorrect field at your decoder

stable shardBOT
digital flume
#

Where is the client secret used in the IOS front end?

#

are you referring to the payment_intent?

#

We checked the pi_3Q7Sp7GFhHqJH6780ycgzS2V_secret_KeC2DpbknWUzXJNZng92GnKbN and looked the same from the Stripe Dashboard

vestal quartz
#

Hi I'm taking over this thread

digital flume
#

Hi Jack Stripe

vestal quartz
#

How does your backend response json looks like? is the client secret returned as client_secret or clientSecret ?

digital flume
#

Let me check

#

paymentIntent.client_secret

#

so client_secret

vestal quartz
#

This is your code, is self.payment_intent == paymentIntent.client_secret?

digital flume
#

yes

vestal quartz
#

Do you have any crash log?

digital flume
vestal quartz
#

I don't see any crash here

digital flume
#

the stripe paymentsheet hangs

#

The wheel keeps spinning

#

Don't see the fields for the user to enter payment

vestal quartz
#

Is your Simulator connected to internet?

digital flume
#

Yes

#

It is able to connect to backend an fetch the keys

vestal quartz
#

Can you share a sample xcode project so that I can run and reproduce?

digital flume
#

How do I do that?

#

Cannot share the entire source code

vestal quartz
#

No I don't need the entire source code, I just a simple xcode project that contains code that I can run and reproduce the problem.

digital flume
#

This seems to be the issue. Does it give any pointers to you?

vestal quartz
#

What issue? I'm afraid that I don't understand. I don't see any error in the screenshot

digital flume
#

In Xcode this is the line that get's highlighted when the Stripe PaymentSheet starts to hang

vestal quartz
#

Do you pass a default billing address to paymentSheet?

#

Also are you using the latest version of Stripe iOS SDK?

digital flume
#

pod 'Stripe', '~> 23.31.0'
pod 'StripePaymentSheet', '~> 23.31.0'

#

I don't think we pass default billing address

#

Is there a parameter?

vestal quartz
#

What happen if you press the continue button?

digital flume
#

Added this to the config - configuration.defaultBillingDetails.address.country = "US"

#

Same issues

vestal quartz
#

Can you check your breakpoint settings and remove unncessary breakpoints?

digital flume
#

Ok. Thanks. That helped. I had set breakpoints for all obj-c errors. They were getting triggered. Not sure why.