Giter Club home page Giter Club logo

merkadopago's Introduction

๐Ÿ’ธ MerkadoPago ๐Ÿ’ธ

MerkadoPago is a Kotlin wrapper for MercadoPago's API.

๐Ÿ˜ก But there's already an official SDK!

Yes, there is.

But I didn't like how the SDK fundamentally works, example:

  • It uses a global static class for the SDK, you can't use multiple SDK clients in the same application unless if you get the access token and then set the access token for every request.
  • Some methods are named... badly. save() methods that actually block the thread and sends a request to MercadoPago to create the payment/preference/etc.

Of course, MerkadoPago isn't perfect and I created it for my own projects, but that's the reason we decided to create our own library instead of using the official SDK.

๐Ÿค” How to use?

Dependency Info

repositories {
    ...
    maven("https://repo.perfectdreams.net/")
}

dependencies {
    ...
    implementation("net.perfectdreams:merkadopago:1.0.0")
}

Creating a MercadoPago API instance

With the client ID + client secret

val mercadoPago = MercadoPago(
	clientId = yourClientIdHere,
	clientSecret = yourClientSecretHere
)

With an access token

val mercadoPago = MercadoPago(
	accessToken = yourAccessTokenHere
)

Creating a Payment

val settings = paymentSettings {
	item {
		title = "Loritta's Plushie"
		quantity = 1
		currencyId = "BRL"
        
        unitPrice = 10f

		if (userEmail != null) {
			payer {
				email = userEmail
			}
		}
    }

	externalReference = "MY-EXTERNAL-REFERENCE-HERE"

	notificationUrl = "https://my.website.com/api/v1/callbacks/mercadopago"
}

val payment = mercadoPago.createPayment(settings)

println("Your payment URL: ${payment.initPoint}")
println("Your sandboxed payment URL: ${payment.sandboxInitPoint}")

Getting a payment

val payment = mercadoPago.getPaymentInfoById(12345L)

merkadopago's People

Contributors

mrpowergamerbr avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.