Flutter集成Stripe支付弹窗货币切换:如何强制显示PKR而非USD
在Flutter Stripe集成中修改支付弹窗货币为PKR的解决方案
核心逻辑:Stripe支付弹窗显示的货币由支付请求(PaymentIntent)中的currency参数决定,无需依赖账号全局客户设置,直接通过代码即可强制指定。
步骤1:前端(Flutter)代码配置
使用flutter_stripe包时,在初始化PaymentSheet时明确指定货币代码为pkr:
import 'package:flutter_stripe/flutter_stripe.dart'; // 1. 获取后端返回的PaymentIntent Client Secret // (后端需同步设置currency为pkr,见步骤2) final String intentClientSecret = '从后端获取的client_secret'; // 2. 配置PaymentSheet参数 final paymentSheetParams = SetupPaymentSheetParameters( paymentIntentClientSecret: intentClientSecret, merchantDisplayName: '你的商家名称', currencyCode: 'pkr', // 强制设置为巴基斯坦卢比 ); // 3. 初始化并展示PaymentSheet await Stripe.instance.initPaymentSheet(parameters: paymentSheetParams); await Stripe.instance.presentPaymentSheet();
步骤2:后端PaymentIntent创建配置
无论使用哪种后端语言,创建PaymentIntent时必须指定currency: 'pkr',同时注意金额需按货币最小单位计算(PKR最小单位为派萨,1PKR=100派萨):
示例(Node.js):
const stripe = require('stripe')('你的Stripe密钥'); const createPaymentIntent = async (req, res) => { const paymentIntent = await stripe.paymentIntents.create({ amount: 10000, // 等价于100 PKR(100*100派萨) currency: 'pkr', payment_method_types: ['card'], }); res.json({ clientSecret: paymentIntent.client_secret }); };
关键注意事项
- 确保你的Stripe账号已启用PKR作为收款货币:在Stripe后台「支付设置」→「货币」中添加并验证PKR,否则会返回货币不支持的错误。
- 货币代码必须严格遵循ISO 4217标准,使用小写的
pkr,不能用大写或其他格式。 - 账号中的「客户默认货币」设置仅影响客户账单的默认显示,不会覆盖单个PaymentIntent中指定的货币。
内容的提问来源于stack exchange,提问作者Tauseef Ahmed
相关产品推荐
相关产品推荐

