jalik / meteor-jalik-mangopay

MangoPay REST SDK for Meteor [DEPRECATED]
MIT License
2 stars 4 forks source link

MangoPay REST SDK

This package is not official, it's a personal work but you can use it freely.

This project is deprecated since the official SDK for NodeJS has been released by MangoPay, please use the official MangoPay NodeJS SDK to have the latest features and security fixes.

Installation

To install the package, execute this command in the root of your project :

meteor add jalik:mangopay

If later you want to remove the package :

meteor remove jalik:mangopay

Authentication

Basic authentication

Execute once the code below using your own credentials and before any call to the API.

// Define which environment to use (sandbox or live)
MangoPaySDK.production = true;

// Define which version of the API to use
MangoPaySDK.apiVersion = 'v2';

// Define your credentials
MangoPaySDK.authenticate(clientId, clientPass);

Users

Create a natural user

MangoPaySDK.user.create(new MangoPaySDK.user.NaturalUser({
    Birthday: timestamp,
    Nationality: 'FR',
    CountryOfResidence: 'FR',
    Email: 'buyer@gmail.com',
    FirstName: 'Big',
    LastName: 'Buyer'
}), function (err, user) {
    if (err || !user) {
        console.error(err);
    } else {
        console.log(user);
    }
});

Create a legal user

MangoPaySDK.user.create(new MangoPaySDK.user.LegalUser({
    Email: 'seller@gmail.com',
    Name: 'Seller',
    LegalPersonType: MangoPaySDK.user.personTypes.BUSINESS,
    LegalRepresentativeFirstName: 'Big',
    LegalRepresentativeLastName: 'Seller',
    LegalRepresentativeBirthday: timestamp,
    LegalRepresentativeNationality: 'FR',
    LegalRepresentativeCountryOfResidence: 'FR'
}), function (err, user) {
    if (err || !user) {
        console.error(err);
    } else {
        console.log(user);
    }
});

Update a user

MangoPaySDK.user.update(userId, {
    Email: 'newmail@gmail.com'
}, function (err, user) {
    if (err || !user) {
      console.error(err);
    } else {
      console.log(user);
    }
});

Fetch a user

MangoPaySDK.user.fetch(userId, function (err, user) {
    if (err || !user) {
        console.error(err);
    } else {
        console.log(user);
    }
});

List all users

MangoPaySDK.user.list(params, function (err, list) {
    if (err || !list) {
        console.error(err);
    } else {
        console.log(list);
    }
});

List bank accounts of a user

MangoPaySDK.user.bankAccounts(userId, params, function (err, list) {
    if (err || !list) {
      console.error(err);
    } else {
      console.log(list);
    }
});

List cards of a user

MangoPaySDK.user.cards(userId, params, function (err, list) {
    if (err || !list) {
      console.error(err);
    } else {
      console.log(list);
    }
});

List KYC documents of a user

MangoPaySDK.user.documents(userId, params, function (err, list) {
    if (err || !list) {
      console.error(err);
    } else {
      console.log(list);
    }
});

List transactions of a user

MangoPaySDK.user.transactions(userId, params, function (err, list) {
    if (err || !list) {
      console.error(err);
    } else {
      console.log(list);
    }
});

List wallets of a user

MangoPaySDK.user.wallets(userId, params, function (err, list) {
    if (err || !list) {
      console.error(err);
    } else {
      console.log(list);
    }
});

Wallets

Create a wallet

MangoPaySDK.wallet.create(new MangoPaySDK.wallet.Wallet({
    Owners: [userId],
    Currency: 'EUR',
    Description: 'Buyer\'s wallet'
}), function (err, wallet) {
    if (err || !wallet) {
       console.error(err);
    } else {
       console.log(wallet);
    }
});

Update a wallet

MangoPaySDK.wallet.update(walletId, {
    Description: 'Seller\'s wallet'
}, function (err, wallet) {
    if (err || !wallet) {
       console.error(err);
    } else {
       console.log(wallet);
    }
});

Fetch a wallet

MangoPaySDK.wallet.fetch(walletId, function (err, wallet) {
    if (err || !wallet) {
       console.error(err);
    } else {
       console.log(wallet);
    }
});

List transactions of a wallet

MangoPaySDK.wallet.transactions(params, function (err, list) {
    if (err || !list) {
        console.error(err);
    } else {
        console.log(list);
    }
});

Transfers

Create a transfer

MangoPaySDK.transfer.create(new MangoPaySDK.transfer.Transfer({
    AuthorId: authorId,
    DebitedWalletID: fromWalletId,
    CreditedWalletID: toWalletId,
    DebitedFunds: {Currency: "EUR", Amount: 50},
    Fees: {Currency: "EUR", Amount: 10}
}), function (err, transfer) {
    if (err || !transfer) {
       console.error(err);
    } else {
       console.log(transfer);
    }
});

Cards

Create a card

MangoPaySDK.card.create(new MangoPaySDK.card.Card({
    Currency: 'EUR',
    CardType: MangoPaySDK.card.type.VISA_MASTERCARD,
    UserId: userId,
    CardNumber: 3569990000000140,
    CardExpirationDate: 1016,
    CardCvx: 123
}), function (err, cardRegistration) {
    if (err || !cardRegistration || cardRegistration.Status !== MangoPaySDK.cardRegistraton.status.VALIDATED) {
        console.error(err);
    } else {
        console.log(cardRegistration.CardId);
    }
});

Update a card

MangoPaySDK.card.update(cardId, {
    Active: false
}, function (err, card) {
    if (err || !card) {
        console.error(err);
    } else {
        console.log(card);
    }
});

