mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
can add account just about into recurly
This commit is contained in:
parent
47fb2a0878
commit
cc545db17b
5 changed files with 62 additions and 24 deletions
|
@ -8,6 +8,28 @@ logger = require("logger-sharelatex")
|
|||
module.exports = RecurlyWrapper =
|
||||
apiUrl : "https://api.recurly.com/v2"
|
||||
|
||||
createSubscription: (subscription, recurly_token_id, callback)->
|
||||
requestBody = """
|
||||
<subscription>
|
||||
<plan_code>student</plan_code>
|
||||
<currency>USD</currency>
|
||||
<account>
|
||||
<account_code>TEST_SUBSCRIPTION</account_code>
|
||||
<billing_info>
|
||||
<token_id>#{recurly_token_id}</token_id>
|
||||
</billing_info>
|
||||
</account>
|
||||
</subscription>
|
||||
"""
|
||||
@apiRequest({
|
||||
url : "subscriptions"
|
||||
method : "POST"
|
||||
body : requestBody
|
||||
}, (error, response, responseBody) =>
|
||||
return callback(error) if error?
|
||||
@_parseSubscriptionXml responseBody, callback
|
||||
)
|
||||
|
||||
apiRequest : (options, callback) ->
|
||||
options.url = @apiUrl + "/" + options.url
|
||||
options.headers =
|
||||
|
@ -16,7 +38,7 @@ module.exports = RecurlyWrapper =
|
|||
"Content-Type" : "application/xml; charset=utf-8"
|
||||
request options, (error, response, body) ->
|
||||
unless error? or response.statusCode == 200 or response.statusCode == 201 or response.statusCode == 204
|
||||
logger.err err:error, options:options, "error returned from recurly"
|
||||
logger.err err:error, body:body, options:options, statusCode:response?.statusCode, "error returned from recurly"
|
||||
error = "Recurly API returned with status code: #{response.statusCode}"
|
||||
callback(error, response, body)
|
||||
|
||||
|
|
|
@ -132,9 +132,9 @@ module.exports = SubscriptionController =
|
|||
createSubscription: (req, res, next)->
|
||||
SecurityManager.getCurrentUser req, (error, user) ->
|
||||
return callback(error) if error?
|
||||
subscriptionId = req.body.recurly_token
|
||||
logger.log subscription_id: subscriptionId, user_id:user._id, "creating subscription"
|
||||
SubscriptionHandler.createSubscription user, subscriptionId, (err)->
|
||||
recurly_token_id = req.body.recurly_token_id
|
||||
logger.log recurly_token_id: recurly_token_id, user_id:user._id, "creating subscription"
|
||||
SubscriptionHandler.createSubscription user, recurly_token_id, (err)->
|
||||
if err?
|
||||
logger.err err:err, user_id:user._id, "something went wrong creating subscription"
|
||||
res.redirect "/user/subscription/thank-you"
|
||||
|
|
|
@ -10,9 +10,10 @@ DropboxHandler = require("../Dropbox/DropboxHandler")
|
|||
|
||||
module.exports =
|
||||
|
||||
createSubscription: (user, recurlySubscriptionId, callback)->
|
||||
createSubscription: (user, recurly_token_id, callback)->
|
||||
self = @
|
||||
RecurlyWrapper.getSubscription recurlySubscriptionId, {recurlyJsResult: true}, (error, recurlySubscription) ->
|
||||
clientTokenId = ""
|
||||
RecurlyWrapper.createSubscription user, recurly_token_id, (error, recurlySubscription)->
|
||||
return callback(error) if error?
|
||||
SubscriptionUpdater.syncSubscription recurlySubscription, user._id, (error) ->
|
||||
return callback(error) if error?
|
||||
|
|
|
@ -6,7 +6,7 @@ block scripts
|
|||
window.recomendedCurrency = '#{currency}'
|
||||
window.plan_code = '#{plan_code}'
|
||||
|
||||
window.recurlyCreds = { apiKey : "", apiUrl:""}
|
||||
window.recurlyCreds = { apiKey : "sc-GVdZOe7akgWbZRIFPllOx9", apiUrl:""}
|
||||
|
||||
|
||||
block content
|
||||
|
@ -34,7 +34,7 @@ block content
|
|||
ng-click="changeCurrency(currency)",
|
||||
) {{currency}} ({{value['symbol']}})
|
||||
h1 #{translate("new_subscription")}
|
||||
span {{ error }}
|
||||
|
||||
form
|
||||
.form-group
|
||||
label #{translate("credit_card_number")}
|
||||
|
@ -54,7 +54,19 @@ block content
|
|||
.form-group
|
||||
label #{translate("last_name")}
|
||||
input.form-control(type='text', value='', maxlength='255', tabindex='1', onkeyup='', data-recurly="last_name", ng-model="data.last_name")
|
||||
|
||||
.form-group
|
||||
label #{translate("address")}
|
||||
input.form-control(type='text', value='', maxlength='255', tabindex='1', onkeyup='', data-recurly="address1", ng-model="data.address1")
|
||||
.form-group
|
||||
label #{translate("city")}
|
||||
input.form-control(type='text', value='', maxlength='255', tabindex='1', onkeyup='', data-recurly="city", ng-model="data.city")
|
||||
.form-group
|
||||
label #{translate("country")}
|
||||
input.form-control(type='text', value='', maxlength='255', tabindex='1', onkeyup='', data-recurly="country", ng-model="data.country")
|
||||
.form-group
|
||||
label #{translate("country")}
|
||||
input.form-control(type='text', value='', maxlength='255', tabindex='1', onkeyup='', data-recurly="postal_code", ng-model="data.postal_code")
|
||||
|
||||
.form-group
|
||||
button.btn.btn-success(ng-click="submit()") #{translate("submit")}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ define [
|
|||
"base"
|
||||
], (App)->
|
||||
|
||||
App.controller "NewSubscriptionController", ($scope, MultiCurrencyPricing, abTestManager)->
|
||||
App.controller "NewSubscriptionController", ($scope, MultiCurrencyPricing, abTestManager, $http)->
|
||||
|
||||
$scope.currencyCode = MultiCurrencyPricing.currencyCode
|
||||
$scope.plans = MultiCurrencyPricing.plans
|
||||
|
@ -13,23 +13,23 @@ define [
|
|||
$scope.switchToStudent = ()->
|
||||
window.location = "/user/subscription/new?planCode=student¤cy=#{$scope.currencyCode}"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
__api_key = recurlyCreds.apiKey
|
||||
__api_url = recurlyCreds.apiUrl
|
||||
configured = false
|
||||
$scope.error = false
|
||||
$scope.token = false
|
||||
$scope.data =
|
||||
number: ""
|
||||
month: ""
|
||||
year: ""
|
||||
cvv: ""
|
||||
first_name: ""
|
||||
last_last: ""
|
||||
postal_code: ""
|
||||
number: "4111111111111111"
|
||||
month: "02"
|
||||
year: "2015"
|
||||
cvv: "111"
|
||||
first_name: "h"
|
||||
last_name: "o"
|
||||
postal_code: "se153tt"
|
||||
address1 : "7 somewhere"
|
||||
city:"london"
|
||||
country:"uk"
|
||||
|
||||
|
||||
|
||||
$scope.submit = ->
|
||||
throw new Error("Recurly API Library Missing.") if typeof recurly is "undefined"
|
||||
|
@ -38,9 +38,12 @@ define [
|
|||
if !configured
|
||||
recurly.configure __api_key
|
||||
configured = true
|
||||
recurly.token $scope.data, (err, token) ->
|
||||
recurly.token $scope.data, (err, recurly_token_id) ->
|
||||
if err
|
||||
$scope.error = err.message
|
||||
else
|
||||
$scope.token = token
|
||||
$http.post("/user/subscription/create", {_csrf: window.csrfToken, recurly_token_id:recurly_token_id.id})
|
||||
.success ->
|
||||
console.log "success"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue