【问题标题】:Customer is not getting created in braintree (js+python)客户未在 Braintree (js+python) 中创建
【发布时间】:2015-10-05 05:21:32
【问题描述】:

我在创建客户时遇到错误

AuthenticationError at /vissa/assign-plan/

我的js

<script src="https://js.braintreegateway.com/v2/braintree.js"></script>

{% 如果客户 %} $(文档).ready(函数() { Braintree.setup("{{ client_token }}", "dropin", { 容器:“结帐”, 表格:“结帐表格” });

    $("#submitPayment").on("click", function () {

        $("button").off("click");
        $("a").off("click");
        $('body').off("click");

        var btn = $(this).button("loading")
        setTimeout(function () {
            btn.button('reset');
        }, 3500)
    });
});
</script>

{% endif %} 我正试图在上下文处理器中获取客户端令牌。

def payment_data(request):
    try:
        userone = UserProfile.objects.get(user=request.user)
        indi_user = IndividualUser.objects.get(user_profile=userone)
        plan = int(indi_user.selected_plan)
        amount = int(plan)
    except:
        plan = None
        amount = None
    try:
        merchant_obj = UserMerchantId.objects.get(user=request.user)
        cust = True
        merchant_customer_id = merchant_obj.customer_id
        print merchant_customer_id
        client_token = braintree.ClientToken.generate({
                "customer_id": merchant_customer_id
            })
    except:
        cust = False
        client_token = None
    try:
        custom = Transaction.objects.filter(user=request.user)[0]

        paid = custom.success
    except:
        paid = False
    return {'cust':cust, "plan":plan,"amount": amount, "paid": paid,"client_token":client_token} #"plan": plan}

但我遇到了错误。

如果我尝试过

client_token = braintree.ClientToken.generate()

出现身份验证错误。 我没有得到如何在 django 中创建客户端令牌。 有没有办法在没有 customer_id 的情况下创建客户端令牌?

Creating customer.
    def new_user_receiver( instance, *args, **kwargs):
        try:
            merchant_obj = UserMerchantId.objects.get(user=instance)
        except:
            new_customer_result = braintree.Customer.create({
                    "first_name": instance.first_name,
                    "last_name": instance.last_name,
                    "email": instance.email,
                    "phone": instance.get_profile().telephone_number
                })
            if new_customer_result.is_success:
                merchant_obj, created = UserMerchantId.objects.get_or_create(user=instance)
                merchant_obj.customer_id = new_customer_result.customer.id
                merchant_obj.save()
                print """Customer created with id = {0}""".format(new_customer_result.customer.id)
            else:
                print "Error: {0}".format(new_customer_result.message)

【问题讨论】:

    标签: javascript python django braintree


    【解决方案1】:

    修改后生效

    import braintree
    
    braintree.Configuration.configure(braintree.Environment.Production,
                                      merchant_id=settings.BRAINTREE_MERCHANT_ID,
                                      public_key=settings.BRAINTREE_PUBLIC_KEY,
                                      private_key=settings.BRAINTREE_PRIVATE_KEY)
    

    在生产中而不是“沙盒”需要使用“生产”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-15
      • 2015-12-09
      • 2016-12-14
      • 2016-11-27
      • 2016-07-28
      • 2017-10-02
      • 2018-03-05
      • 2017-09-27
      相关资源
      最近更新 更多