You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
3.4 KiB
PHTML
123 lines
3.4 KiB
PHTML
12 years ago
|
<?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
|
||
|
));
|
||
|
|