Exemplo n.º 1
0
        def __init__(self, order, *args, **kwargs):
            from django.db import models
            initial = settings.PAYPAL_DEFAULT_FORM_CONTEXT(order)
            initial.update({'cmd': self.CMD_CHOICES[1][0]})
            kwargs['initial'] = initial
            super(PayPalForm, self).__init__(*args, **kwargs)

            items = list(order.orderitem_set \
                              .filter(price__gte=0).values('code','description','price') \
                              .annotate(count=models.Count('price')) \
                              .order_by('-price'))

            discount = order.total(apply_discounts=False) - order.total()

            if discount > 0:
                self.fields['discount_amount_cart'] = forms.IntegerField(
                    widget=ValueHiddenInput(), initial=discount)
            self.fields['upload'] = forms.IntegerField(
                widget=ValueHiddenInput(), initial=1)
            for n, item in enumerate(items, start=1):
                self.fields['item_name_%d' % n] = forms.CharField(
                    widget=ValueHiddenInput(),
                    initial=settings.PAYPAL_ITEM_NAME(item))
                self.fields['quantity_%d' % n] = forms.CharField(
                    widget=ValueHiddenInput(), initial=item['count'])
                self.fields['amount_%d' % n] = forms.CharField(
                    widget=ValueHiddenInput(), initial=item['price'])
Exemplo n.º 2
0
 def __init__(self, button_type="buy", *args, **kwargs):
     super(PayPalPaymentsForm, self).__init__(*args, **kwargs)
     self.button_type = button_type
     if 'initial' in kwargs:
         # Dynamically create, so we can support everything PayPal does.
         for k, v in kwargs['initial'].items():
             if k not in self.base_fields:
                 self.fields[k] = forms.CharField(label=k, widget=ValueHiddenInput(), initial=v)
Exemplo n.º 3
0
 def __init__(self, button_type="buy", sandbox=None, *args, **kwargs):
     super(PayPalPaymentsForm, self).__init__(*args, **kwargs)
     self.button_type = button_type
     if 'initial' in kwargs:
         kwargs['initial'] = self._fix_deprecated_paypal_receiver_email(kwargs['initial'])
         kwargs['initial'] = self._fix_deprecated_return_url(kwargs['initial'])
         # Dynamically create, so we can support everything PayPal does.
         for k, v in kwargs['initial'].items():
             if k not in self.base_fields:
                 self.fields[k] = forms.CharField(label=k, widget=ValueHiddenInput(), initial=v)
    # Allow test mode to be set per-form, rather than require it to be global
     self.sandbox = sandbox if sandbox != None else getattr(settings, 'PAYPAL_TEST', True)
