-
Notifications
You must be signed in to change notification settings - Fork 4
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 #6 from ETHNYC-ZK-KYC-Soulbound/add-kyc-backend
KYC Backend
- Loading branch information
Showing
13 changed files
with
8,920 additions
and
10,839 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
import { VercelRequest, VercelResponse } from "@vercel/node"; | ||
import { utils } from "ethers"; | ||
import Stripe from "stripe"; | ||
|
||
const stripe = new Stripe(process.env.STRIPE_TEST_API_KEY as string, { | ||
apiVersion: "2020-08-27", | ||
typescript: true, | ||
}); | ||
|
||
interface VerificationSessionInput { | ||
address: string | undefined; | ||
} | ||
|
||
export default async (req: VercelRequest, res: VercelResponse) => { | ||
try { | ||
const { address } = req.body as VerificationSessionInput; | ||
|
||
// Check if address is provided and is legit | ||
if (typeof address !== "string" || !utils.isAddress(address)) { | ||
return res.status(401).send("Invalid parameters"); | ||
} | ||
|
||
const verificationSession = | ||
await stripe.identity.verificationSessions.create({ | ||
type: "document", | ||
metadata: { | ||
user_id: address, | ||
}, | ||
// Additional options for configuring the verification session: | ||
options: { | ||
document: { | ||
allowed_types: ["driving_license", "passport", "id_card"], | ||
require_id_number: true, // https://stripe.com/docs/identity/verification-checks?type=id-number | ||
require_live_capture: true, | ||
require_matching_selfie: true, // https://stripe.com/docs/identity/selfie#session | ||
}, | ||
}, | ||
}); | ||
const clientSecret = verificationSession.client_secret; | ||
res.status(200).json({ | ||
address, | ||
clientSecret, | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
res.status(500); | ||
} | ||
}; |
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,5 @@ | ||
import type { VercelRequest, VercelResponse } from "@vercel/node"; | ||
|
||
export default (request: VercelRequest, response: VercelResponse) => { | ||
response.status(200).send("Hello"); | ||
}; |
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,64 @@ | ||
import { VercelRequest, VercelResponse } from "@vercel/node"; | ||
import Stripe from "stripe"; | ||
|
||
const stripe = new Stripe(process.env.STRIPE_TEST_API_KEY as string, { | ||
apiVersion: "2020-08-27", | ||
typescript: true, | ||
}); | ||
|
||
export default (req: VercelRequest, res: VercelResponse) => { | ||
let event; | ||
const stripeEndpointSecret = process.env.STRIPE_TEST_WEBHOOK_KEY; | ||
|
||
// Verify the event came from Stripe | ||
try { | ||
const sig = req.headers["stripe-signature"]; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
event = stripe.webhooks.constructEvent(req.body, sig, stripeEndpointSecret); | ||
} catch (err) { | ||
// On error, log and return the error message | ||
console.log(err); | ||
return res.status(400).send("Webhook Error"); | ||
} | ||
|
||
// Successfully constructed event | ||
console.log(event); | ||
|
||
// If event is not the 'verified' event, skip it | ||
if (event.type !== "identity.verification_session.verified") { | ||
if (event.type !== "identity.verification_session.requires_input") { | ||
const verificationSession = event.data | ||
.object as Stripe.Identity.VerificationSession; | ||
console.log("Verification check failed!"); | ||
if (verificationSession?.last_error) | ||
console.log(verificationSession.last_error); | ||
} | ||
return res.json({ received: true }); // send back to webhook to end | ||
} | ||
|
||
// Verified! | ||
// https://stripe.com/docs/api/identity/verification_sessions/object#identity_verification_session_object-verified_outputs | ||
const verificationSession = event.data | ||
.object as Stripe.Identity.VerificationSession; | ||
const { verified_outputs: verifiedOutputs } = verificationSession; | ||
if (verifiedOutputs !== null) { | ||
const { | ||
address, | ||
dob, | ||
id_number: idNumber, | ||
first_name: firstName, | ||
last_name: lastName, | ||
} = verifiedOutputs; | ||
if (!address) { | ||
console.log("Invalid address after verification!"); | ||
console.log(verifiedOutputs); | ||
return res.json({ received: true }); // send back to webhook to end | ||
} | ||
|
||
const { city, state } = address; | ||
} | ||
|
||
return res.json({ received: true }); // send back to webhook to end | ||
}; |
Oops, something went wrong.
c8e82aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
web-stuff – ./
web-stuff-devlyn37.vercel.app
web-stuff-git-main-devlyn37.vercel.app
web-stuff-lac.vercel.app