Created
August 13, 2017 18:26
-
-
Save harveyslash/88be8c1e491d9f9c39ce19bef7024c4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@payment_controller.route('/enable_tests', methods=['POST']) | |
def enable_tests(): | |
json = request.get_json() | |
test_ids = json['test_ids'] | |
user_id = json['user_id'] | |
wallet_amount_used = json['wallet_amount_used'] | |
user = db.session.query(User).filter_by(id=user_id).first() | |
if user.wallet is None: | |
user.wallet = 0 | |
elif wallet_amount_used != 0: | |
user.wallet -= wallet_amount_used | |
db.session.add(user) | |
for tid in test_ids: | |
if not db.session.query(exists().where(and_(Payments.userId == user_id, Payments.testId == tid))).scalar(): | |
exam_purchased = Payments(userId=user_id, testId=tid, paymentSuccess=True) | |
db.session.add(exam_purchased) | |
db.session.commit() | |
return jsonify({'success': True}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment