Paysafe (Paysafe v1.0.0)

Copy Markdown View Source

Production-grade Elixir client for the Paysafe API.

Overview

This library provides complete coverage of the Paysafe developer platform:

  • Payments API — Payment handles, payments, settlements, refunds, payouts, verifications, and customer/vault management.
  • Payment Scheduler API — Plans and subscriptions for recurring billing.
  • Applications API — Programmatic merchant onboarding.
  • Value Added Services — FX Rates, Customer Identity (KYC), Bank Account Validation, Network Tokenization, Account Updater.
  • Webhooks — HMAC-SHA256 verification and typed event parsing.

Configuration

Build a config struct from your credentials:

config = Paysafe.Config.new!(
  username: "1001062690",
  password: "B-qa2-0-...",
  environment: :test,
  account_id: "1009688230"
)

Or load from config/config.exs:

# config/config.exs
config :paysafe,
  username: System.get_env("PAYSAFE_USERNAME"),
  password: System.get_env("PAYSAFE_PASSWORD"),
  environment: :test,
  account_id: "1009688230"

# runtime:
config = Paysafe.Config.from_env!()

Quick start — card payment

config = Paysafe.Config.new!(
  username: "...",
  password: "...",
  environment: :test,
  account_id: "1009688230"
)

# 1. Create a payment handle
{:ok, handle} = Paysafe.create_payment_handle(config, %{
  merchant_ref_num: "order-669170",
  amount: 5000,
  currency_code: "USD",
  payment_type: "CARD",
  transaction_type: "PAYMENT",
  card: %{
    card_num: "4111111111111111",
    card_expiry: %{month: 12, year: 2030},
    cvv: "123",
    holder_name: "Jane Doe"
  },
  billing_details: %{
    street: "123 Main St",
    city: "New York",
    state: "NY",
    country: "US",
    zip: "10001"
  },
  settle_with_auth: true
})

# 2. Use the token in a payment
{:ok, payment} = Paysafe.create_payment(config, %{
  merchant_ref_num: "payment-001",
  amount: 5000,
  currency_code: "USD",
  settle_with_auth: true,
  payment_handle_token: handle.payment_handle_token
})

Payment method coverage

The Payments API supports 30+ payment methods:

  • Cards — Visa, Mastercard, Amex, Discover, Debit, Prepaid, Corporate.
  • Digital Wallets — Apple Pay, Google Pay, PayPal, Venmo, Skrill, Neteller.
  • Bank Transfers — iDEAL, EPS, BLIK, Interac e-Transfer, Mazooma, Pay by Bank.
  • Direct Debit — ACH (US), BACS (UK), EFT (CA), SEPA (EU).
  • Cash — PaysafeCash.
  • Vouchers — PaysafeCard, Openbucks, Multibanco.
  • LatAm — SafetyPay (Pix, Boleto, KHIPU, MACH), PagoEfectivo, Rapid Transfer.
  • Crypto — Pay with Crypto.

Architecture

  • Config validated at construction via NimbleOptions.
  • All requests have exponential backoff retry on transient failures.
  • Token-bucket rate limiting per account via ExRated.
  • Telemetry events on every request (:paysafe, :request, :start/:stop/:exception).
  • HMAC-SHA256 webhook verification with constant-time comparison.
  • All public functions return {:ok, result} | {:error, %Paysafe.Error{}}.

Summary

Functions

Cancel an authorized (pre-settlement) payment.

Create a customer profile in the vault.

Create a multi-use payment handle (saved instrument) for a customer.

Create a payment using a paymentHandleToken.

Create a payment handle (tokenize a payment instrument).

Create a recurring billing plan.

Issue a refund for a completed payment or settlement.

Create a settlement for an authorized payment.

Create a single-use customer token (SUCT), tokenizing a customer's entire saved profile (cards, addresses, bank mandates) for 900 seconds.

Create a subscription for a customer under a plan.

Create a card verification (zero-value auth check).

Delete (discontinue) a billing plan.

Retrieve a customer profile.

Retrieve a customer profile by your own merchantCustomerId.

Retrieve a payment handle by ID.

Retrieve a billing plan by ID.

Check if a PaymentHandle requires a customer redirect.

List saved payment handles for a customer.

List payments with optional filters.

List all billing plans.

Create an original credit (payout for iGaming merchants).

Parse a verified webhook body.

Re-activate a suspended subscription.

Create a standalone credit (payout for non-iGaming merchants).

