@rethred/mercadopago-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.18 • Public • Published

reth-mercadopago-sdk

This library offers developers an uncomplicated collection of connectors to facilitate the seamless integration of the Mercado Pago API into a website, enabling the initiation of payment transactions.

📲 Installation

  1. Install NodeJS SDK for MercadoPago running in command line:
$ npm i @rethred/mercadopago-sdk

🌟 Getting Started

Simple usage looks like:

const mercadoPago = MercadoPago.createInstance({
    accessToken: process.env.MERCADOPAGO_ACCESS_TOKEN!
})
if(mercadoPago.isFailure()) return mercadoPago.value

const payment = await mercadoPago.value.payment.create({
    transaction_amount: 10,
    installments: 1,
    payer: {
        email: "client_mail@gmail.com"
    },
    payment_method_id: "pix"
})

if(payment.isFailure()) return payment.value
return payment.value

✨ Logic

Each operation will yield one of two outcomes: a MercadoPagoError in the event of an error, or the desired value in case of a successful operation.

You can check if the operation was successfull or not by calling the methods:

const payment = await mercadoPago.value.payment.create()
if(payment.isFailure()) console.log("operation failed")
if(payment.isSuccess()) console.log("operation succeeded")

Definition of MercadoPagoError:

class MercadoPagoError {
  message: string;
  aditionalInfo: any;
  status: number;
  code: number | string
}

response if successfull:

const response =  {
  id: string
  payment_method_id: string
  // ...
}

Keep in mind the responses are not typed, so you will have to look at the documentation to consult what each operation will return.

Readme

Keywords

none

Package Sidebar

Install

npm i @rethred/mercadopago-sdk

Weekly Downloads

1

Version

1.0.18

License

ISC

Unpacked Size

134 kB

Total Files

130

Last publish

Collaborators

  • rethred