diff --git a/grav-admin/user/js/registration/billing.vue b/grav-admin/user/js/registration/billing.vue index 2ca4fae..93662a8 100644 --- a/grav-admin/user/js/registration/billing.vue +++ b/grav-admin/user/js/registration/billing.vue @@ -29,7 +29,6 @@ function submit() { } onMounted(() => { - checkPayment() payEl.mount("#payment-element") }) diff --git a/grav-admin/user/js/registration/registration.vue b/grav-admin/user/js/registration/registration.vue index 52df4b3..5c3e4f0 100644 --- a/grav-admin/user/js/registration/registration.vue +++ b/grav-admin/user/js/registration/registration.vue @@ -69,11 +69,11 @@ function create(user) { }) } -function intent(user) { +function intent(u) { return fetch(`/api/user/subscribe`, {method: 'POST', - body: JSON.stringify(user), + body: JSON.stringify(u), headers: { "Accept": "application/json", "Authorization": `Bearer ${token.value}`, @@ -84,9 +84,11 @@ function intent(user) { err.value = "" console.log(s) sub.value = s - step.value++ + if (["processing", "succeeded"].includes(s.paymentStatus) && clientSecret == s.clientSecret) { + step.value = step.value + 2 + } else if (s.paymentStatus == "requires_payment_method") { step.value++ } else { step.value = 0 diff --git a/migrations/0_29092022_setup_tables.sql b/migrations/0_29092022_setup_tables.sql index 47ac1e8..68c2104 100644 --- a/migrations/0_29092022_setup_tables.sql +++ b/migrations/0_29092022_setup_tables.sql @@ -28,7 +28,7 @@ CREATE TABLE user ( email VARCHAR(40) UNIQUE NOT NULL, first_name VARCHAR(30) NOT NULL, last_name VARCHAR(30) NOT NULL, - customer_id VARCHAR(255) UNIQUE NOT NULL DEFAULT '', + customer_id VARCHAR(255) NOT NULL DEFAULT '', phone VARCHAR(20) NOT NULL DEFAULT '', address INT NOT NULL, password CHAR(64) NOT NULL, diff --git a/skouter.go b/skouter.go index c523f48..df0d7cb 100644 --- a/skouter.go +++ b/skouter.go @@ -902,7 +902,7 @@ func setTokenCookie(id int, role string, w http.ResponseWriter) error { cookie := http.Cookie{Name: "skouter", Value: tokenStr, Path: "/", - Expires: time.Now().Add(time.Hour * 24)} + Expires: time.Now().Add(time.Hour * 1)} http.SetCookie(w, &cookie) return nil @@ -1165,9 +1165,11 @@ func queryUser(db *sql.DB, id int) (User, error) { return user, err } - user.Branch, err = queryBranch(db, user.Branch.Id) - if err != nil { - return user, err + if user.Branch.Id > 0 { + user.Branch, err = queryBranch(db, user.Branch.Id) + if err != nil { + return user, err + } } return user, nil @@ -3027,6 +3029,7 @@ func createSubscription(cid string) (*stripe.Subscription, error) { func subscribe(w http.ResponseWriter, db *sql.DB, r *http.Request) { claims, err := getClaims(r) user, err := queryUser(db, claims.Id) + if err != nil { w.WriteHeader(422) return