-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): Service Plans & Billing - Entitlement purchase integra…
…tion (#2432)
- Loading branch information
1 parent
3ed5128
commit 90f740f
Showing
25 changed files
with
890 additions
and
323 deletions.
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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,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 = "" |
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,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), | ||
}, | ||
}) | ||
} | ||
) |
Oops, something went wrong.