PaperTiger.ChargeHelper (PaperTiger v1.1.1)

Copy Markdown View Source

Creates Charge objects from PaymentIntents.

Handles the PI -> Charge -> BalanceTransaction chain that Stripe performs when a PaymentIntent succeeds. This is used by checkout session completion and the billing engine to produce the same object graph that real Stripe does.

Summary

Functions

Captures an authorized PaymentIntent charge and links the resulting balance transaction.

Creates a Charge (and its BalanceTransaction) for a succeeded PaymentIntent.

Functions

capture_payment_intent_charge(payment_intent, amount_to_capture, final_capture?)

@spec capture_payment_intent_charge(map(), integer(), boolean()) ::
  {:ok, map()} | {:error, :not_found}

Captures an authorized PaymentIntent charge and links the resulting balance transaction.

create_for_payment_intent(payment_intent, opts \\ [])

@spec create_for_payment_intent(
  map(),
  keyword()
) :: {:ok, map()}

Creates a Charge (and its BalanceTransaction) for a succeeded PaymentIntent.

  1. Builds a charge map from the PI fields
  2. Inserts into the Charges store
  3. Creates a BalanceTransaction via BalanceTransactionHelper
  4. Updates the charge with the balance_transaction ID
  5. Updates the PI with latest_charge
  6. Fires telemetry
  7. Returns {:ok, charge}