Detect one time or recurring product

This commit is contained in:
PCoder 2019-09-14 17:42:10 +05:30
parent e32baf65a0
commit 5749b644ee
1 changed files with 23 additions and 0 deletions

View File

@ -225,6 +225,8 @@ class ProductOrder(Resource):
if otp_response != 200:
return {"message": "Wrong Credentials"}, 403
stripe_utils = StripeUtils()
# Validate the given product is ok
product_id = data["product_id"]
product = client.get(
@ -237,8 +239,29 @@ class ProductOrder(Resource):
logging.debug("Got product {}: {}".format(product.key, product.value))
# Check the user has a payment source added
stripe_customer = stripe_utils.get_stripe_customer_from_email(
data["email"]
)
if not stripe_customer or len(stripe_customer.sources) == 0:
logging.error("{} does not exist in Stripe => no cards".format(
data["email"])
)
return {"message": "Please register a payment source"}, 400
# Initiate a one-time/subscription based on product type
product_obj = product.value
if product_obj['type'] == "recurring":
logging.debug("Product {} is recurring payment".format(
product_obj["name"])
)
elif product_obj['type'] == "one-time":
logging.debug(
"Product {} is one-time "
"payment".format(product_obj["type"])
)
# If charge successful, create an order object