示例#1
0
def render_payment_standard_button(owner, amount="10.00"):
    logging.info('rendering standard payment button. sandbox? %d, %d' %
                 (settings.PAYPAL_TEST, TEST))

    # What you want the button to do.
    invoice = Invoice(owner=owner, pk=int(time.time()))
    invoice.save()

    #TODO remove hardcoded URLs and domain name
    paypal_dict = {
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "amount": amount,
        "item_name": "On-demand OCR",
        "invoice": str(invoice.pk),
        "notify_url":
        "https://archive.donomo.com/account/pay/ipn/gpxjyxmrzzqpncosnbenvkkzcmxz/",
        "return_url": "https://archive.donomo.com/account/pay/return/",
        "cancel_return": "https://archive.donomo.com/account/pay/cancel/",
    }

    # Create the instance.
    form = PayPalEncryptedPaymentsForm(
        initial=paypal_dict
    )  #PayPalSharedSecretEncryptedPaymentsForm(initial=paypal_dict)

    # Output the button.
    result = form.render()

    return result
示例#2
0
    def test_encrypted_button(self):
        data = {
            'amount': '10.50',
            'shipping': '2.00',
        }

        # Paypal Certificate Information
        here = os.path.dirname(os.path.abspath(__file__))
        paypal_private_cert = os.path.join(here, 'test_cert__do_not_use__private.pem')
        paypal_public_cert = os.path.join(here, 'test_cert__do_not_use__public.pem')
        paypal_cert = os.path.join(here, 'test_cert_from_paypal__do_not_use.pem')
        paypal_cert_id = 'another-paypal-id'

        # Create the instance.
        form = PayPalEncryptedPaymentsForm(
            initial=data,
            private_cert=paypal_private_cert,
            public_cert=paypal_public_cert,
            paypal_cert=paypal_cert,
            cert_id=paypal_cert_id
        )

        rendered = form.render()

        self.assertIn('''name="cmd" value="_s-xclick"''', rendered)
        self.assertIn('''name="encrypted" value="-----BEGIN PKCS7-----''', rendered)
        expected_regex = re.compile(
            r'.*name="encrypted" value="-----BEGIN PKCS7-----\n' +
            r'([A-Za-z0-9/\+]{64}\n)*[A-Za-z0-9/\+]{1,64}={0,2}\n' +
            r'-----END PKCS7-----\n.*'
        )
        self.assertTrue(
            expected_regex.search(rendered),
            msg='Button encryption has wrong form - expected a block of PKCS7 data'
        )
示例#3
0
def render_subscription_button(owner, amount):
    # What you want the button to do.
    paypal_dict = {
        "cmd": "_xclick-subscriptions",
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "a3": amount,  # monthly price
        "p3": 1,  # duration of each unit (depends on unit)
        "t3": "M",  # duration unit ("M for Month")
        "src": "1",  # make payments recur
        "sra": "1",  # reattempt payment on payment error
        "no_note": "1",  # remove extra notes (optional)
        "item_name": "Cloud OCR subscription",
        "notify_url":
        "https://archive.donomo.com/account/pay/ipn/gpxjyxmrzzqpncosnbenvkkzcmxz/",
        "return_url": "https://archive.donomo.com/account/pay/return/",
        "cancel_return": "https://archive.donomo.com/account/pay/cancel/",
    }

    # Create the instance.
    form = PayPalEncryptedPaymentsForm(initial=paypal_dict,
                                       button_type="subscribe")

    # Output the button.
    result = form.render()

    return result
示例#4
0
    def test_encrypted_button(self):
        data = {
            "amount": "10.50",
            "shipping": "2.00",
        }

        # Paypal Certificate Information
        here = os.path.dirname(os.path.abspath(__file__))
        paypal_private_cert = os.path.join(here, "test_cert__do_not_use__private.pem")
        paypal_public_cert = os.path.join(here, "test_cert__do_not_use__public.pem")
        paypal_cert = os.path.join(here, "test_cert_from_paypal__do_not_use.pem")
        paypal_cert_id = "another-paypal-id"

        # Create the instance.
        form = PayPalEncryptedPaymentsForm(
            initial=data,
            private_cert=paypal_private_cert,
            public_cert=paypal_public_cert,
            paypal_cert=paypal_cert,
            cert_id=paypal_cert_id,
        )
        rendered = form.render()

        self.assertIn('''name="cmd" value="_s-xclick"''', rendered)
        self.assertIn("""name="encrypted" value="-----BEGIN PKCS7-----""", rendered)
        expected_regex = re.compile(
            r'.*name="encrypted" value="-----BEGIN PKCS7-----\n'
            + r"([A-Za-z0-9/\+]{64}\n)*[A-Za-z0-9/\+]{1,64}={0,2}\n"
            + r"-----END PKCS7-----\n.*"
        )
        self.assertTrue(
            expected_regex.search(rendered),
            msg="Button encryption has wrong form - expected a block of PKCS7 data",
        )
