cover/Elixir.WalletIntegrations.AdapterRequest.html

1 defmodule WalletIntegrations.AdapterRequest do
2 @moduledoc """
3 Normalized outbound request model for all provider adapters.
4
5 Fields:
6 - `payment_id` — internal idempotency key (maps to wallet transfer/idempotency key).
7 - `amount` — amount in minor currency units (e.g. paise, cents).
8 - `currency` — ISO 4217 currency code (e.g. "INR", "USD").
9 - `provider` — atom identifying the provider (e.g. :stripe, :razorpay).
10 - `provider_ref` — provider reference for status/cancel/refund operations (nil for initiate).
11 - `refund_amount` — amount to refund in minor units (only for refund_payment).
12 - `metadata` — arbitrary pass-through metadata map.
13 - `correlation_id` — propagated correlation identifier for tracing.
14 """
15
16 @enforce_keys [:payment_id, :amount, :currency, :provider]
17
:-(
defstruct [
18 :payment_id,
19 :amount,
20 :currency,
21 :provider,
22 :provider_ref,
23 :refund_amount,
24 :correlation_id,
25 metadata: %{}
26 ]
27
28 @type t :: %__MODULE__{
29 payment_id: String.t(),
30 amount: pos_integer(),
31 currency: String.t(),
32 provider: atom(),
33 provider_ref: String.t() | nil,
34 refund_amount: pos_integer() | nil,
35 correlation_id: String.t() | nil,
36 metadata: map()
37 }
38
39 @doc "Build a request for initiating a new payment."
40 @spec new_initiate(payment_id :: String.t(), amount :: pos_integer(), currency :: String.t(), opts :: keyword()) ::
41 t()
42 7 def new_initiate(payment_id, amount, currency, opts \\ []) do
43 25 %__MODULE__{
44 payment_id: payment_id,
45 amount: amount,
46 currency: currency,
47 provider: Keyword.get(opts, :provider, :stripe),
48 correlation_id: Keyword.get(opts, :correlation_id),
49 metadata: Keyword.get(opts, :metadata, %{})
50 }
51 end
52
53 @doc "Build a request for a status query, cancel, or refund using an existing provider reference."
54 @spec new_with_ref(payment_id :: String.t(), provider_ref :: String.t(), opts :: keyword()) :: t()
55
:-(
def new_with_ref(payment_id, provider_ref, opts \\ []) do
56 2 %__MODULE__{
57 payment_id: payment_id,
58 amount: Keyword.get(opts, :amount, 0),
59 currency: Keyword.get(opts, :currency, "INR"),
60 provider: Keyword.get(opts, :provider, :stripe),
61 provider_ref: provider_ref,
62 refund_amount: Keyword.get(opts, :refund_amount),
63 correlation_id: Keyword.get(opts, :correlation_id),
64 metadata: Keyword.get(opts, :metadata, %{})
65 }
66 end
67 end
Line Hits Source