Browse Source

Fix user retrieval errors

Empty branch IDs and missing payment information caused network errors
and a missing billing component.
master
Immanuel Onyeka 11 months ago
parent
commit
10b88f12bc
4 changed files with 13 additions and 9 deletions
  1. +0
    -1
      grav-admin/user/js/registration/billing.vue
  2. +5
    -3
      grav-admin/user/js/registration/registration.vue
  3. +1
    -1
      migrations/0_29092022_setup_tables.sql
  4. +7
    -4
      skouter.go

+ 0
- 1
grav-admin/user/js/registration/billing.vue View File

@@ -29,7 +29,6 @@ function submit() {
}

onMounted(() => {
checkPayment()
payEl.mount("#payment-element")
})
</script>


+ 5
- 3
grav-admin/user/js/registration/registration.vue View File

@@ -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


+ 1
- 1
migrations/0_29092022_setup_tables.sql View File

@@ -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,


+ 7
- 4
skouter.go View File

@@ -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


Loading…
Cancel
Save