0
,同時爲客戶創造客戶(JS +蟒蛇)
我收到錯誤AuthenticationError at /vissa/assign-plan/
我的JS
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
{如果%卡斯特%}
的$(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%} 而我試圖在上下文處理器中獲取客戶端令牌。
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)