feat: add donation support with footer card and navigation
Add donation functionality to encourage community support, including a footer card on the home page, a highlighted "Apoiar" link in the header, and comprehensive English messages for the donation section to promote transparency and user engagement.
This commit is contained in:
1 parent
b5093cb49a
commit
01e97eb078
16 files changed
+1161
-2
No files matched your search
@@ -0,0 +1,100 @@
|
||||
interface AbacatePayConfig {
|
||||
apiKey: string;
|
||||
accountId: string;
|
||||
baseUrl?: string;
|
||||
}
|
||||
|
||||
interface CreateBillingParams {
|
||||
amount: number;
|
||||
metadata?: {
|
||||
donorName?: string;
|
||||
donorEmail?: string;
|
||||
message?: string;
|
||||
};
|
||||
returnUrl?: string;
|
||||
completionUrl?: string;
|
||||
}
|
||||
|
||||
interface BillingResponse {
|
||||
id: string;
|
||||
amount: number;
|
||||
status: "PENDING" | "PAID" | "EXPIRED" | "CANCELLED";
|
||||
pixCode: string;
|
||||
pixQrCode: string;
|
||||
expiresAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
class AbacatePayClient {
|
||||
private config: AbacatePayConfig;
|
||||
|
||||
constructor(config: AbacatePayConfig) {
|
||||
this.config = {
|
||||
...config,
|
||||
baseUrl: config.baseUrl || "https://api.abacatepay.com/v1",
|
||||
};
|
||||
}
|
||||
|
||||
async createBilling(params: CreateBillingParams): Promise<BillingResponse> {
|
||||
const response = await fetch(`${this.config.baseUrl}/billing`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.config.apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
account_id: this.config.accountId,
|
||||
amount: params.amount * 100, // centavos
|
||||
metadata: params.metadata,
|
||||
return_url: params.returnUrl,
|
||||
completion_url: params.completionUrl,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(
|
||||
`Failed to create billing: ${errorData.message || response.statusText}`
|
||||
);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async getBillingStatus(billingId: string): Promise<BillingResponse> {
|
||||
const response = await fetch(
|
||||
`${this.config.baseUrl}/billing/${billingId}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.config.apiKey}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(
|
||||
`Failed to get billing status: ${
|
||||
errorData.message || response.statusText
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
verifyWebhookSignature(payload: string, signature: string): boolean {
|
||||
// Implementar verificação de assinatura conforme documentação do AbacatePay
|
||||
// Por enquanto, retorna true para desenvolvimento
|
||||
// Em produção, implementar a verificação real
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Instância do cliente (será configurada com variáveis de ambiente)
|
||||
export const abacatePay = new AbacatePayClient({
|
||||
apiKey: process.env.ABACATEPAY_API_KEY || "demo_key",
|
||||
accountId: process.env.ABACATEPAY_ACCOUNT_ID || "demo_account",
|
||||
});
|
||||
|
||||
export type { CreateBillingParams, BillingResponse };
|
||||
Reference in new issue
Block a user