问题
Was implementing the razorpay,got the above error. I need to create a new customer in the razorpay api. unable to get the customer as it is saying the error is unable to get customer.
from django.db import models
from customers.models import Customer
from django.db.models.signals import post_save,pre_save
import razorpay
client = razorpay.Client(auth=("", ""))
class BillingProfile(models.Model):
customer = models.OneToOneField(Customer,null=True,blank=True)
inserted = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
b_customer_id = models.CharField(max_length=120,null=True,blank=True)
def __str__(self):
return self.customer.name
def billing_profile_recieved(sender,instance,*args,**kwargs):
if not instance.b_customer_id and instance.customer:
print(instance.id,"OOOOOOOOOOOOOOOOOOOoo")
print(client,"------------------------------")
customer = client.customer.create(customer=instance.id) //_______ ERROR
print(customer)
pre_save.connect(billing_profile_recieved,sender=BillingProfile)
def user_created_reciever(sender,instance,created,*args,**kwargs):
if created:
BillingProfile.objects.get_or_create(customer=instance)
print(instance.user_customer,client)
post_save.connect(user_created_reciever, sender=Customer)
回答1:
name = instance.customer.name
email = instance.customer.user_customer.email
contact = instance.customer.phone_no
if not instance.b_customer_id and instance.customer:
try:
customer = client.customer.create( {
"name" : name,
"email" : email,
"contact" : contact,
"notes": {}
}
)
instance.b_customer_id = customer["id"]
except Exception as e:
print(e)
pre_save.connect(billing_profile_recieved,sender=BillingProfile)
This is way is I should have passed the data. This format was integrated in their api.
回答2:
May be because user with Email already existing. You can pass an additional parameter called "fail_existing":"0" . Then the customer_id will be returned. If there is no existing customer, it will create a new customer and return customer_id.
The body should be something like this:
{
"name" : "Cornelius123",
"email" : "cornelius19901@gmail.com",
"contact" : "+919000000000",
"fail_existing":"0",
"notes": {}
}
来源:https://stackoverflow.com/questions/51672428/request-got-an-unexpected-keyword-argument-customer