Ejemplo n.º 1
0
def pay_online(request, invoice_id, guid="", merchant_account=None, template_name="payments/pay_online.html"):
    # check if they have the right to view the invoice
    invoice = get_object_or_404(Invoice, pk=invoice_id)
    if not invoice.allow_view_by(request.user, guid):
        raise Http403

    # tender the invoice
    if not invoice.is_tendered:
        invoice.tender(request.user)
        # log an event for invoice edit
        EventLog.objects.log(instance=invoice)

    # generate the payment
    payment = Payment()

    boo = payment.payments_pop_by_invoice_user(request.user, invoice, guid)
    # log an event for payment add
    EventLog.objects.log(instance=payment)

    # post payment form to gateway and redirect to the vendor so customer can pay from there
    if boo:
        merchant_account = merchant_account or (get_setting("site", "global", "merchantaccount")).lower()

        if merchant_account == 'stripe':
            return HttpResponseRedirect(reverse('stripe.payonline', args=[payment.id, payment.guid]))
        else:

            if merchant_account == "authorizenet":
                form = prepare_authorizenet_sim_form(request, payment)
                post_url = settings.AUTHNET_POST_URL
            elif merchant_account == 'firstdata':
                from tendenci.apps.payments.firstdata.utils import prepare_firstdata_form
                form = prepare_firstdata_form(request, payment)
                post_url = settings.FIRSTDATA_POST_URL
            elif merchant_account == 'firstdatae4':
                from tendenci.apps.payments.firstdatae4.utils import prepare_firstdatae4_form
                form = prepare_firstdatae4_form(request, payment)
                post_url = settings.FIRSTDATAE4_POST_URL
            elif merchant_account == 'paypalpayflowlink':
                from tendenci.apps.payments.payflowlink.utils import prepare_payflowlink_form
                form = prepare_payflowlink_form(request, payment)
                post_url = settings.PAYFLOWLINK_POST_URL
            elif merchant_account == 'paypal':
                from tendenci.apps.payments.paypal.utils import prepare_paypal_form
                form = prepare_paypal_form(request, payment)
                post_url = settings.PAYPAL_POST_URL
            else:   # more vendors
                logger.error(
                    '"{}" did not match a known online payment method. Check the PaymentMethod.machine_name.'.format(
                        merchant_account))
                form = None
                post_url = ""
    else:
        form = None
        post_url = ""
    return render_to_resp(request=request, template_name=template_name, context={'form': form, 'post_url': post_url
        })
