import { Provider } from 'pagamentos'
import type { Cliente, Cobranca, Checkout } from 'pagamentos'
const resources = {
clientes: {
async create(input) {
const response = await fetch('https://api.meuprovedor.com/clientes', {
method: 'POST',
headers: { Authorization: `Bearer ${apiKey}` },
body: JSON.stringify(input)
})
return response.json() as Promise<Cliente>
},
async get(id) {
const response = await fetch(
`https://api.meuprovedor.com/clientes/${id}`,
{ headers: { Authorization: `Bearer ${apiKey}` } }
)
return response.json() as Promise<Cliente>
},
async update(id, input) { /* ... */ },
async list(input) { /* ... */ },
async delete(id) { /* ... */ }
},
cobrancas: {
async create(input) {
// Implemente a criação de cobrança
},
async get(id) { /* ... */ },
async update(id, input) { /* ... */ },
async list(input) { /* ... */ },
async cancel(id) { /* ... */ }
},
checkout: {
async create(input) { /* ... */ }
},
webhooks: {
signatureHeader: 'x-meu-provedor-signature',
verifySecret(secretFromQuery, expectedSecret) {
return secretFromQuery === expectedSecret
},
async verifySignature(rawBody, signatureFromHeader, publicHmacKey) {
// Valide a assinatura do webhook
},
async decodePayload(payload) {
// Decodifique o payload do webhook para o formato do SDK
},
async verifyAndDecode({ rawBody, signatureFromHeader, publicHmacKey }) {
// Valide e decodifique em um único passo
}
}
}