Implement one-off donations

master
Sven Slootweg 11 years ago
parent 9dc40072ab
commit a7b49b5cd3

@ -0,0 +1,122 @@
<?php
/*
* ReDonate is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_APP)) { die("Unauthorized."); }
try
{
$sCampaign = Campaign::FindByUrlName($router->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}&currency_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
));

@ -26,6 +26,24 @@ catch (NotFoundException $e)
$sCampaign->UpdateStatistics(); $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 = new LogEntry(0);
$sLogEntry->uType = LogEntry::PAGELOAD; $sLogEntry->uType = LogEntry::PAGELOAD;
$sLogEntry->uIp = $_SERVER['REMOTE_ADDR']; $sLogEntry->uIp = $_SERVER['REMOTE_ADDR'];
@ -39,5 +57,6 @@ $sPageTitle = "Contribute to {$sCampaign->sName}";
$sPageContents = NewTemplater::Render("landing", $locale->strings, array( $sPageContents = NewTemplater::Render("landing", $locale->strings, array(
"can-donate-once" => true, "can-donate-once" => true,
"project-name" => $sCampaign->sName, "project-name" => $sCampaign->sName,
"urlname" => $sCampaign->sUrlName "urlname" => $sCampaign->sUrlName,
"methods" => $sPaymentMethods
)); ));

@ -0,0 +1,27 @@
<?php
/*
* ReDonate is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_APP)) { die("Unauthorized."); }
try
{
$sCampaign = Campaign::FindByUrlName($router->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}");

@ -105,6 +105,8 @@ $router->routes = array(
), ),
"^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php", "^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php",
"^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.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" "^/test$" => "modules/test.php"
) )
); );

@ -462,16 +462,20 @@ img.logo.thumb
height: 20px; height: 20px;
} }
div.logo div.logo, span.logo
{ {
font-weight: bold; font-weight: bold;
font-style: italic; font-style: italic;
color: #1F2E0B; color: #1F2E0B;
display: inline-block;
font-size: 35px; font-size: 35px;
} }
div.logo.thumb div.logo
{
display: inline-block;
}
div.logo.thumb, span.logo.thumb
{ {
font-size: 18px; font-size: 18px;
} }
@ -770,6 +774,27 @@ p.pledge-button
padding: 16px 20px; 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 * * COMPLEX HEADERS *
**************************************/ **************************************/

@ -0,0 +1,30 @@
<div class="formwrapper">
<h2 class="spaced">Donate to {%?campaign-name} once using {%?method-name}.</h2>
{%if isempty|errors == false}
{%foreach error in errors}
<div class="errors">
{%?error}
</div>
{%/foreach}
{%/if}
<form method="post" action="/campaign/{%?urlname}/donate/{%?method-id}">
<div class="formfield">
<label>Currency</label>
{%select name="currency"}
{%option value="usd" text="US Dollar"}
{%option value="eur" text="Euro"}
{%option value="btc" text="Bitcoin"}
{%/select}
</div>
<div class="formfield">
<label>Amount</label>
{%input type="text" name="amount"}
<div class="clear"></div>
</div>
<div class="formfield submit">
<button type="submit" name="submit" value="submit">Donate</button>
</div>
</form>
</div>

@ -1,5 +1,13 @@
<h2>Contribute to {%?project-name} monthly, no automatic charges.</h2> <h2>Contribute to {%?project-name} monthly, no automatic charges.</h2>
{%if isempty|notices == false}
{%foreach notice in notices}
<div class="notices">
{%?notice}
</div>
{%/foreach}
{%/if}
<div class="details"> <div class="details">
<h3>How does it work?</h3> <h3>How does it work?</h3>
<p class="leader"> <p class="leader">
@ -56,11 +64,16 @@
</form> </form>
{%if can-donate-once == true} {%if can-donate-once == true}
<h3 class="section">One-off donation</h3> <h3 class="section" style="margin-bottom: 16px;">One-off donation</h3>
<p> {%foreach method in methods}
<img src="/static/images/paypal.png"> <a class="no-style donate-once" href="/campaign/{%?urlname}/donate/{%?method[id]}">
<img src="/static/images/bitcoin.png" style="margin-left: 16px;"> {%if isempty|method[image] == false}
</p> <img src="{%?method[image]}" alt="{%?method[text]}">
{%else}
<span class="logo">{%?method[text]}</span>
{%/if}
</a>
{%/foreach}
{%/if} {%/if}
</div> </div>
<div class="clear"></div> <div class="clear"></div>

Loading…
Cancel
Save