diff --git a/public_html/authenticators/payment.php b/public_html/authenticators/payment.php new file mode 100644 index 0000000..95fa375 --- /dev/null +++ b/public_html/authenticators/payment.php @@ -0,0 +1,40 @@ +uParameters[2]); +} +catch (NotFoundException $e) +{ + throw new RouterException("No such payment request exists."); +} + +if($sPaymentRequest->sSubscription->uEmailAddress != $router->uParameters[1]) +{ + throw new RouterException("The given e-mail address does not match the e-mail address for this payment request."); +} + +if($sPaymentRequest->uKey != $router->uParameters[3]) +{ + throw new RouterException("The given key does not match the key for this payment request."); +} + +if($sPaymentRequest->sPaid === true) +{ + throw new RouterException("The payment request was already fulfilled."); +} + +$sRouterAuthenticated = true; diff --git a/public_html/classes/campaign.php b/public_html/classes/campaign.php index 063f212..4c1574a 100644 --- a/public_html/classes/campaign.php +++ b/public_html/classes/campaign.php @@ -94,6 +94,21 @@ class Campaign extends CPHPDatabaseRecordClass return ($this->sOwnerId == $userid); } + public function GetPaymentMethod($type) + { + try + { + $sPaymentMethod = PaymentMethod::CreateFromQuery("SELECT * FROM payment_methods WHERE `CampaignId` = :CampaignId AND `Type` = :Type", + array(":CampaignId" => $this->sId, ":Type" => $type), 30, true); + } + catch (NotFoundException $e) + { + throw new NotFoundException("No valid payment method specified."); + } + + return $sPaymentMethod; + } + public function UpdateStatistics() { global $database, $cphp_config; diff --git a/public_html/classes/paymentrequest.php b/public_html/classes/paymentrequest.php new file mode 100644 index 0000000..6603d14 --- /dev/null +++ b/public_html/classes/paymentrequest.php @@ -0,0 +1,45 @@ + array( + 'Currency' => "Currency", + 'Key' => "Key" + ), + 'numeric' => array( + 'CampaignId' => "CampaignId", + 'SubscriptionId' => "SubscriptionId", + 'Amount' => "Amount" + ), + 'boolean' => array( + 'Paid' => "Paid" + ), + 'timestamp' => array( + 'IssueDate' => "Date" + ), + 'campaign' => array( + 'Campaign' => "CampaignId" + ), + 'subscription' => array( + 'Subscription' => "SubscriptionId" + ) + ); +} diff --git a/public_html/modules/error/nosuchpayment.php b/public_html/modules/error/nosuchpayment.php new file mode 100644 index 0000000..7f9fb03 --- /dev/null +++ b/public_html/modules/error/nosuchpayment.php @@ -0,0 +1,16 @@ +uPaid = true; +$sPaymentRequest->InsertIntoDatabase(); + +$sPageTitle = "Thanks!"; +$sPageContents = NewTemplater::Render("payment/done", $locale->strings, array()); diff --git a/public_html/modules/payment/paypal.php b/public_html/modules/payment/paypal.php new file mode 100644 index 0000000..0e755b8 --- /dev/null +++ b/public_html/modules/payment/paypal.php @@ -0,0 +1,40 @@ +sCampaign->GetPaymentMethod(PaymentMethod::PAYPAL); +} +catch (NotFoundException $e) +{ + throw new RouterException("No such payment method found."); +} + +if($sPaymentRequest->sCurrency == "btc") +{ + $sCurrency = urlencode("USD"); + $sAmount = Currency::Convert("usd", "btc", $sPaymentRequest->sAmount); +} +else +{ + $sCurrency = urlencode(strtoupper($sPaymentRequest->sCurrency)); + $sAmount = urlencode($sPaymentRequest->sAmount); +} + +$sQuotedRecipient = urlencode($sPaymentMethod->sAddress); +$sQuotedName = urlencode("{$sPaymentRequest->sCampaign->sName} (via ReDonate.net)"); +$sQuotedNumber = urlencode("{$sPaymentRequest->sId}"); +$sQuotedReturnUrl = urlencode("http://redonate.net/pay/{$sPaymentRequest->sSubscription->sEmailAddress}/{$sPaymentRequest->sId}/{$sPaymentRequest->sKey}/paypal/done"); +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}"); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index 80a179d..c14916c 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -58,6 +58,26 @@ $router->routes = array( 'authenticator' => "authenticators/user.php", 'auth_error' => "modules/error/guest.php" ), + "^/pay/(.+)/([0-9]+)/([a-zA-Z0-9]+)/(.+)/done$" => array( + 'target' => "modules/payment/notify_done.php", + 'authenticator' => "authenticators/payment.php", + 'auth_error' => "modules/error/nosuchpayment.php" + ), + "^/pay/(.+)/([0-9]+)/([a-zA-Z0-9]+)/paypal$" => array( + 'target' => "modules/payment/paypal.php", + 'authenticator' => "authenticators/payment.php", + 'auth_error' => "modules/error/nosuchpayment.php" + ), + "^/pay/(.+)/([0-9]+)/([a-zA-Z0-9]+)/bitcoin$" => array( + 'target' => "modules/payment/bitcoin.php", + 'authenticator' => "authenticators/payment.php", + 'auth_error' => "modules/error/nosuchpayment.php" + ), + "^/pay/(.+)/([0-9]+)/([a-zA-Z0-9]+)/([0-9]+)$" => array( + 'target' => "modules/payment/other.php", + 'authenticator' => "authenticators/payment.php", + 'auth_error' => "modules/error/nosuchpayment.php" + ), "^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php", "^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.php" ) diff --git a/public_html/templates/payment/done.tpl b/public_html/templates/payment/done.tpl new file mode 100644 index 0000000..9976b9c --- /dev/null +++ b/public_html/templates/payment/done.tpl @@ -0,0 +1,5 @@ +

Thanks for donating!

+ +

+ Thank you for your contribution. You can close this page now. +