Skip to content

Commit

Permalink
feat: ✨ Add in logic for Stripe Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kio-td committed Jul 12, 2024
1 parent 47a80df commit 33cbfb2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class AgeVerificationSystem {

switch (info.type) {
case "identity.verification_session.requires_input":
// Handle requires_input event
await this.handleStripeCancel(session);
break;
case "identity.verification_session.verified":
if (session.status === "verified") {
Expand Down Expand Up @@ -292,6 +292,23 @@ export class AgeVerificationSystem {
});
}

private async handleStripeCancel(
session: Stripe.Identity.VerificationSession,
): Promise<void> {
const ws = this.accountsOpen[session.metadata.identity].ws;

if (session.last_error?.code === "under_supported_age") {
await this.handleUnsupportedAge(ws);
} else {
ws.send(
JSON.stringify({
type: MessageTypes.VerificationFailed,
data: session.last_error?.code,
}),
);
}
}

/**
* Handles Stripe errors
* @param ws - The WebSocket connection
Expand Down

0 comments on commit 33cbfb2

Please sign in to comment.