payment.ts
1 "use server" 2 3 import { sdk } from "@lib/config" 4 import { getAuthHeaders, getCacheOptions } from "./cookies" 5 import { HttpTypes } from "@medusajs/types" 6 7 export const listCartPaymentMethods = async (regionId: string) => { 8 const headers = { 9 ...(await getAuthHeaders()), 10 } 11 12 const next = { 13 ...(await getCacheOptions("payment_providers")), 14 } 15 16 return sdk.client 17 .fetch<HttpTypes.StorePaymentProviderListResponse>( 18 `/store/payment-providers`, 19 { 20 method: "GET", 21 query: { region_id: regionId }, 22 headers, 23 next, 24 cache: "force-cache", 25 } 26 ) 27 .then(({ payment_providers }) => 28 payment_providers.sort((a, b) => { 29 return a.id > b.id ? 1 : -1 30 }) 31 ) 32 .catch(() => { 33 return null 34 }) 35 }