def fetch_customer(subhub_account: SubHubAccount, user_id: str) -> Customer: customer = None db_account = subhub_account.get_user(user_id) if db_account: customer = Customer.retrieve(db_account.cust_id) if "deleted" in customer and customer["deleted"]: subhub_account.remove_from_db(user_id) customer = None return customer
def form_valid(self, form): trans = form.cleaned_data["transactionDetails"] try: stripe_customer = StripeCustomer.retrieve(trans["customer_id"]) cus = Customer.objects.create( user=self.request.user, stripe_id=stripe_customer["id"] ) sync_customer(cus, stripe_customer) return redirect(reverse("pinax_stripe_subscription_list")) except StripeError as e: messages.error(self.request, "Unable to communicate with stripe. Please try again later") logger.error("Stripe Error during checkout for customer {}".format( self.request.user ), exc_info=True) return redirect(reverse("pinax_stripe_subscription_list"))
def retrieve_stripe_customer(customer_id: str) -> Optional[Customer]: """ Retrieve Stripe Customer :param customer_id: :return: Customer """ try: customer = Customer.retrieve(id=customer_id) return customer except ( InvalidRequestError, APIConnectionError, APIError, RateLimitError, StripeErrorWithParamCode, ) as e: logger.error("retrieve stripe customer error", error=e) raise e
def fetch_customer(subhub_account: SubHubAccount, user_id: str) -> Customer: customer = None db_account = subhub_account.get_user(user_id) if db_account: customer = Customer.retrieve(db_account.cust_id) return customer