PayPal iOS SDK生产环境登录报Invalid user credentials求助
Hey there, let's break down why you're hitting this invalid_user error in production even though your sandbox works and you've got the right Client ID. Here are the key checks and fixes to resolve this:
1. Ensure Production Environment is Properly Enabled
Looking at your code, you’ve got a commented line for setting the production environment—but just defining a variable doesn’t make the SDK use it. The PayPal SDK defaults to Sandbox mode unless explicitly told otherwise, which would explain why your production Client ID is failing (Sandbox doesn’t recognize production credentials).
Update your viewDidLoad PayPal configuration section to explicitly set the environment on your PayPalConfiguration instance:
// Enable production environment explicitly payPalConfig.environment = PayPalEnvironmentProduction
2. Fix Malformed URL Quotation Marks
Your privacy policy and user agreement URLs use Chinese quotation marks (“”) instead of standard English ones (""). This creates invalid URLs, which might not directly cause the auth error but can break SDK configuration and lead to unexpected behavior. Correct those lines to:
payPalConfig.merchantPrivacyPolicyURL = URL(string: "https://www.paypal.com/webapps/mpp/ua/privacy-full") payPalConfig.merchantUserAgreementURL = URL(string: "https://www.paypal.com/webapps/mpp/ua/useragreement-full")
3. Double-Check Your Production Client ID
Even if you think it’s correct, it’s easy to mix up Sandbox and Live Client IDs. Head to your PayPal Developer Dashboard, switch to the Live tab under "My Apps & Credentials", and copy the exact Client ID for your app. Ensure there are no extra spaces or truncated characters in your code.
4. Update Your Outdated PayPal SDK Version
You’re using version 2.16.2, which is quite old. PayPal regularly deprecates older SDK versions, and compatibility issues with production APIs could lead to authentication failures. Upgrading to the latest stable version of the PayPal iOS SDK might resolve this issue entirely.
Quick Adjusted Code Snippet
Here’s your viewDidLoad config with the critical fixes applied:
//=======Paypal Configuration======================================================================== // Set up payPalConfig payPalConfig.acceptCreditCards = true payPalConfig.merchantName = "Donation to Edhi"//Give your company name here. payPalConfig.merchantPrivacyPolicyURL = URL(string: "https://www.paypal.com/webapps/mpp/ua/privacy-full") payPalConfig.merchantUserAgreementURL = URL(string: "https://www.paypal.com/webapps/mpp/ua/useragreement-full") //This is the language in which your paypal sdk will be shown to users. payPalConfig.languageOrLocale = Locale.preferredLanguages[0] // Enable production environment explicitly payPalConfig.environment = PayPalEnvironmentProduction //Here you can set the shipping address. You can choose either the address associated with PayPal account or different address. We’ll use .both here. payPalConfig.payPalShippingAddressOption = .both; //====================================================================
Give these steps a try—most likely the missing environment assignment is the root cause. If you still run into issues, reach out to PayPal Developer Support with your Debug-ID (b2cedad5b6842) for deeper investigation.
内容的提问来源于stack exchange,提问作者Ovais Khan

