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
Nov 22, 11:18 AM +10 credits subscription_credits first_cycle expires in 30 days
Nov 22, 12:28 PM +1000 credits credit_pack_purchase –
Nov 22, 1:11 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Nov 22, 1:11 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Nov 22, 1:34 PM +10 credits credit_pack_purchase –
Nov 22, 1:49 PM +5100 credits credit_pack_purchase –
Nov 22, 1:49 PM +5100 credits credit_pack_purchase –
Nov 22, 1:49 PM +5100 credits credit_pack_purchase –
Nov 22, 2:08 PM +1000 credits credit_pack_purchase –
Nov 22, 2:08 PM +1000 credits credit_pack_purchase –
Nov 22, 4:53 PM +1000 credits credit_pack_purchase –
Nov 22, 5:08 PM +20 credits referral_bonus referral –
Nov 22, 6:31 PM +10 credits subscription_credits first_cycle expires in 30 days

Payment records (pay gem)

The user has paid $793.99 total

Pay::Charge (8)
# {
                        :id => 4250,
               :customer_id => 5892,
           :subscription_id => nil,
              :processor_id => "5NvhcN_l2H0pYM56WNp9i",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-22 12:28:32.456322000 UTC +00:00,
                :updated_at => 2026-11-22 12:28:32.456322000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4257,
               :customer_id => 5892,
           :subscription_id => nil,
              :processor_id => "L4_dISR4EQJT-wPE9uPIW",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-22 16:53:22.306253000 UTC +00:00,
                :updated_at => 2026-11-22 16:53:22.306253000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4254,
               :customer_id => 5892,
           :subscription_id => nil,
              :processor_id => "LJazOFDpLsePUMSeKaR4x",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-22 13:49:56.871838000 UTC +00:00,
                :updated_at => 2026-11-22 13:49:56.871838000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4252,
               :customer_id => 5892,
           :subscription_id => nil,
              :processor_id => "NgQH3EQ9RdVmBUPJSOtUZ",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-22 13:49:18.952903000 UTC +00:00,
                :updated_at => 2026-11-22 13:49:18.952903000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4251,
               :customer_id => 5892,
           :subscription_id => nil,
              :processor_id => "Z-fHhdsNpe5_MPQ9B5az5",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-22 13:34:37.605106000 UTC +00:00,
                :updated_at => 2026-11-22 13:34:37.605106000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4255,
               :customer_id => 5892,
           :subscription_id => nil,
              :processor_id => "fuNH0CDfPptIROPcT123w",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-22 14:08:52.412567000 UTC +00:00,
                :updated_at => 2026-11-22 14:08:52.412567000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4253,
               :customer_id => 5892,
           :subscription_id => nil,
              :processor_id => "pA5zRyPnGrhBer4xQH3aY",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-22 13:49:39.127614000 UTC +00:00,
                :updated_at => 2026-11-22 13:49:39.127614000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4256,
               :customer_id => 5892,
           :subscription_id => nil,
              :processor_id => "sUol6qyWN3WgpQP5JJAjS",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-22 14:08:59.665328000 UTC +00:00,
                :updated_at => 2026-11-22 14:08:59.665328000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (2)
# {
                         "id" => 1895,
                "customer_id" => 5892,
                       "name" => "default",
               "processor_id" => "8ooFPYMDd6uE4_SHfZInk",
             "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-11-22 18:31:05.685627000 UTC +00:00,
                 "updated_at" => 2026-11-22 18:31:05.685627000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1893,
                "customer_id" => 5892,
                       "name" => "default",
               "processor_id" => "IyQVIyAM4eJyfPCmo55KV",
             "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-11-22 11:18:48.580444000 UTC +00:00,
                 "updated_at" => 2026-11-22 11:18:48.580444000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (10)
