简体   繁体   中英

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

I am getting error while creating customer

AuthenticationError at /vissa/assign-plan/

My 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" });

    $("#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.

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. is there a way to create client token without 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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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