Capturar uma Venda pré-autorizada
curl --request POST \
--url https://api.malga.io/v1/purchases/{id}/capture \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--header 'X-Client-Id: <api-key>' \
--header 'X-Idempotency-Key: <x-idempotency-key>' \
--data '{}'const options = {
method: 'POST',
headers: {
'X-Idempotency-Key': '<x-idempotency-key>',
'X-Client-Id': '<api-key>',
'X-Api-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({})
};
fetch('https://api.malga.io/v1/purchases/{id}/capture', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.malga.io/v1/purchases/{id}/capture"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Idempotency-Key", "<x-idempotency-key>")
req.Header.Add("X-Client-Id", "<api-key>")
req.Header.Add("X-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "1c6381d1-9fcd-4e9a-a012-93cf0457dcb9",
"merchantId": "6d5b0464-090b-480b-a4e9-e1a0fb60a495",
"amount": 15000,
"currency": "BRL",
"capture": false,
"status": "pending",
"updatedAt": "2026-07-27T18:05:00Z",
"payments": [
{
"slotIndex": 0,
"amount": 10000,
"paymentMethod": {
"paymentType": "credit",
"installments": 1
},
"status": "pre_authorized",
"refundedAmount": 0,
"chargeId": "b1204633-999d-4cb2-9546-f9b3108b23df",
"paymentSource": {
"sourceType": "card",
"cardId": "3fd63170-ffa4-4b33-9d45-c3ab8fe6ce61"
},
"card": {
"brand": "Visa",
"last4": "4242"
}
},
{
"slotIndex": 1,
"amount": 5000,
"paymentMethod": {
"paymentType": "credit",
"installments": 1
},
"status": "pre_authorized",
"refundedAmount": 0,
"chargeId": "13cf9d05-e0d7-4927-ae24-f967258c210a",
"paymentSource": {
"sourceType": "token",
"tokenId": "c9783dec-0900-401c-8946-58e1b626f85a"
},
"card": {
"brand": "Mastercard",
"last4": "4444"
}
}
],
"createdAt": "2026-07-27T18:00:00Z",
"operation": {
"id": "0bb96a26-fc53-405c-8e3a-21762913f1a0",
"type": "capture",
"status": "pending"
}
}Purchases
Capturar uma Venda pré-autorizada
Captura os cartões pre_authorized de uma Venda criada com capture: false e responde 202 com operation.type: capture. O corpo da requisição é opcional e, quando enviado, deve ser {}: qualquer campo extra devolve 400.
Se a Venda estiver em estado misto (cartões authorized e pre_authorized), a captura atua somente nos cartões restantes e responde 202.
Envie o header X-Idempotency-Key; sem ele a API devolve 422 com invalid_request. Reenviar a mesma chave com o mesmo corpo devolve 202 com o estado atual da Venda.
Casos de 409:
idempotency_key_payload_mismatch: a chave já foi usada com outro corpo ou em outra operação.purchase_invalid_state: a Venda foi criada comcapture: true(a captura é automática), não estápendingou não tem cartõespre_authorized.purchase_operation_in_progress: já existe uma operação em andamento e você enviou uma chave nova.
POST
/
v1
/
purchases
/
{id}
/
capture
Capturar uma Venda pré-autorizada
curl --request POST \
--url https://api.malga.io/v1/purchases/{id}/capture \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--header 'X-Client-Id: <api-key>' \
--header 'X-Idempotency-Key: <x-idempotency-key>' \
--data '{}'const options = {
method: 'POST',
headers: {
'X-Idempotency-Key': '<x-idempotency-key>',
'X-Client-Id': '<api-key>',
'X-Api-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({})
};
fetch('https://api.malga.io/v1/purchases/{id}/capture', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.malga.io/v1/purchases/{id}/capture"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Idempotency-Key", "<x-idempotency-key>")
req.Header.Add("X-Client-Id", "<api-key>")
req.Header.Add("X-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "1c6381d1-9fcd-4e9a-a012-93cf0457dcb9",
"merchantId": "6d5b0464-090b-480b-a4e9-e1a0fb60a495",
"amount": 15000,
"currency": "BRL",
"capture": false,
"status": "pending",
"updatedAt": "2026-07-27T18:05:00Z",
"payments": [
{
"slotIndex": 0,
"amount": 10000,
"paymentMethod": {
"paymentType": "credit",
"installments": 1
},
"status": "pre_authorized",
"refundedAmount": 0,
"chargeId": "b1204633-999d-4cb2-9546-f9b3108b23df",
"paymentSource": {
"sourceType": "card",
"cardId": "3fd63170-ffa4-4b33-9d45-c3ab8fe6ce61"
},
"card": {
"brand": "Visa",
"last4": "4242"
}
},
{
"slotIndex": 1,
"amount": 5000,
"paymentMethod": {
"paymentType": "credit",
"installments": 1
},
"status": "pre_authorized",
"refundedAmount": 0,
"chargeId": "13cf9d05-e0d7-4927-ae24-f967258c210a",
"paymentSource": {
"sourceType": "token",
"tokenId": "c9783dec-0900-401c-8946-58e1b626f85a"
},
"card": {
"brand": "Mastercard",
"last4": "4444"
}
}
],
"createdAt": "2026-07-27T18:00:00Z",
"operation": {
"id": "0bb96a26-fc53-405c-8e3a-21762913f1a0",
"type": "capture",
"status": "pending"
}
}Headers
Body
application/json
Corpo vazio
Response
Captura aceita. A resposta traz a Venda e operation com type: capture e status: pending. Numa repetição idempotente, a operação pode já estar processing
Venda paga com 2 ou 3 cartões
Was this page helpful?