fix a few silly issues. Appears to work now

This commit is contained in:
Shane Kilkelly 2016-06-27 10:38:10 +01:00
parent 72c73809f6
commit 9938787e4a
3 changed files with 8 additions and 6 deletions

View file

@ -10,7 +10,7 @@ module.exports = RecurlyWrapper =
apiUrl : "https://api.recurly.com/v2"
_addressToXml: (address) ->
allowedKeys = ['address1', 'address2', 'city', 'country', 'state', 'zip', 'postal_code']
allowedKeys = ['address1', 'address2', 'city', 'country', 'state', 'zip']
resultString = "<billing_info>\n"
for k, v of address
if v and (k in allowedKeys)
@ -27,13 +27,13 @@ module.exports = RecurlyWrapper =
url: "accounts/#{user._id}"
method: "GET"
}, (error, response, responseBody) ->
result = {userExists: true}
if error
if response.statusCode == 404 # actually not an error in this case, just no existing account
result.userExists = false
return next(null, result)
logger.error {error, user_id: user._id, recurly_token_id}, "error response from recurly while checking account"
return next(error)
result = {userExists: true}
if response.statusCode == 404
result.userExists = false
return next(null, result)
logger.log {user_id: user._id, recurly_token_id}, "user appears to exist in recurly"
RecurlyWrapper._parseAccountXml responseBody, (err, account) ->
if err

View file

@ -121,7 +121,7 @@ define [
address2: $scope.data.address2
country: $scope.data.country
state: $scope.data.state
postal_code: $scope.date.postal_code
postal_code: $scope.data.postal_code
zip: $scope.data.zip
$http.post("/user/subscription/create", postData)
.success (data, status, headers)->

View file

@ -338,6 +338,7 @@ describe "RecurlyWrapper", ->
country: "some_country"
state: "some_state"
zip: "some_zip"
postal_code: "some_postal_code"
nonsenseKey: "rubbish"
it 'should generate the correct xml', () ->
@ -351,6 +352,7 @@ describe "RecurlyWrapper", ->
<country>some_country</country>
<state>some_state</state>
<zip>some_zip</zip>
<postal_code>some_postal_code</postal_code>
</billing_info>\n
"""
)