示例#5
0
def render_payment_standard_button(owner, amount = "10.00"):
    logging.info('rendering standard payment button. sandbox? %d, %d' % (settings.PAYPAL_TEST, TEST))

    # What you want the button to do.
    invoice = Invoice(owner = owner, pk = int(time.time()))
    invoice.save()

    #TODO remove hardcoded URLs and domain name
    paypal_dict = {
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "amount": amount,
        "item_name": "On-demand OCR",
        "invoice": str(invoice.pk),
        "notify_url": "https://archive.donomo.com/account/pay/ipn/gpxjyxmrzzqpncosnbenvkkzcmxz/",
        "return_url": "https://archive.donomo.com/account/pay/return/",
        "cancel_return": "https://archive.donomo.com/account/pay/cancel/",
    }

    # Create the instance.
    form = PayPalEncryptedPaymentsForm(initial=paypal_dict) #PayPalSharedSecretEncryptedPaymentsForm(initial=paypal_dict)


    # Output the button.
    result = form.render()

    return result
示例#6
0
def render_subscription_button(owner, amount):
    # What you want the button to do.
    paypal_dict = {
        "cmd": "_xclick-subscriptions",
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "a3": amount,                      # monthly price
        "p3": 1,                           # duration of each unit (depends on unit)
        "t3": "M",                         # duration unit ("M for Month")
        "src": "1",                        # make payments recur
        "sra": "1",                        # reattempt payment on payment error
        "no_note": "1",                    # remove extra notes (optional)
        "item_name": "Cloud OCR subscription",
        "notify_url": "https://archive.donomo.com/account/pay/ipn/gpxjyxmrzzqpncosnbenvkkzcmxz/",
        "return_url": "https://archive.donomo.com/account/pay/return/",
        "cancel_return": "https://archive.donomo.com/account/pay/cancel/",
    }

    # Create the instance.
    form = PayPalEncryptedPaymentsForm(initial=paypal_dict, button_type="subscribe")


    # Output the button.
    result = form.render()

    return result
示例#7
0
def checkout(request):
    if not request.user.is_authenticated():
        messages.info(request, "Please login or register before continue.")
        return HttpResponseRedirect('%s?next=%s' %
                                    (reverse('accounts.views.login_register'),
                                     reverse('baskets.views.checkout')))
    if request.user.is_staff:
        messages.info(
            request,
            "You are logged in as adminstrator, please logout and login with your customer accounts"
        )
        referer = request.META.get('HTTP_REFERER', '/')
        return HttpResponseRedirect(referer)

    delivery = None
    note = None

    deliveries = Delivery.objects.all()
    cart = Cart(request, 'cart')
    cart_subtotal = cart.total_price
    if not cart.items:
        messages.info(request, 'Your shopping bag is empty.')
        return HttpResponseRedirect('/')

    if request.method == "POST":
        if request.POST.has_key('note'):
            note = request.POST.get('note')

    delivery = Delivery.objects.all()[0]

    order_pk = request.session.get('order_pk', '')
    if order_pk:
        try:
            order = Order.objects.get(pk=order_pk)
            order = update_order(request, order, cart, delivery, note)
        except Order.DoesNotExist:
            order = create_order(request, cart)
    else:
        order = create_order(request, cart)

    paypal_dict = {
        'business': settings.PAYPAL_RECEIVER_EMAIL,
        'return_url': settings.PAYPAL_RETURN_URL,
        'invoice': '{0}'.format(order.pk),
        'notify_url': settings.PAYPAL_NOTIFY_URL,
    }
    form = PayPalEncryptedPaymentsForm(cart, order=order, initial=paypal_dict)
    if settings.SERVER_STATUS == "LIVE":
        form_type = form.render()
    else:
        form_type = form.render()

    orderlines = order.orderline_set.all()

    return render_to_response('baskets/checkout.html', {
        'cart': cart,
        'cart_subtotal': cart_subtotal,
        'deliveries': deliveries,
        'delivery': delivery,
        'order': order,
        'orderlines': orderlines,
        'form': form_type
    },
                              context_instance=RequestContext(request))
示例#8
0
 def make_form(d):
     if getattr(settings, 'PAYPAL_ENCRYPTED', False):
         form = PayPalEncryptedPaymentsForm(initial=d)
     else:
         form = PayPalPaymentsForm(initial=d)
     return form
示例#9
0
文件: views.py 项目: kelvinn/helomx
def pay_invoice(request):
    from random import random
    engineer = Engineer.objects.get(user__username=request.user.username)
    mailserver_list = get_mx_list(engineer.company)
    message = None

    company = engineer.company
    engineer_list = Engineer.objects.filter(company=company)

    inv_num = int(random() * 10000000)

    # What you want the button to do.
    ten_dolla_dict = {
        "business": "*****@*****.**",
        "item_name": "HeloMX Credit",
        "amount": "10.00",
        "invoice": inv_num,
        'custom': "%s" % company.slug,
        "notify_url": "https://www.helomx.com/paypal/api/notify/",
        "return_url": "https://www.helomx.com/dashboard/?success=funds",
        "cancel_return":
        "https://www.helomx.com/dashboard/?success=fundscancel",
    }

    test_dolla_dict = {
        "business": "*****@*****.**",
        "item_name": "HeloMX Credit",
        "amount": "1.00",
        "invoice": inv_num,
        'custom': "%s" % company.slug,
        "notify_url": "https://www.helomx.com/paypal/api/notify/",
        "return_url": "https://www.helomx.com/dashboard/?success=funds",
        "cancel_return":
        "https://www.helomx.com/dashboard/?success=fundscancel",
    }

    tf_dolla_dict = {
        "business": "*****@*****.**",
        "item_name": "HeloMX Credit",
        "amount": "25.00",
        "invoice": inv_num,
        'custom': "%s" % company.slug,
        "notify_url": "https://www.helomx.com/paypal/api/notify/",
        "return_url": "https://www.helomx.com/dashboard/?success=funds",
        "cancel_return":
        "https://www.helomx.com/dashboard/?success=fundscancel",
    }
    f_dolla_dict = {
        "business": "*****@*****.**",
        "item_name": "HeloMX Credit",
        "amount": "50.00",
        "invoice": inv_num,
        'custom': "%s" % company.slug,
        "notify_url": "https://www.helomx.com/paypal/api/notify/",
        "return_url": "https://www.helomx.com/dashboard/?success=funds",
        "cancel_return":
        "https://www.helomx.com/dashboard/?success=fundscancel",
    }

    oh_dolla_dict = {
        "business": "*****@*****.**",
        "item_name": "HeloMX Credit",
        "amount": "100.00",
        "invoice": inv_num,
        'custom': "%s" % company.slug,
        "notify_url": "https://www.helomx.com/paypal/api/notify/",
        "return_url": "https://www.helomx.com/dashboard/?success=funds",
        "cancel_return":
        "https://www.helomx.com/dashboard/?success=fundscancel",
    }
    fh_dolla_dict = {
        "business": "*****@*****.**",
        "item_name": "HeloMX Credit",
        "amount": "500.00",
        "invoice": inv_num,
        'custom': "%s" % company.slug,
        "notify_url": "https://www.helomx.com/paypal/api/notify/",
        "return_url": "https://www.helomx.com/dashboard/?success=funds",
        "cancel_return":
        "https://www.helomx.com/dashboard/?success=fundscancel",
    }
    # Create the instance.
    #coupon_form = CouponForm(request.POST)

    return render_to_response(
        "billing/payment.html", {
            'mailserver_list': mailserver_list,
            'message': message,
            'company': company,
            'engineer_list': engineer_list,
            'test_dolla_form':
            PayPalEncryptedPaymentsForm(initial=test_dolla_dict),
            'ten_dolla_form':
            PayPalEncryptedPaymentsForm(initial=ten_dolla_dict),
            'tf_dolla_form':
            PayPalEncryptedPaymentsForm(initial=tf_dolla_dict),
            'f_dolla_form': PayPalEncryptedPaymentsForm(initial=f_dolla_dict),
            'oh_dolla_form':
            PayPalEncryptedPaymentsForm(initial=oh_dolla_dict),
            'fh_dolla_form':
            PayPalEncryptedPaymentsForm(initial=fh_dolla_dict),
        },
        context_instance=RequestContext(request))
示例#10
0
def checkout(request):
    if not request.user.is_authenticated():
        messages.info(request, "Please login or register before continue.")
        return HttpResponseRedirect('%s?next=%s' % (reverse('accounts.views.login_register'), reverse('baskets.views.checkout')))
    if request.user.is_staff:
        messages.info(request, "You are logged in as adminstrator, please logout and login with your customer accounts")
        referer = request.META.get('HTTP_REFERER','/')
        return HttpResponseRedirect(referer)

    delivery = None
    note = None

    deliveries = Delivery.objects.all()
    cart = Cart(request, 'cart')
    cart_subtotal = cart.total_price
    if not cart.items:
        messages.info(request, 'Your shopping bag is empty.')
        return HttpResponseRedirect('/')


    if request.method == "POST":
        if request.POST.has_key('note'):
            note = request.POST.get('note')

    delivery = Delivery.objects.all()[0]

    order_pk = request.session.get('order_pk', '')
    if order_pk:
        try:
            order = Order.objects.get(pk=order_pk)
            order = update_order(request, order, cart, delivery, note)
        except Order.DoesNotExist:
            order = create_order(request, cart)
    else:
        order = create_order(request, cart)

    paypal_dict = {
            'business': settings.PAYPAL_RECEIVER_EMAIL,
            'return_url': settings.PAYPAL_RETURN_URL,
            'invoice': '{0}'.format(order.pk),
            'notify_url': settings.PAYPAL_NOTIFY_URL,
    }
    form = PayPalEncryptedPaymentsForm(cart,
                                       order=order,
                                       initial=paypal_dict)
    if settings.SERVER_STATUS == "LIVE":
        form_type = form.render()
    else:
        form_type = form.render()

    orderlines = order.orderline_set.all()

    return render_to_response('baskets/checkout.html', {
             'cart':cart,
             'cart_subtotal':cart_subtotal,
             'deliveries': deliveries,
             'delivery': delivery,
             'order':order,
             'orderlines': orderlines,
             'form': form_type
             },
             context_instance=RequestContext(request))