# MD for: https://www.mercadopago.com.br/developers/en/docs/wallet-connect/integration-test.md \# 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. > WARNING > > The tests are performed on the \*\*production endpoints\*\* using test credentials, which means there is no separate sandbox domain. Make sure to use the :toolTipComponent\[test Access Token\]{content="Private 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 in all requests so as not to generate real charges. Before starting, make sure the items below are available. | Prerequisite | Description | |---|---| | Test accounts | You must have two distinct \[test accounts\](https://www.mercadopago.com.br/developers/en/docs/wallet-connect/resources/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\](https://www.mercadopago.com.br/developers/en/docs/wallet-connect/resources/credentials) section. | :::AccordionComponent{title="Create the test agreement" pill="1"} In this stage, you will validate whether your application is able to generate authorization links. To do this, send a request to the endpoint :TagComponent{tag="POST" text="/v2/wallet\_connect/agreements" href="/developers/en/reference/online-payments/wallet-connect/orders/create-agreement/post" color="green"}, including the :toolTipComponent\[test Access Token\]{content="Private 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. \`\`\`curl curl -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}}" } \`\`\` > NOTE > > To learn about all the parameters accepted in this request, see the \[Configure agreements\](https://www.mercadopago.com.br/developers/en/docs/wallet-connect/configure-agreements) section. ::: :::AccordionComponent{title="Approve the agreement" pill="2"} 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\](https://www.mercadopago.com.br/developers/panel/app) > \*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. > WARNING > > The \`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. ::: :::AccordionComponent{title="Generate the payment token" pill="3"} 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 :TagComponent{tag="POST" text="/v2/wallet\_connect/agreements/{agreement\_id}/payer\_token" href="/developers/en/reference/online-payments/wallet-connect/orders/generate-payer-token/post" color="green"}, providing the \`agreement\_id\` obtained in the first stage and the \`code\` obtained in the approval. \`\`\`curl curl -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" } \`\`\` ::: :::AccordionComponent{title="Process a test payment" pill="4"} 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 :TagComponent{tag="POST" text="/v1/orders" href="/developers/en/reference/online-payments/wallet-connect/orders/create-order/post" color="green"}, using the \`payer\_token\` obtained in the previous stage. \`\`\`curl curl -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" } \] } } \`\`\` > NOTE > > If the payment returns status 402 with \`insufficient\_amount\`, check whether the buyer's test account has sufficient balance. For the other error scenarios, see the \[Possible errors\](https://www.mercadopago.com.br/developers/en/docs/wallet-connect/integration-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\](https://www.mercadopago.com.br/developers/en/docs/wallet-connect/go-to-production).