| import { apiRequest } from './client' |
| import type { PaymentView, ProvidersResponse } from '../types' |
|
|
| export interface CreatePaymentInput { |
| userId: string |
| amountMinor: number |
| merchantId: string |
| payeeIban: string |
| country?: string |
| currency?: string |
| description?: string |
| idempotencyKey: string |
| } |
|
|
| export async function createPayment(input: CreatePaymentInput): Promise<PaymentView> { |
| return apiRequest<PaymentView>('/payments', { |
| headers: { 'Idempotency-Key': input.idempotencyKey }, |
| body: { |
| user_id: input.userId, |
| amount_minor: input.amountMinor, |
| merchant_id: input.merchantId, |
| payee_iban: input.payeeIban, |
| country: input.country, |
| currency: input.currency, |
| description: input.description ?? '', |
| consent: { granted: true, purpose: 'payment initiation' }, |
| }, |
| }) |
| } |
|
|
| export async function getPayment(paymentId: string): Promise<PaymentView> { |
| |
| return apiRequest<PaymentView>(`/payments/${encodeURIComponent(paymentId)}`) |
| } |
|
|
| export async function cancelPayment(paymentId: string): Promise<PaymentView> { |
| return apiRequest<PaymentView>(`/payments/${encodeURIComponent(paymentId)}/cancel`, { method: 'POST', body: {} }) |
| } |
|
|
| |
| |
| export async function refundPayment(paymentId: string, amountMinor?: number, reason?: string): Promise<PaymentView> { |
| const body: Record<string, unknown> = {} |
| if (amountMinor !== undefined) body.amount_minor = amountMinor |
| if (reason) body.reason = reason |
| return apiRequest<PaymentView>(`/payments/${encodeURIComponent(paymentId)}/refund`, { method: 'POST', body }) |
| } |
|
|
| export async function getProviders(): Promise<ProvidersResponse> { |
| return apiRequest<ProvidersResponse>('/payments/providers') |
| } |
|
|
| |
| |
| export async function mockAdvance(paymentId: string, rawStatus: string): Promise<unknown> { |
| return apiRequest(`/payments/${encodeURIComponent(paymentId)}/mock-advance`, { |
| body: { raw_status: rawStatus }, |
| }) |
| } |
|
|