Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -494,26 +494,31 @@ def checkout():
|
|
| 494 |
return jsonify({"success": False, "error": str(e)})
|
| 495 |
|
| 496 |
|
| 497 |
-
@app.route('/get_coupon_codes', methods=['
|
| 498 |
def get_coupon_codes():
|
| 499 |
-
|
|
|
|
| 500 |
|
| 501 |
if not email:
|
| 502 |
return jsonify({'success': False, 'message': 'Email is required.'})
|
| 503 |
|
| 504 |
try:
|
| 505 |
-
# Query
|
| 506 |
-
|
| 507 |
-
|
|
|
|
|
|
|
|
|
|
| 508 |
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
return jsonify({'success':
|
| 512 |
|
| 513 |
-
return jsonify({'success':
|
| 514 |
|
| 515 |
except Exception as e:
|
| 516 |
-
|
|
|
|
| 517 |
|
| 518 |
|
| 519 |
@app.route('/apply_coupon', methods=['POST'])
|
|
|
|
| 494 |
return jsonify({"success": False, "error": str(e)})
|
| 495 |
|
| 496 |
|
| 497 |
+
@app.route('/get_coupon_codes', methods=['POST'])
|
| 498 |
def get_coupon_codes():
|
| 499 |
+
data = request.json
|
| 500 |
+
email = data.get('email')
|
| 501 |
|
| 502 |
if not email:
|
| 503 |
return jsonify({'success': False, 'message': 'Email is required.'})
|
| 504 |
|
| 505 |
try:
|
| 506 |
+
# Query to fetch active coupon codes for the user
|
| 507 |
+
result = sf.query(f"""
|
| 508 |
+
SELECT Coupon_Code__c
|
| 509 |
+
FROM Referral_Coupon__c
|
| 510 |
+
WHERE Referral_Email__c = '{email}' AND Coupon_Status__c = 'Active'
|
| 511 |
+
""")
|
| 512 |
|
| 513 |
+
coupons = result.get('records', [])
|
| 514 |
+
if not coupons:
|
| 515 |
+
return jsonify({'success': False, 'message': 'No active coupons found.'})
|
| 516 |
|
| 517 |
+
return jsonify({'success': True, 'coupons': coupons})
|
| 518 |
|
| 519 |
except Exception as e:
|
| 520 |
+
print(f"Error fetching coupons: {str(e)}")
|
| 521 |
+
return jsonify({'success': False, 'message': 'Error fetching coupons.'})
|
| 522 |
|
| 523 |
|
| 524 |
@app.route('/apply_coupon', methods=['POST'])
|