Implement one-off donations
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}¤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
|
||||
));
|
||||
|
@ -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}");
|
@ -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>
|
Loading…
Reference in New Issue