Métodos de pagamento
Vincular um método de pagamento
Anexa um método de pagamento salvo a um customer.
curl -X POST "https://api.chargefy.io/v1/payment-methods/pm_ssD2LD5BxSJezhL2/attach" \
-H "Authorization: Bearer {{API_KEY}}" \
-H "Content-Type: application/json" \
-d '{
"customer": "cus_xdV21QgkCZYHwqmh"
}'
{
"id": "pm_ssD2LD5BxSJezhL2",
"object": "payment_method",
"billing_details": {
"address": null,
"email": "cliente@email.com",
"name": "Ana Silva",
"phone": null
},
"card": {
"brand": "visa",
"exp_month": 12,
"exp_year": 2030,
"last4": "4242"
},
"created_at": "2026-05-16T18:30:00Z",
"customer": "cus_xdV21QgkCZYHwqmh",
"livemode": true,
"metadata": {},
"type": "credit_card",
"updated_at": "2026-05-16T18:45:00Z"
}
{
"error": {
"code": "invalid_request",
"message": "Payment method belongs to a different buyer than this customer.",
"param": "customer",
"type": "invalid_request_error"
}
}
{
"error": {
"code": "authentication_failed",
"message": "Invalid API key provided.",
"type": "authentication_error"
}
}
{
"error": {
"code": "resource_missing",
"message": "Payment method not found.",
"type": "invalid_request_error"
}
}
Anexa um
payment_method salvo ao customer informado. O método precisa
pertencer ao mesmo comprador do customer.
string
required
ID do payment method (
pm_*).string
required
Customer que receberá o método como padrão.
curl -X POST "https://api.chargefy.io/v1/payment-methods/pm_ssD2LD5BxSJezhL2/attach" \
-H "Authorization: Bearer {{API_KEY}}" \
-H "Content-Type: application/json" \
-d '{
"customer": "cus_xdV21QgkCZYHwqmh"
}'
Resposta
200 OK com o objeto payment_method completo — mesmo shape de GET /v1/payment-methods/:id. O customer retorna apontando para o customer informado.
{
"id": "pm_ssD2LD5BxSJezhL2",
"object": "payment_method",
"billing_details": {
"address": null,
"email": "cliente@email.com",
"name": "Ana Silva",
"phone": null
},
"card": {
"brand": "visa",
"exp_month": 12,
"exp_year": 2030,
"last4": "4242"
},
"created_at": "2026-05-16T18:30:00Z",
"customer": "cus_xdV21QgkCZYHwqmh",
"livemode": true,
"metadata": {},
"type": "credit_card",
"updated_at": "2026-05-16T18:45:00Z"
}
{
"error": {
"code": "invalid_request",
"message": "Payment method belongs to a different buyer than this customer.",
"param": "customer",
"type": "invalid_request_error"
}
}
{
"error": {
"code": "authentication_failed",
"message": "Invalid API key provided.",
"type": "authentication_error"
}
}
{
"error": {
"code": "resource_missing",
"message": "Payment method not found.",
"type": "invalid_request_error"
}
}
⌘I
curl -X POST "https://api.chargefy.io/v1/payment-methods/pm_ssD2LD5BxSJezhL2/attach" \
-H "Authorization: Bearer {{API_KEY}}" \
-H "Content-Type: application/json" \
-d '{
"customer": "cus_xdV21QgkCZYHwqmh"
}'
{
"id": "pm_ssD2LD5BxSJezhL2",
"object": "payment_method",
"billing_details": {
"address": null,
"email": "cliente@email.com",
"name": "Ana Silva",
"phone": null
},
"card": {
"brand": "visa",
"exp_month": 12,
"exp_year": 2030,
"last4": "4242"
},
"created_at": "2026-05-16T18:30:00Z",
"customer": "cus_xdV21QgkCZYHwqmh",
"livemode": true,
"metadata": {},
"type": "credit_card",
"updated_at": "2026-05-16T18:45:00Z"
}
{
"error": {
"code": "invalid_request",
"message": "Payment method belongs to a different buyer than this customer.",
"param": "customer",
"type": "invalid_request_error"
}
}
{
"error": {
"code": "authentication_failed",
"message": "Invalid API key provided.",
"type": "authentication_error"
}
}
{
"error": {
"code": "resource_missing",
"message": "Payment method not found.",
"type": "invalid_request_error"
}
}