# {
                          :id => 6142,
                   :wallet_id => 5900,
                 :source_type => "Pay::Subscription",
                   :source_id => 1893,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-11-22 11:18:48.584041000 UTC +00:00,
         :next_fulfillment_at => 2026-12-22 11:18:48.580444000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1893,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-11-22 11:18:48.584573000 UTC +00:00,
                  :updated_at => 2026-11-22 11:18:48.584573000 UTC +00:00
}
# {
                          :id => 6143,
                   :wallet_id => 5900,
                 :source_type => "Pay::Charge",
                   :source_id => 4250,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-22 12:28:32.460582000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4250,
              "purchased_at" => "2026-11-22T12:28:32.456Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-22 12:28:32.460962000 UTC +00:00,
                  :updated_at => 2026-11-22 12:28:32.460962000 UTC +00:00
}
# {
                          :id => 6144,
                   :wallet_id => 5900,
                 :source_type => "Pay::Charge",
                   :source_id => 4251,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-22 13:34:37.610960000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4251,
              "purchased_at" => "2026-11-22T13:34:37.605Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-22 13:34:37.611401000 UTC +00:00,
                  :updated_at => 2026-11-22 13:34:37.611401000 UTC +00:00
}
# {
                          :id => 6145,
                   :wallet_id => 5900,
                 :source_type => "Pay::Charge",
                   :source_id => 4252,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-22 13:49:18.957466000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4252,
              "purchased_at" => "2026-11-22T13:49:18.952Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-22 13:49:18.957804000 UTC +00:00,
                  :updated_at => 2026-11-22 13:49:18.957804000 UTC +00:00
}
# {
                          :id => 6146,
                   :wallet_id => 5900,
                 :source_type => "Pay::Charge",
                   :source_id => 4253,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-22 13:49:39.131105000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4253,
              "purchased_at" => "2026-11-22T13:49:39.127Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-22 13:49:39.131441000 UTC +00:00,
                  :updated_at => 2026-11-22 13:49:39.131441000 UTC +00:00
}
# {
                          :id => 6147,
                   :wallet_id => 5900,
                 :source_type => "Pay::Charge",
                   :source_id => 4254,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-22 13:49:56.876034000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4254,
              "purchased_at" => "2026-11-22T13:49:56.871Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-22 13:49:56.876380000 UTC +00:00,
                  :updated_at => 2026-11-22 13:49:56.876380000 UTC +00:00
}
# {
                          :id => 6148,
                   :wallet_id => 5900,
                 :source_type => "Pay::Charge",
                   :source_id => 4255,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-22 14:08:52.417084000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4255,
              "purchased_at" => "2026-11-22T14:08:52.412Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-22 14:08:52.417414000 UTC +00:00,
                  :updated_at => 2026-11-22 14:08:52.417414000 UTC +00:00
}
# {
                          :id => 6149,
                   :wallet_id => 5900,
                 :source_type => "Pay::Charge",
                   :source_id => 4256,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-22 14:08:59.669168000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4256,
              "purchased_at" => "2026-11-22T14:08:59.665Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-22 14:08:59.669505000 UTC +00:00,
                  :updated_at => 2026-11-22 14:08:59.669505000 UTC +00:00
}
# {
                          :id => 6150,
                   :wallet_id => 5900,
                 :source_type => "Pay::Charge",
                   :source_id => 4257,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-22 16:53:22.310245000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4257,
              "purchased_at" => "2026-11-22T16:53:22.306Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-22 16:53:22.310577000 UTC +00:00,
                  :updated_at => 2026-11-22 16:53:22.310577000 UTC +00:00
}
# {
                          :id => 6155,
                   :wallet_id => 5900,
                 :source_type => "Pay::Subscription",
                   :source_id => 1895,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-11-22 18:31:05.688814000 UTC +00:00,
         :next_fulfillment_at => 2026-12-22 18:31:05.685627000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1895,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-11-22 18:31:05.689269000 UTC +00:00,
                  :updated_at => 2026-11-22 18:31:05.689269000 UTC +00:00
}
UsageCredits::Transaction (13)
# {
                :id => 10042,
         :wallet_id => 5900,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-12-22 11:23:48.580444000 UTC +00:00,
    :fulfillment_id => 6142,
          :metadata => {
        "subscription_id" => 1893,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-11-22T11:18:48.581Z"
    },
        :created_at => 2026-11-22 11:18:48.582684000 UTC +00:00,
        :updated_at => 2026-11-22 11:18:48.582684000 UTC +00:00
}
# {
                :id => 10043,
         :wallet_id => 5900,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4250,
              "purchased_at" => "2026-11-22T12:28:32.456Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-22T12:28:32.458Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-22 12:28:32.459543000 UTC +00:00,
        :updated_at => 2026-11-22 12:28:32.459543000 UTC +00:00
}
# {
                :id => 10044,
         :wallet_id => 5900,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-11-22 13:12:05.835296000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-11-22 13:11:05.839488000 UTC +00:00,
        :updated_at => 2026-11-22 13:11:05.839488000 UTC +00:00
}
# {
                :id => 10045,
         :wallet_id => 5900,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-11-22 13:12:29.798232000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-11-22 13:11:29.800870000 UTC +00:00,
        :updated_at => 2026-11-22 13:11:29.800870000 UTC +00:00
}
# {
                :id => 10046,
         :wallet_id => 5900,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4251,
              "purchased_at" => "2026-11-22T13:34:37.605Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-22T13:34:37.608Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-22 13:34:37.609619000 UTC +00:00,
        :updated_at => 2026-11-22 13:34:37.609619000 UTC +00:00
}
# {
                :id => 10047,
         :wallet_id => 5900,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4252,
              "purchased_at" => "2026-11-22T13:49:18.952Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-22T13:49:18.955Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-22 13:49:18.956450000 UTC +00:00,
        :updated_at => 2026-11-22 13:49:18.956450000 UTC +00:00
}
# {
                :id => 10048,
         :wallet_id => 5900,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4253,
              "purchased_at" => "2026-11-22T13:49:39.127Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-22T13:49:39.129Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-22 13:49:39.130103000 UTC +00:00,
        :updated_at => 2026-11-22 13:49:39.130103000 UTC +00:00
}
# {
                :id => 10049,
         :wallet_id => 5900,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4254,
              "purchased_at" => "2026-11-22T13:49:56.871Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-22T13:49:56.873Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-22 13:49:56.874528000 UTC +00:00,
        :updated_at => 2026-11-22 13:49:56.874528000 UTC +00:00
}
# {
                :id => 10050,
         :wallet_id => 5900,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4255,
              "purchased_at" => "2026-11-22T14:08:52.412Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-22T14:08:52.415Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-22 14:08:52.416086000 UTC +00:00,
        :updated_at => 2026-11-22 14:08:52.416086000 UTC +00:00
}
# {
                :id => 10051,
         :wallet_id => 5900,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4256,
              "purchased_at" => "2026-11-22T14:08:59.665Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-22T14:08:59.667Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-22 14:08:59.668113000 UTC +00:00,
        :updated_at => 2026-11-22 14:08:59.668113000 UTC +00:00
}
# {
                :id => 10052,
         :wallet_id => 5900,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4257,
              "purchased_at" => "2026-11-22T16:53:22.306Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-22T16:53:22.308Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-22 16:53:22.309297000 UTC +00:00,
        :updated_at => 2026-11-22 16:53:22.309297000 UTC +00:00
}
# {
                :id => 10053,
         :wallet_id => 5900,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-11-22 17:08:10.622421000 UTC +00:00,
        :updated_at => 2026-11-22 17:08:10.622421000 UTC +00:00
}
# {
                :id => 10061,
         :wallet_id => 5900,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-12-22 18:36:05.685627000 UTC +00:00,
    :fulfillment_id => 6155,
          :metadata => {
        "subscription_id" => 1895,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-11-22T18:31:05.686Z"
    },
        :created_at => 2026-11-22 18:31:05.687828000 UTC +00:00,
        :updated_at => 2026-11-22 18:31:05.687828000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1893,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-11-22T11:18:48.581Z"
        }
    ],
    [ 1] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4250,
                  "purchased_at" => "2026-11-22T12:28:32.456Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-22T12:28:32.458Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 2] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 3] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 4] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 4251,
                  "purchased_at" => "2026-11-22T13:34:37.605Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-22T13:34:37.608Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 5] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 4252,
                  "purchased_at" => "2026-11-22T13:49:18.952Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-22T13:49:18.955Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 6] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 4253,
                  "purchased_at" => "2026-11-22T13:49:39.127Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-22T13:49:39.129Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 7] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 4254,
                  "purchased_at" => "2026-11-22T13:49:56.871Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-22T13:49:56.873Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 8] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4255,
                  "purchased_at" => "2026-11-22T14:08:52.412Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-22T14:08:52.415Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 9] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4256,
                  "purchased_at" => "2026-11-22T14:08:59.665Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-22T14:08:59.667Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [10] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4257,
                  "purchased_at" => "2026-11-22T16:53:22.306Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-22T16:53:22.308Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [11] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [12] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1895,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-11-22T18:31:05.686Z"
        }
    ]
]

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
}