【问题标题】:request() got an unexpected keyword argument 'customer'request() 得到了一个意外的关键字参数“客户”
【发布时间】:2019-01-11 08:03:11
【问题描述】:

正在实施razorpay,出现上述错误。 我需要在 razorpay api 中创建一个新客户。 无法获取客户,因为它说错误无法获取客户。

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)

【问题讨论】:

  • 请发布完整回溯,并正确缩进代码。
  • 那是不是回溯,另外请edit问题。由于回溯是多行的,它会使 cmets 变得一团糟。
  • 是的,当然。我也会这样做。@WillemVanOnsem

标签: django python-3.x django-rest-framework razorpay


【解决方案1】:

可能是因为拥有电子邮件的用户已经存在。您可以传递一个名为 "fail_existing":"0" 的附加参数。然后 customer_id 将被返回。如果没有现有客户,则会创建一个新客户并返回 customer_id。

主体应该是这样的:

{
  "name" : "Cornelius123",
  "email" : "cornelius19901@gmail.com",
  "contact" : "+919000000000",
  "fail_existing":"0",
  "notes": {}
}

【讨论】:

    【解决方案2】:
    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)
    

    这是我应该传递数据的方式。 这种格式已集成在他们的 api 中。

    【讨论】:

      猜你喜欢
      • 2013-11-27
      • 2022-06-16
      • 2016-09-17
      • 2015-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      • 2021-12-08
      相关资源
      最近更新 更多