集成PayPal遇币种错误求助:已添加USD仍提示不接受该币种
抱歉,该商家不接受您使用的币种,请返回商家页面选择其他支付方式。
Hey there, I see you're hitting this error even though you've set up USD in your PayPal account and configured it in your code (great job checking those account settings first!). Let's break down the most likely reasons and fix them step by step.
Possible Causes & Fixes
1. Verify the Currency Value in Your Code
PayPal strictly uses ISO 4217 3-letter uppercase currency codes—so even a tiny typo like "usd" or "US" will trigger this error. Let's confirm what your code is actually sending:
Add a debug line right before setting the currency to check the value:
// Add this to debug the currency value var_dump($this->payment_detail['currency']); $amount = new \PayPal\Api\Amount(); $amount->setTotal($transaction_value); $amount->setCurrency($this->payment_detail['currency']);
If the output isn't string(3) "USD", you'll need to fix the value stored in $this->payment_detail['currency'].
2. Check Environment Mix-Ups (Sandbox vs Production)
PayPal Sandbox accounts have separate currency settings from your live production account. If you're testing with Sandbox API credentials, you need to log into your Sandbox Dashboard and enable USD for your test merchant account—just like you did for your live account in the screenshots.
Double-check that you're using the correct credentials (Sandbox vs Production) for your current testing environment too. Mixing them up is a common culprit here.
3. Ensure Your Amount Format is Valid
PayPal requires amounts to have exactly two decimal places (e.g., "10.00" instead of "10" or "10.0"). Invalid amount formatting can sometimes trigger a generic currency error instead of a specific amount error.
Test by hardcoding a valid amount to rule this out:
$amount->setTotal('9.99'); // Use a string with two decimals for reliability
4. Get Detailed Error Context from PayPal
Your current error handling only prints raw data—expanding it will give you specific clues about why the currency is being rejected. Update your catch block to:
catch (\PayPal\Exception\PayPalConnectionException $ex) { echo "Error Message: " . $ex->getMessage() . "\n"; echo "Detailed Error Data:\n"; print_r(json_decode($ex->getData(), true)); }
This might reveal issues like "currency not supported for merchant account" or hidden validation problems that aren't obvious from the generic error message.
5. Confirm Live Account Receiving Permissions
Even though you added USD to your account, double-check that your PayPal account is allowed to receive payments in USD. Some regional accounts have restrictions on accepted currencies, or may require additional verification to enable certain ones. You can confirm this in your account's "Payment Receiving Preferences" or reach out to PayPal support if needed.
Quick Sanity Test
As a fast way to narrow down the issue, temporarily hardcode the currency to "USD" in your code instead of using $this->payment_detail['currency']:
$amount->setCurrency('USD'); // Hardcode for testing
If this works, the problem is definitely with the value coming from $this->payment_detail['currency']. If it still fails, focus on account settings or environment issues.
内容的提问来源于stack exchange,提问作者Satys

