Exemple #1
0
def verify_order_payment(order_identifier):

    order = Order.query.filter_by(identifier=order_identifier).first()

    try:
        session = StripePaymentsManager.retrieve_session(
            order.event, order.stripe_session_id)
        payment_intent = StripePaymentsManager.retrieve_payment_intent(
            order.event, session.payment_intent)
    except Exception as e:
        raise e

    if session['payment_status'] == 'paid':
        order.status = 'completed'
        order.completed_at = datetime.utcnow()
        order.paid_via = payment_intent['charges']['data'][0][
            'payment_method_details']['type']
        order.transaction_id = payment_intent['charges']['data'][0][
            'balance_transaction']
        save_to_db(order)

        on_order_completed(order)

    else:
        order.status = 'expired'

        db.session.commit()
        # delete related attendees to unlock the tickets
        delete_related_attendees_for_order(order)

    return jsonify({'payment_status': session['payment_status']})
Exemple #2
0
def verify_order_payment(order_identifier):

    order = Order.query.filter_by(identifier=order_identifier).first()
    
    if order.payment_mode == 'stripe':
        try:
            payment_intent = StripePaymentsManager.retrieve_payment_intent(order.event, order.stripe_payment_intent_id)
        except Exception as e:
            raise e

        if payment_intent['status'] == 'succeeded':
            order.status = 'completed'
            order.completed_at = datetime.utcnow()
            order.paid_via = payment_intent['charges']['data'][0]['payment_method_details']['type']
            order.transaction_id = payment_intent['charges']['data'][0]['balance_transaction']
            if payment_intent['charges']['data'][0]['payment_method_details']['type'] == 'card' :
                order.brand = payment_intent['charges']['data'][0]['payment_method_details']['card']['brand']
                order.exp_month = payment_intent['charges']['data'][0]['payment_method_details']['card']['exp_month']
                order.exp_year = payment_intent['charges']['data'][0]['payment_method_details']['card']['exp_year']
                order.last4 = payment_intent['charges']['data'][0]['payment_method_details']['card']['last4']
            save_to_db(order)

            on_order_completed(order)


    return jsonify({ 'payment_status': order.status})