Update stripe_id for a missing case
This commit is contained in:
parent
600b549704
commit
fb2056bf95
1 changed files with 9 additions and 3 deletions
|
@ -79,14 +79,15 @@ class StripeUtils(object):
|
||||||
customer.save()
|
customer.save()
|
||||||
|
|
||||||
@handleStripeError
|
@handleStripeError
|
||||||
def add_card_to_stripe_customer(self, stripe_customer_id, token):
|
def associate_customer_card(self, stripe_customer_id, token):
|
||||||
customer = stripe.Customer.retrieve(stripe_customer_id)
|
customer = stripe.Customer.retrieve(stripe_customer_id)
|
||||||
customer.sources.create(source=token)
|
customer.sources.create(source=token)
|
||||||
|
|
||||||
@handleStripeError
|
@handleStripeError
|
||||||
def delete_customer_card(self, stripe_customer_id, card_id):
|
def dissociate_customer_card(self, stripe_customer_id, card_id):
|
||||||
customer = stripe.Customer.retrieve(stripe_customer_id)
|
customer = stripe.Customer.retrieve(stripe_customer_id)
|
||||||
customer.sources.retrieve(card_id).delete()
|
card = customer.sources.retrieve(card_id)
|
||||||
|
card.delete()
|
||||||
|
|
||||||
@handleStripeError
|
@handleStripeError
|
||||||
def update_customer_card(self, customer_id, token):
|
def update_customer_card(self, customer_id, token):
|
||||||
|
@ -129,6 +130,9 @@ class StripeUtils(object):
|
||||||
customers = self.stripe.Customer.all()
|
customers = self.stripe.Customer.all()
|
||||||
if not customers.get('data'):
|
if not customers.get('data'):
|
||||||
customer = self.create_customer(token, user.email, user.name)
|
customer = self.create_customer(token, user.email, user.name)
|
||||||
|
user.stripecustomer.stripe_id = customer.get(
|
||||||
|
'response_object').get('id')
|
||||||
|
user.stripecustomer.save()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
customer = stripe.Customer.retrieve(id)
|
customer = stripe.Customer.retrieve(id)
|
||||||
|
@ -137,6 +141,8 @@ class StripeUtils(object):
|
||||||
user.stripecustomer.stripe_id = customer.get(
|
user.stripecustomer.stripe_id = customer.get(
|
||||||
'response_object').get('id')
|
'response_object').get('id')
|
||||||
user.stripecustomer.save()
|
user.stripecustomer.save()
|
||||||
|
if type(customer) is dict:
|
||||||
|
customer = customer['response_object']
|
||||||
return customer
|
return customer
|
||||||
|
|
||||||
@handleStripeError
|
@handleStripeError
|
||||||
|
|
Loading…
Reference in a new issue