def charge_paypal_order_payment(order):
        payment_details = PayPalPaymentsManager.get_approved_payment_details(order)
        if 'PAYERID' in payment_details:
            capture_result = PayPalPaymentsManager.capture_payment(order, payment_details['PAYERID'])
            if capture_result['ACK'] == 'Success':
                order.paid_via = 'paypal'
                order.status = 'completed'
                order.transaction_id = capture_result['PAYMENTINFO_0_TRANSACTIONID']
                order.completed_at = datetime.utcnow()
                save_to_db(order)

                invoice_id = order.get_invoice_number()
                order_url = url_for('ticketing.view_order_after_payment',
                                    order_identifier=order.identifier,
                                    _external=True)
                trigger_after_purchase_notifications(order.user.email, order.event_id, order.event, invoice_id,
                                                     order_url)
                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, capture_result['L_SHORTMESSAGE0']
        else:
            return False, 'Payer ID missing. Payment flow tampered.'
    def charge_paypal_order_payment(order):
        payment_details = PayPalPaymentsManager.get_approved_payment_details(order)
        if 'PAYERID' in payment_details:
            capture_result = PayPalPaymentsManager.capture_payment(order, payment_details['PAYERID'])
            if capture_result['ACK'] == 'Success':
                order.paid_via = 'paypal'
                order.status = 'completed'
                order.transaction_id = capture_result['PAYMENTINFO_0_TRANSACTIONID']
                order.completed_at = datetime.utcnow()
                save_to_db(order)

                invoice_id = order.get_invoice_number()
                order_url = url_for('ticketing.view_order_after_payment',
                                    order_identifier=order.identifier,
                                    _external=True)
                trigger_after_purchase_notifications(order.user.email, order.event_id, order.event, invoice_id,
                                                     order_url)
                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, capture_result['L_SHORTMESSAGE0']
        else:
            return False, 'Payer ID missing. Payment flow tampered.'
def initiate_invoice_payment():
    result = InvoicingManager.initiate_invoice_payment(request.form)
    if result:
        if request.form.get('pay_via_service', 'stripe') == 'stripe':
            return jsonify({
                "status":
                "ok",
                "email":
                result.user.email,
                "action":
                "start_stripe"
                if result.status == 'initialized' else "show_completed"
            })
        else:
            return jsonify({
                "status":
                "ok",
                "email":
                result.user.email,
                "action":
                "start_paypal",
                "redirect_url":
                PayPalPaymentsManager.get_checkout_url(result)
            })
    else:
        return jsonify({"status": "error"})
def view_invoice(invoice_identifier):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    if not invoice:
        abort(404)
    if invoice.status == 'completed':
        return redirect(
            url_for('event_invoicing.view_invoice_after_payment',
                    invoice_identifier=invoice_identifier))

    pay_by_stripe = False
    pay_by_paypal = False

    stripe_publishable_key = "No Key Set"

    if StripePaymentsManager.get_credentials():
        pay_by_stripe = True
        stripe_publishable_key = StripePaymentsManager.get_credentials(
        )['PUBLISHABLE_KEY']

    if PayPalPaymentsManager.get_credentials():
        pay_by_paypal = True

    return render_template(
        'gentelella/guest/invoicing/invoice_pre_payment.html',
        invoice=invoice,
        event=invoice.event,
        countries=list(pycountry.countries),
        pay_by_stripe=pay_by_stripe,
        pay_by_paypal=pay_by_paypal,
        stripe_publishable_key=stripe_publishable_key)
def initiate_order_payment():
    paid_via = request.form.get('pay_via_service', 'stripe')
    result = TicketingManager.initiate_order_payment(request.form, paid_via)
    if result:
        if request.form.get('pay_via_service', 'stripe') != 'paypal':
            return jsonify({
                "status":
                "ok",
                "email":
                result.user.email,
                "action":
                "start_stripe" if result.status == 'initialized'
                and paid_via == 'stripe' else "show_completed"
            })
        else:
            return jsonify({
                "status":
                "ok",
                "email":
                result.user.email,
                "action":
                "start_paypal",
                "redirect_url":
                PayPalPaymentsManager.get_checkout_url(result)
            })
    else:
        return jsonify({"status": "error"})
def view_invoice(invoice_identifier):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    if not invoice:
        abort(404)
    if invoice.status == 'completed':
        return redirect(
            url_for('event_invoicing.view_invoice_after_payment', invoice_identifier=invoice_identifier))

    pay_by_stripe = False
    pay_by_paypal = False

    stripe_publishable_key = "No Key Set"

    if StripePaymentsManager.get_credentials():
        pay_by_stripe = True
        stripe_publishable_key = StripePaymentsManager.get_credentials()['PUBLISHABLE_KEY']

    if PayPalPaymentsManager.get_credentials():
        pay_by_paypal = True

    return render_template('gentelella/guest/invoicing/invoice_pre_payment.html', invoice=invoice, event=invoice.event,
                           countries=list(pycountry.countries),
                           pay_by_stripe=pay_by_stripe,
                           pay_by_paypal=pay_by_paypal,
                           stripe_publishable_key=stripe_publishable_key)
    def charge_paypal_invoice_payment(invoice):
        payment_details = PayPalPaymentsManager \
            .get_approved_payment_details(invoice, credentials=PayPalPaymentsManager.get_credentials())

        if 'PAYERID' in payment_details:
            capture_result = PayPalPaymentsManager \
                .capture_payment(invoice, payment_details['PAYERID'],
                                 credentials=PayPalPaymentsManager.get_credentials())

            if capture_result['ACK'] == 'Success':
                invoice.paid_via = 'paypal'
                invoice.status = 'completed'
                invoice.transaction_id = capture_result['PAYMENTINFO_0_TRANSACTIONID']
                invoice.completed_at = datetime.utcnow()
                save_to_db(invoice)
                return True, invoice
            else:
                return False, capture_result['L_SHORTMESSAGE0']
        else:
            return False, 'Payer ID missing. Payment flow tampered.'
Esempio n. 8
0
    def charge_paypal_invoice_payment(invoice):
        payment_details = PayPalPaymentsManager\
            .get_approved_payment_details(invoice, credentials=PayPalPaymentsManager.get_credentials())

        if 'PAYERID' in payment_details:
            capture_result = PayPalPaymentsManager\
                .capture_payment(invoice, payment_details['PAYERID'],
                                 credentials=PayPalPaymentsManager.get_credentials())

            if capture_result['ACK'] == 'Success':
                invoice.paid_via = 'paypal'
                invoice.status = 'completed'
                invoice.transaction_id = capture_result[
                    'PAYMENTINFO_0_TRANSACTIONID']
                invoice.completed_at = datetime.utcnow()
                save_to_db(invoice)
                return True, invoice
            else:
                return False, capture_result['L_SHORTMESSAGE0']
        else:
            return False, 'Payer ID missing. Payment flow tampered.'
 def initiate_order_payment(self):
     result = TicketingManager.initiate_order_payment(request.form)
     if result:
         if request.form.get('pay_via_service', 'stripe') == 'stripe':
             return jsonify({
                 "status": "ok",
                 "email": result.user.email,
                 "action": "start_stripe" if result.status == 'initialized' else "show_completed"
             })
         else:
             return jsonify({
                 "status": "ok",
                 "email": result.user.email,
                 "action": "start_paypal",
                 "redirect_url": PayPalPaymentsManager.get_checkout_url(result)
             })
     else:
         return jsonify({
             "status": "error"
         })