Implement payment method creation

master
Sven Slootweg 11 years ago
parent e2674b7635
commit b69ebbf7df

@ -21,7 +21,8 @@ class PaymentMethod extends CPHPDatabaseRecordClass
public $prototype = array(
'string' => array(
'Address' => "Address"
'Address' => "Address",
'CustomName' => "CustomName"
),
'numeric' => array(
'Type' => "Type",
@ -46,8 +47,28 @@ class PaymentMethod extends CPHPDatabaseRecordClass
return array("image" => "/static/images/bitcoin.png", "text" => "Bitcoin");
case PaymentMethod::IBAN:
return array("text" => "IBAN");
case 0:
return array("text" => $this->sCustomName);
default:
return array("text" => "Unknown");
}
}
public static function ValidateAddress($type, $address)
{
switch($type)
{
case PaymentMethod::PAYPAL:
return filter_var($address, FILTER_VALIDATE_EMAIL);
case PaymentMethod::BITCOIN:
return (preg_match("/^[a-zA-Z1-9]{27,35}$/", $address) == true);
default:
return true;
}
}
public static function CheckIfValidMethod($type)
{
return in_array($type, array(0, PaymentMethod::PAYPAL, PaymentMethod::BITCOIN));
}
}

@ -0,0 +1,73 @@
<?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::CreateFromQuery("SELECT * FROM campaigns WHERE `UrlName` = :UrlName", array(":UrlName" => $router->uParameters[1]), 30, true);
}
catch (NotFoundException $e)
{
throw new RouterException("Campaign does not exist.");
}
if(!empty($_POST['submit']))
{
if(empty($_POST['address']))
{
flash_error("You did not enter a valid address or account ID.");
}
if(!isset($_POST['method']) || $_POST['method'] == "")
{
flash_error("You did not select a valid payment method.");
}
elseif($_POST['method'] == "0" && empty($_POST['customname']))
{
flash_error("You did not enter a valid name for the payment method.");
}
elseif(PaymentMethod::CheckIfValidMethod($_POST['method']) === false)
{
flash_error("You did not select a valid payment method.");
}
elseif(PaymentMethod::ValidateAddress($_POST['method'], $_POST['address']) === false)
{
flash_error("The address you entered is invalid.");
}
if(count(get_errors(false)) == 0)
{
$sPaymentMethod = new PaymentMethod(0);
$sPaymentMethod->uType = $_POST['method'];
$sPaymentMethod->uAddress = $_POST['address'];
$sPaymentMethod->uCampaignId = $sCampaign->sId;
if($_POST['method'] == 0)
{
$sPaymentMethod->uCustomName = $_POST['customname'];
}
$sPaymentMethod->InsertIntoDatabase();
flash_notice("The payment method was successfully added.");
redirect("/dashboard/{$sCampaign->uUrlName}");
}
}
$sPageTitle = "Add payment method";
$sPageContents = NewTemplater::Render("campaign/addmethod", $locale->strings, array(
"name" => $sCampaign->sName,
"urlname" => $sCampaign->sUrlName
));

@ -30,7 +30,10 @@ try
foreach(PaymentMethod::CreateFromQuery("SELECT * FROM payment_methods WHERE `CampaignId` = :CampaignId",
array(":CampaignId" => $sCampaign->sId)) as $sPaymentMethod)
{
$sPaymentMethods[] = $sPaymentMethod->GetLogo();
$sNewMethod = $sPaymentMethod->GetLogo();
$sNewMethod['address'] = $sPaymentMethod->sAddress;
$sNewMethod['id'] = $sPaymentMethod->sId;
$sPaymentMethods[] = $sNewMethod;
}
}
catch (NotFoundException $e)

@ -24,27 +24,32 @@ $router->ignore_query = true;
$router->routes = array(
0 => array(
"^/$" => array(
'target' => "modules/index.php",
'_padded' => false
),
"^/sign-up$" => "modules/signup.php",
"^/login$" => "modules/login.php",
"^/about$" => "modules/about.php",
"^/logout/([a-zA-Z0-9]+)$" => "modules/logout.php",
"^/confirm/(.+)/([a-zA-Z0-9]+)$" => "modules/confirm.php",
"^/dashboard$" => array(
'target' => "modules/dashboard.php",
'authenticator' => "authenticators/user.php",
'auth_error' => "modules/error/guest.php"
),
"^/dashboard/([a-zA-Z0-9-]+)$" => array(
'target' => "modules/campaign/dashboard.php",
'authenticator' => "authenticators/user.php",
'auth_error' => "modules/error/guest.php"
),
"^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php",
"^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.php"
"^/$" => array(
'target' => "modules/index.php",
'_padded' => false
),
"^/sign-up$" => "modules/signup.php",
"^/login$" => "modules/login.php",
"^/about$" => "modules/about.php",
"^/logout/([a-zA-Z0-9]+)$" => "modules/logout.php",
"^/confirm/(.+)/([a-zA-Z0-9]+)$" => "modules/confirm.php",
"^/dashboard$" => array(
'target' => "modules/dashboard.php",
'authenticator' => "authenticators/user.php",
'auth_error' => "modules/error/guest.php"
),
"^/dashboard/([a-zA-Z0-9-]+)$" => array(
'target' => "modules/campaign/dashboard.php",
'authenticator' => "authenticators/user.php",
'auth_error' => "modules/error/guest.php"
),
"^/dashboard/([a-zA-Z0-9-]+)/add-payment-method$" => array(
'target' => "modules/campaign/addmethod.php",
'authenticator' => "authenticators/user.php",
'auth_error' => "modules/error/guest.php"
),
"^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php",
"^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.php"
)
);

