diff --git a/public_html/classes/campaign.php b/public_html/classes/campaign.php index 4c1574a..3068d6e 100644 --- a/public_html/classes/campaign.php +++ b/public_html/classes/campaign.php @@ -94,6 +94,11 @@ class Campaign extends CPHPDatabaseRecordClass return ($this->sOwnerId == $userid); } + public function GetPaymentMethods() + { + return PaymentMethod::CreateFromQuery("SELECT * FROM payment_methods WHERE `CampaignId` = :CampaignId", array(":CampaignId" => $this->sId), 30); + } + public function GetPaymentMethod($type) { try diff --git a/public_html/classes/paymentmethod.php b/public_html/classes/paymentmethod.php index f50105c..1f995cd 100644 --- a/public_html/classes/paymentmethod.php +++ b/public_html/classes/paymentmethod.php @@ -54,6 +54,42 @@ class PaymentMethod extends CPHPDatabaseRecordClass } } + public function GenerateUrl($sRequest) + { + $sUrlName = $this->GetUrlName(); + return "http://redonate.net/pay/{$sRequest->sSubscription->sEmailAddress}/{$sRequest->sId}/{$sRequest->sKey}/{$sUrlName}"; + } + + public function GetName() + { + switch($this->sType) + { + case PaymentMethod::PAYPAL: + return "PayPal"; + case PaymentMethod::BITCOIN: + return "Bitcoin"; + case 0: + return "{$this->sCustomName}"; + default: + throw Exception("No valid payment method type."); + } + } + + public function GetUrlName() + { + switch($this->sType) + { + case PaymentMethod::PAYPAL: + return "paypal"; + case PaymentMethod::BITCOIN: + return "bitcoin"; + case 0: + return "{$this->sId}"; + default: + throw Exception("No valid payment method type."); + } + } + public static function ValidateAddress($type, $address) { switch($type) diff --git a/public_html/classes/paymentrequest.php b/public_html/classes/paymentrequest.php index 6603d14..053a739 100644 --- a/public_html/classes/paymentrequest.php +++ b/public_html/classes/paymentrequest.php @@ -42,4 +42,39 @@ class PaymentRequest extends CPHPDatabaseRecordClass 'Subscription' => "SubscriptionId" ) ); + + public function GenerateEmail() + { + global $locale; + + $sMethods = array(); + + foreach($this->sCampaign->GetPaymentMethods() as $sPaymentMethod) + { + $sMethods[] = array( + "name" => $sPaymentMethod->GetName(), + "url" => $sPaymentMethod->GenerateUrl($this) + ); + } + + $sText = NewTemplater::Render("email/reminder.txt", $locale->strings, array( + "campaign-name" => $this->sCampaign->sName, + "amount" => Currency::Format($this->sCurrency, $this->sAmount), + "skip-url" => "http://redonate.net/pay/{$this->sSubscription->sEmailAddress}/{$this->sId}/{$this->sKey}/skip", + "unsubscribe-url" => "http://redonate.com/manage/{$this->sSubscription->sEmailAddress}/{$this->sSubscription->sSettingsKey}", + "methods" => $sMethods + )); + + $sHtml = NewTemplater::Render("email/layout.html", $locale->strings, array( + "contents" => NewTemplater::Render("email/reminder.html", $locale->strings, array( + "campaign-name" => $this->sCampaign->sName, + "amount" => Currency::Format($this->sCurrency, $this->sAmount), + "skip-url" => "http://redonate.net/pay/{$this->sSubscription->sEmailAddress}/{$this->sId}/{$this->sKey}/skip", + "unsubscribe-url" => "http://redonate.com/manage/{$this->sSubscription->sEmailAddress}/{$this->sSubscription->sSettingsKey}", + "methods" => $sMethods + )) + )); + + return array("text" => $sText, "html" => $sHtml); + } } diff --git a/public_html/modules/test.php b/public_html/modules/test.php new file mode 100644 index 0000000..2cee2f3 --- /dev/null +++ b/public_html/modules/test.php @@ -0,0 +1,17 @@ +GenerateEmail()); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index c14916c..ecfd09a 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -79,7 +79,8 @@ $router->routes = array( 'auth_error' => "modules/error/nosuchpayment.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", + "^/test$" => "modules/test.php" ) ); diff --git a/public_html/templates/email/reminder.html.tpl b/public_html/templates/email/reminder.html.tpl new file mode 100644 index 0000000..217ef1f --- /dev/null +++ b/public_html/templates/email/reminder.html.tpl @@ -0,0 +1,48 @@ +

+ Hi there, +

+ +

+ This is your donation pledge reminder for this month. You pledged to + donate {%?amount} every month to {%?campaign-name}. +

+ +

+ To make your donation for this month, use one of the following links: +

+ + + +

+ If you want to skip the donation for this month, then please click the + following link so that we can record it in the statistics: +

+ +

+ {%?skip-url} +

+ +

+ Don't worry - the campaign administrator can't see who has donated, and + who hasn't! +

+ +

+ If you have any further questions about ReDonate, feel free to reply to + this e-mail. We read every e-mail, and reply to them personally. +

+ +

+ - Sven Slootweg, ReDonate +

+ +
+ +

+If you want to cancel your donation pledge, please visit +{%?unsubscribe-url}. +

diff --git a/public_html/templates/email/reminder.txt.tpl b/public_html/templates/email/reminder.txt.tpl new file mode 100644 index 0000000..b78da3f --- /dev/null +++ b/public_html/templates/email/reminder.txt.tpl @@ -0,0 +1,26 @@ +Hi there, + +This is your donation pledge reminder for this month. You pledged to +donate {%?amount} every month to {%?campaign-name}. + +To make your donation for this month, use one of the following links: +{%foreach method in methods} +* {%?method[name]}: {%?method[url]}{%/foreach} + +If you want to skip the donation for this month, then please click the +following link so that we can record it in the statistics: + +{%?skip-url} + +Don't worry - the campaign administrator can't see who has donated, and +who hasn't! + +If you have any further questions about ReDonate, feel free to reply to +this e-mail. We read every e-mail, and reply to them personally. + +- Sven Slootweg, ReDonate + +----- + +If you want to cancel your donation pledge, please visit +{%?unsubscribe-url}.