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": "550e8400-e29b-41d4-a716-446655440000",
"merchantId": "3b8c1f2a-4d5e-6f70-8192-a3b4c5d6e7f8",
"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": "11111111-2222-3333-4444-555555555555",
"paymentSource": {
"sourceType": "card",
"cardId": "7c9e6679-7425-40de-944b-e07fc1f90ae7"
},
"card": {
"brand": "Visa",
"last4": "4242"
}
},
{
"slotIndex": 1,
"amount": 5000,
"paymentMethod": {
"paymentType": "credit",
"installments": 1
},
"status": "pre_authorized",
"refundedAmount": 0,
"chargeId": "66666666-7777-8888-9999-000000000000",
"paymentSource": {
"sourceType": "token",
"tokenId": "9f8e7d6c-5b4a-3928-1706-5e4d3c2b1a09"
},
"card": {
"brand": "Mastercard",
"last4": "4444"
}
}
],
"createdAt": "2026-07-27T18:00:00Z",
"operation": {
"id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"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": "550e8400-e29b-41d4-a716-446655440000",
"merchantId": "3b8c1f2a-4d5e-6f70-8192-a3b4c5d6e7f8",
"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": "11111111-2222-3333-4444-555555555555",
"paymentSource": {
"sourceType": "card",
"cardId": "7c9e6679-7425-40de-944b-e07fc1f90ae7"
},
"card": {
"brand": "Visa",
"last4": "4242"
}
},
{
"slotIndex": 1,
"amount": 5000,
"paymentMethod": {
"paymentType": "credit",
"installments": 1
},
"status": "pre_authorized",
"refundedAmount": 0,
"chargeId": "66666666-7777-8888-9999-000000000000",
"paymentSource": {
"sourceType": "token",
"tokenId": "9f8e7d6c-5b4a-3928-1706-5e4d3c2b1a09"
},
"card": {
"brand": "Mastercard",
"last4": "4444"
}
}
],
"createdAt": "2026-07-27T18:00:00Z",
"operation": {
"id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"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?