Fetch a card

MangoPaySDK.card.fetch(cardId, function (err, card) {
    if (err || !card) {
        console.error(err);
    } else {
        console.log(card);
    }
});

Events

List all events

MangoPaySDK.event.list(params, function (err, list) {
    if (err || !list) {
        console.error(err);
    } else {
        console.log(list);
    }
});

Payins

Create a bank wire payin

MangoPaySDK.payin.create(new MangoPaySDK.payin.BankWire({
    AuthorId: authorId,
    CreditedWalletId: walletId,
    DeclaredDebitedFunds: {
        Currency: 'EUR',
        Amount: 5000
    },
    DeclaredFees: {
        Currency: 'EUR',
        Amount: 0
    }
}), function (err, payin) {
    if (err || !payin) {
        console.error(err);
    } else {
        console.log(payin);
    }
});

Create a direct debit payin

MangoPaySDK.payin.create(new MangoPaySDK.payin.DirectDebit({
    AuthorId: 8837505,
    CreditedWalletId: 8837797,
    ReturnUrl:'https://www.domain.com/return',
    Culture:'FR',
    DebitedFunds: {
        Currency: 'EUR',
        Amount: 5000
    },
    DeclaredFees: {
        Currency: 'EUR',
        Amount: 0
    }
}), function (err, payin) {
    if (err || !payin) {
        console.error(err);
    } else {
        console.log(payin);
    }
});

Create a pre-authorized payin

MangoPaySDK.payin.create(new MangoPaySDK.payin.PreAuthorizedAmount({
    AuthorId: authorId,
    PreauthorizationId: preAuthId,
    CreditedWalletId: walletId,
    DebitedFunds: {
        Currency: 'EUR',
        Amount: 5000
    },
    Fees: {
        Currency: 'EUR',
        Amount: 0
    }
}), function (err, payin) {
    if (err || !payin) {
        console.error(err);
    } else {
        console.log(payin);
    }
});

Create a tokenized card payin

MangoPaySDK.payin.create(new MangoPaySDK.payin.TokenizedCard({
    AuthorId: authorId,
    CardId: cardId,
    CreditedWalletId: walletId,
    SecureModeReturnURL: 'https://www.domain.com/return',
    DebitedFunds: {
        Currency: 'EUR',
        Amount: 5000
    },
    Fees: {
        Currency: 'EUR',
        Amount: 0
    }
}), function (err, payin) {
    if (err || !payin) {
        console.error(err);
    } else {
        console.log(payin);
    }
});

Create a web form payin

MangoPaySDK.payin.create(new MangoPaySDK.payin.WebForm({
    AuthorId: authorId,
    CreditedWalletId: walletId,
    ReturnUrl: 'https://www.domain.com/return',
    Culture: 'FR',
    CardType: MangoPaySDK.card.type.VISA_MASTERCARD,
    DebitedFunds: {
        Currency: 'EUR',
        Amount: 5000
    },
    Fees: {
        Currency: 'EUR',
        Amount: 1000
    }
}), function (err, payin) {
    if (err || !payin) {
        console.error(err);
    } else {
        console.log(payin);
    }
});

Payouts

Create a bank wire payout

MangoPaySDK.payout.create(new MangoPaySDK.payout.BankWire({
    AuthorId: authorId,
    BankWireRef: 'Reward',
    BankAccountId: bankAccountId,
    DebitedWalletId: walletId,
    DebitedFunds: {
        Currency: 'EUR',
        Amount: 6000
    },
    Fees: {
        Currency: 'EUR',
        Amount: 1000
    }
}), function (err, payout) {
    if (err || !payout) {
        console.error(err);
    } else {
        console.log(payout);
    }
});

Fetch a payout

MangoPaySDK.payout.fetch(payoutId, function (err, payout) {
    if (err || !payout) {
        console.error(err);
    } else {
        console.log(payout);
    }
});

Hooks

Create a hook

MangoPaySDK.hook.create(new MangoPaySDK.hook.Hook({
    Url: 'http://www.domain.com/myhook',
    EventType: MangoPaySDK.hook.eventType.PAYIN_NORMAL_CREATED
}), function (err, hook) {
    if (err || !hook) {
        console.error(err);
    } else {
        console.log(hook);
    }
});

Update a hook

MangoPaySDK.hook.update(hookId, {
    Tag: 'edited'
}, function (err, hook) {
    if (err || !hook) {
        console.error(err);
    } else {
        console.log(hook);
    }
});

Fetch a hook

MangoPaySDK.hook.fetch(hookId, function (err, hook) {
    if (err || !hook) {
        console.error(err);
    } else {
        console.log(hook);
    }
});

List all hooks

MangoPaySDK.hook.list(params, function (err, list) {
    if (err || !list) {
        console.error(err);
    } else {
        console.log(list);
    }
});

Result pagination

https://docs.mangopay.com/api-references/pagination/ You can paginate list results like below.

var params = {page: 5, per_page: 25};
MangoPaySDK.hook.list(params, function (err, list) {
    if (err || !list) {
        console.error(err);
    } else {
        console.log(list);
    }
});

Sorting and filtering results

https://docs.mangopay.com/api-references/sort-lists/ You can sort and filter list results like below.

var params = {Status: 'SUCCEEDED', Type: 'PAYIN'};
MangoPaySDK.user.transactions(userId, params, function (err, list) {
    if (err || !list) {
      console.error(err);
    } else {
      console.log(list);
    }
});