diff --git a/CHANGELOG.md b/CHANGELOG.md index fca090d923..966854480f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,58 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [1.15.0-alpha.0](https://github.com/Cap-go/capgo/compare/1.10.0-alpha.0...1.15.0-alpha.0) (2022-08-17) + +### [1.14.6](https://github.com/Cap-go/capgo/compare/1.14.5...1.14.6) (2022-08-15) + + +### Bug Fixes + +* order of remove in device link ([2cf810f](https://github.com/Cap-go/capgo/commit/2cf810fb1b2812e095cffd7bdf6a5d5ec2be5b71)) + +### [1.14.5](https://github.com/Cap-go/capgo/compare/1.14.4...1.14.5) (2022-08-15) + +### [1.14.4](https://github.com/Cap-go/capgo/compare/1.14.3...1.14.4) (2022-08-12) + + +### Bug Fixes + +* issue with Foreign key ([50ba11b](https://github.com/Cap-go/capgo/commit/50ba11be9ece5fdddf1217f5b13625cb4b22d8e8)) + +### [1.14.3](https://github.com/Cap-go/capgo/compare/1.14.2...1.14.3) (2022-08-12) + + +### Bug Fixes + +* in no log today ([2f70755](https://github.com/Cap-go/capgo/commit/2f70755e9e54a99ba3fcc3b42925be2db6a43ba2)) + +### [1.14.2](https://github.com/Cap-go/capgo/compare/1.14.1...1.14.2) (2022-08-12) + + +### Bug Fixes + +* increase only if change ([6948731](https://github.com/Cap-go/capgo/commit/6948731dac1be459406161a71f322e556ad4cfa2)) + +### [1.14.1](https://github.com/Cap-go/capgo/compare/1.14.0...1.14.1) (2022-08-12) + + +### Bug Fixes + +* issue build ([c95944c](https://github.com/Cap-go/capgo/commit/c95944c3371b3c6ec8cdda5c7fb3c256a78faad5)) + +## [1.14.0](https://github.com/Cap-go/capgo/compare/1.13.14...1.14.0) (2022-08-12) + + +### Features + +* add bandwidth calc ([221abb6](https://github.com/Cap-go/capgo/commit/221abb62a05e8bff4a997e7c1383cfe8131a6d3d)) + +### [1.13.14](https://github.com/Cap-go/capgo/compare/1.9.11-alpha.5...1.13.14) (2022-08-12) + +### [1.13.13](https://github.com/Cap-go/capgo/compare/1.9.11-alpha.1...1.13.13) (2022-08-12) + +### [1.13.12](https://github.com/Cap-go/capgo/compare/1.9.11-alpha.0...1.13.12) (2022-08-12) + ### [1.14.6](https://github.com/Cap-go/capgo/compare/1.14.5...1.14.6) (2022-08-15) diff --git a/android/app/build.gradle b/android/app/build.gradle index 7f00452622..8b3110cdd3 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "ee.forgr.capacitor_go" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1140600 - versionName "1.14.6" + versionCode 1150000 + versionName "1.15.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/ios/App/App.xcodeproj/project.pbxproj b/ios/App/App.xcodeproj/project.pbxproj index 531b50e586..fdb0634971 100644 --- a/ios/App/App.xcodeproj/project.pbxproj +++ b/ios/App/App.xcodeproj/project.pbxproj @@ -349,12 +349,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = App/App.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = "1.14.6"; + CURRENT_PROJECT_VERSION = "1.15.0"; DEVELOPMENT_TEAM = UVTJ336J2D; INFOPLIST_FILE = App/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = "1.14.6"; + MARKETING_VERSION = "1.15.0"; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\""; PRODUCT_BUNDLE_IDENTIFIER = ee.forgr.capacitorgo; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -371,12 +371,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = App/App.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = "1.14.6"; + CURRENT_PROJECT_VERSION = "1.15.0"; DEVELOPMENT_TEAM = UVTJ336J2D; INFOPLIST_FILE = App/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = "1.14.6"; + MARKETING_VERSION = "1.15.0"; PRODUCT_BUNDLE_IDENTIFIER = ee.forgr.capacitorgo; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = ""; diff --git a/package.json b/package.json index 12aa099ae8..25c71dd42a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "1.14.6", + "version": "1.15.0-alpha.0", "scripts": { "build": "vite build", "test": "cypress open", diff --git a/supabase/functions/_utils/stripe.ts b/supabase/functions/_utils/stripe.ts index 4d0e100bb1..7aa985af0a 100644 --- a/supabase/functions/_utils/stripe.ts +++ b/supabase/functions/_utils/stripe.ts @@ -67,3 +67,18 @@ export const createCustomer = async (email: string) => { return response.data } +export const removeOldSubscription = async (subscriptionId: string) => { + console.log('removeOldSubscription', subscriptionId) + const STRIPE_SECRET_KEY = Deno.env.get('STRIPE_SECRET_KEY') || '' + const STRIPE_TOKEN = `${STRIPE_SECRET_KEY}` + console.log('STRIPE_TOKEN', STRIPE_TOKEN) + const requestOptions = { + method: 'DELETE', + headers: { + Authorization: `Bearer ${STRIPE_TOKEN}`, + }, + } + + const response = await fetch(`https://api.stripe.com/v1/subscriptions/${subscriptionId}`, requestOptions) + return response.json() +} diff --git a/supabase/functions/_utils/stripe_event.ts b/supabase/functions/_utils/stripe_event.ts index d1542aec91..7fdc478d8b 100644 --- a/supabase/functions/_utils/stripe_event.ts +++ b/supabase/functions/_utils/stripe_event.ts @@ -82,7 +82,7 @@ export const extractDataEvent = (event: any): definitions['stripe_info'] => { const charge = event.data.object as any data.status = 'canceled' data.customer_id = String(charge.customer) - data.subscription_id = undefined + data.subscription_id = charge.id } else { console.log('Other event', event.type, event) diff --git a/supabase/functions/stripe_event/index.ts b/supabase/functions/stripe_event/index.ts index 66443777c5..4bb86a262d 100644 --- a/supabase/functions/stripe_event/index.ts +++ b/supabase/functions/stripe_event/index.ts @@ -4,6 +4,7 @@ import { extractDataEvent, parseStripeEvent } from '../_utils/stripe_event.ts' import { supabaseAdmin } from '../_utils/supabase.ts' import type { definitions } from '../_utils/types_supabase.ts' import { sendRes } from '../_utils/utils.ts' +import { removeOldSubscription } from '../_utils/stripe.ts' serve(async (event: Request) => { if (!event.headers.get('stripe-signature') || !Deno.env.get('STRIPE_WEBHOOK_SECRET') || !Deno.env.get('STRIPE_SECRET_KEY')) @@ -28,14 +29,15 @@ serve(async (event: Request) => { return sendRes(dbError, 500) if (!user) return sendRes('no user found', 500) - const { error: dbError2 } = await supabaseAdmin + + const { data: customer } = await supabaseAdmin .from('stripe_info') - .update(stripeData) + .select() .eq('customer_id', stripeData.customer_id) + .single() console.log('stripeData', stripeData) - if (dbError2) - return sendRes(dbError, 500) + await addDataPerson(user.email, { id: user.id, customer_id: stripeData.customer_id, @@ -50,6 +52,16 @@ serve(async (event: Request) => { .eq('stripe_id', stripeData.product_id) .single() if (plan) { + const { error: dbError2 } = await supabaseAdmin + .from('stripe_info') + .update(stripeData) + .eq('customer_id', stripeData.customer_id) + if (customer && customer.product_id !== 'free' && customer.subscription_id) + await removeOldSubscription(customer.subscription_id) + + if (dbError2) + return sendRes(dbError, 500) + const isMonthly = plan.price_m_id === stripeData.price_id await updatePerson(user.email, undefined, [plan.name, isMonthly ? 'Monthly' : 'Yearly']) await addEventPerson(user.email, { @@ -60,8 +72,16 @@ serve(async (event: Request) => { else { await updatePerson(user.email, undefined, ['Not_found']) } } else if (stripeData.status === 'canceled') { - await updatePerson(user.email, undefined, ['Canceled']) - await addEventPerson(user.email, {}, 'user:cancel', 'red') + if (customer && customer.subscription_id === stripeData.subscription_id) { + const { error: dbError2 } = await supabaseAdmin + .from('stripe_info') + .update(stripeData) + .eq('customer_id', stripeData.customer_id) + if (dbError2) + return sendRes(dbError, 500) + await updatePerson(user.email, undefined, ['Canceled']) + await addEventPerson(user.email, {}, 'user:cancel', 'red') + } } else { await updatePerson(user.email, undefined, ['Free']) @@ -72,7 +92,7 @@ serve(async (event: Request) => { catch (e) { console.log('Error', e) return sendRes({ - status: 'Error unknow', + status: 'Error unknown', error: JSON.stringify(e), }, 500) }