Ejemplo n.º 2
0
def pay_online(request, invoice_id, guid="", template_name="payments/pay_online.html"):
    # check if they have the right to view the invoice
    invoice = get_object_or_404(Invoice, pk=invoice_id)
    if not invoice.allow_view_by(request.user, guid):
        raise Http403

    # tender the invoice
    if not invoice.is_tendered:
        invoice.tender(request.user)
        # log an event for invoice edit
        EventLog.objects.log(instance=invoice)

    # generate the payment
    payment = Payment()

    boo = payment.payments_pop_by_invoice_user(request.user, invoice, guid)
    # log an event for payment add
    EventLog.objects.log(instance=payment)

    # post payment form to gateway and redirect to the vendor so customer can pay from there
    if boo:
        merchant_account = (get_setting("site", "global", "merchantaccount")).lower()

        if merchant_account == 'stripe':
            return HttpResponseRedirect(reverse('stripe.payonline', args=[payment.id]))
        else:

            if merchant_account == "authorizenet":
                form = prepare_authorizenet_sim_form(request, payment)
                post_url = settings.AUTHNET_POST_URL
            elif merchant_account == 'firstdata':
                from tendenci.apps.payments.firstdata.utils import prepare_firstdata_form
                form = prepare_firstdata_form(request, payment)
                post_url = settings.FIRSTDATA_POST_URL
            elif merchant_account == 'firstdatae4':
                from tendenci.apps.payments.firstdatae4.utils import prepare_firstdatae4_form
                form = prepare_firstdatae4_form(request, payment)
                post_url = settings.FIRSTDATAE4_POST_URL
            elif merchant_account == 'paypalpayflowlink':
                from tendenci.apps.payments.payflowlink.utils import prepare_payflowlink_form
                form = prepare_payflowlink_form(request, payment)
                post_url = settings.PAYFLOWLINK_POST_URL
            elif merchant_account == 'paypal':
                from tendenci.apps.payments.paypal.utils import prepare_paypal_form
                form = prepare_paypal_form(request, payment)
                post_url = settings.PAYPAL_POST_URL
            else:   # more vendors
                form = None
                post_url = ""
    else:
        form = None
        post_url = ""
    return render_to_response(template_name,
        {'form': form, 'post_url': post_url
        }, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def pay_online(request, invoice_id, guid="", merchant_account=None, template_name="payments/pay_online.html"):
    # check if they have the right to view the invoice
    invoice = get_object_or_404(Invoice, pk=invoice_id)
    if not invoice.allow_view_by(request.user, guid):
        raise Http403

    # tender the invoice
    if not invoice.is_tendered:
        invoice.tender(request.user)
        # log an event for invoice edit
        EventLog.objects.log(instance=invoice)

    # For event registration, check if we have enough seats available
    obj = invoice.get_object()
    if obj.__class__.__name__ == 'Registration':
        block_message = ''
        event = obj.event
        spots_available = event.get_spots_status()[1]
        if not spots_available:
            block_message = ugettext('No seats available for this event. Please cancel your registration or contact event organizer.')
        else:
            pricings = {}
            for registrant in obj.registrant_set.filter(cancel_dt__isnull=True):
                pricing = registrant.pricing
                if pricing.registration_cap:
                    if pricing not in pricings:
                        pricings[pricing] = 1
                    else:
                        pricings[pricing] += 1
            for p in pricings:
                price_spots_available = p.spots_available()
                if price_spots_available < pricings[p]:
                    if not price_spots_available:
                        block_message += ugettext('No seats available for price option "{}". '.format(p.title))
                    else:
                        block_message += ugettext('The available seats for price option "{}" is not enough for this registration. '.format(p.title))
            if block_message:
                block_message += ugettext('Please cancel your registration and re-register at a different price.')

        if block_message:
            messages.add_message(request, messages.ERROR, block_message)
            return HttpResponseRedirect(reverse(
                                'event.registration_confirmation',
                                args=(event.id, obj.registrant.hash)))

    # generate the payment
    payment = Payment()

    boo = payment.payments_pop_by_invoice_user(request.user, invoice, guid)
    # log an event for payment add
    EventLog.objects.log(instance=payment)

    # post payment form to gateway and redirect to the vendor so customer can pay from there
    if boo:
        merchant_account = merchant_account or (get_setting("site", "global", "merchantaccount")).lower()

        if merchant_account == 'stripe':
            return HttpResponseRedirect(reverse('stripe.payonline', args=[payment.id, payment.guid]))
        else:

            if merchant_account == "authorizenet":
                form = prepare_authorizenet_sim_form(request, payment)
                post_url = settings.AUTHNET_POST_URL
            elif merchant_account == 'firstdata':
                from tendenci.apps.payments.firstdata.utils import prepare_firstdata_form
                form = prepare_firstdata_form(request, payment)
                post_url = settings.FIRSTDATA_POST_URL
            elif merchant_account == 'firstdatae4':
                from tendenci.apps.payments.firstdatae4.utils import prepare_firstdatae4_form
                form = prepare_firstdatae4_form(request, payment)
                post_url = settings.FIRSTDATAE4_POST_URL
            elif merchant_account == 'paypalpayflowlink':
                from tendenci.apps.payments.payflowlink.utils import prepare_payflowlink_form
                form = prepare_payflowlink_form(request, payment)
                post_url = settings.PAYFLOWLINK_POST_URL
            elif merchant_account == 'paypal':
                from tendenci.apps.payments.paypal.utils import prepare_paypal_form
                form = prepare_paypal_form(request, payment)
                post_url = settings.PAYPAL_POST_URL
            else:   # more vendors
                logger.error(
                    '"{}" did not match a known online payment method. Check the PaymentMethod.machine_name.'.format(
                        merchant_account))
                form = None
                post_url = ""
    else:
        form = None
        post_url = ""
    return render_to_resp(request=request, template_name=template_name, context={'form': form, 'post_url': post_url
        })
Ejemplo n.º 4
0
def pay_online(request, invoice_id, guid="", template_name="payments/pay_online.html"):
    # check if they have the right to view the invoice
    invoice = get_object_or_404(Invoice, pk=invoice_id)

    if not invoice.allow_view_by(request.user, guid):
        raise Http403

    # tender the invoice
    if not invoice.is_tendered:
        invoice.tender(request.user)
        # log an event for invoice edit
        EventLog.objects.log(instance=invoice)

    # check payment exist
    payments = Payment.objects.filter(Q(invoice_id=invoice_id))
    if payments and payments.count() > 0 and payments[0].invoice_id == invoice_id:
        template_name="payments/thankyou.html"
        payment = payments[0]
        return render_to_response(template_name, {'payment': payment}, context_instance=RequestContext(request))

    # generate the payment
    payment = Payment()

    boo = payment.payments_pop_by_invoice_user(request.user, invoice, guid)
    # log an event for payment add
    EventLog.objects.log(instance=payment)

    # post payment form to gateway and redirect to the vendor so customer can pay from there
    if boo:
        merchant_account = (get_setting("site", "global", "merchantaccount")).lower()
        if merchant_account == 'stripe':
            return HttpResponseRedirect(reverse('stripe.payonline', args=[payment.id]))
        elif merchant_account == "authorizenet":
            form = prepare_authorizenet_sim_form(request, payment)
            post_url = settings.AUTHNET_POST_URL
        elif merchant_account == 'firstdata':
            from tendenci.apps.payments.firstdata.utils import prepare_firstdata_form
            form = prepare_firstdata_form(request, payment)
            post_url = settings.FIRSTDATA_POST_URL
        elif merchant_account == 'firstdatae4':
            from tendenci.apps.payments.firstdatae4.utils import prepare_firstdatae4_form
            form = prepare_firstdatae4_form(request, payment)
            post_url = settings.FIRSTDATAE4_POST_URL
        elif merchant_account == 'paypalpayflowlink':
            from tendenci.apps.payments.payflowlink.utils import prepare_payflowlink_form
            form = prepare_payflowlink_form(request, payment)
            post_url = settings.PAYFLOWLINK_POST_URL
        elif merchant_account == 'paypal':
            from tendenci.apps.payments.paypal.utils import prepare_paypal_form
            form = prepare_paypal_form(request, payment)
            post_url = settings.PAYPAL_POST_URL
        elif merchant_account == 'wechat-pay':
            wechatpay_config = get_wechatpay_config()
            if wechatpay_config == None:
                return HttpResponseRedirect(reverse('settings.index', args=['site', 'global']) + '#id_sitewebmaster')

            params = {
                # urlencode to wechatpay api get params ,body max length is 128
                #'body': urlencode({'xyz1': payment.description[0:128]}).replace('xyz1=',''),  # 商品或支付单简要描述,例如:Ipad mini  16G  白色
                # 'body': u'%s' % payment.description[0:128],
                'body': u'Ipad mini  16G  白色',
                'out_trade_no': payment.guid.replace('-', ''),  # 商户系统内部的订单号,32个字符内、可包含字母

                'total_fee': int(payment.amount * 100),  # 订单总金额,单位为分

                'product_id': invoice_id,  # 商品ID

                'notify_url': 'https://www.kunshanfa.com/payments/wxcallback/',

                'trade_type': 'NATIVE',

            }
            wxpay = WxPayBasic(wechatpay_config)
            code_url = wxpay.unifiedorder2_get_code_url(**params)
            print(code_url)
            template_name = 'payments/wechatpay.html'
            return render_to_response(template_name,
                                      {'code_url': code_url, 'payment': payment}, context_instance=RequestContext(request))
        else:   # more vendors
            form = None
            post_url = ""
    else:
        form = None
        post_url = ""
    return render_to_response(template_name,
        {'form': form, 'post_url': post_url
        }, context_instance=RequestContext(request))