Implement change requests when user with existing subscription attempts to subscribe again

master
Sven Slootweg 11 years ago
parent 3fe016dc54
commit c79658a878

@ -0,0 +1,40 @@
<?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
{
$sChangeRequest = new ChangeRequest($router->uParameters[2]);
}
catch (NotFoundException $e)
{
throw new RouterException("No such change request exists.");
}
if($sChangeRequest->sSubscription->uEmailAddress != $router->uParameters[1])
{
throw new RouterException("The given e-mail address does not match the e-mail address for this change request.");
}
if($sChangeRequest->uKey != $router->uParameters[3])
{
throw new RouterException("The given key does not match the key for this change request.");
}
if($sChangeRequest->sIsConfirmed === true)
{
throw new RouterException("The change request was already fulfilled.");
}
$sRouterAuthenticated = true;

@ -0,0 +1,72 @@
<?php
/*
* projectname 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."); }
class ChangeRequest extends CPHPDatabaseRecordClass
{
public $table_name = "change_requests";
public $fill_query = "SELECT * FROM change_requests WHERE `Id` = :Id";
public $verify_query = "SELECT * FROM change_requests WHERE `Id` = :Id";
public $prototype = array(
'string' => array(
'OldCurrency' => "OldCurrency",
'NewCurrency' => "NewCurrency",
'Key' => "Key"
),
'numeric' => array(
'SubscriptionId' => "SubscriptionId",
'CampaignId' => "CampaignId",
'OldAmount' => "OldAmount",
'NewAmount' => "NewAmount"
),
'boolean' => array(
'IsConfirmed' => "Confirmed"
),
'timestamp' => array(
'Date' => "Date"
),
'campaign' => array(
'Campaign' => "CampaignId"
),
'subscription' => array(
'Subscription' => "SubscriptionId"
)
);
public function GenerateEmail()
{
global $locale;
$sText = NewTemplater::Render("email/change.txt", $locale->strings, array(
"campaign-name" => $this->sCampaign->sName,
"confirmation-url" => "http://redonate.net/change/{$this->sSubscription->sEmailAddress}/{$this->sId}/{$this->sKey}",
"unsubscribe-url" => "http://redonate.com/manage/{$this->sSubscription->sEmailAddress}/{$this->sSubscription->sSettingsKey}",
"old" => Currency::Format($this->sOldCurrency, $this->sOldAmount),
"new" => Currency::Format($this->sNewCurrency, $this->sNewAmount)
));
$sHtml = NewTemplater::Render("email/layout.html", $locale->strings, array(
"contents" => NewTemplater::Render("email/change.html", $locale->strings, array(
"campaign-name" => $this->sCampaign->sName,
"confirmation-url" => "http://redonate.net/change/{$this->sSubscription->sEmailAddress}/{$this->sId}/{$this->sKey}",
"unsubscribe-url" => "http://redonate.com/manage/{$this->sSubscription->sEmailAddress}/{$this->sSubscription->sSettingsKey}",
"old" => Currency::Format($this->sOldCurrency, $this->sOldAmount),
"new" => Currency::Format($this->sNewCurrency, $this->sNewAmount)
))
));
return array("text" => $sText, "html" => $sHtml);
}
}

@ -0,0 +1,24 @@
<?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."); }
$sChangeRequest->sSubscription->uCurrency = $sChangeRequest->uNewCurrency;
$sChangeRequest->sSubscription->uAmount = $sChangeRequest->uNewAmount;
$sChangeRequest->sSubscription->InsertIntoDatabase();
$sChangeRequest->uIsConfirmed = true;
$sChangeRequest->InsertIntoDatabase();
flash_notice("The change was successfully applied.");
redirect("/manage/{$sChangeRequest->sSubscription->sEmailAddress}/{$sChangeRequest->sSubscription->sSettingsKey}");

@ -0,0 +1,16 @@
<?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."); }
throw new NotFoundException("No such change request was found.");

@ -53,6 +53,7 @@ try
if($sSubscription->sCampaignId == $sCampaign->sId && $sSubscription->sIsActive == true)
{
$exists = true;
$sExistingSubscription = $sSubscription;
}
}
@ -65,7 +66,23 @@ catch (NotFoundException $e)
if($exists)
{
$sPageContents = NewTemplater::Render("subscription/change", $locale->strings, array());
/* TODO: Change request */
$sChangeRequest = new ChangeRequest(0);
$sChangeRequest->uKey = random_string(16);
$sChangeRequest->uOldCurrency = $sExistingSubscription->sCurrency;
$sChangeRequest->uOldAmount = $sExistingSubscription->sAmount;
$sChangeRequest->uNewCurrency = $_POST['currency'];
$sChangeRequest->uNewAmount = str_replace(",", ".", $_POST['amount']);
$sChangeRequest->uSubscriptionId = $sExistingSubscription->sId;
$sChangeRequest->uCampaignId = $sExistingSubscription->sCampaign->sId;
$sChangeRequest->uIsConfirmed = false;
$sChangeRequest->uDate = time();
$sChangeRequest->InsertIntoDatabase();
$sEmail = $sChangeRequest->GenerateEmail();
send_mail($sExistingSubscription->sEmailAddress, "Changes to your pledge to {$sExistingSubscription->sCampaign->sName}", $sEmail['text'], $sEmail['html']);
return;
}

@ -78,6 +78,11 @@ $router->routes = array(
'authenticator' => "authenticators/payment.php",
'auth_error' => "modules/error/nosuchpayment.php"
),
"^/change/(.+)/([0-9]+)/([a-zA-Z0-9]+)$" => array(
'target' => "modules/change.php",
'authenticator' => "authenticators/change.php",
'auth_error' => "modules/error/nosuchchange.php"
),
"^/manage/(.+?)/([a-zA-Z0-9]+)/change-amount$" => array(
'target' => "modules/subscription/change_amount.php",
'authenticator' => "authenticators/subscription.php",

@ -0,0 +1,44 @@
<p>
Hi there,
</p>
<p>
You entered your e-mail address for a campaign that you already
subscribed to in the past. If you meant to change your settings, please
click the confirmation link, and we'll update your settings.
</p>
<p>
If you didn't mean to change your settings and want to keep things as
they were before, you can simply ignore this e-mail. If you have any
further questions, don't hesitate to reply to this e-mail!
</p>
<p>
Campaign: {%?campaign-name}
</p>
<p>
Previous monthly amount: {%?old}
</p>
<p>
<strong>New monthly amount: {%?new}</strong>
</p>
<p>
Click this link to confirm the change:
<a href="{%?confirmation-url}">{%?confirmation-url}</a>
</p>
<p>
<em>- Sven Slootweg, ReDonate</em>
</p>
<hr>
<p>
If you want to cancel your donation pledge or change your settings, please visit
<a href="{%?unsubscribe-url}">{%?unsubscribe-url}</a>.
</p>

@ -0,0 +1,25 @@
Hi there,
You entered your e-mail address for a campaign that you already
subscribed to in the past. If you meant to change your settings, please
click the confirmation link, and we'll update your settings.
If you didn't mean to change your settings and want to keep things as
they were before, you can simply ignore this e-mail. If you have any
further questions, don't hesitate to reply to this e-mail!
Campaign: {%?campaign-name}
Previous monthly amount: {%?old}
New monthly amount: {%?new}
Click this link to confirm the change: {%?confirmation-url}
- Sven Slootweg, ReDonate
-----
If you want to cancel your donation pledge or change other settings,
please visit {%?unsubscribe-url}.
Loading…
Cancel
Save