]>
git.ipfire.org Git - ipfire.org.git/blob - src/web/donate.py
3f54cbe8b6c4c715e3134f160383985fe9adc9da
8 class DonateHandler(base
.BaseHandler
):
10 location
= self
.get_remote_location()
13 country
= location
.country
18 first_name
= self
.get_argument("first_name", None)
19 last_name
= self
.get_argument("last_name", None)
20 amount
= self
.get_argument_float("amount", None)
21 currency
= self
.get_argument("currency", None)
22 frequency
= self
.get_argument("frequency", None)
24 # Set default currency
25 if not currency
in ("EUR", "USD"):
28 # Default to USD for the US only
32 # Set default frequency
33 if not frequency
in ("one-time", "monthly"):
34 frequency
= "one-time"
36 self
.render("donate/donate.html", countries
=iso3166
.countries
,
37 country
=country
, first_name
=first_name
, last_name
=last_name
,
38 amount
=amount
, currency
=currency
, frequency
=frequency
)
40 @base.ratelimit(minutes
=15, requests
=5)
42 amount
= self
.get_argument("amount")
43 currency
= self
.get_argument("currency", "EUR")
44 frequency
= self
.get_argument("frequency")
46 # Collect donor information
48 "email" : self
.get_argument("email"),
49 "title" : self
.get_argument("title"),
50 "first_name" : self
.get_argument("first_name"),
51 "last_name" : self
.get_argument("last_name"),
54 # Collect company information
55 company_name
= self
.get_argument("company_name", None)
57 # Collect address information
59 "street1" : self
.get_argument("street1"),
60 "street2" : self
.get_argument("street2", None),
61 "post_code" : self
.get_argument("post_code"),
62 "city" : self
.get_argument("city"),
63 "state" : self
.get_argument("state", None),
64 "country_code" : self
.get_argument("country_code"),
67 # Send everything to Zeiterfassung
69 # Search for person or create a new one
70 response
= await self
.backend
.zeiterfassung
.send_request(
71 "/api/v1/persons/search", **donor
75 response
= await self
.backend
.zeiterfassung
.send_request(
76 "/api/v1/persons/create", **donor
, **address
79 person
= response
.get("number")
81 # Fetch properties of this person
82 response
= await self
.backend
.zeiterfassung
.send_request(
83 "/api/v1/persons/%s/properties" % person
,
86 # Does this person already have an organization?
87 organization
= response
.get("organization", None)
89 # Search for organization or create a new one
90 if not organization
and company_name
:
91 response
= await self
.backend
.zeiterfassung
.send_request(
92 "/api/v1/organizations/search", name
=name
,
95 # Create a new one if we could not find anything
97 response
= await self
.backend
.zeiterfassung
.send_request(
98 "/api/v1/organizations/create", name
=name
, **address
,
101 organization
= response
.get("number")
103 # Connect organization and person
104 await self
.backend
.zeiterfassung
.send_request(
105 "/api/v1/organizations/%s/persons/add", person
=person
,
109 "organization" : organization
,
114 "currency" : currency
,
116 # Is this a recurring donation?
117 "recurring" : frequency
== "monthly",
119 # Add URLs to redirect the user back
120 "success_url" : "https://%s/donate/thank-you" % self
.request
.host
,
121 "error_url" : "https://%s/donate/error" % self
.request
.host
,
122 "back_url" : "https://%s/donate?amount=%s¤cy=%s&frequency=%s" %
123 (self
.request
.host
, amount
, currency
, frequency
),
127 response
= await self
.backend
.zeiterfassung
.send_request(
128 "/api/v1/donations/create/ipfire-project", **donation
)
130 # Redirect the user to the payment page
131 redirect_url
= response
.get("redirect_url")
133 raise tornado
.web
.HTTPError(500, "Did not receive a redirect URL")
135 self
.redirect(redirect_url
)
137 # XXX handle any problems when Zeiterfassung is unreachable
142 class ThankYouHandler(base
.BaseHandler
):
144 self
.render("donate/thank-you.html")
147 class ErrorHandler(base
.BaseHandler
):
149 self
.render("donate/error.html")