larafale / mangopay

Mango API Wrapper
22 stars 19 forks source link

Address field error #68

Closed masterofdaemon closed 8 years ago

masterofdaemon commented 8 years ago

When i creating natural user without address all is fine but if i add it, i get error, here is data:

var res = {
            Address:{
                AddressLine1: e.target.address.value,
                AddressLine2: e.target.address2.value,
                City: e.target.city.value,
                Country: e.target.country.value,
                PostalCode: e.target.zip.value
        }};
        res.Birthday = Math.round(+new Date(e.target.age.value)/1000);
        res.Email = e.target.email.value;
        res.Tag = e.target.tag.value;
        res.FirstName = e.target.firstname.value;
        res.LastName = e.target.lastname.value;

        res.Nationality = e.target.nationality.value;
        res.CountryOfResidence = e.target.residence.value;

error:

{ '0': [Error: Address: Error reading string. Unexpected token: StartObject. Path 'Address', line 1, position 12.] }

godspeedelbow commented 8 years ago

Don't think that error comes from this module, but rather from Mangopay API. Did you try to reach out to Mangopay?

masterofdaemon commented 8 years ago

yes, they tell me, we not support nodejs,i can try do the other way, get transcription of this error from them

masterofdaemon commented 8 years ago

here full output(earlier it was from meteor wrapper now more info):

err { [MangoPayError: [object Object]]
  name: 'MangoPayError',
  message: 
   { Message: 'One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error.',
     Type: 'param_error',
     Id: '99b35040-1362-4f36-a3a8-5608264be095#1460123359',
     Date: 1460123360,
     errors: { Address: 'Error reading string. Unexpected token: StartObject. Path \'Address\', line 1, position 226.' } } }
user { Message: 'One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error.',
  Type: 'param_error',
  Id: '99b35040-1362-4f36-a3a8-5608264be095#1460123359',
  Date: 1460123360,
  errors: { Address: 'Error reading string. Unexpected token: StartObject. Path \'Address\', line 1, position 226.' } }
res 400
n40lab commented 8 years ago

Hi there, I think the error is shown because by default versión 2 of Mangopay API is used, and so Address should be a String and not a JSON object. If you use the 2.01 version, the Address is indeed and object and you can use what you've coded.

You can set what api version to use when declaring your mango object, in my case I've used the following:

var mango = require('mangopay')({ username: 'youruser', password: 'yourpassphrase', version: 'v2.01', production: false });

And it works fine. By the way, you can add users to mangopay but you can't delete them, so use fake info :-D

So I think it's not a bug and maybe the default API version shoud be changed to v2.01

Thanks a lot to this project's developers for this great API for NodeJS.

godspeedelbow commented 8 years ago

Hi @n40lab thanks for pitching in! @masterofdaemon does this fix your issue? If so, do you want to write a regression unit test for it for this module (so that it never breaks again)? That'd be great! If you need any directions, let me know.

@n40lab By default, it's indeed set to v2, but v2.01 has been available for a while the docs. see #69

masterofdaemon commented 8 years ago

yes, thanks.