MerkadoPago is a Kotlin wrapper for MercadoPago's API.
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.
repositories {
...
maven("https://repo.perfectdreams.net/")
}
dependencies {
...
implementation("net.perfectdreams:merkadopago:1.0.0")
}
val mercadoPago = MercadoPago(
clientId = yourClientIdHere,
clientSecret = yourClientSecretHere
)
val mercadoPago = MercadoPago(
accessToken = yourAccessTokenHere
)
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}")
val payment = mercadoPago.getPaymentInfoById(12345L)