-
-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathreturn.js
More file actions
38 lines (33 loc) · 1.1 KB
/
return.js
File metadata and controls
38 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
if (window.location.pathname === '/courses/enrolled') {
initialize()
}
async function initialize() {
const queryString = window.location.search
const urlParams = new URLSearchParams(queryString)
const sessionId = urlParams.get('session_id')
const enrollmentUuid = urlParams.get('enrollment_uuid')
let failurePath = urlParams.get('failure_path')
if (!failurePath || !failurePath.startsWith('/courses/')) {
failurePath = '/bootcamp'
}
if (!sessionId) {
window.location.replace(failurePath)
return
}
const response = await fetch(
`/courses/stripe/session-status?session_id=${sessionId}&enrollment_uuid=${enrollmentUuid}`
)
if (!response.ok) {
window.location.replace(failurePath)
return
}
const session = await response.json()
if (session.status == 'open') {
window.location.replace(failurePath)
} else if (session.status == 'complete') {
document.getElementById('pending').classList.add('hidden')
document.getElementById('success').classList.remove('hidden')
document.getElementById('customer-email').textContent =
session.customer_email
}
}