Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove card setup #86

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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