/** * Conversion states a webhook can deliver. The server-side machine also has an * initial `pending` state, but it is never sent on a webhook - events fire only * on a vendor report or a reversal. `refunded` and `chargedback` carry a * `reversalValue`. */ export type ConversionStatus = 'completed' | 'failed' | 'abandoned' | 'refunded' | 'chargedback'; /** Input to {@link M2CClient.createAuction}. */ export type CreateAuctionParams = CreateAuctionContext & ({ /** Transaction amount in the major units of `currency`. Must be >= 0.000001 and <= 5000000000.00. */ transactionValue: number; /** What the customer is buying, shown at checkout. Truncated to 256 bytes at a UTF-8 boundary. */ description?: string; productId?: never; quantity?: never; } | { /** Your case-sensitive product ID in this account's catalog, shared across live and test. */ productId: string; /** Integer from 1 to the configured maximum (at most 1000). Defaults to 1. */ quantity?: number; transactionValue?: never; description?: never; }); interface CreateAuctionContext { /** * Supported ISO 4217 code. Raw pricing defaults to USD. Catalog pricing * requires uppercase and selects an active price; required when the product * has multiple active currencies, otherwise defaults to its sole price. */ currency?: string; /** * End user's IP address. Pass this when your backend calls on a device's * behalf: the connection IP M2C observes is your server's, and secret keys * derive geo from this field rather than the connection. */ customerIp?: string; /** ISO 3166-1 alpha-2 country override. */ country?: string; /** IETF language tag override. Inferred from country when omitted. */ language?: string; /** Your opaque order/session ID, echoed back in conversion webhooks: 1-128 ASCII letters, digits, `.`, `_`, `:` or `-`. M2C rejects anything else with a 400. */ reference?: string; /** http/https URL the customer returns to after a successful payment. Truncated to 2048 bytes at a UTF-8 boundary. */ successUrl?: string; /** http/https URL for a cancelled payment. Truncated to 2048 bytes at a UTF-8 boundary. */ cancelUrl?: string; /** Device form factor: mobile, tablet, desktop, console, or tv. M2C rejects anything else with a 400. */ deviceType?: string; /** Checkout surface (web|webgl|ios|android|desktop). Optional metadata; never auth. */ platform?: string; /** Referrer URL, if available. M2C keeps only its origin before storing or forwarding it. */ referrer?: string; /** Audience segments from M2C's fixed list (`SupportedSegment` in openapi.yaml); M2C rejects any other value with a 400. */ segments?: string[]; } /** Input to {@link M2CClient.requestRefund}. */ export interface RequestRefundParams { /** Refund amount in the major units of the conversion's currency. Must be > 0 and <= the refundable total. */ amount: number; /** Optional reason code relayed to the vendor: requested_by_customer, duplicate, fraudulent, not_received, or other. M2C rejects anything else with a 400. */ reason?: string; /** * Required idempotency key (1-255 printable ASCII). A retry with the same key * returns the existing request. Use a new key for each partial refund. */ idempotencyKey: string; } /** Result of {@link M2CClient.requestRefund}. */ export type RefundRequestStatus = 'pending' | 'sent' | 'confirmed' | 'failed' | 'rejected'; export interface RefundRequestResult { /** M2C's id for the refund request; correlate it with the eventual webhook. */ refundRequestId: string; /** Current request state. `failed` is uncertain; `rejected` was definitively not accepted. */ status: RefundRequestStatus; cumulativeReversalValue: number; remainingRefundableValue: number; /** Original request time, unchanged on idempotent replays. */ requestedAt: string; /** Fixed confirmation deadline; null when a historical deadline is unknown. */ mustConfirmBy: string | null; } /** Winning bid, as returned to a secret key. Individual bids are sealed. */ export interface AuctionWinner { vendorId: string; /** Hosted checkout URL to open. Time-boxed by {@link AuctionWinner.ttl}. */ checkoutUrl: string; /** Seconds the checkout URL remains valid. */ ttl: number; } /** Result of a successful {@link M2CClient.createAuction} call (secret key). */ export interface AuctionResult { winner: AuctionWinner; /** Winning fee rate as a percentage (e.g. 2.9 means 2.9%). */ clearingRate: number; /** Fee charged on the transaction, in the auction currency. */ feeProceeds: number; /** Number of valid bids received. */ bidCount: number; /** Correlate with the conversion webhook. */ requestId: string; /** Auction latency in milliseconds. */ latencyMs: number; } /** * A verified conversion event delivered to your webhook URL and returned by * {@link verifyConversionWebhook}. Known fields are mapped; verify the raw * payload yourself if you need fields added after this SDK version. */ export interface ConversionEvent { /** Server-resolved immutable purchase. Amounts are integer microcents. */ catalogPurchase?: { productId: string; productName: string; quantity: number; currency: string; unitAmountMicrocents: number; totalAmountMicrocents: number; }; event: 'conversion'; /** Matches the requestId from the auction. Primary correlation key. */ requestId: string; /** Parent shop session for a session purchase. Absent for checkout conversions. */ sessionId?: string; /** Vendor purchase identifier within sessionId. */ purchaseId?: string; status: ConversionStatus; /** Winning vendor's id. */ vendor: string; /** Vendor's transaction identifier (may be empty if the vendor supplied none). */ transactionId: string; /** When M2C emitted the event (RFC 3339, UTC). Distinct from the signing timestamp header. */ timestamp: string; /** * True on sandbox (test-mode) conversions, absent on live ones. The flag is * inside the HMAC-signed body, so it cannot be forged or stripped. Always * branch on it before fulfilling: sandbox checkouts deliver to the same * webhook URL as live traffic. */ test?: boolean; /** Stable across retries of the same delivery, when a delivery ledger row exists. */ deliveryId?: string; /** * Monotonic order of this live conversion transition within its auction. * Compare and advance this value in the same transaction as fulfillment or * reversal mutations. Absent on sandbox and legacy queued deliveries. */ eventSequence?: number; /** Your reference from the auction, echoed back when it was non-empty. */ reference?: string; /** * Checkout surface the transaction came from (web|webgl|ios|android|desktop), * attached by M2C from the auction record when known. Metadata only - carries * no attestation and must not gate fulfillment. */ platform?: string; /** * Coarse device form factor (e.g. "mobile" / "desktop"), attached by M2C from * the auction record when present. Metadata only; may be empty. */ deviceType?: string; /** Converted amount in the original auction currency, when applicable. */ value?: number; /** Reversed amount in the original auction currency, for refunds/chargebacks. */ reversalValue?: number; /** Persistent identity of this incremental reversal event. */ reversalId?: string; /** Total reversed amount after this event. */ cumulativeReversalValue?: number; /** Refundable amount remaining after this event. */ remainingRefundableValue?: number; } export {};