Exemplo n.º 4
0
 def __init__(self, button_type="buy", *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.button_type = button_type
     if "initial" in kwargs:
         kwargs["initial"] = self._fix_deprecated_return_url(
             kwargs["initial"])
         # Dynamically create, so we can support everything PayPal does.
         for k, v in kwargs["initial"].items():
             if k not in self.base_fields:
                 self.fields[k] = forms.CharField(label=k,
                                                  widget=ValueHiddenInput(),
                                                  initial=v)
Exemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        super(PayPalCreditsPacketPurchaseForm, self).__init__(*args, **kwargs)

        # Automatically set business email address to the correct value
        self.fields['business'] = forms.CharField(
            widget=ValueHiddenInput(),
            initial=settings.PAYPAL_BUSINESS_EMAIL_ADDRESS)

        # Let the user choose the quantity
        self.fields['quantity'] = forms.IntegerField(
            label=_('Quantity'),
            widget=NumberInput(attrs={'min': 1}),
            initial=1)

        current_domain = Site.objects.get_current().domain
        self.fields['notify_url'] = forms.URLField(
            widget=ValueHiddenInput(),
            initial=(current_domain + reverse('paypal-ipn')))
        self.fields['return_url'] = forms.URLField(
            widget=ValueHiddenInput(),
            initial=(current_domain + reverse('dashboard:payment-completed')))
        self.fields['cancel_return'] = forms.URLField(
            widget=ValueHiddenInput(),
            initial=(current_domain + reverse('dashboard:payment-cancelled')))

        # Subscription options
        # monthly price
        self.fields['a3'] = forms.FloatField(widget=ValueHiddenInput(),
                                             initial=.0)
        # duration of each units (depends on unit)
        self.fields['p3'] = forms.IntegerField(widget=ValueHiddenInput(),
                                               initial=12)
        # duration unit ('M' for Months)
        self.fields['t3'] = forms.CharField(max_length=1,
                                            min_length=1,
                                            widget=ValueHiddenInput(),
                                            initial='M')
        # make payment recur
        self.fields['src'] = forms.IntegerField(widget=ValueHiddenInput(),
                                                initial=True)
        # reattempt payment on error
        self.fields['sra'] = forms.IntegerField(widget=ValueHiddenInput(),
                                                initial=True)
Exemplo n.º 6
0
class AliPayDirectPayForm(AliPayPaymentBaseForm):
    def __init__(self, *args, **kwargs):
        AliPayPaymentBaseForm.__init__(self, *args, **kwargs)

    service = forms.CharField(widget=ValueHiddenInput(), initial=SERVICE[0])
    '''
    生成html的form表单
    '''

    def render(self):
        return mark_safe(u"""<form action="%s" method="post">
    %s
    <input type="image" src="%s" border="0" name="submit" alt="Buy it Now" />
</form>""" % (self.get_action(), self.as_p(), ''))
Exemplo n.º 7
0
class PayPalPaymentsForm(forms.Form):
    """
    Creates a PayPal Payments Standard "Buy It Now" button, configured for a
    selling a single item with no shipping.
    
    For a full overview of all the fields you can set (there is a lot!) see:
    http://tinyurl.com/pps-integration
    
    Usage:
    >>> f = PayPalPaymentsForm(initial={'item_name':'Widget 001', ...})
    >>> f.render()
    u'<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> ...'
    
    """    
    CMD_CHOICES = (("_xclick", "Buy now or Donations"), ("_cart", "Shopping cart"), ("_xclick-subscriptions", "Subscribe"))
    SHIPPING_CHOICES = ((1, "No shipping"), (0, "Shipping"))
    NO_NOTE_CHOICES = ((1, "No Note"), (0, "Include Note"))
    RECURRING_PAYMENT_CHOICES = ((1, "Subscription Payments Recur"), (0, "Subscription payments do not recur"))
    REATTEMPT_ON_FAIL_CHOICES = ((1, "reattempt billing on Failure"), (0, "Do Not reattempt on failure"))
        
    # Where the money goes.
    business = forms.CharField(widget=ValueHiddenInput(), initial=RECEIVER_EMAIL)

    # Item information.
    amount = forms.IntegerField(widget=ValueHiddenInput())
    item_name = forms.CharField(widget=ValueHiddenInput())
    item_number = forms.CharField(widget=ValueHiddenInput())
    quantity = forms.CharField(widget=ValueHiddenInput())
    
    # Subscription Related.
    a3 = forms.CharField(widget=ValueHiddenInput())  # Subscription Price
    p3 = forms.CharField(widget=ValueHiddenInput())  # Subscription Duration
    t3 = forms.CharField(widget=ValueHiddenInput())  # Subscription unit of Duration, default to Month
    src = forms.CharField(widget=ValueHiddenInput()) # Is billing recurring? default to yes
    sra = forms.CharField(widget=ValueHiddenInput()) # Reattempt billing on failed cc transaction
    no_note = forms.CharField(widget=ValueHiddenInput())

    # Localization / PayPal Setup
    lc = forms.CharField(widget=ValueHiddenInput())
    page_style = forms.CharField(widget=ValueHiddenInput())
    cbt = forms.CharField(widget=ValueHiddenInput())

    # IPN control.
    notify_url = forms.CharField(widget=ValueHiddenInput())
    cancel_return = forms.CharField(widget=ValueHiddenInput())
    return_url = forms.CharField(widget=ReservedValueHiddenInput(attrs={"name":"return"}))
    custom = forms.CharField(widget=ValueHiddenInput())
    invoice = forms.CharField(widget=ValueHiddenInput())
    
    # Default fields.
    cmd = forms.ChoiceField(widget=forms.HiddenInput(), initial=CMD_CHOICES[0][0])
    charset = forms.CharField(widget=forms.HiddenInput(), initial="utf-8")
    currency_code = forms.CharField(widget=forms.HiddenInput(), initial="USD")
    no_shipping = forms.ChoiceField(widget=forms.HiddenInput(), choices=SHIPPING_CHOICES, initial=SHIPPING_CHOICES[0][0])

    def __init__(self, button_type="buy", *args, **kwargs):
        super(PayPalPaymentsForm, self).__init__(*args, **kwargs)
        self.button_type = button_type
    
    def render(self):
        return mark_safe(u"""<form action="%s" method="post">
    %s
    <input type="image" src="%s" border="0" name="submit" alt="Buy it Now" />
</form>""" % (self.get_endpoint(), self.as_p(), self.get_image())) 
    
    def get_endpoint(self):
        if TEST:
            return SANDBOX_POSTBACK_ENDPOINT
        else:
            return POSTBACK_ENDPOINT
        
    def get_image(self):
        return {(True, True): SUBSCRIPTION_SANDBOX_IMAGE,
                (True, False): SANDBOX_IMAGE,
                (False, True): SUBSCRIPTION_IMAGE,
                (False, False): IMAGE}[TEST, self.is_subscription()]

    def is_transaction(self):
        return self.button_type == "buy"

    def is_subscription(self):
        return self.button_type == "subscribe"
Exemplo n.º 8
0
class PayPalPaymentsForm(forms.Form):
    """
    Creates a PayPal Payments Standard "Buy It Now" button, configured for a
    selling a single item with no shipping.
    
    For a full overview of all the fields you can set (there is a lot!) see:
    http://tinyurl.com/pps-integration
    
    Usage:
    >>> f = PayPalPaymentsForm(initial={'item_name':'Widget 001', ...})
    >>> f.render()
    u'<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> ...'
    
    """
    CMD_CHOICES = (("_xclick", "Buy now or Donations"),
                   ("_donations", "Donations"), ("_cart", "Shopping cart"),
                   ("_xclick-subscriptions", "Subscribe"))
    SHIPPING_CHOICES = ((1, "No shipping"), (0, "Shipping"))
    NO_NOTE_CHOICES = ((1, "No Note"), (0, "Include Note"))
    RECURRING_PAYMENT_CHOICES = ((1, "Subscription Payments Recur"),
                                 (0, "Subscription payments do not recur"))
    REATTEMPT_ON_FAIL_CHOICES = ((1, "reattempt billing on Failure"),
                                 (0, "Do Not reattempt on failure"))

    BUY = 'buy'
    SUBSCRIBE = 'subscribe'
    DONATE = 'donate'

    # Where the money goes,
    business = forms.CharField(widget=ValueHiddenInput(),
                               initial=RECEIVER_EMAIL)

    # Item information.
    amount = forms.IntegerField(widget=ValueHiddenInput())
    item_name = forms.CharField(widget=ValueHiddenInput())
    item_number = forms.CharField(widget=ValueHiddenInput())
    quantity = forms.CharField(widget=ValueHiddenInput())

    # Subscription Related.
    a1 = forms.CharField(widget=ValueHiddenInput())  # Trial 1 Price
    p1 = forms.CharField(widget=ValueHiddenInput())  # Trial 1 Duration
    t1 = forms.CharField(widget=ValueHiddenInput()
                         )  # Trial 1 unit of Duration, default to Month
    a2 = forms.CharField(widget=ValueHiddenInput())  # Trial 2 Price
    p2 = forms.CharField(widget=ValueHiddenInput())  # Trial 2 Duration
    t2 = forms.CharField(widget=ValueHiddenInput()
                         )  # Trial 2 unit of Duration, default to Month
    a3 = forms.CharField(widget=ValueHiddenInput())  # Subscription Price
    p3 = forms.CharField(widget=ValueHiddenInput())  # Subscription Duration
    t3 = forms.CharField(widget=ValueHiddenInput()
                         )  # Subscription unit of Duration, default to Month
    src = forms.CharField(
        widget=ValueHiddenInput())  # Is billing recurring? default to yes
    sra = forms.CharField(widget=ValueHiddenInput()
                          )  # Reattempt billing on failed cc transaction
    no_note = forms.CharField(widget=ValueHiddenInput())
    # Can be either 1 or 2. 1 = modify or allow new subscription creation, 2 = modify only
    modify = forms.IntegerField(widget=ValueHiddenInput()
                                )  # Are we modifying an existing subscription?

    # Localization / PayPal Setup
    lc = forms.CharField(widget=ValueHiddenInput())
    page_style = forms.CharField(widget=ValueHiddenInput())
    cbt = forms.CharField(widget=ValueHiddenInput())

    # IPN control.
    notify_url = forms.CharField(widget=ValueHiddenInput())
    cancel_return = forms.CharField(widget=ValueHiddenInput())
    return_url = forms.CharField(widget=ReservedValueHiddenInput(
        attrs={"name": "return"}))
    invoice = forms.CharField(widget=ValueHiddenInput())

    #Invoice is added tot he payplak IPN - it is in paypal.standard.forms.py -

    #adding host and enduser email form-- can't do  this.. not registered
    #host_email = forms.CharField(widget=ValueHiddenInput())
    #enduser_email = forms.CharField(widget=ValueHiddenInput())
    custom = forms.CharField(widget=ValueHiddenInput())
    receiver_id = forms.CharField(widget=ValueHiddenInput())

    # Default fields.
    cmd = forms.ChoiceField(widget=forms.HiddenInput(),
                            initial=CMD_CHOICES[0][0])
    charset = forms.CharField(widget=forms.HiddenInput(), initial="utf-8")
    currency_code = forms.CharField(widget=forms.HiddenInput(), initial="USD")
    no_shipping = forms.ChoiceField(widget=forms.HiddenInput(),
                                    choices=SHIPPING_CHOICES,
                                    initial=SHIPPING_CHOICES[0][0])

    def __init__(self, button_type="buy", *args, **kwargs):
        super(PayPalPaymentsForm, self).__init__(*args, **kwargs)
        self.button_type = button_type
        if 'initial' in kwargs:
            # Dynamically create, so we can support everything PayPal does.
            for k, v in kwargs['initial'].items():
                if k not in self.base_fields:
                    self.fields[k] = forms.CharField(label=k,
                                                     widget=ValueHiddenInput(),
                                                     initial=v)

    def test_mode(self):
        return getattr(settings, 'PAYPAL_TEST', True)

    def get_endpoint(self):
        "Returns the endpoint url for the form."
        if self.test_mode():
            return SANDBOX_POSTBACK_ENDPOINT
        else:
            return POSTBACK_ENDPOINT

    def render(self):
        return mark_safe(u"""<form action="%s" method="post">
    %s
    <input type="image" class="paypal" src="%s" border="0" name="submit" alt="Buy it Now" />
</form>""" % (self.get_endpoint(), self.as_p(), self.get_image()))

#JMY - may need to add height and width dimensions.. or alter the image.., JB had width="122" height="40"
#JMY: the SRC above renders as... https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif
# the URL is defined in paypal/standard/conf.py under SANDBOX_IMAGE
#I want to redirect to John's image, which is at: src="/static/blocbox/images/paypal.png"

    def sandbox(self):
        "Deprecated.  Use self.render() instead."
        import warnings
        warnings.warn(
            """PaypalPaymentsForm.sandbox() is deprecated.
                    Use the render() method instead.""", DeprecationWarning)
        return self.render()

    def get_image(self):
        return {
            (True, self.SUBSCRIBE): SUBSCRIPTION_SANDBOX_IMAGE,
            (True, self.BUY):
            JB_PAYPAL_IMAGE,  #SANDBOX_IMAGE, #defined in conf.py as "https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif")
            (True, self.DONATE): DONATION_SANDBOX_IMAGE,
            (False, self.SUBSCRIBE): SUBSCRIPTION_IMAGE,
            (False, self.BUY): IMAGE,
            (False, self.DONATE): DONATION_IMAGE,
        }[self.test_mode(), self.button_type]

    def is_transaction(self):
        return not self.is_subscription()

    def is_donation(self):
        return self.button_type == self.DONATE

    def is_subscription(self):
        return self.button_type == self.SUBSCRIBE
Exemplo n.º 9
0
class PayPalPaymentsForm(forms.Form):
    """
    Creates a PayPal Payments Standard "Buy It Now" button, configured for a
    selling a single item with no shipping.

    For a full overview of all the fields you can set (there is a lot!) see:
    http://tinyurl.com/pps-integration

    Usage:
    >>> f = PayPalPaymentsForm(initial={'item_name':'Widget 001', ...})
    >>> f.render()
    u'<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> ...'

    """
    CMD_CHOICES = (("_xclick", "Buy now or Donations"),
                   ("_donations", "Donations"), ("_cart", "Shopping cart"),
                   ("_xclick-subscriptions", "Subscribe"))
    SHIPPING_CHOICES = ((1, "No shipping"), (0, "Shipping"))
    NO_NOTE_CHOICES = ((1, "No Note"), (0, "Include Note"))
    RECURRING_PAYMENT_CHOICES = ((1, "Subscription Payments Recur"),
                                 (0, "Subscription payments do not recur"))
    REATTEMPT_ON_FAIL_CHOICES = ((1, "reattempt billing on Failure"),
                                 (0, "Do Not reattempt on failure"))

    BUY = 'buy'
    SUBSCRIBE = 'subscribe'
    DONATE = 'donate'

    # Where the money goes.
    business = forms.CharField(widget=ValueHiddenInput())

    # Item information.
    amount = forms.IntegerField(widget=ValueHiddenInput())
    item_name = forms.CharField(widget=ValueHiddenInput())
    item_number = forms.CharField(widget=ValueHiddenInput())
    quantity = forms.CharField(widget=ValueHiddenInput())

    # Subscription Related.
    a1 = forms.CharField(widget=ValueHiddenInput())  # Trial 1 Price
    p1 = forms.CharField(widget=ValueHiddenInput())  # Trial 1 Duration
    t1 = forms.CharField(widget=ValueHiddenInput()
                         )  # Trial 1 unit of Duration, default to Month
    a2 = forms.CharField(widget=ValueHiddenInput())  # Trial 2 Price
    p2 = forms.CharField(widget=ValueHiddenInput())  # Trial 2 Duration
    t2 = forms.CharField(widget=ValueHiddenInput()
                         )  # Trial 2 unit of Duration, default to Month
    a3 = forms.CharField(widget=ValueHiddenInput())  # Subscription Price
    p3 = forms.CharField(widget=ValueHiddenInput())  # Subscription Duration
    t3 = forms.CharField(widget=ValueHiddenInput()
                         )  # Subscription unit of Duration, default to Month
    src = forms.CharField(
        widget=ValueHiddenInput())  # Is billing recurring? default to yes
    sra = forms.CharField(widget=ValueHiddenInput()
                          )  # Reattempt billing on failed cc transaction
    no_note = forms.CharField(widget=ValueHiddenInput())
    # Can be either 1 or 2. 1 = modify or allow new subscription creation, 2 = modify only
    modify = forms.IntegerField(widget=ValueHiddenInput()
                                )  # Are we modifying an existing subscription?

    # Localization / PayPal Setup
    lc = forms.CharField(widget=ValueHiddenInput())
    page_style = forms.CharField(widget=ValueHiddenInput())
    cbt = forms.CharField(widget=ValueHiddenInput())

    # IPN control.
    notify_url = forms.CharField(widget=ValueHiddenInput())
    cancel_return = forms.CharField(widget=ValueHiddenInput())
    return_url = forms.CharField(widget=ReservedValueHiddenInput(
        attrs={"name": "return"}))
    custom = forms.CharField(widget=ValueHiddenInput())
    invoice = forms.CharField(widget=ValueHiddenInput())

    # Default fields.
    cmd = forms.ChoiceField(widget=forms.HiddenInput(),
                            initial=CMD_CHOICES[0][0])
    charset = forms.CharField(widget=forms.HiddenInput(), initial="utf-8")
    currency_code = forms.CharField(widget=forms.HiddenInput(), initial="USD")
    no_shipping = forms.ChoiceField(widget=forms.HiddenInput(),
                                    choices=SHIPPING_CHOICES,
                                    initial=SHIPPING_CHOICES[0][0])

    def __init__(self, button_type="buy", *args, **kwargs):
        super(PayPalPaymentsForm, self).__init__(*args, **kwargs)
        self.button_type = button_type
        if 'initial' in kwargs:
            kwargs['initial'] = self._fix_deprecated_paypal_receiver_email(
                kwargs['initial'])
            # Dynamically create, so we can support everything PayPal does.
            for k, v in kwargs['initial'].items():
                if k not in self.base_fields:
                    self.fields[k] = forms.CharField(label=k,
                                                     widget=ValueHiddenInput(),
                                                     initial=v)

    def _fix_deprecated_paypal_receiver_email(self, initial_args):
        if 'business' not in initial_args:
            if hasattr(settings, 'PAYPAL_RECEIVER_EMAIL'):
                warn(
                    """The use of the settings.PAYPAL_RECEIVER_EMAIL is Deprecated.
                        The keyword business argument must be given to PayPalPaymentsForm
                        on creation""", DeprecationWarning)
                initial_args['business'] = settings.PAYPAL_RECEIVER_EMAIL
        return initial_args

    def test_mode(self):
        return getattr(settings, 'PAYPAL_TEST', True)

    def get_endpoint(self):
        "Returns the endpoint url for the form."
        if self.test_mode():
            return SANDBOX_POSTBACK_ENDPOINT
        else:
            return POSTBACK_ENDPOINT

    def render(self):
        return format_html(
            u"""<form action="{0}" method="post">
    {1}
    <input type="image" src="{2}" border="0" name="submit" alt="Buy it Now" />
</form>""", self.get_endpoint(), self.as_p(), self.get_image())

    def sandbox(self):
        "Deprecated.  Use self.render() instead."
        import warnings
        warnings.warn(
            """PaypalPaymentsForm.sandbox() is deprecated.
                    Use the render() method instead.""", DeprecationWarning)
        return self.render()

    def get_image(self):
        return {
            (True, self.SUBSCRIBE): SUBSCRIPTION_SANDBOX_IMAGE,
            (True, self.BUY): SANDBOX_IMAGE,
            (True, self.DONATE): DONATION_SANDBOX_IMAGE,
            (False, self.SUBSCRIBE): SUBSCRIPTION_IMAGE,
            (False, self.BUY): IMAGE,
            (False, self.DONATE): DONATION_IMAGE,
        }[self.test_mode(), self.button_type]

    def is_transaction(self):
        warn_untested()
        return not self.is_subscription()

    def is_donation(self):
        warn_untested()
        return self.button_type == self.DONATE

    def is_subscription(self):
        warn_untested()
        return self.button_type == self.SUBSCRIBE
Exemplo n.º 10
0
class PayPalPaymentsForm(forms.Form):
    """
    Creates a PayPal Payments Standard "Buy It Now" button, configured for a
    selling a single item with no shipping.
    
    For a full overview of all the fields you can set (there is a lot!) see:
    http://tinyurl.com/pps-integration
    
    Usage:
    >>> f = PayPalPaymentsForm(initial={'item_name':'Widget 001', ...})
    >>> f.render()
    u'<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> ...'
    
    """    
    CMD_CHOICES = (
        ("_xclick", "Buy now or Donations"), 
        ("_cart", "Shopping cart"), 
        ("_xclick-subscriptions", "Subscribe")
    )
    SHIPPING_CHOICES = ((1, "No shipping"), (0, "Shipping"))
    NO_NOTE_CHOICES = ((1, "No Note"), (0, "Include Note"))
    RECURRING_PAYMENT_CHOICES = (
        (1, "Subscription Payments Recur"), 
        (0, "Subscription payments do not recur")
    )
    REATTEMPT_ON_FAIL_CHOICES = (
        (1, "reattempt billing on Failure"), 
        (0, "Do Not reattempt on failure")
    )

    BUY = 'buy'
    SUBSCRIBE = 'subscribe'
    DONATE = 'donate'

    # Where the money goes.
    business = forms.CharField(widget=ValueHiddenInput(), initial=RECEIVER_EMAIL)
    
    # Item information.
    amount = forms.IntegerField(widget=ValueHiddenInput())
    item_name = forms.CharField(widget=ValueHiddenInput())
    item_number = forms.CharField(widget=ValueHiddenInput())
    quantity = forms.CharField(widget=ValueHiddenInput())
    
    # Subscription Related.
    a1 = forms.CharField(widget=ValueHiddenInput())  # Trial 1 Price
    p1 = forms.CharField(widget=ValueHiddenInput())  # Trial 1 Duration
    t1 = forms.CharField(widget=ValueHiddenInput())  # Trial 1 unit of Duration, default to Month
    a2 = forms.CharField(widget=ValueHiddenInput())  # Trial 2 Price
    p2 = forms.CharField(widget=ValueHiddenInput())  # Trial 2 Duration
    t2 = forms.CharField(widget=ValueHiddenInput())  # Trial 2 unit of Duration, default to Month    
    a3 = forms.CharField(widget=ValueHiddenInput())  # Subscription Price
    p3 = forms.CharField(widget=ValueHiddenInput())  # Subscription Duration
    t3 = forms.CharField(widget=ValueHiddenInput())  # Subscription unit of Duration, default to Month
    src = forms.CharField(widget=ValueHiddenInput()) # Is billing recurring? default to yes
    sra = forms.CharField(widget=ValueHiddenInput()) # Reattempt billing on failed cc transaction
    no_note = forms.CharField(widget=ValueHiddenInput())    
    # Can be either 1 or 2. 1 = modify or allow new subscription creation, 2 = modify only
    modify = forms.IntegerField(widget=ValueHiddenInput()) # Are we modifying an existing subscription?
    
    # Localization / PayPal Setup
    lc = forms.CharField(widget=ValueHiddenInput())
    page_style = forms.CharField(widget=ValueHiddenInput())
    cbt = forms.CharField(widget=ValueHiddenInput())
    
    # IPN control.
    notify_url = forms.CharField(widget=ValueHiddenInput())
    cancel_return = forms.CharField(widget=ValueHiddenInput())
    return_url = forms.CharField(widget=ReservedValueHiddenInput(attrs={"name":"return"}))
    custom = forms.CharField(widget=ValueHiddenInput())
    invoice = forms.CharField(widget=ValueHiddenInput())
    
    # Default fields.
    cmd = forms.ChoiceField(widget=forms.HiddenInput(), initial=CMD_CHOICES[0][0])
    charset = forms.CharField(widget=forms.HiddenInput(), initial="utf-8")
    currency_code = forms.CharField(widget=forms.HiddenInput(), initial="USD")
    no_shipping = forms.ChoiceField(widget=forms.HiddenInput(), choices=SHIPPING_CHOICES, 
        initial=SHIPPING_CHOICES[0][0])

    def __init__(self, button_type="buy", extra_fields={}, *args, **kwargs):
        super(PayPalPaymentsForm, self).__init__(*args, **kwargs)
        self.button_type = button_type
        self.extra_fields = extra_fields

    def render(self):
        extra_fields = u''.join(['<input type="hidden" name="%s" value="%s" />' % \
                        (escape(name), escape(value)) for name, value in self.extra_fields.iteritems()])

        return mark_safe(FORM_HTML % (POSTBACK_ENDPOINT, self.as_p(), extra_fields, self.get_image()))
        
        
    def sandbox(self):
        extra_fields = u''.join(['<input type="hidden" name="%s" value="%s" />' % \
                        (escape(name), escape(value)) for name, value in self.extra_fields.iteritems()])

        return mark_safe(FORM_HTML % (SANDBOX_POSTBACK_ENDPOINT, self.as_p(), extra_fields, self.get_image()))
        
    def get_image(self):
        return {
            (True, self.SUBSCRIBE): SUBSCRIPTION_SANDBOX_IMAGE,
            (True, self.BUY): SANDBOX_IMAGE,
            (True, self.DONATE): DONATION_SANDBOX_IMAGE,
            (False, self.SUBSCRIBE): SUBSCRIPTION_IMAGE,
            (False, self.BUY): IMAGE,
            (False, self.DONATE): DONATION_IMAGE,
        }[TEST, self.button_type]

    def is_transaction(self):
        return not self.is_subscription()

    def is_donation(self):
        return self.button_type == self.DONATE

    def is_subscription(self):
        return self.button_type == self.SUBSCRIBE
Exemplo n.º 11
0
class PayPalPaymentsForm(forms.Form):
    """
    Creates a PayPal Payments Standard "Buy It Now" button, configured for a
    selling a single item with no shipping.

    For a full overview of all the fields you can set (there is a lot!) see:
    http://tinyurl.com/pps-integration

    Usage:
    >>> f = PayPalPaymentsForm(initial={'item_name':'Widget 001', ...})
    >>> f.render()
    u'<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> ...'

    """
    CMD_CHOICES = (("_xclick", "Buy now or Donations"),
                   ("_cart", "Shopping cart"), ("_xclick-subscriptions",
                                                "Subscribe"))
    SHIPPING_CHOICES = ((1, "No shipping"), (0, "Shipping"))
    NO_NOTE_CHOICES = ((1, "No Note"), (0, "Include Note"))
    RECURRING_PAYMENT_CHOICES = ((1, "Subscription Payments Recur"),
                                 (0, "Subscription payments do not recur"))
    REATTEMPT_ON_FAIL_CHOICES = ((1, "reattempt billing on Failure"),
                                 (0, "Do Not reattempt on failure"))

    # Where the money goes.
    business = forms.CharField(widget=ValueHiddenInput(),
                               initial=RECEIVER_EMAIL)
    upload = forms.CharField(widget=forms.HiddenInput(), initial="1")

    # Item information.
    amount = forms.IntegerField(widget=ValueHiddenInput())
    item_name = forms.CharField(widget=ValueHiddenInput())
    item_number = forms.CharField(widget=ValueHiddenInput())
    quantity = forms.CharField(widget=ValueHiddenInput())

    # Subscription Related.
    a1 = forms.CharField(widget=ValueHiddenInput())  # Trial 1 Price
    p1 = forms.CharField(widget=ValueHiddenInput())  # Trial 1 Duration
    t1 = forms.CharField(widget=ValueHiddenInput()
                         )  # Trial 1 unit of Duration, default to Month
    a2 = forms.CharField(widget=ValueHiddenInput())  # Trial 2 Price
    p2 = forms.CharField(widget=ValueHiddenInput())  # Trial 2 Duration
    t2 = forms.CharField(widget=ValueHiddenInput()
                         )  # Trial 2 unit of Duration, default to Month
    a3 = forms.CharField(widget=ValueHiddenInput())  # Subscription Price
    p3 = forms.CharField(widget=ValueHiddenInput())  # Subscription Duration
    t3 = forms.CharField(widget=ValueHiddenInput()
                         )  # Subscription unit of Duration, default to Month
    src = forms.CharField(
        widget=ValueHiddenInput())  # Is billing recurring? default to yes
    sra = forms.CharField(widget=ValueHiddenInput()
                          )  # Reattempt billing on failed cc transaction
    no_note = forms.CharField(widget=ValueHiddenInput())
    # Can be either 1 or 2. 1 = modify or allow new subscription creation, 2 = modify only
    modify = forms.IntegerField(widget=ValueHiddenInput()
                                )  # Are we modifying an existing subscription?

    # Localization / PayPal Setup
    lc = forms.CharField(widget=ValueHiddenInput())
    page_style = forms.CharField(widget=ValueHiddenInput())
    cbt = forms.CharField(widget=ValueHiddenInput())

    # IPN control.
    notify_url = forms.CharField(widget=ValueHiddenInput())
    cancel_return = forms.CharField(widget=ValueHiddenInput())
    return_url = forms.CharField(widget=ReservedValueHiddenInput(
        attrs={"name": "return"}))
    custom = forms.CharField(widget=ValueHiddenInput())
    invoice = forms.CharField(widget=ValueHiddenInput())
    handling_cart = forms.CharField(widget=ValueHiddenInput())

    # Default fields.
    cmd = forms.ChoiceField(widget=forms.HiddenInput(),
                            initial=CMD_CHOICES[1][0])
    charset = forms.CharField(widget=forms.HiddenInput(), initial="utf-8")
    currency_code = forms.CharField(widget=forms.HiddenInput(), initial="GBP")

    def __init__(self, cart, button_type="buy", *args, **kwargs):
        order = kwargs.pop('order')
        super(PayPalPaymentsForm, self).__init__(*args, **kwargs)

        self.button_type = button_type
        custom_val = ""
        if order.delivery.price:
            self.fields['handling_cart'] = forms.CharField(
                widget=forms.HiddenInput(), initial=str(order.delivery.price))
        for i, line in enumerate(cart):
            self.fields['amount_' + str(i + 1)] = forms.CharField(
                widget=forms.HiddenInput(),
                initial=str(line.item.total_price()))
            self.fields['item_name_' + str(i + 1)] = forms.CharField(
                widget=forms.HiddenInput(), initial=str(line.item.name))
            self.fields['quantity_' + str(i + 1)] = forms.CharField(
                widget=forms.HiddenInput(), initial=str(line.quantity))
        self.fields['custom'] = forms.CharField(widget=forms.HiddenInput(),
                                                initial=custom_val)

    def render(self):
        return mark_safe(u"""<form action="%s" method="post">
    %s
    <button type="submit" id="buy-button" class="btn btn-success">BUY</button>
</form>""" % (POSTBACK_ENDPOINT, self.as_p()))

    def sandbox(self):
        return mark_safe(u"""<form action="%s" method="post">
    %s
    <button type="submit" id="buy-button" class="btn btn-success">BUY</button>
</form>""" % (SANDBOX_POSTBACK_ENDPOINT, self.as_p()))

    def get_image(self):
        return {
            (True, True): SUBSCRIPTION_SANDBOX_IMAGE,
            (True, False): SANDBOX_IMAGE,
            (False, True): SUBSCRIPTION_IMAGE,
            (False, False): IMAGE
        }[TEST, self.is_subscription()]

    def is_transaction(self):
        return self.button_type == "buy"

    def is_subscription(self):
        return self.button_type == "subscribe"
Exemplo n.º 12
0
class AliPayPaymentBaseForm(forms.Form):
    """
request interface. POST method, HTTPS
"""
    # base parameters
    service = forms.CharField(widget=ValueHiddenInput(), initial=SERVICE[0])
    partner = forms.CharField(widget=ValueHiddenInput(),
                              max_length=16,
                              initial=config.ALIPAY_PARTNER)
    # 商户网站使用的编码格式,如utf-8、gbk、gb2312等
    _input_charset = forms.CharField(widget=ValueHiddenInput(),
                                     initial=config.ALIPAY_INPUT_CHARSET)
    # DSA、RSA、MD5三个值可选,必须大写
    sign_type = forms.CharField(widget=ValueHiddenInput(),
                                initial=config.ALIPAY_SIGN_TYPE)
    sign = forms.CharField(widget=ValueHiddenInput())
    notify_url = forms.CharField(widget=ValueHiddenInput())
    return_url = forms.CharField(widget=ValueHiddenInput())
    # 需开通
    error_notify_url = forms.CharField(widget=ValueHiddenInput())
    # business parameters
    out_trade_no = forms.CharField(widget=ValueHiddenInput(), max_length=64)
    subject = forms.CharField(widget=ValueHiddenInput(), max_length=256)
    payment_type = forms.CharField(widget=ValueHiddenInput(),
                                   initial=PAYMENT_TYPE[0])
    # 买家 卖家 信息
    seller_id = forms.CharField(widget=ValueHiddenInput(),
                                max_length=32,
                                initial=config.ALIPAY_SELLER_ID)
    buyer_id = forms.CharField(widget=ValueHiddenInput(), max_length=32)
    seller_account_name = forms.CharField(widget=ValueHiddenInput(),
                                          max_length=100)
    buyer_account_name = forms.CharField(widget=ValueHiddenInput(),
                                         max_length=100)
    seller_email = forms.CharField(widget=ValueHiddenInput(), max_length=100)
    buyer_email = forms.CharField(widget=ValueHiddenInput(), max_length=100)
    # 买家逾期不付款,自动关闭交易
    it_b_pay = forms.CharField(widget=ValueHiddenInput())
    # 价格 unit: RMB
    price = forms.FloatField(widget=ValueHiddenInput(),
                             min_value=0.01,
                             max_value=1000000.00)
    quantity = forms.IntegerField(widget=ValueHiddenInput())
    # 担保交易不支持 total_fee
    total_fee = forms.FloatField(widget=ValueHiddenInput(),
                                 min_value=0.01,
                                 max_value=1000000.00)
    body = forms.CharField(widget=ValueHiddenInput(), max_length=1000)
    show_url = forms.CharField(widget=ValueHiddenInput(), max_length=400)
    paymethod = forms.CharField(widget=ValueHiddenInput())
    discount = forms.FloatField(widget=ValueHiddenInput())
    # CTU 支付宝风险稽查系统,需开通
    need_ctu_check = forms.CharField(widget=ValueHiddenInput())  # Y/N
    royalty_type = forms.CharField(widget=ValueHiddenInput(),
                                   max_length=2)  # 10
    royalty_parameters = forms.CharField(widget=ValueHiddenInput())
    # 需开通
    anti_phishing_key = forms.CharField(widget=ValueHiddenInput())
    # 需开通
    exter_invoke_ip = forms.CharField(widget=ValueHiddenInput(), max_length=15)
    extra_common_param = forms.CharField(widget=ValueHiddenInput(),
                                         max_length=100)
    extend_param = forms.CharField(widget=ValueHiddenInput())
    default_login = forms.CharField(widget=ValueHiddenInput())  # Y/N
    product_type = forms.CharField(widget=ValueHiddenInput(), max_length=50)
    # 需开通快捷登录
    token = forms.CharField(widget=ValueHiddenInput(), max_length=40)

    def get_action(self):
        return '%s?_input_charset=%s' % (config.ALIPAY_GATEWAY,
                                         self['_input_charset'].value())