File size: 1,335 Bytes
70332a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { apiRequest } from './client'

export type OobStatus = 'pending' | 'approved' | 'rejected' | 'expired'

export interface OobConfirmation {
  confirmation_id: string
  code: string
  amount: number
  merchant: string
  channels: string[]
}

/** Set the user's out-of-band channels (push/sms/email/console). */
export function setNotifyPrefs(userId: string, channels: string[]): Promise<unknown> {
  return apiRequest('/notify/prefs', { body: { user_id: userId, channels } })
}

/** Create a demo dynamic-linked confirmation (existing service via /notify/request). */
export function requestConfirmation(userId: string, amount: number, merchant: string): Promise<OobConfirmation> {
  return apiRequest<OobConfirmation>('/notify/request', { body: { user_id: userId, amount, merchant } })
}

export function getConfirmationStatus(confirmationId: string): Promise<{ status: OobStatus }> {
  return apiRequest(`/notify/status?confirmation_id=${encodeURIComponent(confirmationId)}`)
}

/** Approve/deny — the code proves the response is bound to this exact payment (dynamic linking). */
export function respondConfirmation(confirmationId: string, approve: boolean, code: string): Promise<{ success: boolean; reason?: string }> {
  return apiRequest('/notify/respond', { body: { confirmation_id: confirmationId, approve, code } })
}