Skip to content

Commit f671045

Browse files
authored
Merge pull request #646 from gruntwork-io/apt-1373-recurly-checkout
[APT-1373] Switch from Chargebee to Recurly for checkout.
2 parents 0167f62 + a56c2ee commit f671045

File tree

5 files changed

+99
-114
lines changed

5 files changed

+99
-114
lines changed

assets/css/global.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ p + .btn {
4444
transform: translateY(-2px);
4545
box-shadow: 0 6px 9px rgba(0,0,0,.10), 0 2px 5px rgba(0,0,0,.07);
4646
}
47+
max-width: 100%;
48+
text-overflow: ellipsis;
49+
overflow: hidden;
4750
}
4851
.btn-link {
4952
box-shadow: none;
@@ -2319,11 +2322,14 @@ $play-button-height: 44px;
23192322
}
23202323
.checkout-panel-left {
23212324
padding: 0px;
2322-
margin-right: 10px;
23232325

23242326
@media (max-width: $screen-xs-max) {
23252327
padding: 16px 8px;
23262328
}
2329+
2330+
@media (min-width: $screen-sm-max) {
2331+
margin-right: 10px;
2332+
}
23272333
}
23282334
.checkout-panel-right {
23292335
position: relative;

assets/css/pages/checkout.scss

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
}
2020

2121
.checkout-help-notification {
22-
width: 103%;
23-
margin-left: -.8em;
22+
width: calc(100% + 30px);
23+
margin-left: -15px;
2424
}
2525

2626
#checkout-money-back {
@@ -36,15 +36,12 @@
3636

3737
.sub-panel {
3838
background-color: #1D252F;
39-
line-height: 1;
39+
line-height: 1.4;
4040

4141
.addon-amount {
4242
font-size: 25px;
4343
margin-top: 15px;
4444
font-weight: bold;
45-
@media (max-width: $screen-sm-max) {
46-
margin-top: 0px;
47-
}
4845
}
4946
.addon-duration {
5047
margin-top: -25px;
@@ -81,20 +78,11 @@
8178
}
8279
}
8380

84-
#checkout-btn-container {
85-
@media (max-width: $screen-xs-max) {
86-
height: 25px;
87-
}
88-
@media (min-width: $screen-sm-min) {
89-
height: 52px;
90-
}
91-
}
92-
9381
#checkout-btn-container-beta {
9482
@media (max-width: $screen-xs-max) {
95-
height: 41px;
83+
margin: 0;
9684
}
9785
@media (min-width: $screen-sm-min) {
98-
height: 52px;
86+
margin: 1em 0;
9987
}
10088
}

assets/css/pages/pricing.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989
margin-bottom: .6em;
9090
}
9191

