Skip to content

Commit

Permalink
Merge branch '123-stripe-mock' of https://github.com/UoaWDCC/uasc-web
Browse files Browse the repository at this point in the history
…into 123-stripe-mock
  • Loading branch information
zlrkw11 committed Mar 29, 2024
2 parents 6cb761b + dfdd462 commit a6877d7
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-server.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only --config fly.production.toml --env "GOOGLE_SERVICE_ACCOUNT_JSON=$(echo ${{ secrets.PROD_SERVER_SERVICE_ACCOUNT }} | base64 --decode)"
- run: flyctl deploy --remote-only --config fly.production.toml --env "GOOGLE_SERVICE_ACCOUNT_JSON=$(echo ${{ secrets.PROD_SERVER_SERVICE_ACCOUNT }} | base64 --decode)" --env "STRIPE_API_SECRET=${{ secrets.PROD_SERVER_STRIPE_API_SECRET }}" --env "STRIPE_API_KEY=${{ secrets.PROD_SERVER_STRIPE_API_KEY }}"
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_PRODUCTION_API_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/deploy-server.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only --config fly.staging.toml --env "GOOGLE_SERVICE_ACCOUNT_JSON=$(echo ${{ secrets.STAGING_SERVER_SERVICE_ACCOUNT }} | base64 --decode)"
- run: flyctl deploy --remote-only --config fly.staging.toml --env "GOOGLE_SERVICE_ACCOUNT_JSON=$(echo ${{ secrets.STAGING_SERVER_SERVICE_ACCOUNT }} | base64 --decode)" --env "STRIPE_API_SECRET=${{ secrets.STAGING_SERVER_STRIPE_API_SECRET }}" --env "STRIPE_API_KEY=${{ secrets.STAGING_SERVER_STRIPE_API_KEY }}"
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_STAGING_API_TOKEN }}
17 changes: 17 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Prettier
on:
pull_request:
push:
branches:
- master
jobs:
Prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Enable corepack
run: corepack enable

- run: sudo yarn
- run: yarn prettier:ci
1 change: 0 additions & 1 deletion .husky/pre-commit

This file was deleted.

2 changes: 2 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarn lint-all
yarn prettier:ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Meta, StoryObj } from "@storybook/react"

import SignUpForm from "./SignUpForm"
import { BrowserRouter } from "react-router-dom"

// 👇 This default export determines where your story goes in the story list
const meta: Meta<typeof SignUpForm> = {
Expand All @@ -12,6 +13,13 @@ export default meta
type Story = StoryObj<typeof SignUpForm>

export const FirstStory: Story = {
decorators: [
(Story) => (
<BrowserRouter>
<Story />
</BrowserRouter>
)
],
args: {
// 👇 The args you need here will depend on your component
}
Expand Down
29 changes: 0 additions & 29 deletions client/src/components/composite/SignUpForm/SignUpForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import React, { useState } from "react"
import {
getAuth,
createUserWithEmailAndPassword,
updateProfile
} from "firebase/auth"
import { useNavigate } from "react-router-dom"
import { db } from "../../../firebase"
import { setDoc, doc } from "firebase/firestore"
import Button from "@mui/material/Button"
import TextField from "@mui/material/TextField"
import Snackbar from "@mui/material/Snackbar"
Expand Down Expand Up @@ -62,7 +55,6 @@ const SignUpForm = () => {
setOpen(false)
}

const auth = getAuth()
const navigate = useNavigate()

const handleSubmit = async (event: any) => {
Expand Down Expand Up @@ -106,29 +98,8 @@ const SignUpForm = () => {
}

try {
const { user } = await createUserWithEmailAndPassword(
auth,
email,
password
)
console.log("User created")

await updateProfile(user, { displayName: `${firstName} ${lastName}` })
console.log("Profile updated")

await setDoc(doc(db, "users", user.uid), {
uid: user.uid,
firstName,
lastName,
email,
phoneNumber,
dob,
studentId,
yearLevel,
faculty,
sportType,
interestedInRacing
})
console.log("Document set in Firestore")

setOpen(true)
Expand Down
11 changes: 11 additions & 0 deletions client/src/models/__generated__/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@
"lint": "eslint",
"lint-all": "eslint .",
"prettier": "prettier . --write",
"prettier:ci": "prettier . --check",
"vsc-setup": "code --install-extension dbaeumer.vscode-eslint && code --install-extension esbenp.prettier-vscode && code install-extension bradlc.vscode-tailwindcss",
"postinstall": "husky",
"lint-and-fix": "eslint . --fix",
"dev-client": "yarn workspace client start",
"dev-server": "yarn workspace server start",
"storybook": "yarn workspace client storybook",
"test-server": "firebase emulators:exec --only firestore \"node --experimental-vm-modules --dns-result-order=ipv4first ./node_modules/jest/bin/jest.js --setupFiles dotenv/config --passWithNoTests --detectOpenHandles --forceExit --testPathPattern=server/src\"",
"test-server": "yarn firestore-test \"node --experimental-vm-modules --dns-result-order=ipv4first ./node_modules/jest/bin/jest.js --setupFiles dotenv/config --passWithNoTests --detectOpenHandles --forceExit --testPathPattern=server/src\"",
"test-client": "jest --setupFiles dotenv/config --passWithNoTests --detectOpenHandles --forceExit --testPathPattern=server/client",
"test": "yarn test-client && yarn test-server"
"test": "yarn test-client && yarn test-server",
"firestore-test": "firebase emulators:exec --only firestore"
},
"eslintConfig": {
"extends": [
Expand Down
12 changes: 11 additions & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ const importSwaggerJson = async () => {
}

const app: Express = express()
function keepRawBody(
req: any,
res: any,
buf: Buffer,
encoding: BufferEncoding
) {
if (buf && buf.length) {
req.rawBody = buf
}
}

app.use(helmet())
app.use(express.json())
app.use(express.json({ verify: keepRawBody }))
app.use(cors())

app.use("/api-docs", swaggerUi.serve, async (_req: Request, res: Response) => {
Expand Down
27 changes: 27 additions & 0 deletions server/src/middleware/__generated__/routes.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions server/src/middleware/__generated__/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions server/src/service-layer/controllers/StripeWebhook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Controller, SuccessResponse, Route, Post, Request } from "tsoa"
import Stripe from "stripe"

@Route("webhook")
export class StripeWebhook extends Controller {
@Post()
@SuccessResponse(200, "Webhook post received")
public async receiveWebhook(@Request() request: any): Promise<void> {
console.log("webhook received")

const stripe = new Stripe(process.env.STRIPE_API_KEY)

try {
const event: Stripe.Event = stripe.webhooks.constructEvent(
request.rawBody,
request.headers["stripe-signature"],
// process.env.STRIPE_LOCAL // test local api secret
process.env.STRIPE_API_SECRET
)
switch (event.type) {
case "payment_intent.succeeded":
console.log("payment_intent.succeeded")
break
case "payment_method.attached":
console.log("payment_method.attached")
break
default:
console.log(`Unhandled event type ${event.type}.`)
}

return this.setStatus(200) // set status to 200 as success
} catch (err) {
console.error(err)
// set status to 400 due to bad request
return this.setStatus(400)
}
}
}

0 comments on commit a6877d7

Please sign in to comment.