Test the integration
The testing process allows you to verify that the configurations made during your integration work correctly before receiving real payments. With Wallet Connect, the test reproduces the complete flow: creating the agreement, the buyer approval, generating the payment token and processing a payment through the Orders API.
Before starting, make sure the items below are available.
| Prerequisite | Description |
| Test accounts | You must have two distinct test accounts, and both are required: a seller account, to configure the application and perform the charges, and a buyer account, to approve the agreement and simulate the purchase. |
| Balance in the buyer's account | The buyer's test account must have sufficient balance, as the payment is debited directly from the wallet. Set the amount when creating the test account. |
| Test credentials | The seller's test Access Token is provided by the team responsible for your integration and can also be found in the Credentials section. |
In this stage, you will validate whether your application is able to generate authorization links.
To do this, send a request to the endpoint /v2/wallet_connect/agreementsPOST, including the test Access TokenPrivate key used in the backend to authenticate requests. In Wallet Connect, the test and production Access Tokens and Public Keys are provided by the team responsible for creating your application. You can also view them in Your integrations > Integration data > Tests > Test credentials. The test Access Token starts with the prefix `APP_USR`. of the seller's test account.
curlcurl -X POST \ 'https://api.mercadopago.com/v2/wallet_connect/agreements' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer {{YOUR_ACCESS_TOKEN}}' \ -d '{ "return_uri": "https://www.mercadopago.com/", "external_flow_id": "test_flow_001", "external_user": { "id": "test_user_001", "description": "Test user" }, "agreement_data": { "validation_amount": 10.00, "description": "Agreement test" } }'
If the request is successful, the response will return status 201 with the identifier of the created agreement and the authorization URI to be used in the next stage.
json{ "agreement_id": "22abcd1235ed497f945f755fcaba3c6c", "agreement_uri": "{{wc_agreement_uri_example}}" }
In this stage, you must validate the authorization experience from the buyer's point of view.
Access the agreement_uri returned in the previous stage using the test buyer account and complete the authorization flow. When finished, you will be redirected to the return_uri provided at creation, with the operation result in the query parameters.
Log in with the User and Password shown in Your integrations > Your application > Tests > Test accounts. If email verification is requested, enter the Verification code available for that account on the same page.
{return_uri}?agreement_id={agreement_id}&code={code}&flow=agreement&external_flow_id={external_flow_id}&code_type=validation_code
Save the value of the code parameter, as it will be used in the next stage to generate the payment token.
code has limited validity and can be used only once. If the window expires, you will need to create a new test agreement and repeat the approval.In this stage, you will validate the exchange of the authorization code for the credential that allows executing charges.
To do this, send a request to the endpoint /v2/wallet_connect/agreements/{agreement_id}/payer_tokenPOST, providing the agreement_id obtained in the first stage and the code obtained in the approval.
curlcurl -X POST \ 'https://api.mercadopago.com/v2/wallet_connect/agreements/{{AGREEMENT_ID}}/payer_token' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer {{YOUR_ACCESS_TOKEN}}' \ -d '{ "code": "{{AUTHORIZATION_CODE}}" }'
If the request is successful, the response will return status 201 with the payer_token associated with the test agreement.
json{ "payer_token": "abcdef1e23f4567d8e9123eb6591ff68df74c57930551ed980239f4538a7e530" }
In this stage, you validate the charge end to end, debiting the amount from the wallet of the buyer's test account.
To do this, send a request to the endpoint /v1/ordersPOST, using the payer_token obtained in the previous stage.
curlcurl -X POST \ 'https://api.mercadopago.com/v1/orders' \ -H 'Content-Type: application/json' \ -H 'X-Idempotency-Key: 0d5020ed-1af6-469c-ae06-c3bec19954bb' \ -H 'Authorization: Bearer {{YOUR_ACCESS_TOKEN}}' \ -d '{ "type": "online", "external_reference": "test_order_001", "total_amount": "10.00", "description": "Test order", "capture_mode": "automatic", "transactions": { "payments": [ { "amount": "10.00", "payment_method": { "type": "wallet", "id": "wallet", "token": "{{PAYER_TOKEN}}", "statement_descriptor": "Test" } } ] } }'
If the request is successful, the response will return status 201 with the processed order. Check that the status and status_detail fields returned processed and accredited respectively, which confirms that the amount was debited from the test buyer's wallet.
json{ "id": "ORDBTA01KJZ06DEJX3DMY26FAB44BXNN", "type": "online", "external_reference": "test_order_001", "total_amount": "10.00", "total_paid_amount": "10.00", "status": "processed", "status_detail": "accredited", "transactions": { "payments": [ { "id": "PAY01KJZ06DEJX3DMXXXXXXXXXXXX", "amount": "10.00", "paid_amount": "10.00", "status": "processed", "status_detail": "accredited" } ] } }
insufficient_amount, check whether the buyer's test account has sufficient balance. For the other error scenarios, see the Possible errors section.After validating the correct functioning of the integration in the test environment, replace the test credentials with the production ones and move on to go to production.