1.0.18 • Published 3 years ago

@rethred/mercadopago-sdk v1.0.18

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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.

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago