# MD for: https://www.mercadopago.com.mx/developers/en/docs/smartapps/integrate-payment-flow.md \# Integrate payment flow The Mercado Pago SDK offers a comprehensive set of features designed to simplify and optimize the entire payment process. You will be able to configure, adapt and automate the payment flow according to the specific needs of your application. This includes actions such as managing payment methods, optimizing payment flows, handling errors and even processing approved payments. Below, see how to configure each of these features. :::AccordionComponent{title="Get payment methods"} To facilitate the integration of payment methods in your application, our SDK provides an instance of \`PaymentsMethodsTools\`. From this, using the \`getPaymentMethods\` function, it is possible to obtain a list of available payment methods, which are presented in \`PaymentMethod\`. This resource allows you to retrieve supported payment methods according to the specifications of each country. This information is essential when \[starting the payment flow\](https://www.mercadopago.com.mx/developers/en/docs/smartapps/integrate-payment-flow#editor\_2:\~:text=Start%20payment%20flow-,To,-start%20the%20payment). > NOTE > > Enabling the food voucher card (\`FEEDING\_VOUCHER\_LIST\`) as a payment method (\`paymentMethod\`) must be requested from the commercial team responsible for your integration. Below, see an example of how to access this function through the \`MPManager\` object and get the available payment methods according to the country. * [java ](#editor%5F2) * [kotlin ](#editor%5F1) kotlin java ``` MPManager.paymentMethodsTools.getPaymentMethods { response -> response .doIfSuccess { result -> // you can render the list of payment methods in a recycler view }.doIfError { exception -> // error handling } } ``` Copiar ``` /** * Checks the status of a payment using the payment reference. * @param paymentReference Reference of the payment (description entered in the field) */ public static void getPaymentStatus(String paymentReference) { PaymentStatus paymentStatus = MPManager.INSTANCE.getPaymentStatus(); paymentStatus.getPaymentStatus(paymentReference, response -> { doIfSuccess(response, result -> { Log.i("PaymentStatusManager", "Payment status: " + result); return null; }); doIfError(response, error -> { Log.e("PaymentStatusManager", "Payment status error: " + error.getMessage()); return null; }); return null; }); } ``` Copiar ::: :::AccordionComponent{title="Start payment flow"} To start the payment flow in your SmartApp with the Mercado Pago SDK, use the \`PaymentFlow\` function, available in the \`launchPaymentFlow\` class. This function allows you to manage responses through \_callbacks\_, simplifying both implementation and subsequent control. When implementing the \`PaymentFlowRequestData\` object, pay attention to the definition of the \`paymentMethod\` parameter, which may vary depending on the integration country. Use the resource to \[check available payment methods\](https://www.mercadopago.com.mx/developers/en/docs/smartapps/integrate-payment-flow#editor\_2:\~:text=Get%20payment%20methods-,To,-facilitate%20the%20integration) and configure them according to each country. > NOTE > > Enabling the food voucher card (\`FEEDING\_VOUCHER\_LIST\`) as a payment method (\`paymentMethod\`) must be requested from the commercial team responsible for your integration. See below an example of how to access this function through the \`MPManager\` object and start the payment flow. * [java ](#editor%5F4) * [kotlin ](#editor%5F3) kotlin java ``` val paymentFlow = MPManager.paymentFlow val paymentFlowRequestData = PaymentFlowRequestData( amount = 10.0, description = "test description", paymentMethod = paymentMethod, // this parameter is obtained through the getPaymentMethods method printOnTerminal = false // optional field if launching payment without printing on terminal ) paymentFlow.launchPaymentFlow( paymentFlowRequestData = paymentFlowRequestData ) { response -> response.doIfSuccess { result -> // handle success using a message }.doIfError { error -> // handle the error } } ``` Copiar ``` final PaymentFlow paymentFlow = MPManager.INSTANCE.getPaymentFlow(); final String amount = "2.0"; final String description = "Payment description"; final PaymentFlowData paymentFlowData = new PaymentFlowData( amount, description, PaymentMethod, // this parameter is obtained through the getPaymentMethods method 6, // optional field if launching payment with installments false // optional field if launching payment without printing on terminal ); final Function1, Unit> callback = (final MPResponse response) -> { if (response.getStatus() == ResponseStatus.SUCCESS) { // success handling using a message } else { // error handling } return Unit.INSTANCE; }; paymentFlow.launchPaymentFlow(paymentFlowData, callback); ``` Copiar | Parameter | Type | Description | Required | |---|---|---|---| | \`amount\` | \_String\_ | Payment amount. | Yes | | \`description\` | \_String\_ | Payment flow description. This field must contain unique information per transaction because it will be used as a basis to query the payment status. | Yes | | \`paymentMethod\` | \_String\_ | The payment method to use. The possible values can be retrieved from the \`getPaymentMethods\` method, available in \[Get payment methods\](https://www.mercadopago.com.mx/developers/en/docs/smartapps/integrate-payment-flow#bookmark\_get\_payment\_methods). | No | | \`printOnTerminal\` | \_Boolean\_ | \_Flag\_ for automatic printing of payment receipt on terminal (default: \`true\`). | No | subcomerciante recebedor do pagamento, como o seu nome, ID, endereço comercial, razão social, telefone, etc. | No | | \`paymentTransactionMetadata\` | \_Object\_ | Additional metadata for the payment transaction. It allows adding tracking information, external references, cart data, tips, and custom post-payment URLs. | No | | \`paymentTransactionMetadata.external\_reference\` | \_String\_ | External reference associated with the transaction. Allows the integrator to associate their own ID or reference to the transaction to facilitate reconciliation with their systems. This field must have a maximum of 64 characters and must contain only numbers, letters, hyphens (-), and underscores (\_). Special characters (\[ \], (), '', @, etc.) and spaces are not allowed. | No | In case of success, the response will look like the example below. \`\`\`kotlin paymentFlow.launchPaymentFlow( paymentFlowRequestData = paymentFlowRequestData ) { response -> response.doIfSuccess { result -> // result is a PaymentResponse object with the following information: println("Payment reference: ${result.paymentReference}") println("Payment method: ${result.paymentMethod}") println("Amount: ${result.paymentAmount}") println("Creation date: ${result.paymentCreationDate}") println("Last four digits: ${result.paymentLastFourDigits}") println("Device: ${result.paymentSnDevice}") println("User: ${result.paymentBrandName}") println("Tip amount: ${result.tipAmount}") println("External reference: ${result.externalReference}") }.doIfError { error -> // error contains the error message println("Error: ${error.message}") } } \`\`\` | Parameter | Type | Description | |---|---|---| | \`paymentReference\` | \_String\_ | Number that serves as the unique identifier of the transaction. | | \`paymentMethod\` | \_PaymentMethod\_ | Payment method used to process the payment (e.g.: CREDIT\_CARD, DEBIT\_CARD, etc.). | | \`paymentAmount\` | \_Number\_ | Amount of the processed payment. | | \`paymentCreationDate\` | \_String\_ | Date when the transaction was created. | | \`paymentLastFourDigits\` | \_String\_ | Last 4 digits of the card used by the customer for payment. | | \`paymentSnDevice\` | \_String\_ | Serial number of the device that processed the transaction. | | \`paymentBrandName\` | \_String\_ | Name of the user registered on the Point Smart terminal. | | \`tipAmount\` | \_String\_ | Tip amount charged in the payment. | | \`externalReference\` | \_String\_ | External reference of the payment. | | \`paymentStatusError\` | \_String\_ | Field for recording transaction problems and errors. Empty if the payment was successful. | ::: :::AccordionComponent{title="Get payment status"} Our SDK presents a method to query the status of an approved payment at the end of the flow on the payment completion screen. The query is performed based on the payment description. Therefore, this field must contain unique information per transaction. If multiple payments use the same description, the system will update the status based on the most recent payment and will only show the data of the last associated record. ### Implement status query With the \`getPaymentStatus\` method, which receives as a parameter the description (\`description\`) corresponding to the payment, a query is executed in our database and an object of type \`PaymentResponse\` is returned with all the information related to the approved payment. The \`parseResponse\` function, available in \`PaymentFlow\`, allows you to analyze the responses of each transaction. By converting the URI data into a \`PaymentResponse\` object, you can access information such as the payment reference, the method used and possible associated errors. Below, see an example of how to implement this resource. * [java ](#editor%5F6) * [kotlin ](#editor%5F5) kotlin java ``` // We initialize the payment status through MPManager private val paymentStatus = MPManager.paymentStatus // This is the result of what is written in the description field private val paymentReference = "" paymentStatus.getPaymentStatus(paymentReference) { response -> response.doIfSuccess { // handling success case of PaymentResponse object result }.doIfError { // Handling error case } } ``` Copiar ``` // We initialize the payment status through MPManager PaymentStatus paymentStatus = MPManager.getPaymentStatus(); // This is the result of what is written in the description field String paymentReference = ""; paymentStatus.getPaymentStatus(paymentReference, new PaymentStatusCallback() { @Override public void onSuccess(PaymentResponse result) { // Handling success case of PaymentResponse object result } @Override public void onError(Throwable error) { // Handling error case } }); ``` Copiar If successful, the response will be similar to the example below. \`\`\`kotlin // We initialize the payment status through MPManager private val paymentStatus = MPManager.paymentStatus // This is the value from the description field used to fetch the status private val paymentReference = "12345678" paymentStatus.getPaymentStatus(paymentReference) { response -> response.doIfSuccess { result -> // result is an ApprovedPaymentData object with the following information: println("Payment ID: ${result.paymentId}") println("Payment type: ${result.type}") println("Amount: ${result.amount}") println("Creation date: ${result.creationDate}") println("Terminal serial number: ${result.snDevice}") println("Status: ${result.status}") println("Brand name: ${result.brandName}") println("Last four digits: ${result.lastFourDigits}") println("External reference: ${result.externalReference}") println("Description: ${result.description}") println("Tip: ${result.tip}") }.doIfError { error -> // Handle error case println("Error: ${error.message}") } } \`\`\` | Parameter | Type | Description | |---|---|---| | \`paymentId\` | \_String\_ | Payment ID. | | \`type\` | \_String\_ | Payment type. | | \`amount\` | \_Number\_ | Amount of the successful payment. | | \`creationDate\` | \_String\_ | Payment creation date. | | \`snDevice\` | \_String\_ | Serial number of the Point Smart terminal that processed the transaction. | | \`status\` | \_String\_ | Payment status. | | \`brandName\` | \_String\_ | Name of the user registered on the Point Smart terminal. | | \`lastFourDigits\` | \_String\_ | Last 4 digits of the customer's card used for the payment. | | \`externalReference\` | \_String\_ | External reference of the payment. | | \`description\` | \_String\_ | Transaction description. | | \`tip\` | \_String\_ | Tip amount charged in the payment. | | \`paymentStatusError\` | \_String\_ | Field for recording transaction issues and errors. Empty if the payment was successful. | :::