92+
@media (max-width: $screen-xs-max) {
93+
.need-help-button {
94+
margin: 2em;
95+
}
96+
}
97+
9298
.pricing-steps {
9399
display: flex;
94100
align-items: center;

assets/js/checkout.js

Lines changed: 70 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,32 @@ $(function () {
135135
function _updateCheckout(newOptions) {
136136
checkoutOptions = Object.assign({}, checkoutOptions, newOptions);
137137

138-
var enable_pro_support = checkoutOptions.pro_support;
139-
var setup_deployment = checkoutOptions.setup_deployment;
140-
var setup_compliance = checkoutOptions.setup_compliance;
138+
_updateUI();
139+
_updatePrice();
140+
_updateCheckoutLink();
141+
}
142+
143+
function _updateUI() {
144+
var support = checkoutOptions.pro_support;
145+
var refarch = checkoutOptions.setup_deployment;
146+
var compliance = checkoutOptions.setup_compliance;
141147

142148
$('.grunty-sprite').attr('data-sprite', 0);
143149
$('#subscription_type').val(checkoutOptions.subscription_type);
144150

145151
// updates addon switch
146-
$('[data-switch]' + '[name="pro_support"]').prop('checked', enable_pro_support);
147-
$('[data-switch]' + '[name="setup_deployment"]').prop('checked', setup_deployment);
148-
$('[data-switch]' + '[name="setup_compliance"]').prop('checked', setup_compliance);
152+
$('[data-switch]' + '[name="pro_support"]').prop('checked', support);
153+
$('[data-switch]' + '[name="setup_deployment"]').prop('checked', refarch);
154+
$('[data-switch]' + '[name="setup_compliance"]').prop('checked', compliance);
149155

150-
if (enable_pro_support) {
156+
if (support) {
151157
$('.grunty-sprite').attr('data-sprite', 2);
152158
$('#subscription-addon-1').removeClass('check-list-disabled');
153159
} else {
154160
$('#subscription-addon-1').addClass('check-list-disabled');
155161
}
156162

157-
if (setup_deployment) {
163+
if (refarch) {
158164
$('.grunty-sprite').attr('data-sprite', 1);
159165

160166
$('#checkout-price-addon').show();
@@ -170,7 +176,7 @@ $(function () {
170176
$('#subscription-addon-2').addClass('check-list-disabled');
171177
}
172178

173-
if (setup_compliance) {
179+
if (compliance) {
174180
$('#subscription-addon-3').removeClass('check-list-disabled');
175181

176182
// Update Refarch texts to reflect CIS selection
@@ -184,109 +190,92 @@ $(function () {
184190
$('#addon-text-refarch').text('Reference Architecture');
185191
}
186192

187-
if (checkoutOptions.pro_support && checkoutOptions.setup_deployment) {
193+
if (support && refarch) {
188194
$('.grunty-sprite').attr('data-sprite', 3);
189195
}
190-
191-
_calculatePrice();
192196
}
193197

194-
function _calculatePrice() {
195-
var total, subtotal, subscriptionTotal;
198+
function _updatePrice() {
199+
var monthlyTotal, dueNowTotal;
196200

197201
switch (checkoutOptions.subscription_type) {
198202
case 'aws':
199-
total = subtotal = pricing.subscriptions.aws.price.value;
203+
monthlyTotal = pricing.subscriptions.aws.price.value;
200204
break;
201205
case 'gcp':
202-
total = subtotal = pricing.subscriptions.gcp.price.value;
206+
monthlyTotal = pricing.subscriptions.gcp.price.value;
203207
break;
204208
default: // do nothing
205209
}
206210

207211
if (checkoutOptions.pro_support) {
208212
switch (checkoutOptions.subscription_type) {
209213
case 'aws':
210-
total += subtotal = pricing.subscriptions.aws.pro_support_price.value;
214+
monthlyTotal += pricing.subscriptions.aws.pro_support_price.value;
211215
break;
212216
case 'gcp':
213-
total += subtotal = pricing.subscriptions.gcp.pro_support_price.value;
217+
monthlyTotal += pricing.subscriptions.gcp.pro_support_price.value;
214218
break;
215219
default: // do nothing
216220
}
217221
}
218222

223+
// CIS Compliance is only on AWS for now
224+
if (checkoutOptions.setup_compliance) {
225+
monthlyTotal += pricing.subscriptions.aws.cis_compliance_price.value;
226+
}
227+
228+
dueNowTotal = monthlyTotal;
229+
219230
// Only AWS supports the Ref Arch
220231
if (checkoutOptions.setup_deployment) {
221-
subscriptionTotal = subtotal;
222-
//subtotal += 4950;
232+
dueNowTotal += 4950;
233+
$('#due-monthly-block').show();
234+
} else {
235+
// only show the monthly disclaimer when it differs from due now
236+
$('#due-monthly-block').hide();
223237
}
224238

225-
// CIS Compliance is only on AWS for now
226-
if (checkoutOptions.setup_compliance) {
227-
total += subtotal = pricing.subscriptions.aws.cis_compliance_price.value;
239+
$('#due-now').text(dueNowTotal.toLocaleString());
240+
$('.monthly-total').text(monthlyTotal.toLocaleString());
241+
}
242+
243+
// Update the Recurly checkout link URL
244+
function _updateCheckoutLink() {
245+
const type = checkoutOptions.subscription_type;
246+
const support = checkoutOptions.pro_support;
247+
const refarch = checkoutOptions.setup_deployment;
248+
const compliance = checkoutOptions.setup_compliance;
249+
250+
var href = "https://gruntwork.recurly.com/subscribe/" + type + "-monthly?";
251+
252+
// We'll want to pass users when we switch from using the Recurly hosted payment
253+
// page to our own, at which point we can re-enable the users add-on.
254+
255+
const addOns = { /*"users": 20*/ };
256+
if (support) {
257+
addOns["pro-support"] = 1;
258+
}
259+
if (refarch) {
260+
addOns["ref-arch"] = 1;
261+
}
262+
if (compliance) {
263+
addOns["cis-aws-foundations"] = 1;
228264
}
229265

230-
$('#subscription-price').text(total.toLocaleString());
231-
$('#subscription-subtotal').text(subtotal.toLocaleString());
266+
const params = {
267+
theme: "modern",
268+
add_on_code: Object.keys(addOns).toString(),
269+
add_on_quantity: Object.values(addOns).toString(),
270+
};
232271

233-
_deferCheckout(checkoutOptions.subscription_type,
234-
checkoutOptions.pro_support,
235-
checkoutOptions.setup_deployment,
236-
checkoutOptions.setup_compliance);
237-
}
272+
sep = "";
273+
for (const key in params) {
274+
href += sep + key + "=" + params[key];
275+
sep = "&";
276+
}
238277

239-
// Prevents spamming Chargebee registerAgain on every change
240-
function _deferCheckout(type, support, setup, compliance) {
241-
var cbInstance;
242-
if (typeof timeout !== 'undefined') clearTimeout(timeout);
243-
$checkout.attr('disabled', true).text('Please wait...');
244-
245-
timeout = setTimeout(function () {
246-
$checkout.attr('disabled', false).text('Checkout');
247-
clearTimeout(timeout);
248-
//_updateAttrs();
249-
Chargebee.registerAgain();
250-
cbInstance = Chargebee.getInstance();
251-
252-
function htmlEncode(value) {
253-
if (value) {
254-
return jQuery('<div />').text(value).html();
255-
} else {
256-
return '';
257-
}
258-
}
259-
cbInstance.setCheckoutCallbacks(function (cart, product) {
260-
var subscriptionDetails = ("Subscription type: " + type);
261-
if (support) {
262-
subscriptionDetails += " • Professional Support";
263-
}
264-
if (setup) {
265-
subscriptionDetails += " • Reference Architecture";
266-
}
267-
if (compliance) {
268-
subscriptionDetails += " • CIS";
269-
}
270-
//console.log(subscriptionDetails);
271-
// you can define a custom callbacks based on cart object
272-
var customer = {
273-
cf_subscription_details: subscriptionDetails,
274-
cf_website_version: "v1-static"
275-
};
276-
277-
cart.setCustomer(customer);
278-
279-
return {
280-
close: function () {
281-
// Required to remove overflow set by the modal
282-
// Same as: https://lodash.com/docs/4.17.10#debounce
283-
setTimeout(function () {
284-
$body.removeAttr('style');
285-
}, 0);
286-
}
287-
}
288-
});
289-
}, 1250);
278+
$("#recurly-checkout-btn").attr("href", href);
290279
}
291280

292281
_updateCheckout();

pages/checkout/_checkout.html

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<span
1212
class="large-price visible-xs-inline large-price--mobile"
1313
style="white-space: nowrap;"
14-
><span>$</span><strong id="subscription-subtotal"></strong></span
14+
><span>$</span><strong class="monthly-total"></strong></span
1515
><span
1616
class="small text-muted visible-xs-inline"
1717
style="white-space: nowrap;"
@@ -27,7 +27,7 @@
2727
>
2828
<div class="visible-sm-block visible-md-block visible-lg-block">
2929
<span class="large-price"
30-
><span>$</span><strong id="subscription-price"></strong></span
30+
><span>$</span><strong class="monthly-total"></strong></span
3131
>&nbsp; / month
3232
<p
3333
class="text-center"
@@ -151,23 +151,19 @@ <h5 class="margin-top-none text-center no-anchor">
151151
Annual Contract. Billed monthly.
152152
</p>
153153
<div id="checkout-btn-container-beta">
154-
<p
154+
<div
155155
class="small text-white text-bold margin-top-none text-center"
156-
id="deposit-due"
157156
style="margin-bottom: 0"
158157
>
159-
Deposit Due<span class="hide-on-tiny"> Today</span>: $500
160-
</p>
158+
<div>
159+
Due<span class="hide-on-tiny"> Today</span>: $<span id="due-now">500</span>
160+
</div>
161+
<div id="due-monthly-block" class="hidden-xs text-muted">
162+
Then just $<span class="monthly-total"></span><span class="small" style="white-space: nowrap;">&nbsp;/ month</span>
163+
</div>
164+
</div>
161165
</div>
162-
<button
163-
id="checkout-btn"
164-
type="button"
165-
class="btn btn-info btn-block btn-checkout"
166-
data-cb-type="checkout"
167-
data-cb-plan-id="chargebee-subscription"
168-
>
169-
Checkout
170-
</button>
166+
<a id="recurly-checkout-btn" class="btn btn-info btn-block btn-checkout" href="https://gruntwork.recurly.com/subscribe/aws-monthly?theme=modern">Checkout</a>
171167
<p>
172168
<a
173169
id="checkout-contact-btn"

0 commit comments

Comments
 (0)