Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
Add subscription plan creation
Browse files Browse the repository at this point in the history
  • Loading branch information
tayutaedomo committed Feb 20, 2016
1 parent 187a3e4 commit 4d80a0f
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 45 deletions.
68 changes: 27 additions & 41 deletions routes/subscriptions.js
Expand Up @@ -26,7 +26,8 @@ router.get('/', function(req, res, next) {
router.get('/plan', function(req, res, next) {
res.render('subscriptions/plan', {
title: 'Subscription Plan Creation',
error: {}
error: {},
billingPlan: {}
});
});

Expand All @@ -38,59 +39,44 @@ router.post('/plan', function(req, res, next) {
res.render('subscriptions/plan', {
title: 'Subscription Plan Creation Failed',
error: err,
errorStr: beautify(JSON.stringify(err), { indent_size: 2 })
errorStr: beautify(JSON.stringify(err), { indent_size: 2 }),
billingPlan: {}
});
} else {
res.render('subscriptions/plan', {
title: 'Subscription Plan Created',
billingPlan: billingPlan
error: {},
billingPlan: billingPlan,
billingPlanStr: beautify(JSON.stringify(billingPlan), { indent_size: 2 })
});
}
});
});

/*
// Parameter Sample
var billingPlanAttributes = {
"merchant_preferences": {
"auto_bill_amount": "yes",
"cancel_url": "https://example.com/cancel",
"return_url": "https://example.com/success",
},
"name": "Billing Plan",
"description": "Monthly billing plan",
"type": "UNLIMITED", // UNLIMITED or FIXED
"payment_definitions": [
{
"amount": {
"currency": "USD",
"value": "5.10"
},
"cycles": "0",
"frequency": "MONTH",
"frequency_interval": "1",
"name": "Regular Plan",
"type": "REGULAR"
},
{
"amount": {
"currency": "USD",
"value": "5.10"
},
"cycles": "1",
"frequency": "WEEK",
"frequency_interval": "1",
"name": "Trial Plan",
"type": "TRIAL"
}
]
};
*/
function createBillingPlanAttributesFrom(req) {
return {
name: req.body.name,
description: req.body.description,
type: req.body.type
type: req.body.type,
payment_definitions: [
{
name: req.body.pd_name,
type: req.body.pd_type,
frequency_interval: req.body.pd_frequency_interval,
frequency: req.body.pd_frequency,
cycles: req.body.pd_cycles,
amount: {
currency: req.body.pd_currency,
value: req.body.pd_amount
}
},
],
merchant_preferences: {
cancel_url: req.body.mp_cancel_url,
return_url: req.body.mp_return_url,
auto_bill_amount: req.body.mp_auto_bill_amount,
initial_fail_amount_action: req.body.mp_initial_fail_amount_action
}
};
}

Expand Down
91 changes: 87 additions & 4 deletions views/subscriptions/plan.ejs
Expand Up @@ -5,16 +5,92 @@
<h2>Billing Plan Form</h2>
<form method="post" action="/subscriptions/plan">
<div class="row">
<label>Name: </label><input type="text" name="name" value="Billing plan name" size=64>
<label>Name: </label>
<input type="text" name="name" value="Billing plan name" size=64>
</div>
<div class="row">
<label>Description: </label><input type="text" name="description" value="Billing plan description" size=64>
<label>Description: </label>
<input type="text" name="description" value="Billing plan description" size=64>
</div>
<div class="row">
<label>Type: </label>
<input id="type_unlimited" type="radio" name="type" value="unlimited" checked="checked"><label for="type_unlimited">unlimited</label>
<input id="type_fixed" type="radio" name="type" value="fixed"><label for="type_fixed">fixed</label>
<select name="type">
<option value="INFINITE" selected="selected">INFINITE</option>
<option value="UNLIMITED">UNLIMITED</option>
<option value="FIXED">FIXED</option>
</select>
</div>

<h3>Payment Definition</h3>

<div class="row">
<label>Name: </label>
<input type="text" name="pd_name" value="Payment definition name" size=64>
</div>
<div class="row">
<label>Type: </label>
<select name="pd_type">
<option value="REGULAR" selected="selected">REGULAR</option>
<option value="TRIAL">TRIAL</option>
</select>
</div>
<div class="row">
<label>Frequency Interval: </label>
<input type="number" name="pd_frequency_interval" value="1">
</div>
<div class="row">
<label>Frequency: </label>
<select name="pd_frequency">
<option value="YEAR" selected="selected">YEAR</option>
<option value="MONTH">MONTH</option>
<option value="WEEK">WEEK</option>
<option value="DAY">DAY</option>
</select>
</div>
<div class="row">
<label>Cycles: </label>
<input type="number" name="pd_cycles" value="0">
<blockquote>Number of cycles in this payment definition. For INFINITE type plans, cycles should be set to 0 for a REGULAR type payment_definition.</blockquote>
</div>
<div class="row">
<label>Currency: </label>
<select name="pd_currency">
<option value="USD" selected="selected">USD</option>
<option value="JPY">JPY</option>
</select>
</div>
<div class="row">
<label>Amount: </label>
<input type="number" name="pd_amount" value="9.99">
</div>

<h3>Merchant Preferences</h3>

<div class="row">
<label>Cancel URL: </label>
<input type="text" name="mp_cancel_url" value="http://localhost:3000/subscriptions/cancel" size=128>
</div>
<div class="row">
<label>Return URL: </label>
<input type="text" name="mp_return_url" value="http://localhost:3000/subscriptions/success" size=128>
</div>
<div class="row">
<label>Auto bill amount: </label>
<select name="mp_auto_bill_amount">
<option value="YES" selected="selected">YES</option>
<option value="NO">NO</option>
</select>
</div>
<div class="row">
<label>Initial fail amount action: </label>
<select name="mp_initial_fail_amount_action">
<option value="CANCEL" selected="selected">CANCEL</option>
<option value="CONTINUE">CONTINUE</option>
</select>
</div>

<br>

<div class="row">
<input type="submit">
</div>
Expand All @@ -27,3 +103,10 @@
</pre>
<% } %>

<% if (JSON.stringify(billingPlan) !== '{}') { %>
<h2>API call succeeded</h2>
<pre>
<code><%= billingPlanStr %></code>
</pre>
<% } %>

0 comments on commit 4d80a0f

Please sign in to comment.