简体   繁体   English

没有在Braintree中创建客户(js + python)

[英]Customer is not getting created in braintree (js+python)

I am getting error while creating customer 创建客户时出现错误

AuthenticationError at /vissa/assign-plan/

My js 我的js

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

{% if cust %} $(document).ready(function() { braintree.setup("{{ client_token }}", "dropin", { container: "checkout", form: "checkoutForm" }); {%如果cust%} $(document).ready(function(){braintree.setup(“ {{client_token}}”,“ dropin”,{容器:“ checkout”,形式:“ checkoutForm”});

    $("#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 %} And client token i am trying to get in context processor. {%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}

but i am getting above error. 但是我遇到了错误。

if i tried 如果我尝试过

client_token = braintree.ClientToken.generate()

getting authentication error. 收到身份验证错误。 I am not getting how to create client token in django. 我没有得到如何在Django中创建客户端令牌。 is there a way to create client token without customer_id? 有没有没有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)

It worked after making the change 进行更改后它起作用了

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)

in production instead of "Sandbox" need to use "Production". 在生产中代替“沙盒”需要使用“生产”。

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

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