如何在Android(Java)/Flask后端禁用Stripe支付表单的卡片保存功能?
如何禁用Stripe支付表单的“保存支付信息”复选框
Android客户端(Java)操作
如果你用的是Stripe官方推荐的PaymentSheet组件,直接在配置里明确禁用未来支付方式设置即可:
- 初始化
PaymentSheet.Configuration时,设置setAllowsDelayedPaymentMethods(false),同时将setupFutureUsage设为SetupFutureUsage.NONE,就能彻底隐藏“保存支付信息”的复选框。
示例代码:PaymentSheet.Configuration paymentConfig = new PaymentSheet.Configuration.Builder() .setMerchantDisplayName("你的应用名称") .setAllowsDelayedPaymentMethods(false) .setSetupFutureUsage(SetupFutureUsage.NONE) .build(); - 若仍在使用旧版PaymentIntent确认逻辑,确保不要给PaymentIntent设置任何
setup_future_usage相关参数,或者明确传递none值。
Flask后端操作
后端创建PaymentIntent的逻辑是核心,必须避免触发支付方式保存的配置:
- 创建PaymentIntent时,要么不设置
setup_future_usage参数,要么将其显式设为'none'。如果之前设置了'on_session'或'off_session',就会自动显示保存支付方式的复选框。
示例代码:@app.route('/create-payment-intent', methods=['POST']) def create_payment_intent(): req_data = request.get_json() try: intent = stripe.PaymentIntent.create( amount=req_data['amount'], currency='usd', payment_method_types=['card'], # 明确禁用未来支付方式保存 setup_future_usage='none' ) return jsonify({'clientSecret': intent.client_secret}) except Exception as e: return jsonify(error=str(e)), 403 - 注意:如果流程中用到了SetupIntent,必然会触发支付方式保存,所以确保只使用PaymentIntent完成支付流程。
内容的提问来源于stack exchange,提问作者baldest_programmer
相关产品推荐
相关产品推荐

