stripe / stripe-ios

Stripe iOS SDK
https://stripe.com
MIT License
2.12k stars 981 forks source link

PaymentSheet : No valid API key provided. Set `STPAPIClient.shared().publishableKey` - iOS, Swift, UiKit #1867

Closed itsdeepak404 closed 3 years ago

itsdeepak404 commented 3 years ago

Summary

I am following this Doc : https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=payment-sheet

after setup all in frontend and backend. getting log :

**LOG ANALYTICS: ["product_usage": ["PaymentSheet"], "app_name": "Z----Z", "additional_info": [], "bindings_version": "21.8.1", "apple_pay_enabled": 0, "ocr_type": "none", "os_version": "14.4", "analytics_ua": "analytics.stripeios-1.0", "ui_usage_level": "partial", "publishable_key": "pk_test_51J9Te0LW44AR34***bRP2", "device_type": "iPhone12,1", "event": "mc_complete_init_customer", "app_version": "3.4"]**

While presenting the PaymentSheet getting this error:

Error Domain=com.stripe.lib Code=50 "There was an unexpected error -- try again in a few seconds" UserInfo={NSLocalizedDescription=There was an unexpected error -- try again in a few seconds, com.stripe.lib:ErrorMessageKey=No valid API key provided. Set STPAPIClient.shared().publishableKey to your publishable key, which you can find here: https://stripe.com/docs/keys, com.stripe.lib:StripeErrorTypeKey=invalid_request_error, com.stripe.lib:StripeErrorCodeKey=}

There is nowhere defined in documentation to set STPAPIClient.shared().publishableKey. still, I tried to set STPAPIClient.shared.publishableKey in my viewcontroller, still getting the error.

Code to reproduce

iOS version

13.0

Installation method

Pod

SDK version

21.8.1

Other information

yuki-stripe commented 3 years ago

@itsdeepak404 Can you try checking your customer ephemeral key? It should start with "ek_"

itsdeepak404 commented 3 years ago

I got resolved yesterday, update the error message in case of invalid or format not matching ephemeral key, It is so misleading. I read alot around Set STPAPIClient.shared().publishableKey to your publishable key.

Thanks

yuki-stripe commented 3 years ago

@itsdeepak404 Agreed, this error is super misleading :( We are working on fixing it right now.

Glad you got it fixed!