-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from claushaas/staging
Staging
- Loading branch information
Showing
4 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,54 @@ | ||
// X-hubla-token | ||
// 8Lui4amoPJRcDXCLN3MSiFZV9HcBiJAzxCcVynu7xcxF2RDBG9LIFopa8yDeodNz | ||
|
||
import {json, type LoaderFunctionArgs} from '@remix-run/node'; | ||
import {HooksService} from '~/services/hooks.service.server'; | ||
import {SlackService} from '~/services/slack.service.server'; | ||
import {type THublaEvents} from '~/types/hubla.type'; | ||
import {logger} from '~/utils/logger.util'; | ||
|
||
export const meta = () => [ | ||
{name: 'robots', content: 'noindex, nofollow'}, | ||
]; | ||
|
||
export const loader = async ({request}: LoaderFunctionArgs) => { | ||
try { | ||
await new SlackService().sendMessage(await request.json() as Record<string, any>); | ||
|
||
return json({ | ||
message: 'OK', | ||
}, { | ||
status: 200, | ||
}); | ||
} catch (error) { | ||
logger.logError(`Error sending message on hotmart loader: ${(error as Error).message}`); | ||
return json({error: 'An error occurred'}); | ||
} | ||
}; | ||
|
||
export const action = async ({request}: LoaderFunctionArgs) => { | ||
try { | ||
const {headers} = request; | ||
const HUBLA_TOKEN = headers.get('X-hubla-token'); | ||
|
||
if (HUBLA_TOKEN === process.env.HUBLA_TOKEN) { | ||
const body = await request.json() as THublaEvents; | ||
await new HooksService().handleHublaWebhook(body); | ||
|
||
return json({ | ||
message: 'OK', | ||
}, { | ||
status: 200, | ||
}); | ||
} | ||
|
||
return json({ | ||
message: 'Unauthorized', | ||
}, { | ||
status: 401, | ||
}); | ||
} catch (error) { | ||
logger.logError(`Error sending message on hotmart action: ${(error as Error).message}`); | ||
return json({error: 'An error occurred'}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
export type THublaInvoiceEvents = { | ||
'type': 'invoice.created' | 'invoice.status_updated' | 'invoice.payment_succeeded' | 'invoice.payment_failed' | 'invoice.expired' | 'invoice.refunded'; | ||
'event': { | ||
'product': { | ||
'id': string; | ||
'name': string; | ||
}; | ||
'products': [{ | ||
'id': string; | ||
'name': string; | ||
'offers': Array<{ | ||
'id': string; | ||
'name': string; | ||
'cohorts': Array<{'id': string}>; | ||
}>; | ||
}]; | ||
'invoice': { | ||
'id': string; | ||
'subscriptionId': string; | ||
'payerId': string; | ||
'sellerId': string; | ||
'installments': number; | ||
'paymentMethod': string; | ||
'currency': string; | ||
'type': string; | ||
'status': string; | ||
'statusAt': Array<{ | ||
'status': string; | ||
'when': string; | ||
}>; | ||
'amount': { | ||
'subtotalCents': number; | ||
'discountCents': number; | ||
'prorataCents': number; | ||
'installmentFeeCents': number; | ||
'totalCents': number; | ||
}; | ||
'receivers': Array<{ | ||
'id': string; | ||
'name': string; | ||
'email': string; | ||
'phone': string; | ||
'role': string; | ||
'paysForFees': boolean; | ||
'totalCents': number; | ||
}>; | ||
'firstPaymentSession': { | ||
'ip': string; | ||
'utm': { | ||
'source': string; | ||
'medium': string; | ||
'campaign': string; | ||
'content': string; | ||
'term': string; | ||
}; | ||
}; | ||
'billingAddress': { | ||
'countryCode': string; | ||
'state': string; | ||
'city': string; | ||
'neighborhood': string; | ||
'street': string; | ||
'complement': string; | ||
'number': string; | ||
'postalCode': string; | ||
}; | ||
'smartInstallment': { | ||
'sourceInvoiceId': string; | ||
'installment': number; | ||
'installments': number; | ||
}; | ||
'saleDate': string; | ||
'dueDate': string; | ||
'createdAt': string; | ||
'modifiedAt': string; | ||
'version': number; | ||
}; | ||
'user': { | ||
'id': string; | ||
'firstName': string; | ||
'lastName': string; | ||
'document': string; | ||
'email': string; | ||
'phone': string; | ||
}; | ||
}; | ||
'version': string; | ||
}; | ||
|
||
export type THublaSubscriptionEvents = { | ||
'type': 'customer.member_added' | 'customer.member_removed'; | ||
'event': { | ||
'product': { | ||
'id': string; | ||
'name': string; | ||
}; | ||
'products': Array<{ | ||
'id': string; | ||
'name': string; | ||
'offers': Array<{ | ||
'id': string; | ||
'name': string; | ||
'cohorts': Array<{'id': string}>; | ||
}>; | ||
}>; | ||
'subscription': { | ||
'id': string; | ||
'sellerId': string; | ||
'payerId': string; | ||
'type': 'recurring' | 'one_time' | 'free'; | ||
'status': 'active' | 'inactive'; | ||
'billingCycleMonths': 1 | 3 | 6 | 12; | ||
'credits': number; | ||
'paymentMethod': 'credit_card' | 'pix' | 'bank_slip'; | ||
'autoRenew': boolean; | ||
'freeTrial': boolean; | ||
'activatedAt': string; | ||
'modifiedAt': string; | ||
'createdAt': string; | ||
'firstPaymentSession': { | ||
'ip': string; | ||
'utm': { | ||
'source': string; | ||
'medium': string; | ||
'campaign': string; | ||
'content': string; | ||
'term': string; | ||
}; | ||
}; | ||
'version': number; | ||
}; | ||
'user': { | ||
'id': string; | ||
'firstName': string; | ||
'lastName': string; | ||
'document': string; | ||
'email': string; | ||
'phone': string; | ||
}; | ||
}; | ||
'version': string; | ||
}; | ||
|
||
export type THublaEvents = THublaInvoiceEvents | THublaSubscriptionEvents; |