1.0.18 • Published 2 years ago

@rethred/mercadopago-sdk v1.0.18

Weekly downloads
-
License
ISC
Repository
github
Last release
2 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

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago