-
Notifications
You must be signed in to change notification settings - Fork 211
feat: require state for existing US payment methods #2804
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,111 @@ | ||
| <script lang="ts"> | ||
| import { Modal } from '$lib/components'; | ||
| import { Button, InputSelect } from '$lib/elements/forms'; | ||
| import { invalidate } from '$app/navigation'; | ||
| import { Dependencies } from '$lib/constants'; | ||
| import { addNotification } from '$lib/stores/notifications'; | ||
| import { sdk } from '$lib/stores/sdk'; | ||
| import type { PaymentMethodData } from '$lib/sdk/billing'; | ||
| import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; | ||
| import { states } from './state'; | ||
| import { Alert, Card, Layout, Typography } from '@appwrite.io/pink-svelte'; | ||
| import { CreditCardBrandImage } from '../index.js'; | ||
|
|
||
| let { | ||
| show = $bindable(false), | ||
| paymentMethod | ||
| }: { | ||
| show: boolean; | ||
| paymentMethod: PaymentMethodData; | ||
| } = $props(); | ||
|
|
||
| let selectedState = $state(''); | ||
| let isSubmitting = $state(false); | ||
| let error = $state<string | null>(null); | ||
HarshMN2345 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $effect(() => { | ||
| if (!show) { | ||
| selectedState = ''; | ||
| error = null; | ||
| } | ||
| }); | ||
|
|
||
| async function handleSubmit() { | ||
| if (!selectedState) { | ||
| error = 'Please select a state'; | ||
| return; | ||
| } | ||
|
|
||
| isSubmitting = true; | ||
| error = null; | ||
|
|
||
| try { | ||
| await sdk.forConsole.billing.setPaymentMethod( | ||
| paymentMethod.$id, | ||
| paymentMethod.providerMethodId, | ||
| paymentMethod.name, | ||
| selectedState | ||
| ); | ||
| trackEvent(Submit.PaymentMethodUpdate); | ||
| await invalidate(Dependencies.PAYMENT_METHODS); | ||
| addNotification({ | ||
| type: 'success', | ||
| message: 'Payment method state has been updated' | ||
| }); | ||
| show = false; | ||
| } catch (e) { | ||
| error = e.message; | ||
| trackError(e, Submit.PaymentMethodUpdate); | ||
| } finally { | ||
| isSubmitting = false; | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| <Modal | ||
| dismissible={false} | ||
| bind:error | ||
| onSubmit={handleSubmit} | ||
| bind:show | ||
| title="Update payment method state"> | ||
| <Layout.Stack direction="column" gap="m"> | ||
| <Typography.Text> | ||
| State information is required for US payment methods to apply correct taxes and meet | ||
| U.S. legal requirements. | ||
| </Typography.Text> | ||
| {#if paymentMethod} | ||
| <Card.Base variant="secondary" padding="s"> | ||
| <Layout.Stack direction="row" alignItems="center" gap="s"> | ||
| <CreditCardBrandImage brand={paymentMethod.brand} /> | ||
| <span>ending in {paymentMethod.last4}</span> | ||
| </Layout.Stack> | ||
| <Typography.Text size="s"> | ||
| {paymentMethod.country} | ||
| </Typography.Text> | ||
| </Card.Base> | ||
| {/if} | ||
|
|
||
| <Alert.Inline status="info" title="State is required for US payment methods"> | ||
| <Typography.Text size="s"> | ||
| To complete the billing information, select your state so we can apply the correct | ||
| taxes and meet U.S. legal requirements. | ||
| </Typography.Text> | ||
| </Alert.Inline> | ||
|
|
||
| <InputSelect | ||
| bind:value={selectedState} | ||
| required | ||
| label="State" | ||
| placeholder="Select a state" | ||
| id="state-picker" | ||
| options={states.map((stateOption) => ({ | ||
| label: stateOption.name, | ||
| value: stateOption.abbreviation, | ||
| id: stateOption.abbreviation.toLowerCase() | ||
| }))} /> | ||
| </Layout.Stack> | ||
|
|
||
| <svelte:fragment slot="footer"> | ||
| <Button submit disabled={!selectedState || isSubmitting}>Save</Button> | ||
| </svelte:fragment> | ||
| </Modal> | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use $lib alias for src/lib imports.
Relative imports from
src/libshould use the$libalias. This keeps paths consistent and matches the repo conventions.🔧 Suggested change
As per coding guidelines, ...
📝 Committable suggestion
🤖 Prompt for AI Agents