示例#1
0
def store_payment(db, twitter_json, payment_message, message, raw_message):
    subscription = Subscriptions.findOne(db, {'account_id': ObjectId(payment_message.get('account_id')),'parrot_id': ObjectId(payment_message.get('parrot_id'))})
    payment_data = {
        'twitter_response': twitter_json,
        # action date means when this payment has to be tweeted
        'action_date': datetime.now(),
        'account_id': ObjectId(payment_message.get('account_id')),
        'subscription_id': ObjectId(subscription.id),
        'parrot_id': ObjectId(payment_message.get('parrot_id')),
        'message_id': ObjectId(message.get('id')),
        'message_id_sqs': raw_message.id,
        'callback_url': message.get('url', ''),
        'success': True
    }
    if twitter_json.get('error'):
        payment_data['success'] = False
        log('cron2', 'ERROR: Payment coulndt be processed because of twitter error %s' % json.dumps(twitter_json), payment_message.get('subscription_id'))
    else:
        log('cron2', 'Payment executed successfully', payment_message.get('subscription_id'))
    payment = Payments(db, payment_data)
    payment.insert()
    return payment