1.45.3 • Published 4 days ago

mangopay2-nodejs-sdk v1.45.3

Weekly downloads
1,879
License
MIT
Repository
github
Last release
4 days ago

Mangopay Node.js SDK Build Status

MangopaySDK is a Node.js client library to work with Mangopay REST API.

Installation

Install the module via npm

npm install mangopay2-nodejs-sdk --save

Usage inside your app

var mangopay = require('mangopay2-nodejs-sdk');

var api = new mangopay({
    clientId: 'your_client_id',
    clientApiKey: 'your_client_api_key',
    // Set the right production API url. If testing, omit the property since it defaults to sandbox URL
    baseUrl: 'https://api.mangopay.com'
});

api.Users.create(...)

Supported options

OptionDefault valueDescription
clientIdnullAPI Client Id
clientApiKeynullAPI Client Api Key
baseUrl"https://api.sandbox.mangopay.com"API Base URL. The default value points to sandbox. Production is 'https://api.mangopay.com'
debugModefalseActive debugging
logClassfunction() {console.log(arguments)}Log function to be used for debug
connectionTimeout30000Set the connection timeout limit (in milliseconds)
responseTimeout80000Set the response timeout limit (in milliseconds)
apiVersion'v2.01'API Version
errorHandlerfunction(options, err) {console.error(options, err)}Set a custom error handler

Documentation

Github Full Node.js SDK Documentation is located in /docs folder. You can also access API References on our website.

License

MangopaySDK is distributed under MIT license, see the LICENSE file.

Contacts

Report bugs or suggest features using issue tracker on GitHub.

Account creation

You can get yourself a free sandbox account or sign up for a production account by registering on the Mangopay site (note that validation of your production account involves several steps, so think about doing it in advance of when you actually want to go live).

Creating a user

Using a hash of properties:

    mangopay.Users.create({
        "FirstName": "Victor",
        "LastName": "Hugo",
        "Address": "1 rue des Misérables, Paris",
        "Birthday": 1300186358,
        "Nationality": "FR",
        "CountryOfResidence": "FR",
        "Occupation": "Writer",
        "IncomeRange": "6",
        "ProofOfIdentity": null,
        "ProofOfAddress": null,
        "PersonType": "NATURAL",
        "Email": "victor@hugo.com",
        "Tag": "custom tag",
    }, function(model) {
        // User created - using callback
    }).then(function(model){
        // User created - using promise
    });

Using Mangopay SDK pre-defined models:

    var myUser = new api.models.UserLegal({
        Name: 'MangoPay',
        Email: 'info@mangopay.com',
        LegalPersonType: 'BUSINESS',
        LegalRepresentativeFirstName: 'Mango',
        LegalRepresentativeLastName: 'Pay',
        LegalRepresentativeEmail: 'mango@mangopay.com',
        HeadquartersAddress: new api.models.Address({
            AddressLine1: "4101 Reservoir Rd NW",
            AddressLine2: "",
            City: "Washington",
            Region: "District of Columbia",
            PostalCode: "20007",
            Country: "US"
        }),
        LegalRepresentativeBirthday: 1300186358,
        LegalRepresentativeNationality: 'FR',
        LegalRepresentativeCountryOfResidence: 'FR',
        CompanyNumber: 123456789,
        Tag: 'custom tag'
    });

    api.Users.create(myUser).then(function(){
        // Output the created user data to console
        console.log(myUser.Name + ' user created at ' + myUser.CreationDate);
    });

Promise vs Callback

Mangopay Node.js SDK supports both callback and promise approach. Here is how they can be implemented :

    api.Service.method(... , function(data, response, err){
        // Callback method
    })

    api.Service.method(...).then(function(data) {
        // Promise function called
    }, function(error) {
        //exception
    })

Pagination / Filtering

In order to paginate or filter results, we can use options.parameters to specify these options:

    api.Transactions.getAll({
        parameters: {
            // Pagination
            per_page: 2,
            page: 2,

            // Filters
            BeforeDate: 1414000367,
            AfterDate: 1414000367,
            Nature: REGULAR,
            Status: FAILED,
            Type: TRANSFER
        }
    }

Reading server response headers

For reading the server response headers we can use options.resolveWithFullResponse: true

    api.Users.getAll(null, {
      parameters: {
        per_page: 1
      },
      resolveWithFullResponse: true
    }).then(function(response){
      // Read pages count
      console.log(response.headers['x-number-of-pages']);

      // Read response body
      console.log(response.body);
    });

Sample usage of Mangopay SDK installed with npm in a Node.js project

Don't forget to check examples folder !

Contributing

npm start                       // installs dependencies and global mocha for testing and jsdox for documentation
npm test                        // runs the mocha tests
npm run-script documentation    // update documentation using jsdox, make sure to have it installed globally

Unit Tests

Mocha tests are placed under /test/ folder. To run the tests, make sure you have all dependencies installed. Check Contributing section for details.

1.45.3

4 days ago

1.45.2

18 days ago

1.45.1

1 month ago

1.45.0

1 month ago

1.44.0

2 months ago

1.43.1

2 months ago

1.43.0

2 months ago

1.42.1

3 months ago

1.42.0

4 months ago

1.41.1

5 months ago

1.41.0

5 months ago

1.37.0

8 months ago

1.39.0

7 months ago

1.40.0

6 months ago

1.40.1

6 months ago

1.38.0

8 months ago

1.35.1

10 months ago

1.35.0

11 months ago

1.36.0

9 months ago

1.33.1

1 year ago

1.34.0

1 year ago

1.33.0

1 year ago

1.32.0

1 year ago

1.32.1

1 year ago

1.31.1

2 years ago

1.31.0

2 years ago

1.29.0

2 years ago

1.29.1

2 years ago

1.29.2

2 years ago

1.30.0

2 years ago

1.30.1

2 years ago

1.27.0

2 years ago

1.26.1

2 years ago

1.28.0

2 years ago

1.26.0

2 years ago

1.25.0

2 years ago

1.25.1

2 years ago

1.25.2

2 years ago

1.24.1

2 years ago

1.24.0

2 years ago

1.23.0

3 years ago

1.21.0

3 years ago

1.22.0

3 years ago

1.22.1

3 years ago

1.20.2

3 years ago

1.20.1

3 years ago

1.20.0

3 years ago

1.19.0

3 years ago

1.18.0

3 years ago

1.17.0

3 years ago

1.16.0

3 years ago

1.15.0

3 years ago

1.14.5

3 years ago

1.14.4

3 years ago

1.14.3

4 years ago

1.14.2

4 years ago

1.14.1

4 years ago

1.14.0-beta

4 years ago

1.13.1

4 years ago

1.13.0

4 years ago

1.12.0

4 years ago

1.10.0

5 years ago

1.8.0

6 years ago

1.7.0

6 years ago

1.6.0

6 years ago

1.5.0

7 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.0

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago