Permalink
Browse files

Add Donation button to standard form button types. Expose possible bu…

…tton types on the form class.
  • Loading branch information...
1 parent 5d67bb6 commit 6225b403442492a6e922641ba890dd771da631df @john-kurkowski john-kurkowski committed Oct 16, 2010
Showing with 21 additions and 9 deletions.
  1. +4 −1 paypal/standard/conf.py
  2. +17 −8 paypal/standard/forms.py
View
5 paypal/standard/conf.py
@@ -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"
+
View
25 paypal/standard/forms.py
@@ -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)
@@ -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):

0 comments on commit 6225b40

Please sign in to comment.