@@ -135,26 +135,32 @@ $(function () {
135
135
function _updateCheckout ( newOptions ) {
136
136
checkoutOptions = Object . assign ( { } , checkoutOptions , newOptions ) ;
137
137
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 ;
141
147
142
148
$ ( '.grunty-sprite' ) . attr ( 'data-sprite' , 0 ) ;
143
149
$ ( '#subscription_type' ) . val ( checkoutOptions . subscription_type ) ;
144
150
145
151
// 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 ) ;
149
155
150
- if ( enable_pro_support ) {
156
+ if ( support ) {
151
157
$ ( '.grunty-sprite' ) . attr ( 'data-sprite' , 2 ) ;
152
158
$ ( '#subscription-addon-1' ) . removeClass ( 'check-list-disabled' ) ;
153
159
} else {
154
160
$ ( '#subscription-addon-1' ) . addClass ( 'check-list-disabled' ) ;
155
161
}
156
162
157
- if ( setup_deployment ) {
163
+ if ( refarch ) {
158
164
$ ( '.grunty-sprite' ) . attr ( 'data-sprite' , 1 ) ;
159
165
160
166
$ ( '#checkout-price-addon' ) . show ( ) ;
@@ -170,7 +176,7 @@ $(function () {
170
176
$ ( '#subscription-addon-2' ) . addClass ( 'check-list-disabled' ) ;
171
177
}
172
178
173
- if ( setup_compliance ) {
179
+ if ( compliance ) {
174
180
$ ( '#subscription-addon-3' ) . removeClass ( 'check-list-disabled' ) ;
175
181
176
182
// Update Refarch texts to reflect CIS selection
@@ -184,109 +190,92 @@ $(function () {
184
190
$ ( '#addon-text-refarch' ) . text ( 'Reference Architecture' ) ;
185
191
}
186
192
187
- if ( checkoutOptions . pro_support && checkoutOptions . setup_deployment ) {
193
+ if ( support && refarch ) {
188
194
$ ( '.grunty-sprite' ) . attr ( 'data-sprite' , 3 ) ;
189
195
}
190
-
191
- _calculatePrice ( ) ;
192
196
}
193
197
194
- function _calculatePrice ( ) {
195
- var total , subtotal , subscriptionTotal ;
198
+ function _updatePrice ( ) {
199
+ var monthlyTotal , dueNowTotal ;
196
200
197
201
switch ( checkoutOptions . subscription_type ) {
198
202
case 'aws' :
199
- total = subtotal = pricing . subscriptions . aws . price . value ;
203
+ monthlyTotal = pricing . subscriptions . aws . price . value ;
200
204
break ;
201
205
case 'gcp' :
202
- total = subtotal = pricing . subscriptions . gcp . price . value ;
206
+ monthlyTotal = pricing . subscriptions . gcp . price . value ;
203
207
break ;
204
208
default : // do nothing
205
209
}
206
210
207
211
if ( checkoutOptions . pro_support ) {
208
212
switch ( checkoutOptions . subscription_type ) {
209
213
case 'aws' :
210
- total += subtotal = pricing . subscriptions . aws . pro_support_price . value ;
214
+ monthlyTotal + = pricing . subscriptions . aws . pro_support_price . value ;
211
215
break ;
212
216
case 'gcp' :
213
- total += subtotal = pricing . subscriptions . gcp . pro_support_price . value ;
217
+ monthlyTotal + = pricing . subscriptions . gcp . pro_support_price . value ;
214
218
break ;
215
219
default : // do nothing
216
220
}
217
221
}
218
222
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
+
219
230
// Only AWS supports the Ref Arch
220
231
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 ( ) ;
223
237
}
224
238
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 ;
228
264
}
229
265
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
+ } ;
232
271
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
+ }
238
277
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 ) ;
290
279
}
291
280
292
281
_updateCheckout ( ) ;
0 commit comments