PaperTiger.BalanceTransactionHelper (PaperTiger v1.0.2)

Copy Markdown View Source

Helper functions for creating balance transactions.

Balance transactions are created automatically when:

  • A charge is created (type: "charge")
  • A refund is created (type: "refund")
  • A payout is created (type: "payout")

Fee Calculation

Stripe's standard fee is 2.9% + $0.30 per successful card charge. For simplicity, PaperTiger uses this formula for all charges.

Summary

Functions

Calculates Stripe's processing fee for a given amount.

Creates a balance transaction for a charge.

Creates a balance transaction for a refund.

Functions

calculate_fee(amount)

@spec calculate_fee(integer()) :: integer()

Calculates Stripe's processing fee for a given amount.

Formula: 2.9% + $0.30 (in cents)

create_for_charge(charge)

@spec create_for_charge(map()) :: {:ok, String.t()} | {:error, term()}

Creates a balance transaction for a charge.

Returns the balance transaction ID.

create_for_refund(refund, original_charge)

@spec create_for_refund(map(), map()) :: {:ok, String.t()} | {:error, term()}

Creates a balance transaction for a refund.

Refunds have negative amounts and return fees proportionally.