Detect one time or recurring product
This commit is contained in:
parent
e32baf65a0
commit
5749b644ee
|
@ -225,6 +225,8 @@ class ProductOrder(Resource):
|
||||||
if otp_response != 200:
|
if otp_response != 200:
|
||||||
return {"message": "Wrong Credentials"}, 403
|
return {"message": "Wrong Credentials"}, 403
|
||||||
|
|
||||||
|
stripe_utils = StripeUtils()
|
||||||
|
|
||||||
# Validate the given product is ok
|
# Validate the given product is ok
|
||||||
product_id = data["product_id"]
|
product_id = data["product_id"]
|
||||||
product = client.get(
|
product = client.get(
|
||||||
|
@ -237,8 +239,29 @@ class ProductOrder(Resource):
|
||||||
logging.debug("Got product {}: {}".format(product.key, product.value))
|
logging.debug("Got product {}: {}".format(product.key, product.value))
|
||||||
|
|
||||||
# Check the user has a payment source added
|
# 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
|
# 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
|
# If charge successful, create an order object
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue