usage_credits

Demo app for the 💳✨ usage_credits gem

The basics: get and spend credits

 

Subscribe to a plan: Buy credit packs: Get arbitrary bonuses: Spend credits:

Ledger status

Date Amount Category Expiration
Jan 04, 12:14 AM +10 credits subscription_credits first_cycle expires in 29 days
Jan 04, 12:14 AM +10 credits credit_pack_purchase
Jan 04, 12:14 AM +1000 credits credit_pack_purchase
Jan 04, 12:14 AM +5100 credits credit_pack_purchase
Jan 04, 12:14 AM +20 credits referral_bonus referral
Jan 04, 12:14 AM +10 credits bonus expiring_bonus_credits
Jan 04, 12:14 AM +10 credits signup_bonus signup
Jan 04, 6:22 AM +10 credits bonus expiring_bonus_credits 🗑️ expired
Jan 04, 11:50 PM +5100 credits credit_pack_purchase
Jan 05, 12:41 AM +20 credits referral_bonus referral
Jan 05, 3:46 PM +5100 credits credit_pack_purchase
Jan 05, 6:23 PM +10 credits subscription_credits first_cycle expires in about 1 month
Jan 05, 11:47 PM +10 credits bonus expiring_bonus_credits 🗑️ expired

Payment records (pay gem)

The user has paid $646.99 total

Pay::Charge (5)
# {
                        :id => 1890,
               :customer_id => 2919,
           :subscription_id => nil,
              :processor_id => "A4Y3KKEjrxAqyYd5JwMwx",
                    :amount => 19900,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "pro",
               "credits" => 5000,
         "bonus_credits" => 100,
           "price_cents" => 19900,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 1,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-01-04 23:50:45.554914000 UTC +00:00,
                :updated_at => 2026-01-04 23:50:45.554914000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 1887,
               :customer_id => 2919,
           :subscription_id => nil,
              :processor_id => "Brol8x5w_vHb52WqFmJx9",
                    :amount => 99,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "tiny",
               "credits" => 10,
         "bonus_credits" => 0,
           "price_cents" => 99,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 1,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-01-04 00:14:43.239735000 UTC +00:00,
                :updated_at => 2026-01-04 00:14:43.239735000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 1891,
               :customer_id => 2919,
           :subscription_id => nil,
              :processor_id => "c5EuO7p8OfgvUPPFriyhy",
                    :amount => 19900,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "pro",
               "credits" => 5000,
         "bonus_credits" => 100,
           "price_cents" => 19900,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 1,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-01-05 15:46:22.601408000 UTC +00:00,
                :updated_at => 2026-01-05 15:46:22.601408000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 1888,
               :customer_id => 2919,
           :subscription_id => nil,
              :processor_id => "cE3g_WNO0hq6dMUTgleK-",
                    :amount => 4900,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "starter",
               "credits" => 1000,
         "bonus_credits" => 0,
           "price_cents" => 4900,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 1,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-01-04 00:14:43.256385000 UTC +00:00,
                :updated_at => 2026-01-04 00:14:43.256385000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 1889,
               :customer_id => 2919,
           :subscription_id => nil,
              :processor_id => "lgbPaQMdQg3-q6RUiNBcD",
                    :amount => 19900,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "pro",
               "credits" => 5000,
         "bonus_credits" => 100,
           "price_cents" => 19900,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 1,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-01-04 00:14:43.277400000 UTC +00:00,
                :updated_at => 2026-01-04 00:14:43.277400000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (2)
# {
                         "id" => 1038,
                "customer_id" => 2919,
                       "name" => "default",
               "processor_id" => "Oz-oG-ldf0ArN8m3FhTue",
             "processor_plan" => "abcdef123456",
                   "quantity" => 1,
                     "status" => "active",
       "current_period_start" => nil,
         "current_period_end" => nil,
              "trial_ends_at" => nil,
                    "ends_at" => nil,
                    "metered" => nil,
             "pause_behavior" => nil,
            "pause_starts_at" => nil,
           "pause_resumes_at" => nil,
    "application_fee_percent" => nil,
                   "metadata" => {
                   "purchase_type" => "credit_subscription",
               "subscription_name" => "test_plan",
              "fulfillment_period" => "1 month",
              "credits_per_period" => 10,
            "signup_bonus_credits" => 0,
                   "trial_credits" => 0,
                "rollover_enabled" => false,
        "expire_credits_on_cancel" => false,
        "credit_expiration_period" => nil,
                        "metadata" => {}
    },
                       "data" => nil,
             "stripe_account" => nil,
          "payment_method_id" => nil,
                 "created_at" => 2026-01-04 00:14:43.220567000 UTC +00:00,
                 "updated_at" => 2026-01-04 00:14:43.220567000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1042,
                "customer_id" => 2919,
                       "name" => "default",
               "processor_id" => "TYm-m_xLk3MWkUj7u9Qok",
             "processor_plan" => "abcdef123456",
                   "quantity" => 1,
                     "status" => "active",
       "current_period_start" => nil,
         "current_period_end" => nil,
              "trial_ends_at" => nil,
                    "ends_at" => nil,
                    "metered" => nil,
             "pause_behavior" => nil,
            "pause_starts_at" => nil,
           "pause_resumes_at" => nil,
    "application_fee_percent" => nil,
                   "metadata" => {
                   "purchase_type" => "credit_subscription",
               "subscription_name" => "test_plan",
              "fulfillment_period" => "1 month",
              "credits_per_period" => 10,
            "signup_bonus_credits" => 0,
                   "trial_credits" => 0,
                "rollover_enabled" => false,
        "expire_credits_on_cancel" => false,
        "credit_expiration_period" => nil,
                        "metadata" => {}
    },
                       "data" => nil,
             "stripe_account" => nil,
          "payment_method_id" => nil,
                 "created_at" => 2026-01-05 18:23:23.609270000 UTC +00:00,
                 "updated_at" => 2026-01-05 18:23:23.609270000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (7)
# {
                          :id => 2924,
                   :wallet_id => 2924,
                 :source_type => "Pay::Subscription",
                   :source_id => 1038,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-01-04 00:14:43.228175000 UTC +00:00,
         :next_fulfillment_at => 2026-02-04 00:14:43.220567000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1038,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-01-04 00:14:43.229318000 UTC +00:00,
                  :updated_at => 2026-01-04 00:14:43.229318000 UTC +00:00
}
# {
                          :id => 2925,
                   :wallet_id => 2924,
                 :source_type => "Pay::Charge",
                   :source_id => 1887,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-01-04 00:14:43.248305000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 1887,
              "purchased_at" => "2026-01-04T00:14:43.239Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-01-04 00:14:43.249244000 UTC +00:00,
                  :updated_at => 2026-01-04 00:14:43.249244000 UTC +00:00
}
# {
                          :id => 2926,
                   :wallet_id => 2924,
                 :source_type => "Pay::Charge",
                   :source_id => 1888,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-01-04 00:14:43.267346000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 1888,
              "purchased_at" => "2026-01-04T00:14:43.256Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-01-04 00:14:43.268388000 UTC +00:00,
                  :updated_at => 2026-01-04 00:14:43.268388000 UTC +00:00
}
# {
                          :id => 2927,
                   :wallet_id => 2924,
                 :source_type => "Pay::Charge",
                   :source_id => 1889,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-01-04 00:14:43.284741000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 1889,
              "purchased_at" => "2026-01-04T00:14:43.277Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-01-04 00:14:43.285611000 UTC +00:00,
                  :updated_at => 2026-01-04 00:14:43.285611000 UTC +00:00
}
# {
                          :id => 2929,
                   :wallet_id => 2924,
                 :source_type => "Pay::Charge",
                   :source_id => 1890,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-01-04 23:50:45.567295000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 1890,
              "purchased_at" => "2026-01-04T23:50:45.554Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-01-04 23:50:45.568150000 UTC +00:00,
                  :updated_at => 2026-01-04 23:50:45.568150000 UTC +00:00
}
# {
                          :id => 2932,
                   :wallet_id => 2924,
                 :source_type => "Pay::Charge",
                   :source_id => 1891,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-01-05 15:46:22.615059000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 1891,
              "purchased_at" => "2026-01-05T15:46:22.601Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-01-05 15:46:22.616244000 UTC +00:00,
                  :updated_at => 2026-01-05 15:46:22.616244000 UTC +00:00
}
# {
                          :id => 2933,
                   :wallet_id => 2924,
                 :source_type => "Pay::Subscription",
                   :source_id => 1042,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-01-05 18:23:23.617496000 UTC +00:00,
         :next_fulfillment_at => 2026-02-05 18:23:23.609270000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1042,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-01-05 18:23:23.618304000 UTC +00:00,
                  :updated_at => 2026-01-05 18:23:23.618304000 UTC +00:00
}
UsageCredits::Transaction (13)
# {
                :id => 4815,
         :wallet_id => 2924,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-02-04 00:19:43.220567000 UTC +00:00,
    :fulfillment_id => 2924,
          :metadata => {
        "subscription_id" => 1038,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-01-04T00:14:43.223Z"
    },
        :created_at => 2026-01-04 00:14:43.225443000 UTC +00:00,
        :updated_at => 2026-01-04 00:14:43.225443000 UTC +00:00
}
# {
                :id => 4816,
         :wallet_id => 2924,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 1887,
              "purchased_at" => "2026-01-04T00:14:43.239Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-01-04T00:14:43.243Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-01-04 00:14:43.245784000 UTC +00:00,
        :updated_at => 2026-01-04 00:14:43.245784000 UTC +00:00
}
# {
                :id => 4817,
         :wallet_id => 2924,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 1888,
              "purchased_at" => "2026-01-04T00:14:43.256Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-01-04T00:14:43.262Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-01-04 00:14:43.264660000 UTC +00:00,
        :updated_at => 2026-01-04 00:14:43.264660000 UTC +00:00
}
# {
                :id => 4818,
         :wallet_id => 2924,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 1889,
              "purchased_at" => "2026-01-04T00:14:43.277Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-01-04T00:14:43.280Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-01-04 00:14:43.282391000 UTC +00:00,
        :updated_at => 2026-01-04 00:14:43.282391000 UTC +00:00
}
# {
                :id => 4819,
         :wallet_id => 2924,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-01-04 00:14:43.830955000 UTC +00:00,
        :updated_at => 2026-01-04 00:14:43.830955000 UTC +00:00
}
# {
                :id => 4820,
         :wallet_id => 2924,
            :amount => 10,
          :category => "bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-01-04 00:14:44.097956000 UTC +00:00,
        :updated_at => 2026-01-04 00:14:44.097956000 UTC +00:00
}
# {
                :id => 4821,
         :wallet_id => 2924,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-01-04 00:14:44.107598000 UTC +00:00,
        :updated_at => 2026-01-04 00:14:44.107598000 UTC +00:00
}
# {
                :id => 4822,
         :wallet_id => 2924,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-01-04 06:23:31.811294000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-01-04 06:22:31.816879000 UTC +00:00,
        :updated_at => 2026-01-04 06:22:31.816879000 UTC +00:00
}
# {
                :id => 4824,
         :wallet_id => 2924,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 1890,
              "purchased_at" => "2026-01-04T23:50:45.554Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-01-04T23:50:45.561Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-01-04 23:50:45.563798000 UTC +00:00,
        :updated_at => 2026-01-04 23:50:45.563798000 UTC +00:00
}
# {
                :id => 4825,
         :wallet_id => 2924,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-01-05 00:41:37.585808000 UTC +00:00,
        :updated_at => 2026-01-05 00:41:37.585808000 UTC +00:00
}
# {
                :id => 4828,
         :wallet_id => 2924,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 1891,
              "purchased_at" => "2026-01-05T15:46:22.601Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-01-05T15:46:22.608Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-01-05 15:46:22.611272000 UTC +00:00,
        :updated_at => 2026-01-05 15:46:22.611272000 UTC +00:00
}
# {
                :id => 4829,
         :wallet_id => 2924,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-02-05 18:28:23.609270000 UTC +00:00,
    :fulfillment_id => 2933,
          :metadata => {
        "subscription_id" => 1042,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-01-05T18:23:23.613Z"
    },
        :created_at => 2026-01-05 18:23:23.615482000 UTC +00:00,
        :updated_at => 2026-01-05 18:23:23.615482000 UTC +00:00
}
# {
                :id => 4835,
         :wallet_id => 2924,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-01-05 23:48:28.866847000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-01-05 23:47:28.871174000 UTC +00:00,
        :updated_at => 2026-01-05 23:47:28.871174000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1038,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-01-04T00:14:43.223Z"
        }
    ],
    [ 1] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 1887,
                  "purchased_at" => "2026-01-04T00:14:43.239Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-01-04T00:14:43.243Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 2] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 1888,
                  "purchased_at" => "2026-01-04T00:14:43.256Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-01-04T00:14:43.262Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 3] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 1889,
                  "purchased_at" => "2026-01-04T00:14:43.277Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-01-04T00:14:43.280Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 4] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 5] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 6] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [ 7] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 8] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 1890,
                  "purchased_at" => "2026-01-04T23:50:45.554Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-01-04T23:50:45.561Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 9] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [10] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 1891,
                  "purchased_at" => "2026-01-05T15:46:22.601Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-01-05T15:46:22.608Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [11] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1042,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-01-05T18:23:23.613Z"
        }
    ],
    [12] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ]
]

Loaded config

Literal, raw config file
      # frozen_string_literal: true

UsageCredits.configure do |config|

  # Default test operations
  operation :small_operation do
    costs 1.credit
  end

  # operation :test_operation do
  #   costs 10.credits + 1.credits_per(:mb)
  #   validate ->(params) { params[:size].to_i <= 100.megabytes }, "File too large (max: 100 MB)"
  # end

  operation :prohibitive_operation do
    costs 1_000_000.credits
  end

  operation :this_operation_will_always_fail do
    costs 42.credits
  end


  # Define test credit packs
  credit_pack :tiny do
    gives 10.credits
    costs 99.cents
  end

  credit_pack :starter do
    gives 1000.credits
    costs 49.dollars
  end

  credit_pack :pro do
    gives 5000.credits
    bonus 100.credits  # Optional: give bonus credits
    costs 199.dollars
    currency :usd
  end


  # Define subscriptions
  subscription_plan :test_plan do
    processor_plan(:fake_processor, "abcdef123456")
    gives 10.credits.every(:month)
    unused_credits :expire
  end

  # Alert when balance drops below 100 credits
  # Set to nil to disable low balance alerts
  # config.low_balance_threshold = 20.credits

  # # Handle low credit balance alerts
  # config.on_low_balance do |user|
  #   # Send notification to user when their balance drops below the threshold
  #   ApplicationMailer.generic_email(to: user.email, body: "Heads up! You're low on credits.", subject: "Low credits alert").deliver_now
  # end

end

    
Credit-consuming operations
Credit packs
Credit subscription plans
Rest of the config
      {
  "default_currency": "usd",
  "rounding_strategy": "ceil",
  "credit_formatter": {},
  "fulfillment_grace_period": 300,
  "allow_negative_balance": false,
  "low_balance_threshold": null,
  "low_balance_callback": null
}