-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard,core-flows,js-sdk,types,link-modules,payment): ability…
… to copy payment link (#8630) what: - enables a button to create a payment link when a payment delta is present - api to delete order payment collection - adds a pending amount to payment collections Note: Not the happiest with the decision on when to create a payment collection and when not to. The code should programatically create or delete payment collections currently to generate the right collection for the payment delta. Adding a more specific flow to create and manage a payment collection will help reduce this burden from the code path and onto CX/merchant. Another issue I found is that the payment collection status doesn't get updated when payment is complete as it still gets stuck to "authorized" state https://github.com/user-attachments/assets/037a10f9-3621-43c2-94ba-1ada4b0a041b
- Loading branch information
Showing
35 changed files
with
630 additions
and
93 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
63 changes: 63 additions & 0 deletions
63
packages/admin-next/dashboard/src/hooks/api/payment-collections.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,63 @@ | ||
import { FetchError } from "@medusajs/js-sdk" | ||
import { HttpTypes } from "@medusajs/types" | ||
import { useMutation, UseMutationOptions } from "@tanstack/react-query" | ||
import { sdk } from "../../lib/client" | ||
import { queryClient } from "../../lib/query-client" | ||
import { queryKeysFactory } from "../../lib/query-key-factory" | ||
import { ordersQueryKeys } from "./orders" | ||
|
||
const PAYMENT_COLLECTION_QUERY_KEY = "payment-collection" as const | ||
export const paymentCollectionQueryKeys = queryKeysFactory( | ||
PAYMENT_COLLECTION_QUERY_KEY | ||
) | ||
|
||
export const useCreatePaymentCollection = ( | ||
options?: UseMutationOptions< | ||
HttpTypes.AdminPaymentCollectionResponse, | ||
Error, | ||
HttpTypes.AdminCreatePaymentCollection | ||
> | ||
) => { | ||
return useMutation({ | ||
mutationFn: (payload) => sdk.admin.paymentCollection.create(payload), | ||
onSuccess: (data, variables, context) => { | ||
queryClient.invalidateQueries({ | ||
queryKey: ordersQueryKeys.all, | ||
}) | ||
|
||
queryClient.invalidateQueries({ | ||
queryKey: paymentCollectionQueryKeys.all, | ||
}) | ||
|
||
options?.onSuccess?.(data, variables, context) | ||
}, | ||
...options, | ||
}) | ||
} | ||
|
||
export const useDeletePaymentCollection = ( | ||
options?: Omit< | ||
UseMutationOptions< | ||
HttpTypes.AdminDeletePaymentCollectionResponse, | ||
FetchError, | ||
string | ||
>, | ||
"mutationFn" | ||
> | ||
) => { | ||
return useMutation({ | ||
mutationFn: (id: string) => sdk.admin.paymentCollection.delete(id), | ||
onSuccess: (data, variables, context) => { | ||
queryClient.invalidateQueries({ | ||
queryKey: ordersQueryKeys.all, | ||
}) | ||
|
||
queryClient.invalidateQueries({ | ||
queryKey: paymentCollectionQueryKeys.all, | ||
}) | ||
|
||
options?.onSuccess?.(data, variables, context) | ||
}, | ||
...options, | ||
}) | ||
} |
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
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
Oops, something went wrong.