简体   繁体   English

当收费下降时,Stripe正在创建客户

[英]Stripe is creating customers when charge declined

For some reason when some one charges to sign up to the subscription plan if their card is declined stripe is still creating the customer. 出于某种原因,如果某些人因为他们的卡被拒绝而收取订阅计划的费用,那么条带仍在创建客户。

I'm not particularly sure why this is happening since I am creating the customer with the charge, how do I make it so if some one signs up but their card does not go through stripe doesn't make them a customer? 我不是特别确定为什么会发生这种情况,因为我正在通过收费来创建客户,如果有人报名但是他们的卡不通过条纹并不能使他们成为客户,我该怎么做呢?

Here is my code 这是我的代码

import stripe


@app.route('/stripe/charge', methods=['POST'])
def stripe_charge():
    data = json.loads(request.data)
    user = data['user']
    source = data['stripeToken'] # obtained from Stripe.js
    try:
        customer = stripe.Customer.create(
            source=source,
            plan="gold5",
            email=email,
        )
    except stripe.CardError, e:
        return jsonify(error="%s" % e)
    return jsonify(customer)

Because you create the customer with the plan parameter, Stripe will attempt to create both the customer and the subscription in one go. 因为您使用plan参数创建客户 ,所以Stripe将尝试一次创建客户和订阅。 Unless the plan has a trial period, Stripe will immediately attempt to bill the customer for the plan's amount (since Stripe's subscriptions are paid upfront), and if the charge fails, then the call will return an error and the customer will not be created. 除非计划有试用期,否则Stripe将立即尝试向客户收取计划金额的费用(因为Stripe的订阅是预先支付的),如果收费失败,则呼叫将返回错误并且不会创建客户。

If you're seeing a different behavior, I recommend you get in touch with Stripe's support to describe the problem. 如果您看到不同的行为,我建议您与Stripe的支持部门联系以描述问题。 Make sure you include the customer ID and/or request ID in your message. 确保在邮件中包含客户ID和/或请求ID。

Are you sure its a CardError that would be thrown? 你确定它会引发CardError吗? Try doing a general Exception , see what error gets thrown when the card is bad. 尝试做一般的Exception ,看看卡坏的时候会抛出什么错误。 Also their API docs don't actually say an error will be thrown if the card is declined: 此外,他们的API文档实际上并没有说如果卡被拒绝将会抛出错误:

If an invoice payment is due and a source is not provided, the call will raise an error. 如果发票付款到期且未提供来源,则呼叫将引发错误。 If a non-existent plan or a non-existent or expired coupon is provided, the call will raise an error. 如果提供了不存在的计划或不存在或过期的优惠券,则该呼叫将引发错误。

https://stripe.com/docs/api?lang=python#create_customer https://stripe.com/docs/api?lang=python#create_customer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM