示例#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']})
示例#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})
示例#3
0
    def charge_stripe_order_payment(order, token_id):
        """
        Charge the user through Stripe
        :param order: Order for which to charge for
        :param token_id: Stripe token
        :return:
        """
        # save the stripe token with the order
        order.stripe_token = token_id
        save_to_db(order)

        # charge the user
        try:
            charge = StripePaymentsManager.capture_payment(order)
        except ConflictError as e:
            # payment failed hence expire the order
            order.status = 'expired'
            save_to_db(order)

            # delete related attendees to unlock the tickets
            delete_related_attendees_for_order(order)

            raise e

        # charge.paid is true if the charge succeeded, or was successfully authorized for later capture.
        if charge.paid:
            # update the order in the db.
            order.paid_via = charge.source.object
            order.brand = charge.source.brand
            order.exp_month = charge.source.exp_month
            order.exp_year = charge.source.exp_year
            order.last4 = charge.source.last4
            order.transaction_id = charge.id
            order.status = 'completed'
            order.completed_at = datetime.utcnow()
            save_to_db(order)

            on_order_completed(order)

            return True, 'Charge successful'
        # payment failed hence expire the order
        order.status = 'expired'
        save_to_db(order)

        # delete related attendees to unlock the tickets
        delete_related_attendees_for_order(order)

        # return the failure message from stripe.
        return False, charge.failure_message
示例#4
0
    def after_update_object(self, order, data, view_kwargs):
        """
        :param order:
        :param data:
        :param view_kwargs:
        :return:
        """

        if order.status == 'cancelled':
            send_order_cancel_email(order)
            send_notif_ticket_cancel(order)

            # delete the attendees so that the tickets are unlocked.
            delete_related_attendees_for_order(order)

        elif order.status == 'completed' or order.status == 'placed':
            on_order_completed(order)
示例#5
0
def save_order(order):
    order_tickets = {}
    for holder in order.ticket_holders:
        save_to_db(holder)
        if not order_tickets.get(holder.ticket_id):
            order_tickets[holder.ticket_id] = 1
        else:
            order_tickets[holder.ticket_id] += 1

    order.user = current_user

    for ticket in order_tickets:
        od = OrderTicket(
            order_id=order.id, ticket_id=ticket, quantity=order_tickets[ticket]
        )
        save_to_db(od)

    order.quantity = order.tickets_count
    save_to_db(order)

    on_order_completed(order)
示例#6
0
    def charge_paypal_order_payment(order, paypal_payer_id, paypal_payment_id):
        """
        Charge the user through paypal.
        :param order: Order for which to charge for.
        :param paypal_payment_id: payment_id
        :param paypal_payer_id: payer_id
        :return:
        """

        # save the paypal payment_id with the order
        order.paypal_token = paypal_payment_id
        save_to_db(order)

        # create the transaction.
        status, error = PayPalPaymentsManager.execute_payment(
            paypal_payer_id, paypal_payment_id
        )

        if status:
            # successful transaction hence update the order details.
            order.paid_via = 'paypal'
            order.status = 'completed'
            order.transaction_id = paypal_payment_id
            order.completed_at = datetime.utcnow()
            save_to_db(order)

            on_order_completed(order)

            return True, 'Charge successful'
        # payment failed hence expire the order
        order.status = 'expired'
        save_to_db(order)

        # delete related attendees to unlock the tickets
        delete_related_attendees_for_order(order)

        # return the error message from Paypal
        return False, error