Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(console): Service Plans & Billing - Entitlement purchase integration #2432

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/main-console.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ jobs:
secrets: |
SECRET_SESSION_KEY
SECRET_SESSION_SALT
STRIPE_API_SECRET
STRIPE_WEBHOOK_SECRET
STRIPE_PRO_PLAN_ID
env:
NODE_ENV: 'development'
# A secret used for session encryption.
SECRET_SESSION_KEY: ${{ secrets.SECRET_SESSION_KEY_DEV }}
SECRET_SESSION_SALT: ${{ secrets.SECRET_SESSION_SALT_DEV }}
# CF_ROUTE: https://console-dev.kubelt.com/*
STRIPE_API_SECRET: ${{ secrets.STRIPE_API_SECRET_DEV }}
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET_DEV }}
STRIPE_PRO_PLAN_ID: ${{ secrets.STRIPE_PRO_PLAN_ID_DEV }}

- name: Setup Playwright
working-directory: 'apps/console'
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/next-console.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ jobs:
secrets: |
SECRET_SESSION_KEY
SECRET_SESSION_SALT
STRIPE_API_SECRET
STRIPE_WEBHOOK_SECRET
STRIPE_PRO_PLAN_ID
env:
# A secret used for session encryption.
SECRET_SESSION_KEY: ${{ secrets.SECRET_SESSION_KEY_TEST }}
SECRET_SESSION_SALT: ${{ secrets.SECRET_SESSION_SALT_TEST }}
STRIPE_API_SECRET: ${{ secrets.STRIPE_API_SECRET_TEST }}
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET_TEST }}
STRIPE_PRO_PLAN_ID: ${{ secrets.STRIPE_PRO_PLAN_ID_TEST }}
6 changes: 6 additions & 0 deletions .github/workflows/release-console.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ jobs:
secrets: |
SECRET_SESSION_KEY
SECRET_SESSION_SALT
STRIPE_API_SECRET
STRIPE_WEBHOOK_SECRET
STRIPE_PRO_PLAN_ID
env:
# A secret used for session encryption.
SECRET_SESSION_KEY: ${{ secrets.SECRET_SESSION_KEY_PROD }}
SECRET_SESSION_SALT: ${{ secrets.SECRET_SESSION_SALT_PROD }}
STRIPE_API_SECRET: ${{ secrets.STRIPE_API_SECRET_PROD }}
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET_PROD }}
STRIPE_PRO_PLAN_ID: ${{ secrets.STRIPE_PRO_PLAN_ID_PROD }}
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions apps/console/.dev.vars.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
SECRET_SESSION_SALT = ""
SECRET_SESSION_KEY = ""
INTERNAL_GOOGLE_ANALYTICS_TAG = "G-NHNH4KRWC3"

STRIPE_API_SECRET = ""
STRIPE_WEBHOOK_SECRET = ""
STRIPE_PRO_PLAN_ID = ""
71 changes: 0 additions & 71 deletions apps/console/app/routes/__layout/gnillib/checkout.tsx

This file was deleted.

83 changes: 83 additions & 0 deletions apps/console/app/routes/__layout/gnillib/details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { generateTraceContextHeaders } from '@proofzero/platform-middleware/trace'
import { getRollupReqFunctionErrorWrapper } from '@proofzero/utils/errors'
import { ActionFunction, redirect } from '@remix-run/cloudflare'
import {
commitFlashSession,
getFlashSession,
requireJWT,
} from '~/utilities/session.server'
import createAccountClient from '@proofzero/platform-clients/account'
import {
getAuthzHeaderConditionallyFromToken,
parseJwt,
} from '@proofzero/utils'
import { createCustomer, updateCustomer } from '~/services/billing/stripe'
import { AccountURN } from '@proofzero/urns/account'
import { AddressURN } from '@proofzero/urns/address'

export const action: ActionFunction = getRollupReqFunctionErrorWrapper(
async ({ request, context }) => {
const jwt = await requireJWT(request)
const parsedJwt = parseJwt(jwt!)
const accountURN = parsedJwt.sub as AccountURN

const traceHeader = generateTraceContextHeaders(context.traceSpan)

const accountClient = createAccountClient(Account, {
...getAuthzHeaderConditionallyFromToken(jwt),
...traceHeader,
})

const fd = await request.formData()
const { email, emailURN, name } = JSON.parse(
fd.get('payload') as string
) as {
email: string
emailURN: AddressURN
name: string
}

let paymentData = await accountClient.getStripePaymentData.query({
accountURN,
})
if (!paymentData) {
const customer = await createCustomer({
email,
name,
accountURN,
})

paymentData = {
customerID: customer.id,
email,
name,
}
} else {
paymentData = {
...paymentData,
email,
name,
}

await updateCustomer({
customerID: paymentData.customerID,
email,
name,
})
}

await accountClient.setStripePaymentData.mutate({
...paymentData,
accountURN,
})

const flashSession = await getFlashSession(request.headers.get('Cookie'))
flashSession.flash('success_toast', 'Payment data updated')

return redirect('/gnillib', {
headers: {
'Set-Cookie': await commitFlashSession(flashSession),
},
})
}
)
Loading