-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into feat/prod-cicd-changes
Signed-off-by: Purshottam Patidar <[email protected]>
- Loading branch information
Showing
33 changed files
with
670 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
apps/api/src/app/user/usecases/apply-coupon/apply-coupon.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { PaymentAPIService } from '@impler/shared'; | ||
import { BadRequestException, Injectable, InternalServerErrorException } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class ApplyCoupon { | ||
constructor(private paymentApiService: PaymentAPIService) {} | ||
|
||
async execute(couponCode: string, userEmail: string, planCode: string) { | ||
try { | ||
return await this.paymentApiService.checkAppliedCoupon(couponCode, userEmail, planCode); | ||
} catch (error) { | ||
if (error) { | ||
throw new BadRequestException(error); | ||
} else throw new InternalServerErrorException(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
apps/api/src/app/user/usecases/checkout/checkout.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PaymentAPIService } from '@impler/shared'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class Checkout { | ||
constructor(private paymentApiService: PaymentAPIService) {} | ||
|
||
async execute({ | ||
externalId, | ||
paymentMethodId, | ||
planCode, | ||
couponCode, | ||
}: { | ||
externalId: string; | ||
planCode: string; | ||
paymentMethodId: string; | ||
couponCode?: string; | ||
}) { | ||
return this.paymentApiService.checkout({ | ||
externalId: externalId, | ||
planCode: planCode, | ||
paymentMethodId: paymentMethodId, | ||
couponCode: couponCode, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { Alert, Group, TextInput } from '@mantine/core'; | ||
import { CheckIcon } from '@assets/icons/Check.icon'; | ||
import { useCoupon } from '@hooks/useCoupon'; | ||
import { Button } from '@ui/button'; | ||
|
||
interface CouponProps { | ||
planCode: string; | ||
couponCode: string | undefined; | ||
setAppliedCouponCode: (couponCode?: string) => void; | ||
} | ||
|
||
const Coupon = ({ planCode, couponCode, setAppliedCouponCode }: CouponProps) => { | ||
const { register, errors, applyCouponSubmit, handleSubmit, isApplyCouponLoading } = useCoupon({ | ||
planCode, | ||
setAppliedCouponCode, | ||
}); | ||
|
||
return ( | ||
<div> | ||
{couponCode ? ( | ||
<Alert | ||
fw="bolder" | ||
color="green" | ||
variant="outline" | ||
withCloseButton | ||
onClose={() => setAppliedCouponCode(undefined)} | ||
icon={<CheckIcon color="white" size="md" />} | ||
> | ||
{`Coupon ${couponCode} is applied!`} | ||
</Alert> | ||
) : ( | ||
<form onSubmit={handleSubmit(applyCouponSubmit)}> | ||
<Group spacing={0} align="flex-start"> | ||
<TextInput | ||
placeholder="Enter coupon code" | ||
style={{ flexGrow: 1 }} | ||
{...register('couponCode')} | ||
error={errors.couponCode?.message} | ||
/> | ||
<Button type="submit" compact loading={isApplyCouponLoading}> | ||
Apply | ||
</Button> | ||
</Group> | ||
</form> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Coupon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Coupon'; |
56 changes: 56 additions & 0 deletions
56
apps/web/components/settings/AddCard/PaymentMethods/PaymentMethodOption.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Image from 'next/image'; | ||
import { Flex, Radio, Stack, Text, useMantineTheme } from '@mantine/core'; | ||
import { capitalizeFirstLetter } from '@shared/utils'; | ||
import { colors } from '@config'; | ||
import React from 'react'; | ||
|
||
interface PaymentMethodOptionProps { | ||
method: { | ||
paymentMethodId: string; | ||
brand: string; | ||
last4Digits: string; | ||
expMonth: number; | ||
expYear: number; | ||
}; | ||
selected: boolean; | ||
onChange: (methodId: string) => void; | ||
} | ||
|
||
export default function PaymentMethodOption({ method, selected, onChange }: PaymentMethodOptionProps) { | ||
const theme = useMantineTheme(); | ||
const cardBrandsSrc = method.brand.toLowerCase().replaceAll(' ', '_') || 'default'; | ||
|
||
const handleClick = () => { | ||
onChange(method.paymentMethodId); | ||
}; | ||
|
||
return ( | ||
<div style={{ marginBottom: '20px', cursor: 'pointer' }} onClick={handleClick}> | ||
<Flex | ||
justify="space-between" | ||
align="center" | ||
p="xl" | ||
style={{ | ||
border: `1px solid ${selected ? colors.blue : 'transparent'}`, | ||
backgroundColor: selected | ||
? theme.colorScheme === 'dark' | ||
? colors.BGSecondaryDark | ||
: colors.BGSecondaryLight | ||
: 'transparent', | ||
padding: '8px', | ||
}} | ||
> | ||
<Flex align="center" gap="xl"> | ||
<Radio value={method.paymentMethodId} id={method.paymentMethodId} checked={selected} /> | ||
<Stack spacing={4}> | ||
<Text fw={700} size="md"> | ||
{capitalizeFirstLetter(method.brand)} **** {method.last4Digits} | ||
</Text> | ||
<Text size="sm">Expires {`${method.expMonth}/${method.expYear}`}</Text> | ||
</Stack> | ||
</Flex> | ||
<Image width={50} height={30} src={`/images/cards/${cardBrandsSrc}.png`} alt="Card Company" /> | ||
</Flex> | ||
</div> | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
apps/web/components/settings/AddCard/PaymentMethods/PaymentMethods.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Radio } from '@mantine/core'; | ||
import { useRouter } from 'next/router'; | ||
import { modals } from '@mantine/modals'; | ||
import { MODAL_KEYS, ROUTES } from '@config'; | ||
import { ICardData } from '@impler/shared'; | ||
import { Button } from '@ui/button'; | ||
|
||
import PaymentMethodOption from './PaymentMethodOption'; | ||
|
||
interface PaymentMethodsProps { | ||
paymentMethods: ICardData[] | undefined; | ||
selectedPaymentMethod: string | undefined; | ||
handlePaymentMethodChange: (methodId: string) => void; | ||
} | ||
|
||
export function PaymentMethods({ | ||
paymentMethods, | ||
selectedPaymentMethod, | ||
handlePaymentMethodChange, | ||
}: PaymentMethodsProps) { | ||
const router = useRouter(); | ||
|
||
const handleAddMoreCard = () => { | ||
modals.close(MODAL_KEYS.SELECT_CARD); | ||
modals.close(MODAL_KEYS.PAYMENT_PLANS); | ||
router.push(ROUTES.ADD_CARD); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Radio.Group | ||
w={480} | ||
name="paymentMethod" | ||
value={selectedPaymentMethod || undefined} | ||
onChange={(event) => handlePaymentMethodChange(event)} | ||
> | ||
{paymentMethods?.map((method) => ( | ||
<PaymentMethodOption | ||
key={method.paymentMethodId} | ||
method={method} | ||
selected={selectedPaymentMethod === method.paymentMethodId} | ||
onChange={() => handlePaymentMethodChange(method.paymentMethodId)} | ||
/> | ||
))} | ||
</Radio.Group> | ||
|
||
<Button variant="outline" color="yellow" fullWidth onClick={handleAddMoreCard}> | ||
+ Add Card | ||
</Button> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './PaymentMethods'; | ||
export * from './PaymentMethodOption'; |
Oops, something went wrong.