Code Monkey home page Code Monkey logo

mercadopago-sdk-rust's Introduction

MercadoPago SDK

Crate version on crates.io Crate documentation on docs.rs Crate license

An open source, strongly-typed SDK for the MercadoPago API.

It will try to hold your hand and reduce the possibility of errors, providing the correct API surface.

Note

The library is still under development and its public API is subject to change.

Installation

Added the following into your Cargo.toml:

mercadopago_sdk_rust = "0.1"

Usage

The client is built using the MercadoPagoSDKBuilder::with_token with_token method.

use mercadopago_sdk_rust::{MercadoPagoSDK, MercadoPagoSDKBuilder};

let mp_sdk: MercadoPagoSDK = MercadoPagoSDKBuilder::with_token("MP_ACCESS_TOKEN");

Once the token is inserted, you can call methods on [crate::MercadoPagoSDK]

Creating a CheckoutPro Preference

use mercadopago_sdk_rust::common_types::{CheckoutProPayer, Item};
use mercadopago_sdk_rust::payments::requests::DocumentType;
use mercadopago_sdk_rust::preferences::requests::CheckoutProPreferences;
use mercadopago_sdk_rust::MercadoPagoSDKBuilder;

#[tokio::main]
async fn async_main() {
    let mp_sdk = MercadoPagoSDKBuilder::with_token("MP_ACCESS_TOKEN");

    let sample_item =
        Item::minimal_item("Sample item".to_string(), "".to_string(), 15.00, 1).unwrap();

    let preferences = CheckoutProPreferences::new()
        .set_items(vec![sample_item])
        .set_payer(CheckoutProPayer::minimal_payer(
            "[email protected]".to_string(),
            DocumentType::CPF,
            41810524485,
        ));

    mp_sdk
        .create_preferences_checkout_pro(preferences)
        .expect("Failed to validate checkout preference. Something is wrong.")
        .execute()
        .await
        .unwrap();
}

Other Examples

Check out the tests folder inside our repository to check for more examples.

License

Project is licensed under the permissive MIT license.

mercadopago-sdk-rust's People

Contributors

saskenuba avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.