export type BraintreeConfigurationRequest = {paymentServiceProvider: 'braintree' | 'braintreeSandbox' | 'stripe' | 'stripeTest', paymentProviderState: 'active' | 'inactive', merchantId: string, publicKey: string, privateKey: string}; export type StripeConfigurationRequest = {paymentServiceProvider: 'braintree' | 'braintreeSandbox' | 'stripe' | 'stripeTest', paymentProviderState: 'active' | 'inactive', secretKey: string}; export type CreateApiPaymentExecutionTenantLocatorPaymentProvidersArgs = {tenantLocator: string, body: BraintreeConfigurationRequest | StripeConfigurationRequest}; export type CreateApiPaymentExecutionTenantLocatorPaymentProvidersOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * POST /payment-execution/{tenantLocator}/paymentProviders */ export const createApiPaymentExecutionTenantLocatorPaymentProviders = async (args: CreateApiPaymentExecutionTenantLocatorPaymentProvidersArgs, options: CreateApiPaymentExecutionTenantLocatorPaymentProvidersOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") const url = `${baseUrl.replace(/\/+$/, '')}/payment-execution/${encodeURIComponent(String(args.tenantLocator))}/paymentProviders${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };