diff --git a/public_html/modules/donate.php b/public_html/modules/donate.php new file mode 100644 index 0000000..79038dc --- /dev/null +++ b/public_html/modules/donate.php @@ -0,0 +1,122 @@ +uParameters[1]); +} +catch (NotFoundException $e) +{ + /* TODO: 404 via RouterException */ + throw new RouterException("No such campaign."); +} + +try +{ + $sPaymentMethod = new PaymentMethod($router->uParameters[2]); +} +catch (NotFoundException $e) +{ + throw new RouterException("No such payment method."); +} + +if($sPaymentMethod->sCampaignId !== $sCampaign->sId) +{ + throw new RouterException("Payment method does not belong to campaign."); +} + +switch($sPaymentMethod->sType) +{ + case PaymentMethod::PAYPAL: + $sMethodName = "PayPal"; + break; + case PaymentMethod::BITCOIN: + $sMethodName = "Bitcoin"; + break; + default: + $sMethodName = $sPaymentMethod->sCustomName; + break; +} + +if(!empty($_POST['submit'])) +{ + if(empty($_POST['currency'])) + { + flash_error("You did not select a valid currency."); + } + + if(empty($_POST['amount'])) + { + flash_error("You did not enter a valid amount."); + } + + if(count(get_errors(false)) == 0) + { + switch($sPaymentMethod->sType) + { + case PaymentMethod::PAYPAL: + if($sPaymentRequest->sCurrency == "btc") + { + $sCurrency = urlencode("USD"); + $sAmount = round(Currency::Convert("usd", "btc", $_POST['amount']), 2); + } + else + { + $sCurrency = urlencode(strtoupper($_POST['currency'])); + $sAmount = urlencode($_POST['amount']); + } + + $sQuotedRecipient = urlencode($sPaymentMethod->sAddress); + $sQuotedName = urlencode("{$sCampaign->sName} (via ReDonate.net)"); + $sQuotedNumber = urlencode("0"); + $sQuotedReturnUrl = urlencode("http://redonate.net/thanks/{$sCampaign->sUrlName}"); + redirect("https://www.paypal.com/cgi-bin/webscr?business={$sQuotedRecipient}&cmd=_donations&item_name={$sQuotedName}&item_number={$sQuotedNumber}¤cy_code={$sCurrency}&amount={$sAmount}&return={$sQuotedReturnUrl}"); + return; + case PaymentMethod::BITCOIN: + if($sPaymentRequest->sCurrency != "btc") + { + $sAmount = Currency::Convert("btc", $_POST['currency'], $_POST['amount']); + } + else + { + $sAmount = htmlspecialchars($_POST['amount']); + } + + $sPageContents = NewTemplater::Render("payment/bitcoin", $locale->strings, array( + "address" => $sPaymentMethod->sAddress, + "amount" => Currency::Format("btc", $sAmount), + "done-url" => "/thanks/{$sCampaign->sUrlName}" + )); + return; + default: + $sPageContents = NewTemplater::Render("payment/other", $locale->strings, array( + "name" => $sPaymentMethod->sCustomName, + "address" => $sPaymentMethod->sAddress, + "amount" => Currency::Format($_POST['currency'], $_POST['amount']), + "done-url" => "/thanks/{$sCampaign->sUrlName}" + )); + return; + } + } +} + +$sPageTitle = "Donate to {$sCampaign->sName} once"; +$sPageContents = NewTemplater::Render("donate", $locale->strings, array( + "campaign-name" => $sCampaign->sName, + "method-id" => $sPaymentMethod->sId, + "urlname" => $sCampaign->sUrlName, + "method-name" => $sMethodName +)); + diff --git a/public_html/modules/landing.php b/public_html/modules/landing.php index 0a4d551..da44bb0 100644 --- a/public_html/modules/landing.php +++ b/public_html/modules/landing.php @@ -26,6 +26,24 @@ catch (NotFoundException $e) $sCampaign->UpdateStatistics(); +$sPaymentMethods = array(); + +try +{ + foreach(PaymentMethod::CreateFromQuery("SELECT * FROM payment_methods WHERE `CampaignId` = :CampaignId", + array(":CampaignId" => $sCampaign->sId)) as $sPaymentMethod) + { + $sNewMethod = $sPaymentMethod->GetLogo(); + $sNewMethod['address'] = $sPaymentMethod->sAddress; + $sNewMethod['id'] = $sPaymentMethod->sId; + $sPaymentMethods[] = $sNewMethod; + } +} +catch (NotFoundException $e) +{ + /* No payment methods...? */ +} + $sLogEntry = new LogEntry(0); $sLogEntry->uType = LogEntry::PAGELOAD; $sLogEntry->uIp = $_SERVER['REMOTE_ADDR']; @@ -39,5 +57,6 @@ $sPageTitle = "Contribute to {$sCampaign->sName}"; $sPageContents = NewTemplater::Render("landing", $locale->strings, array( "can-donate-once" => true, "project-name" => $sCampaign->sName, - "urlname" => $sCampaign->sUrlName + "urlname" => $sCampaign->sUrlName, + "methods" => $sPaymentMethods )); diff --git a/public_html/modules/thanks.php b/public_html/modules/thanks.php new file mode 100644 index 0000000..7b16c35 --- /dev/null +++ b/public_html/modules/thanks.php @@ -0,0 +1,27 @@ +uParameters[1]); +} +catch (NotFoundException $e) +{ + /* TODO: 404 via RouterException */ + throw new RouterException("No such campaign."); +} + +flash_notice("Thank you for your contribution!"); +redirect("/campaign/{$sCampaign->sUrlName}"); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index eda9f7f..d0f355d 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -105,6 +105,8 @@ $router->routes = array( ), "^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php", "^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.php", + "^/campaign/([a-zA-Z0-9-]+)/donate/([0-9]+)$" => "modules/donate.php", + "^/thanks/([a-zA-Z0-9-]+)$" => "modules/thanks.php", "^/test$" => "modules/test.php" ) ); diff --git a/public_html/static/css/style.css b/public_html/static/css/style.css index 7cbf876..68a2437 100644 --- a/public_html/static/css/style.css +++ b/public_html/static/css/style.css @@ -462,16 +462,20 @@ img.logo.thumb height: 20px; } -div.logo +div.logo, span.logo { font-weight: bold; font-style: italic; color: #1F2E0B; - display: inline-block; font-size: 35px; } -div.logo.thumb +div.logo +{ + display: inline-block; +} + +div.logo.thumb, span.logo.thumb { font-size: 18px; } @@ -770,6 +774,27 @@ p.pledge-button padding: 16px 20px; } +.donate-once +{ + border: 1px solid gray; + border-radius: 7px; + float: left; + height: 45px; + padding: 8px 10px; + display: block; + margin-right: 4px; +} + +.donate-once:hover +{ + background-color: #F3F8EB; +} + +.donate-once img +{ + margin: 8px 10px; +} + /************************************** * COMPLEX HEADERS * **************************************/ diff --git a/public_html/templates/donate.tpl b/public_html/templates/donate.tpl new file mode 100644 index 0000000..32e9b53 --- /dev/null +++ b/public_html/templates/donate.tpl @@ -0,0 +1,30 @@ +
+

Donate to {%?campaign-name} once using {%?method-name}.

+ + {%if isempty|errors == false} + {%foreach error in errors} +
+ {%?error} +
+ {%/foreach} + {%/if} + +
+
+ + {%select name="currency"} + {%option value="usd" text="US Dollar"} + {%option value="eur" text="Euro"} + {%option value="btc" text="Bitcoin"} + {%/select} +
+
+ + {%input type="text" name="amount"} +
+
+
+ +
+
+
diff --git a/public_html/templates/landing.tpl b/public_html/templates/landing.tpl index b3daacf..a7d8aa0 100644 --- a/public_html/templates/landing.tpl +++ b/public_html/templates/landing.tpl @@ -1,5 +1,13 @@

Contribute to {%?project-name} monthly, no automatic charges.

+{%if isempty|notices == false} + {%foreach notice in notices} +
+ {%?notice} +
+ {%/foreach} +{%/if} +

How does it work?

@@ -56,11 +64,16 @@ {%if can-donate-once == true} -

One-off donation

-

- - -

+

One-off donation

+ {%foreach method in methods} + + {%/foreach} {%/if}