Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Fix billing page

Acho Arnoldc18f36a68cf7
diff --git a/web/.env.production b/web/.env.production
index 885c6be5..8c05d115 100644
--- a/web/.env.production
+++ b/web/.env.production
@@ -6,3 +6,5 @@ APP_GITHUB_URL=https://github.com/NdoleStudio/httpsms
APP_DOCUMENTATION_URL=https://docs.httpsms.com
APP_DOWNLOAD_URL=https://github.com/NdoleStudio/httpsms/releases/latest/download/HttpSms.apk
APP_ENV=production
+
+CHECKOUT_URL=https://httpsms.lemonsqueezy.com/checkout/buy/277d9687-836f-4bfb-8065-8bbc9b9ca674
diff --git a/web/components/LoadingButton.vue b/web/components/LoadingButton.vue
new file mode 100644
index 00000000..2cd5c17a
--- /dev/null
+++ b/web/components/LoadingButton.vue
@@ -0,0 +1,56 @@
+<template>
+ <v-btn
+ :block="block"
+ :type="type"
+ :small="small"
+ :large="large"
+ :x-large="xLarge"
+ :color="color"
+ :text="text"
+ :tile="tile"
+ exact
+ :disabled="isLoading"
+ @click.prevent="onClick"
+ >
+ <v-progress-circular
+ v-if="isClicked"
+ :size="small ? 20 : 25"
+ color="grey"
+ class="mr-2"
+ indeterminate
+ ></v-progress-circular>
+ <v-icon v-if="icon && !isLoading" left>{{ icon }}</v-icon>
+ <slot></slot>
+ </v-btn>
+</template>
+
+<script lang="ts">
+import { Component, PropSync, Prop, Vue, Watch } from 'vue-property-decorator'
+@Component
+export default class SocialButtons extends Vue {
+ @Prop({ required: false, type: String, default: 'submit' }) type!: string
+ @Prop({ required: false, type: Boolean, default: false }) block!: boolean
+ @Prop({ required: false, type: Boolean, default: false }) large!: boolean
+ @Prop({ required: false, type: Boolean, default: false }) xLarge!: boolean
+ @Prop({ required: false, type: Boolean, default: false }) tile!: boolean
+ @Prop({ required: false, type: Boolean, default: false }) text!: boolean
+ @Prop({ required: false, type: Boolean, default: false }) small!: boolean
+ @Prop({ required: false, type: String, default: 'primary' }) color!: string
+ @Prop({ required: false, type: String, default: null }) icon!: string | null
+ @PropSync('loading', { required: true, type: Boolean }) isLoading!: boolean
+
+ isClicked = false
+
+ @Watch('loading')
+ onChildChanged(submitting: boolean) {
+ if (!submitting && this.isClicked) {
+ this.isClicked = false
+ }
+ }
+
+ onClick() {
+ this.isClicked = true
+ this.$emit('click')
+ }
+}
+</script>
diff --git a/web/layouts/default.vue b/web/layouts/default.vue
index f8e73db0..4138f817 100644
--- a/web/layouts/default.vue
+++ b/web/layouts/default.vue
@@ -57,7 +57,7 @@ export default class DefaultLayout extends Vue {
if (this.$store.getters.getAuthUser && this.$store.getters.getOwner) {
promises.push(
this.$store.dispatch('loadThreads'),
- this.$store.dispatch('getHeartbeat')
+ this.$store.dispatch('getHeartbeat'),
)
}
@@ -69,8 +69,8 @@ export default class DefaultLayout extends Vue {
promises.push(
this.$store.dispatch(
'loadThreadMessages',
- this.$store.getters.getThread.id
- )
+ this.$store.getters.getThread.id,
+ ),
)
}
await Promise.all(promises)
diff --git a/web/middleware/user.ts b/web/middleware/user.ts
index f7316d9c..6be1cc4b 100644
--- a/web/middleware/user.ts
+++ b/web/middleware/user.ts
@@ -15,6 +15,8 @@ const setUser = (context: Context): Promise<User | null> => {
let stateUser: StateUser | null = null
if (user) {
stateUser = {
+ email: user.email,
+ displayName: user.displayName,
id: user.uid,
}
setAuthHeader(await user.getIdToken())
@@ -23,7 +25,7 @@ const setUser = (context: Context): Promise<User | null> => {
resolve(user)
})
},
- reject
+ reject,
)
})
}
diff --git a/web/models/user.ts b/web/models/user.ts
index 3eff6fe2..022144fc 100644
--- a/web/models/user.ts
+++ b/web/models/user.ts
@@ -3,6 +3,15 @@ export interface User {
email: string
api_key: string
active_phone_id: string | null
+ subscription_ends_at: string
+ /** @example "8f9c71b8-b84e-4417-8408-a62274f65a08" */
+ subscription_id: string
+ /** @example "free" */
+ subscription_name: string
+ /** @example "2022-06-05T14:26:02.302718+03:00" */
+ subscription_renews_at: string
+ /** @example "on_trial" */
+ subscription_status: string
created_at: string
updated_at: string
}
diff --git a/web/nuxt.config.js b/web/nuxt.config.js
index 550b1bd3..c4faf75c 100644
--- a/web/nuxt.config.js
+++ b/web/nuxt.config.js
@@ -107,8 +107,16 @@ export default {
measurementId: 'G-EZ5W9DVK8T',
},
services: {
- auth: true,
analytics: true,
+ auth: {
+ persistence: 'local', // default
+ initialize: {
+ onAuthStateChangedAction: 'onAuthStateChanged',
+ onIdTokenChangedAction: 'onAuthStateChanged',
+ subscribeManually: false,
+ },
+ ssr: false,
+ },
},
},
],
@@ -150,6 +158,10 @@ export default {
exclude: ['/messages', '/settings', '/threads**'],
},
+ publicRuntimeConfig: {
+ checkoutURL: process.env.CHECKOUT_URL,
+ },
+
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {},
}
diff --git a/web/pages/billing/index.vue b/web/pages/billing/index.vue
index 574026dd..adf39425 100644
--- a/web/pages/billing/index.vue
+++ b/web/pages/billing/index.vue
@@ -18,7 +18,157 @@
<v-container>
<v-row>
<v-col cols="12" md="9" offset-md="1" xl="8" offset-xl="2">
- <h5 class="text-h4 mb-3 mt-3">Overview</h5>
+ <h5 class="text-h4 mb-3 mt-3">Current Plan</h5>
+ <v-row v-if="$store.getters.getUser">
+ <v-col md="6" xl="4">
+ <v-alert dense text prominent color="info">
+ <v-row align="center">
+ <v-col cols="12">
+ <h1
+ class="subtitle-1 font-weight-bold text-uppercase mt-3"
+ >
+ Free
+ </h1>
+ <p v-if="plan.price" class="text--secondary">
+ Your next bill is for <b>${{ plan.price }}</b> on
+ <b>{{
+ new Date(
+ $store.getters.getUser.subscription_renews_at,
+ ).toLocaleDateString()
+ }}</b>
+ </p>
+ <p
+ v-else-if="subscriptionIsCancelled"
+ class="text--secondary"
+ >
+ You will be downgraded to the <b>FREE</b> plan on
+ <b>{{
+ new Date(
+ $store.getters.getUser.subscription_ends_at,
+ ).toLocaleDateString()
+ }}</b>
+ </p>
+ <p v-else class="text--secondary">
+ {{ totalMessages }}/{{ plan.messagesPerMonth }} messages
+ </p>
+ </v-col>
+ <v-col cols="12" class="d-flex mb-2 mt-n6">
+ <loading-button
+ v-if="!subscriptionIsCancelled && !isOnFreePlan"
+ color="primary"
+ :loading="loading"
+ @click="updateDetails"
+ >
+ Update Details
+ </loading-button>
+ <v-btn v-else color="primary" :href="checkoutURL"
+ >Upgrade Plan</v-btn
+ >
+ <v-spacer></v-spacer>
+ <v-dialog
+ v-if="!subscriptionIsCancelled && !isOnFreePlan"
+ v-model="dialog"
+ max-width="590"
+ >
+ <template #activator="{ on, attrs }">
+ <v-btn v-bind="attrs" color="error" text v-on="on">
+ Cancel Plan
+ </v-btn>
+ </template>
+ <v-card>
+ <v-card-text class="pt-4 mb-n6">
+ <h2 class="text--primary text-h5 mb-2">
+ Are you sure you want to cancel your subscription?
+ </h2>
+ <p>
+ You will be downgraded to the free plan at the end
+ of the current billing period on
+ <b>{{
+ new Date(
+ $store.getters.getUser.subscription_renews_at,
+ ).toLocaleDateString()
+ }}</b>
+ </p>
+ </v-card-text>
+ <v-card-actions>
+ <v-btn color="primary" @click="dialog = false">
+ Keep Subscription
+ </v-btn>
+ <v-spacer></v-spacer>
+ <loading-button
+ v-if="!isOnFreePlan"
+ :text="true"
+ :loading="loading"
+ color="error"
+ @click="cancelPlan"
+ >
+ Cancel Plan
+ </loading-button>
+ </v-card-actions>
+ </v-card>
+ </v-dialog>
+ </v-col>
+ </v-row>
+ </v-alert>
+ </v-col>
+ </v-row>
+ <h2 v-if="isOnFreePlan" class="text-h4 mt-4 mb-2">Upgrade Plan</h2>
+ <v-row v-if="isOnFreePlan">
+ <v-col cols="12" md="6" xl="4">
+ <v-hover v-slot="{ hover }">
+ <v-card
+ :color="hover ? 'black' : 'default'"
+ :href="checkoutURL"
+ outlined
+ >
+ <v-card-text>
+ <v-row align="center">
+ <v-col class="grow">
+ <h1
+ class="subtitle-1 font-weight-bold text-uppercase mt-3"
+ >
+ Pro - Monthly
+ </h1>
+ <p class="text--secondary">5,000 messages</p>
+ </v-col>
+ <v-col class="shrink">
+ <span class="text-h5 text--primary">$6</span>/month
+ </v-col>
+ </v-row>
+ </v-card-text>
+ </v-card>
+ </v-hover>
+ </v-col>
+ <v-col cols="12" md="6" xl="4">
+ <v-hover v-slot="{ hover }">
+ <v-card
+ :color="hover ? 'black' : 'default'"
+ :href="checkoutURL"
+ outlined
+ >
+ <v-card-text>
+ <v-row align="center">
+ <v-col class="grow">
+ <h1
+ class="subtitle-1 font-weight-bold text-uppercase mt-3"
+ >
+ Pro - Yearly
+ <v-chip small color="primary" class="mt-n1"
+ >Save 20%</v-chip
+ >
+ </h1>
+ <p class="text--secondary">5,000 messages</p>
+ </v-col>
+ <v-col class="shrink">
+ <span class="text-h5 text--primary">$5</span>/month
+ </v-col>
+ </v-row>
+ </v-card-text>
+ </v-card>
+ </v-hover>
+ </v-col>
+ </v-row>
+ <h5 class="text-h4 mb-3 mt-4">Overview</h5>
<p class="text--secondary">
This is the summary of the sent messages and received messages in
<code
@@ -148,6 +298,13 @@ import {
mdiSquareEditOutline,
} from '@mdi/js'
+type PaymentPlan = {
+ name: string
+ id: string
+ price: number
+ messagesPerMonth: number
+}
+
export default Vue.extend({
name: 'BillingIndex',
middleware: ['auth'],
@@ -165,19 +322,65 @@ export default Vue.extend({
mdiCreditCard,
mdiSquareEditOutline,
loading: true,
+ dialog: false,
+ plans: [
+ {
+ name: 'Free',
+ id: 'free',
+ messagesPerMonth: 1000,
+ price: 0,
+ },
+ {
+ name: 'PRO - Monthly',
+ id: 'pro-monthly',
+ messagesPerMonth: 5000,
+ price: 6,
+ },
+ {
+ name: 'PRO - Yearly',
+ id: 'pro-yearly',
+ messagesPerMonth: 5000,
+ price: 60,
+ },
+ ],
}
},
head() {
return {
- title: 'Usage & Billing - Http SMS',
+ title: 'Usage & Billing - httpSMS',
}
},
computed: {
- apiKey() {
- if (this.$store.getters.getUser === null) {
- return ''
+ checkoutURL() {
+ const url = new URL(this.$config.checkoutURL)
+ const user = this.$store.getters.getAuthUser
+ console.log(this.$store.getters.getAuthUser)
+ url.searchParams.append('checkout[custom][user_id]', user?.uid)
+ url.searchParams.append('checkout[email]', user?.email)
+ url.searchParams.append('checkout[name]', user?.displayName)
+ console.log(url.toString())
+ return url.toString()
+ },
+ plan(): PaymentPlan {
+ return this.plans.find(
+ (x) =>
+ x.id === (this.$store.getters.getUser?.subscription_name || 'free'),
+ )!
+ },
+ isOnFreePlan(): boolean {
+ return this.plan.id === 'free'
+ },
+ subscriptionIsCancelled(): boolean {
+ return this.$store.getters.getUser?.subscription_status === 'cancelled'
+ },
+ totalMessages(): number {
+ if (this.$store.getters.getBillingUsage == null) {
+ return 0
}
- return this.$store.getters.getUser.api_key
+ return (
+ this.$store.getters.getBillingUsage.sent_messages +
+ this.$store.getters.getBillingUsage.received_messages
+ )
},
},
async mounted() {
@@ -193,11 +396,38 @@ export default Vue.extend({
methods: {
async loadData() {
await Promise.all([
+ this.$store.dispatch('loadUser'),
this.$store.dispatch('loadBillingUsage'),
this.$store.dispatch('loadBillingUsageHistory'),
])
this.loading = false
},
+ updateDetails() {
+ this.loading = true
+ this.$store
+ .dispatch('getSubscriptionUpdateLink')
+ .then((link: string) => {
+ window.location.href = link
+ })
+ .catch(() => {
+ this.loading = false
+ })
+ },
+ cancelPlan() {
+ this.loading = true
+ this.$store
+ .dispatch('cancelSubscription')
+ .then(() => {
+ this.$store.dispatch('addNotification', {
+ message: 'Subscription cancelled successfully',
+ type: 'success',
+ })
+ this.$router.push('/')
+ })
+ .catch(() => {
+ this.loading = false
+ })
+ },
},
})
</script>
diff --git a/web/pages/index.vue b/web/pages/index.vue
index 6fe499a6..5d3953f8 100644
--- a/web/pages/index.vue
+++ b/web/pages/index.vue
@@ -158,7 +158,7 @@
<h2 class="text-h3 text-center">Get Started</h2>
</v-col>
</v-row>
- <v-row class="pb-16">
+ <v-row>
<v-col cols="12">
<v-row>
<v-col cols="12" md="5" class="pr-4">
@@ -213,13 +213,9 @@
<v-col
cols="12"
md="7"
- class="mb-16"
- :class="{ 'pt-16': $vuetify.breakpoint.mdAndUp }"
+ :class="{ 'pt-16 mb-16mb-16': $vuetify.breakpoint.mdAndUp }"
>
- <div
- class="w-full mt-4"
- :class="{ 'mb-16': $vuetify.breakpoint.smAndDown }"
- >
+ <div class="w-full mt-4">
<v-tabs v-model="selectedTab" show-arrows>
<v-tab href="#javascript">
<v-icon color="#efd81d" class="mr-1">{{
@@ -463,15 +459,15 @@ Console.WriteLine(await response.Content.ReadAsStringAsync());
features.
</p>
<p v-if="!yearlyPricing" class="text-center text--primary">
- <span class="text-h3">$12</span>/month
+ <span class="text-h3">$6</span>/month
</p>
<p v-else class="text-center text--primary">
- <span class="text-h3">$120</span>/year
+ <span class="text-h3">$60</span>/year
</p>
<p v-if="!yearlyPricing" class="text-center mt-n3">
- or <b>$144</b> per year
+ or <b>$72</b> per year
</p>
- <p v-else class="text-center mt-n3">or <b>$10</b> per month</p>
+ <p v-else class="text-center mt-n3">or <b>$5</b> per month</p>
<v-btn block color="primary" :to="{ name: 'login' }" large
>Try For Free</v-btn
>
diff --git a/web/store/index.ts b/web/store/index.ts
index e94fe76a..e4120a84 100644
--- a/web/store/index.ts
+++ b/web/store/index.ts
@@ -3,7 +3,7 @@ import { AxiosError } from 'axios'
import { MessageThread } from '~/models/message-thread'
import { Message } from '~/models/message'
import { Heartbeat } from '~/models/heartbeat'
-import axios from '~/plugins/axios'
+import axios, { setAuthHeader } from '~/plugins/axios'
import { Phone } from '~/models/phone'
import { User } from '~/models/user'
import { BillingUsage } from '~/models/billing'
@@ -25,6 +25,8 @@ export interface NotificationRequest {
}
export type AuthUser = {
+ email: string | null
+ displayName: string | null
id: string
}
@@ -348,7 +350,7 @@ export const actions = {
fcm_token: phone.fcm_token,
phone_number: phone.phone_number,
message_expiration_seconds: parseInt(
- phone.message_expiration_seconds.toString()
+ phone.message_expiration_seconds.toString(),
),
max_send_attempts: parseInt(phone.max_send_attempts.toString()),
messages_per_minute: parseInt(phone.messages_per_minute.toString()),
@@ -368,7 +370,7 @@ export const actions = {
async handleAxiosError(
context: ActionContext<State, State>,
- error: AxiosError
+ error: AxiosError,
) {
const errorMessage =
error.response?.data?.data[Object.keys(error.response?.data?.data)[0]][0]
@@ -403,7 +405,7 @@ export const actions = {
async sendMessage(
context: ActionContext<State, State>,
- request: SendMessageRequest
+ request: SendMessageRequest,
) {
await axios.post('/v1/messages/send', request)
await Promise.all([
@@ -418,7 +420,7 @@ export const actions = {
addNotification(
context: ActionContext<State, State>,
- request: NotificationRequest
+ request: NotificationRequest,
) {
context.commit('setNotification', request)
},
@@ -433,7 +435,7 @@ export const actions = {
async loadThreadMessages(
context: ActionContext<State, State>,
- threadId: string | null
+ threadId: string | null,
) {
await context.commit('setThreadId', threadId)
const response = await axios.get('/v1/messages', {
@@ -448,7 +450,7 @@ export const actions = {
async setAuthUser(
context: ActionContext<State, State>,
- user: AuthUser | null | undefined
+ user: AuthUser | null | undefined,
) {
const userChanged = user?.id !== context.getters.getAuthUser?.id
@@ -465,13 +467,27 @@ export const actions = {
])
const phone = context.getters.getPhones.find(
- (x: Phone) => x.id === context.getters.getUser.active_phone_id
+ (x: Phone) => x.id === context.getters.getUser.active_phone_id,
)
if (phone) {
await context.dispatch('setOwner', phone.phone_number)
}
}
},
+ async onAuthStateChanged(
+ context: ActionContext<State, State>,
+ // @ts-ignore
+ { authUser },
+ ) {
+ if (authUser == null) {
+ context.commit('setAuthUser', null)
+ context.commit('setUser', null)
+ return
+ }
+ setAuthHeader(await authUser.getIdToken())
+ const { uid, email, displayName } = authUser
+ await context.commit('setAuthUser', { id: uid, email, displayName })
+ },
async clearAxiosError(context: ActionContext<State, State>) {
await context.commit('setAxiosError', null)
@@ -494,7 +510,7 @@ export const actions = {
async updateThread(
context: ActionContext<State, State>,
- payload: { threadId: string; isArchived: boolean }
+ payload: { threadId: string; isArchived: boolean },
) {
await axios.put(`/v1/message-threads/${payload.threadId}`, {
is_archived: payload.isArchived,