Skip to content

Commit

Permalink
Merge pull request #86 from Ilhasoft/fix/remove_card_setup
Browse files Browse the repository at this point in the history
fix: remove card setup
  • Loading branch information
BarbosaJackson committed Dec 1, 2021
2 parents a8a6b52 + ff508f1 commit 9366a6a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 5 additions & 4 deletions connect/api/v1/organization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ def remove_card_setup(

self.check_object_permissions(self.request, organization)

organization.organization_billing.remove_credit_card()
if organization.organization_billing.remove_credit_card:

organization.is_suspended = True
organization.save(update_fields=["is_suspended"])
organization.is_suspended = True
organization.save(update_fields=["is_suspended"])

return JsonResponse(data={"status": True}, status=status.HTTP_200_OK)
return JsonResponse(data={"status": True}, status=status.HTTP_200_OK)
return JsonResponse(data={"status": False}, status=status.HTTP_304_NOT_MODIFIED)

@action(
detail=True,
Expand Down
4 changes: 2 additions & 2 deletions connect/billing/gateways/stripe_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ def purchase(self, money: float, identification, options: dict = None):

def unstore(self, identification, options: dict = None):
response = []

existing_cards = stripe.PaymentMethod.list(
customer=identification,
type="card",
)

for card in existing_cards.get("data"):
if options.get("card_id") and str(card["id"]) == str(
if options and options.get("card_id") and str(card["id"]) == str(
options.get("card_id")
):
continue
Expand Down
5 changes: 4 additions & 1 deletion connect/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,10 @@ def payment_warnings(self):
@property
def remove_credit_card(self):
gateway = billing.get_gateway("stripe")
return gateway.unstore(identification=self.stripe_customer)
unstore = gateway.unstore(identification=self.stripe_customer)
if unstore['status'] == 'SUCCESS':
return True
return False

@staticmethod
def calculate_amount(contact_count: int):
Expand Down

0 comments on commit 9366a6a

Please sign in to comment.