Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Boleto as Stripe payment method #2007

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/customers/CustomerMainInfos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const PaymentProviderMethodTranslationsLookup = {
[ProviderPaymentMethodsEnum.Link]: 'text_6686b316b672a6e75a29eea0',
[ProviderPaymentMethodsEnum.SepaDebit]: 'text_64aeb7b998c4322918c8420c',
[ProviderPaymentMethodsEnum.UsBankAccount]: 'text_65e1f90471bc198c0c934d8e',
[ProviderPaymentMethodsEnum.Boleto]: 'text_1738234109827diqh4eswleu',
}

gql`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Dispatch, FC, ReactNode, SetStateAction, useMemo } from 'react'
import { Accordion, Alert, Avatar, Typography } from '~/components/designSystem'
import { Checkbox, ComboBox, ComboboxDataGrouped, TextInputField } from '~/components/form'
import { ADD_CUSTOMER_PAYMENT_PROVIDER_ACCORDION } from '~/core/constants/form'
import { FeatureFlags, isFeatureFlagActive } from '~/core/utils/featureFlags'
import {
CreateCustomerInput,
CurrencyEnum,
Expand Down Expand Up @@ -78,6 +79,7 @@ export const PaymentProvidersAccordion: FC<PaymentProvidersAccordionProps> = ({
usePaymentProvidersListForCustomerCreateEditExternalAppsAccordionQuery({
variables: { limit: 1000 },
})
const hasAccessToBoletoOption = isFeatureFlagActive(FeatureFlags.FTR_STRIPE_BOLETO)

const selectedPaymentProvider = paymentProviders?.collection.find(
(p) => p.code === formikProps.values.paymentProviderCode,
Expand Down Expand Up @@ -246,16 +248,19 @@ export const PaymentProvidersAccordion: FC<PaymentProvidersAccordionProps> = ({
))
}
onChange={(e, checked) => {
const newValue = [
let newValue = [
...(formikProps.values.providerCustomer?.providerPaymentMethods || []),
]

if (checked) {
newValue.push(ProviderPaymentMethodsEnum.Card)
} else {
newValue.splice(newValue.indexOf(ProviderPaymentMethodsEnum.Card), 1)
// Link cannot be selected without card
newValue.splice(newValue.indexOf(ProviderPaymentMethodsEnum.Link), 1)
// Note: Link option cannot be selected without card
newValue = newValue.filter(
(method) =>
method !== ProviderPaymentMethodsEnum.Card &&
method !== ProviderPaymentMethodsEnum.Link,
)
}

formikProps.setFieldValue('providerCustomer.providerPaymentMethods', newValue)
Expand All @@ -277,14 +282,16 @@ export const PaymentProvidersAccordion: FC<PaymentProvidersAccordionProps> = ({
)
}
onChange={(e, checked) => {
const newValue = [
let newValue = [
...(formikProps.values.providerCustomer?.providerPaymentMethods || []),
]

if (checked) {
newValue.push(ProviderPaymentMethodsEnum.Link)
} else {
newValue.splice(newValue.indexOf(ProviderPaymentMethodsEnum.Link), 1)
newValue = newValue.filter(
(method) => method !== ProviderPaymentMethodsEnum.Link,
)
}

formikProps.setFieldValue('providerCustomer.providerPaymentMethods', newValue)
Expand Down Expand Up @@ -314,14 +321,16 @@ export const PaymentProvidersAccordion: FC<PaymentProvidersAccordionProps> = ({
)
}
onChange={(e, checked) => {
const newValue = [
let newValue = [
...(formikProps.values.providerCustomer?.providerPaymentMethods || []),
]

if (checked) {
newValue.push(ProviderPaymentMethodsEnum.SepaDebit)
} else {
newValue.splice(newValue.indexOf(ProviderPaymentMethodsEnum.SepaDebit), 1)
newValue = newValue.filter(
(method) => method !== ProviderPaymentMethodsEnum.SepaDebit,
)
}

formikProps.setFieldValue('providerCustomer.providerPaymentMethods', newValue)
Expand All @@ -344,16 +353,15 @@ export const PaymentProvidersAccordion: FC<PaymentProvidersAccordionProps> = ({
)
}
onChange={(e, checked) => {
const newValue = [
let newValue = [
...(formikProps.values.providerCustomer?.providerPaymentMethods || []),
]

if (checked) {
newValue.push(ProviderPaymentMethodsEnum.UsBankAccount)
} else {
newValue.splice(
newValue.indexOf(ProviderPaymentMethodsEnum.UsBankAccount),
1,
newValue = newValue.filter(
(method) => method !== ProviderPaymentMethodsEnum.UsBankAccount,
)
}

Expand All @@ -376,19 +384,58 @@ export const PaymentProvidersAccordion: FC<PaymentProvidersAccordionProps> = ({
)
}
onChange={(e, checked) => {
const newValue = [
let newValue = [
...(formikProps.values.providerCustomer?.providerPaymentMethods || []),
]

if (checked) {
newValue.push(ProviderPaymentMethodsEnum.BacsDebit)
} else {
newValue.splice(newValue.indexOf(ProviderPaymentMethodsEnum.BacsDebit), 1)
newValue = newValue.filter(
(method) => method !== ProviderPaymentMethodsEnum.BacsDebit,
)
}

formikProps.setFieldValue('providerCustomer.providerPaymentMethods', newValue)
}}
/>

{hasAccessToBoletoOption && (
<Checkbox
name="providerCustomer.providerPaymentMethods.boleto"
value={
!!formikProps.values.providerCustomer?.providerPaymentMethods?.includes(
ProviderPaymentMethodsEnum.Boleto,
)
}
label={translate('text_1738234109827diqh4eswleu')}
sublabel={translate('text_1738234109827hev75h17loy')}
disabled={
formikProps.values.providerCustomer?.providerPaymentMethods?.length === 1 &&
formikProps.values.providerCustomer?.providerPaymentMethods.includes(
ProviderPaymentMethodsEnum.Boleto,
)
}
onChange={(e, checked) => {
let newValue = [
...(formikProps.values.providerCustomer?.providerPaymentMethods || []),
]

if (checked) {
newValue.push(ProviderPaymentMethodsEnum.Boleto)
} else {
newValue = newValue.filter(
(method) => method !== ProviderPaymentMethodsEnum.Boleto,
)
}

formikProps.setFieldValue(
'providerCustomer.providerPaymentMethods',
newValue,
)
}}
/>
)}
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/featureFlags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// You can list your features such as FTR_ENABLED = 'ftr_enabled'
export enum FeatureFlags {
FTR_ENABLED = 'ftr_enabled',
FTR_SALESFORCE_ENABLED = 'ftr_salesforce_enabled',
FTR_STRIPE_BOLETO = 'ftr_stripe_boleto',
}

const FF_KEY = 'featureFlags'
Expand Down
1 change: 1 addition & 0 deletions src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4526,6 +4526,7 @@ export type ProviderCustomerInput = {

export enum ProviderPaymentMethodsEnum {
BacsDebit = 'bacs_debit',
Boleto = 'boleto',
Card = 'card',
Link = 'link',
SepaDebit = 'sepa_debit',
Expand Down
4 changes: 3 additions & 1 deletion translations/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2811,5 +2811,7 @@
"text_1737731953885tbem8s4xo8t": "Charge",
"text_1737733582553rmmlatfbk1r": "Search or select a specific charge",
"text_1737733582553dm4huzkoee6": "Search or select a specific filters",
"text_1738084927595tzdnuy6oxyu": "Fee successfully reset"
"text_1738084927595tzdnuy6oxyu": "Fee successfully reset",
"text_1738234109827diqh4eswleu": "Boleto Payments",
"text_1738234109827hev75h17loy": "For customers invoiced in BRL"
}
Loading