验证Stripe账户提供ACH支付时银行账户功能异常,无客户/账户ID无法访问
Hey there, let's work through this issue you're having with Stripe's bank account functionality while setting up ACH payments. Based on your code and problem description, here are key fixes and checks to resolve this:
First, Confirm Account Validation & ACH Enablement
Before diving into code, make sure your Stripe account is fully verified and that ACH payments are explicitly enabled in your dashboard. If your account is still under review or ACH isn't turned on, the Bank Account API endpoints will be restricted—this is a common gotcha that's easy to miss.
Fix Your Bank Account Retrieval Code
Your current code uses the older BankAccount API, and there's a critical check you're missing: verifying that default_source actually points to a bank account (not a card). Here's a refined approach, including Stripe's recommended PaymentMethod API (more reliable for modern integrations):
// Retrieve the customer object $customer = \Stripe\Customer::retrieve($cust->id); // Check if a default payment method exists if ($customer->default_source) { // Fetch the payment method details $paymentMethod = \Stripe\PaymentMethod::retrieve($customer->default_source); // Verify it's a US bank account (for ACH) if ($paymentMethod->type === 'us_bank_account') { // Access bank account details like routing number, last 4 digits, etc. $bankAccount = $paymentMethod->us_bank_account; echo "Routing Number: " . $bankAccount->routing_number; echo "Account Last 4: " . $bankAccount->last4; } else { echo "The default payment method is not a bank account (it's likely a card)!"; } } else { echo "This customer doesn't have a default payment method set up yet."; }
Why You Need Customer/Account IDs
Stripe's API is designed to restrict access to sensitive payment data—you can't retrieve a bank account without linking it to a valid customer ID and its associated payment method ID. This is a security measure to ensure you only access data you're authorized to manage. Double-check that $cust->id is a valid, existing customer ID in your Stripe account, and that this customer has a bank account attached.
Additional Debugging Steps
- Check API Logs: Head to your Stripe Dashboard's "Logs" section to see the exact error response from your API calls. Common issues include invalid API keys, permission errors, or non-existent resources.
- Use Test Data: In sandbox mode, use Stripe's official test bank account details (e.g., routing number
110000000, account number000123456789) to rule out real-world validation issues. - Verify API Key: Ensure you're using your Secret Key (not Publishable Key) for server-side calls—Publishable Keys don't have permission to retrieve sensitive payment data.
内容的提问来源于stack exchange,提问作者ralphy

