Skip to content

Commit 15b90d8

Browse files
authored
Merge pull request #1931 from appwrite/fix-coupon-not-applying
Fix coupon not applying
2 parents 65c6093 + a782590 commit 15b90d8

File tree

6 files changed

+14
-28
lines changed

6 files changed

+14
-28
lines changed

src/lib/components/billing/validateCreditModal.svelte

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@
3838
message: 'Credits applied successfully'
3939
});
4040
}
41-
couponData = response;
42-
dispatch('validation', couponData);
43-
coupon = null;
44-
show = false;
45-
addNotification({
46-
type: 'success',
47-
message: 'Credits applied successfully'
48-
});
4941
} catch (e) {
5042
error = e.message;
5143
}

src/routes/(console)/apply-credit/+page.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { Button, Form, InputSelect, InputTags, InputText } from '$lib/elements/forms';
99
import { toLocaleDate } from '$lib/helpers/date';
1010
import { Wizard } from '$lib/layout';
11-
import { type PaymentList, type Plan } from '$lib/sdk/billing';
11+
import type { PaymentList, Plan } from '$lib/sdk/billing';
1212
import { addNotification } from '$lib/stores/notifications';
1313
import {
1414
organizationList,
@@ -72,7 +72,7 @@
7272
let tempOrgId = null;
7373
let currentPlan: Plan;
7474
75-
$: onlyNewOrgs = (campaign && campaign.onlyNewOrgs) || (couponData && couponData.onlyNewOrgs);
75+
$: onlyNewOrgs = campaign?.onlyNewOrgs || couponData?.onlyNewOrgs;
7676
7777
$: selectedOrgId = tempOrgId;
7878
@@ -174,7 +174,7 @@
174174
'',
175175
clientSecret,
176176
paymentMethodId,
177-
'/console/apply-credit?' + params.toString()
177+
`/console/apply-credit?${params}`
178178
);
179179
org = await sdk.forConsole.billing.validateOrganization(org.teamId, collaborators);
180180
}
@@ -205,7 +205,7 @@
205205
206206
async function addCoupon() {
207207
try {
208-
const response = await sdk.forConsole.billing.getCoupon(coupon);
208+
const response = await sdk.forConsole.billing.getCouponAccount(coupon);
209209
couponData = response;
210210
coupon = null;
211211
addNotification({

src/routes/(console)/create-organization/+page.svelte

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import type { Coupon } from '$lib/sdk/billing';
1212
import { isOrganization, tierToPlan } from '$lib/stores/billing';
1313
import { addNotification } from '$lib/stores/notifications';
14-
import { type OrganizationError, type Organization } from '$lib/stores/organization';
14+
import type { OrganizationError, Organization } from '$lib/stores/organization';
1515
import { sdk } from '$lib/stores/sdk';
1616
import { confirmPayment } from '$lib/stores/stripe';
1717
import { ID } from '@appwrite.io/console';
@@ -35,11 +35,6 @@
3535
let billingPlan: BillingPlan = BillingPlan.FREE;
3636
let paymentMethodId: string;
3737
let collaborators: string[] = [];
38-
let couponData: Partial<Coupon> = {
39-
code: null,
40-
status: null,
41-
credits: null
42-
};
4338
let taxId: string;
4439
4540
let billingBudget: number;
@@ -54,9 +49,9 @@
5449
const coupon = page.url.searchParams.get('coupon');
5550
try {
5651
const response = await sdk.forConsole.billing.getCouponAccount(coupon);
57-
couponData = response;
52+
selectedCoupon = response;
5853
} catch (e) {
59-
couponData = {
54+
selectedCoupon = {
6055
code: null,
6156
status: null,
6257
credits: null
@@ -127,7 +122,7 @@
127122
selectedPlan,
128123
paymentMethodId,
129124
null,
130-
couponData.code ? couponData.code : null,
125+
selectedCoupon.code ? selectedCoupon.code : null,
131126
collaborators,
132127
billingBudget,
133128
taxId
@@ -148,7 +143,7 @@
148143
'',
149144
clientSecret,
150145
paymentMethodId,
151-
'/console/create-organization?' + params.toString()
146+
`/console/create-organization?${params}`
152147
);
153148
await validate(org.teamId, collaborators);
154149
}

src/routes/(console)/create-organization/+page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async function getCoupon(url: URL): Promise<Coupon | null> {
4242
if (url.searchParams.has('code')) {
4343
const coupon = url.searchParams.get('code');
4444
try {
45-
return sdk.forConsole.billing.getCoupon(coupon);
45+
return sdk.forConsole.billing.getCouponAccount(coupon);
4646
} catch (e) {
4747
return null;
4848
}

src/routes/(console)/organization-[organization]/change-plan/+page.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
let showCreditModal = false;
5555
let feedbackDowngradeReason: string;
5656
let feedbackMessage: string;
57-
let couponData: Partial<Coupon> = data.coupon;
5857
5958
afterNavigate(({ from }) => {
6059
previousPage = from?.url?.pathname || previousPage;
@@ -63,9 +62,9 @@
6362
if (page.url.searchParams.has('code')) {
6463
const coupon = page.url.searchParams.get('code');
6564
try {
66-
couponData = await sdk.forConsole.billing.getCouponAccount(coupon);
65+
selectedCoupon = await sdk.forConsole.billing.getCouponAccount(coupon);
6766
} catch (e) {
68-
couponData = {
67+
selectedCoupon = {
6968
code: null,
7069
status: null,
7170
credits: null
@@ -191,7 +190,7 @@
191190
selectedPlan,
192191
paymentMethodId,
193192
null,
194-
couponData?.code,
193+
selectedCoupon?.code,
195194
newCollaborators,
196195
billingBudget,
197196
taxId ? taxId : null

src/routes/(console)/organization-[organization]/change-plan/+page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function getCoupon(url: URL): Promise<Coupon | null> {
4949
if (url.searchParams.has('code')) {
5050
const coupon = url.searchParams.get('code');
5151
try {
52-
return sdk.forConsole.billing.getCoupon(coupon);
52+
return sdk.forConsole.billing.getCouponAccount(coupon);
5353
} catch (e) {
5454
return null;
5555
}

0 commit comments

Comments
 (0)