Beispiel #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']})
 def before_create_object(self, data, view_kwargs):
     """
     method to check if stripe authorization object already exists for an event.
     Raises ConflictError if it already exists.
     If it doesn't, then uses the StripePaymentManager to get the other credentials from Stripe.
     :param data:
     :param view_kwargs:
     :return:
     """
     try:
         self.session.query(StripeAuthorization).filter_by(
             event_id=data['event'], deleted_at=None).one()
     except NoResultFound:
         credentials = StripePaymentsManager.get_event_organizer_credentials_from_stripe(
             data['stripe_auth_code'])
         if 'error' in credentials:
             raise UnprocessableEntityError(
                 {'pointer': '/data/stripe_auth_code'},
                 credentials['error_description'],
             )
         data['stripe_secret_key'] = credentials['access_token']
         data['stripe_refresh_token'] = credentials['refresh_token']
         data['stripe_publishable_key'] = credentials[
             'stripe_publishable_key']
         data['stripe_user_id'] = credentials['stripe_user_id']
     else:
         raise ConflictError(
             {'pointer': '/data/relationships/event'},
             "Stripe Authorization already exists for this event",
         )
    def charge_stripe_order_payment(order, token_id):
        order.stripe_token = token_id
        save_to_db(order)
        charge = StripePaymentsManager.capture_payment(order)

        if charge:
            order.paid_via = 'stripe'
            order.payment_mode = 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)

            invoice_id = order.get_invoice_number()
            order_url = make_frontend_url(path="/{identifier}/view/".format(
                identifier=order.identifier))
            # send_email_for_after_purchase(order.user.email, invoice_id, order_url, order.event.name,
            # order.event.organizer_name)
            # send_notif_for_after_purchase(order.user, invoice_id, order_url)

            return True, order
        else:
            return False, 'Error'
    def charge_stripe_order_payment(order, token_id):
        order.stripe_token = token_id
        save_to_db(order)
        charge = StripePaymentsManager.capture_payment(order)

        if charge:
            order.paid_via = 'stripe'
            order.payment_mode = 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)

            invoice_id = order.get_invoice_number()
            order_url = make_frontend_url(path="/{identifier}/view/".format(identifier=order.identifier))
            # send_email_for_after_purchase(order.user.email, invoice_id, order_url, order.event.name,
                                          # order.event.organizer_name)
            # send_notif_for_after_purchase(order.user, invoice_id, order_url)

            return True, order
        else:
            return False, 'Error'
Beispiel #5
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})
Beispiel #6
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
Beispiel #7
0
    def charge_stripe_order_payment(order):
        """
        Create session for order
        :param order: Order for which to charge for
        :return:
        """
        # create session for the user
        try:
            session = StripePaymentsManager.capture_payment(order)
            order.stripe_session_id = session['id']
            db.session.commit()
            return True, session
        except ConflictError as e:
            # session creation 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, e
    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)

            # create tickets.
            create_pdf_tickets_for_holder(order)

            # send email and notifications.
            send_email_to_attendees(order, current_user.id)
            send_notif_to_attendees(order, current_user.id)

            order_url = make_frontend_url(path=f'/orders/{order.identifier}')
            for organizer in order.event.organizers:
                send_notif_ticket_purchase_organizer(organizer,
                                                     order.invoice_number,
                                                     order_url,
                                                     order.event.name,
                                                     order.id)
            if order.event.owner:
                send_notif_ticket_purchase_organizer(
                    order.event.owner,
                    order.invoice_number,
                    order_url,
                    order.event.name,
                    order.id,
                )

            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