Suspend a subscription (billing paused; can be re-activated).

Verify the HMAC-SHA256 signature and parse a webhook payload.

Returns the currently configured package version.

Functions

cancel_payment(config, payment_id, opts \\ [])

Cancel an authorized (pre-settlement) payment.

cancel_refund(config, refund_id, opts \\ [])

Cancel a pending refund.

cancel_settlement(config, settlement_id, opts \\ [])

Cancel a pending settlement.

cancel_subscription(config, subscription_id, opts \\ [])

Cancel a subscription.

create_customer(config, params, opts \\ [])

Create a customer profile in the vault.

create_customer_payment_handle(config, customer_id, params, opts \\ [])

Create a multi-use payment handle (saved instrument) for a customer.

create_payment(config, params, opts \\ [])

Create a payment using a paymentHandleToken.

See Paysafe.Payments.Payments.create/3 for full parameter docs.

create_payment_handle(config, params, opts \\ [])

Create a payment handle (tokenize a payment instrument).

See Paysafe.Payments.PaymentHandles.create/3 for full parameter docs.

create_plan(config, params, opts \\ [])

Create a recurring billing plan.

See Paysafe.Scheduler.Plans.create/3 for full parameter docs.

create_refund(config, settlement_id, params, opts \\ [])

Issue a refund for a completed payment or settlement.

Pass the settlement ID (or the payment ID, if settle_with_auth was true on the original payment).

create_settlement(config, payment_id, params, opts \\ [])

Create a settlement for an authorized payment.

create_single_use_customer_token(config, customer_id, opts \\ [])

Create a single-use customer token (SUCT), tokenizing a customer's entire saved profile (cards, addresses, bank mandates) for 900 seconds.

create_subscription(config, params, opts \\ [])

Create a subscription for a customer under a plan.

See Paysafe.Scheduler.Subscriptions.create/3 for full parameter docs.

create_verification(config, params, opts \\ [])

Create a card verification (zero-value auth check).

delete_customer(config, customer_id, opts \\ [])

Delete a customer profile.

delete_plan(config, plan_id, opts \\ [])

Delete (discontinue) a billing plan.

get_customer(config, customer_id, opts \\ [])

Retrieve a customer profile.

get_customer_by_merchant_customer_id(config, merchant_customer_id, opts \\ [])

Retrieve a customer profile by your own merchantCustomerId.

get_payment(config, payment_id, opts \\ [])

Retrieve a payment by ID.

get_payment_handle(config, handle_id, opts \\ [])

Retrieve a payment handle by ID.

get_plan(config, plan_id, opts \\ [])

Retrieve a billing plan by ID.

get_subscription(config, subscription_id, opts \\ [])

Retrieve a subscription by ID.

handle_action(payment_handle)

@spec handle_action(Paysafe.Types.PaymentHandle.t()) ::
  {:redirect, String.t()} | :proceed

Check if a PaymentHandle requires a customer redirect.

Returns {:redirect, url} or :proceed.

Example

{:ok, handle} = Paysafe.create_payment_handle(config, params)
case Paysafe.handle_action(handle) do
  {:redirect, url} -> redirect(conn, url)
  :proceed -> create_payment(config, payment_params)
end

list_customer_payment_handles(config, customer_id, opts \\ [])

List saved payment handles for a customer.

list_payments(config, opts \\ [])

List payments with optional filters.

list_plans(config, opts \\ [])

List all billing plans.

list_subscriptions(config, opts \\ [])

List subscriptions.

original_credit(config, params, opts \\ [])

Create an original credit (payout for iGaming merchants).

parse_webhook(raw_body)

Parse a verified webhook body.

reactivate_subscription(config, subscription_id, opts \\ [])

Re-activate a suspended subscription.

standalone_credit(config, params, opts \\ [])

Create a standalone credit (payout for non-iGaming merchants).

suspend_subscription(config, subscription_id, opts \\ [])

Suspend a subscription (billing paused; can be re-activated).

update_customer(config, customer_id, params, opts \\ [])

Update a customer profile.

update_plan(config, plan_id, params, opts \\ [])

Update a billing plan.

update_subscription(config, subscription_id, params, opts \\ [])

Update a subscription.

verify_webhook(raw_body, signature, hmac_key)

Verify the HMAC-SHA256 signature and parse a webhook payload.

See Paysafe.Webhooks.verify_and_parse/3 for full docs.

version()

@spec version() :: String.t()

Returns the currently configured package version.