Skip to content

Commit

Permalink
Add Donation button to standard form button types. Expose possible bu…
Browse files Browse the repository at this point in the history
…tton types on the form class.
  • Loading branch information
john-kurkowski committed Oct 16, 2010
1 parent 5d67bb6 commit 6225b40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
5 changes: 4 additions & 1 deletion paypal/standard/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ class PayPalSettingsError(Exception):
# Images
IMAGE = getattr(settings, "PAYPAL_IMAGE", "http://images.paypal.com/images/x-click-but01.gif")
SUBSCRIPTION_IMAGE = "https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif"
DONATION_IMAGE = "https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif"
SANDBOX_IMAGE = getattr(settings, "PAYPAL_SANDBOX_IMAGE", "https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif")
SUBSCRIPTION_SANDBOX_IMAGE = "https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif"
SUBSCRIPTION_SANDBOX_IMAGE = "https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif"
DONATION_SANDBOX_IMAGE = "https://www.sandbox.paypal.com/en_US/i/btn/btn_donateCC_LG.gif"

25 changes: 17 additions & 8 deletions paypal/standard/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ class PayPalPaymentsForm(forms.Form):
(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)

Expand Down Expand Up @@ -110,17 +114,22 @@ def sandbox(self):

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()]
(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 self.button_type == "buy"
return not self.is_subscription()

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

def is_subscription(self):
return self.button_type == "subscribe"
return self.button_type == self.SUBSCRIBE


class PayPalEncryptedPaymentsForm(PayPalPaymentsForm):
Expand Down

0 comments on commit 6225b40

Please sign in to comment.