Empty branch IDs and missing payment information caused network errors and a missing billing component.master
@@ -29,7 +29,6 @@ function submit() { | |||||
} | } | ||||
onMounted(() => { | onMounted(() => { | ||||
checkPayment() | |||||
payEl.mount("#payment-element") | payEl.mount("#payment-element") | ||||
}) | }) | ||||
</script> | </script> | ||||
@@ -69,11 +69,11 @@ function create(user) { | |||||
}) | }) | ||||
} | } | ||||
function intent(user) { | |||||
function intent(u) { | |||||
return fetch(`/api/user/subscribe`, | return fetch(`/api/user/subscribe`, | ||||
{method: 'POST', | {method: 'POST', | ||||
body: JSON.stringify(user), | |||||
body: JSON.stringify(u), | |||||
headers: { | headers: { | ||||
"Accept": "application/json", | "Accept": "application/json", | ||||
"Authorization": `Bearer ${token.value}`, | "Authorization": `Bearer ${token.value}`, | ||||
@@ -84,9 +84,11 @@ function intent(user) { | |||||
err.value = "" | err.value = "" | ||||
console.log(s) | console.log(s) | ||||
sub.value = s | sub.value = s | ||||
step.value++ | |||||
if (["processing", "succeeded"].includes(s.paymentStatus) && | if (["processing", "succeeded"].includes(s.paymentStatus) && | ||||
clientSecret == s.clientSecret) { | clientSecret == s.clientSecret) { | ||||
step.value = step.value + 2 | |||||
} else if (s.paymentStatus == "requires_payment_method") { | |||||
step.value++ | step.value++ | ||||
} else { | } else { | ||||
step.value = 0 | step.value = 0 | ||||
@@ -28,7 +28,7 @@ CREATE TABLE user ( | |||||
email VARCHAR(40) UNIQUE NOT NULL, | email VARCHAR(40) UNIQUE NOT NULL, | ||||
first_name VARCHAR(30) NOT NULL, | first_name VARCHAR(30) NOT NULL, | ||||
last_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 '', | phone VARCHAR(20) NOT NULL DEFAULT '', | ||||
address INT NOT NULL, | address INT NOT NULL, | ||||
password CHAR(64) NOT NULL, | password CHAR(64) NOT NULL, | ||||
@@ -902,7 +902,7 @@ func setTokenCookie(id int, role string, w http.ResponseWriter) error { | |||||
cookie := http.Cookie{Name: "skouter", | cookie := http.Cookie{Name: "skouter", | ||||
Value: tokenStr, | Value: tokenStr, | ||||
Path: "/", | Path: "/", | ||||
Expires: time.Now().Add(time.Hour * 24)} | |||||
Expires: time.Now().Add(time.Hour * 1)} | |||||
http.SetCookie(w, &cookie) | http.SetCookie(w, &cookie) | ||||
return nil | return nil | ||||
@@ -1165,9 +1165,11 @@ func queryUser(db *sql.DB, id int) (User, error) { | |||||
return user, err | 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 | 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) { | func subscribe(w http.ResponseWriter, db *sql.DB, r *http.Request) { | ||||
claims, err := getClaims(r) | claims, err := getClaims(r) | ||||
user, err := queryUser(db, claims.Id) | user, err := queryUser(db, claims.Id) | ||||
if err != nil { | if err != nil { | ||||
w.WriteHeader(422) | w.WriteHeader(422) | ||||
return | return | ||||