Handle one-time payment

This commit is contained in:
PCoder 2019-09-19 21:08:20 +05:30
parent 4c31e40411
commit 671ec75584

View file

@ -351,6 +351,38 @@ class ProductOrder(Resource):
"Product {} is one-time "
"payment".format(product_obj["type"])
)
charge_response = stripe_utils.make_charge(
amount=product_obj['price'],
customer=stripe_customer.id
)
stripe_onetime_charge = charge_response.get('response_object')
# Check if the payment was approved
if not stripe_onetime_charge:
msg = charge_response.get('error')
logging.error("Could not make a one time payment")
logging.error("Details = {}".format(msg))
return {"message": "Error subscribing to plan. "
"Details: {}".format(msg)}, 400
order_obj = {
"order_id": get_order_id(),
"ordered_at": int(time.time()),
"product": product_obj,
}
client.put("/v1/user/{}/orders".format(
data['name']), json.dumps(order_obj),
value_in_json=True)
order_obj["ordered_at"] = datetime.fromtimestamp(
order_obj["ordered_at"]).strftime("%c")
order_obj["product"] = get_user_friendly_product(
product_obj
)
logging.debug(str(order_obj))
return {"message": "Order successful",
"order_details": order_obj}, 200
except KeyError as key_error:
logging.error("Key error occurred")
logging.error(str(key_error))