2014-10-13 12:28:00 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App)->
|
|
|
|
|
2014-12-18 13:59:29 -05:00
|
|
|
App.controller "NewSubscriptionController", ($scope, MultiCurrencyPricing, abTestManager, $http)->
|
2014-12-22 07:55:29 -05:00
|
|
|
throw new Error("Recurly API Library Missing.") if typeof recurly is "undefined"
|
2014-10-13 12:28:00 -04:00
|
|
|
|
|
|
|
$scope.currencyCode = MultiCurrencyPricing.currencyCode
|
|
|
|
$scope.plans = MultiCurrencyPricing.plans
|
|
|
|
|
|
|
|
$scope.changeCurrency = (newCurrency)->
|
2014-12-22 07:55:29 -05:00
|
|
|
$scope.currencyCode = newCurrency
|
|
|
|
updatePlan()
|
2014-11-24 11:21:03 -05:00
|
|
|
|
|
|
|
$scope.switchToStudent = ()->
|
2014-12-18 12:48:23 -05:00
|
|
|
window.location = "/user/subscription/new?planCode=student¤cy=#{$scope.currencyCode}"
|
|
|
|
|
|
|
|
__api_key = recurlyCreds.apiKey
|
|
|
|
configured = false
|
|
|
|
$scope.error = false
|
|
|
|
$scope.token = false
|
|
|
|
$scope.data =
|
2014-12-18 13:59:29 -05:00
|
|
|
number: "4111111111111111"
|
|
|
|
month: "02"
|
|
|
|
year: "2015"
|
|
|
|
cvv: "111"
|
|
|
|
first_name: "h"
|
|
|
|
last_name: "o"
|
|
|
|
postal_code: "se153tt"
|
|
|
|
address1 : "7 somewhere"
|
|
|
|
city:"london"
|
2014-12-19 06:17:35 -05:00
|
|
|
country:"GB"
|
2014-12-22 07:55:29 -05:00
|
|
|
recurly.configure __api_key
|
|
|
|
pricing = recurly.Pricing()
|
|
|
|
#pricing.attach(document.querySelector('#pricing'))
|
|
|
|
window.pricing = pricing
|
2014-12-18 13:59:29 -05:00
|
|
|
|
2014-12-22 07:55:29 -05:00
|
|
|
$scope.planName = "no yet set"
|
|
|
|
|
|
|
|
updatePlan = ->
|
|
|
|
pricing.plan(window.plan_code, { quantity: 1 }).currency($scope.currencyCode).done()
|
2014-12-18 13:59:29 -05:00
|
|
|
|
2014-12-22 07:55:29 -05:00
|
|
|
updatePlan()
|
|
|
|
|
|
|
|
|
|
|
|
pricing.on "change", =>
|
|
|
|
$scope.planName = pricing.items.plan.name
|
|
|
|
$scope.price = pricing.price.currency.symbol+pricing.price.next.total
|
|
|
|
$scope.trialLength = pricing.items.plan.trial.length
|
|
|
|
$scope.billingCycleType = if pricing.items.plan.period.interval == "months" then "month" else "year"
|
|
|
|
$scope.$apply()
|
2014-12-18 12:48:23 -05:00
|
|
|
|
|
|
|
$scope.submit = ->
|
|
|
|
$scope.error = ""
|
2014-12-18 13:59:29 -05:00
|
|
|
recurly.token $scope.data, (err, recurly_token_id) ->
|
2014-12-18 12:48:23 -05:00
|
|
|
if err
|
|
|
|
$scope.error = err.message
|
|
|
|
else
|
2014-12-19 06:17:35 -05:00
|
|
|
postData =
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
recurly_token_id:recurly_token_id.id
|
|
|
|
subscriptionDetails:
|
|
|
|
currencyCode:"USD"
|
|
|
|
plan_code:"student"
|
|
|
|
$http.post("/user/subscription/create", postData)
|
2014-12-18 13:59:29 -05:00
|
|
|
.success ->
|
|
|
|
console.log "success"
|
|
|
|
|
2014-12-18 12:48:23 -05:00
|
|
|
|