@ -99,6 +99,11 @@ pre.debug
margin-bottom: 12px;
}
.main h3.spaced
{
margin-bottom: 18px;
}
/**************************************
* FOOTER *
**************************************/
@ -196,11 +201,12 @@ pre.debug
float: left;
}
.formfield input
.formfield input, .formfield select
{
font-size: 17px;
padding: 4px;
width: 270px;
box-sizing: content-box;
border: 1px solid #6CA825;
border-radius: 1px;
background-color: #F4FDE4;
@ -429,7 +435,7 @@ div.logo
font-style: italic;
color: #1F2E0B;
display: inline-block;
font-size: 39px;
font-size: 35px;
}
div.logo.thumb
@ -451,6 +457,32 @@ td.payment-methods
margin-top: 18px;
}
table.payment-methods td.logo
{
width: 250px;
padding: 16px;
text-align: center;
}
table.payment-methods td.address
{
padding: 18px;
font-size: 19px;
}
table.payment-methods td.remove
{
padding-top: 20px;
text-align: center;
width: 110px;
}
table.payment-methods td.remove button
{
padding: 9px 10px;
font-size: 15px;
}
/**************************************
* BAR GRAPH *
**************************************/

@ -27,4 +27,30 @@ $(function(){
}
}
});
$('.conditional').each(function(element){
var affected = $(this);
var target = $("#" + affected.data("conditional-element"));
var desired = $(this).data("conditional-value");
target.change(function(){
if($(this).val() == desired)
{
affected.show();
}
else
{
affected.hide();
}
});
if(target.val() == desired)
{
affected.show();
}
else
{
affected.hide();
}
});
});

@ -0,0 +1,42 @@
<div class="formwrapper">
<h2 class="spaced">Add payment method for {%?name}</h2>
{%if isempty|errors == false}
<div class="errors">
One or more errors occurred:
<ul>
{%foreach error in errors}
<li>{%?error}</li>
{%/foreach}
</ul>
</div>
{%/if}
<form method="post" action="/dashboard/{%?urlname}/add-payment-method">
<div class="formfield">
<label>Payment method</label>
{%select name="method" id="field_method"}
{%option value="1" text="PayPal"}
{%option value="2" text="Bitcoin"}
{%option value="0" text="Other..."}
{%/select}
<div class="clear"></div>
</div>
<div class="formfield conditional" data-conditional-element="field_method" data-conditional-value="0">
<label>Custom name</label>
{%input type="text" name="customname"}
<div class="clear"></div>
</div>
<div class="formfield">
<label>Address / ID</label>
{%input type="text" name="address"}
<div class="clear"></div>
</div>
<div class="formfield submit">
<button type="submit" name="submit" value="submit">Add</button>
</div>
</form>
</div>

@ -1,5 +1,13 @@
<h2 class="spaced">Dashboard &gt; {%?name}</h2>
{%if isempty|notices == false}
{%foreach notice in notices}
<div class="notices">
{%?notice}
</div>
{%/foreach}
{%/if}
<div class="dashboard-section">
<h3>Past month</h3>
@ -38,16 +46,30 @@
<div class="dashboard-section">
<div class="complex-header">
<h3>Payment methods</h3>
<h3 class="spaced">Payment methods</h3>
<a class="button" href="/dashboard/{%?urlname}/add-payment-method">Add method</a>
<div class="clear"></div>
</div>
{%foreach method in payment-methods}
{%if isempty|method[image] == false}
<img class="logo" src="{%?method[image]}" alt="{%?method[text]}">
{%else}
<div class="logo">{%?method[text]}</div>
{%/if}
{%/foreach}
<table class="payment-methods">
{%foreach method in payment-methods}
<tr>
<td class="logo">
{%if isempty|method[image] == false}
<img class="logo" src="{%?method[image]}" alt="{%?method[text]}">
{%else}
<div class="logo">{%?method[text]}</div>
{%/if}
</td>
<td class="address">
{%?method[address]}
</td>
<td class="remove">
<form method="post" action="/dashboard/{%?urlname}/remove-payment-method/{%?method[id]}">
<button type="submit">Remove</button>
</form>
</td>
</tr>
{%/foreach}
</table>
</div>

Loading…
Cancel
Save