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
Dec 03, 4:23 AM +10 credits subscription_credits first_cycle expires in about 1 month
Dec 03, 4:23 AM +5100 credits credit_pack_purchase –
Dec 03, 4:23 AM +1000 credits credit_pack_purchase –
Dec 03, 10:50 AM +1000 credits credit_pack_purchase –
Dec 03, 11:33 AM +1000 credits credit_pack_purchase –
Dec 03, 12:10 PM +1000 credits credit_pack_purchase –
Dec 03, 1:02 PM +1000 credits credit_pack_purchase –
Dec 03, 1:17 PM +10 credits subscription_credits first_cycle expires in about 1 month
Dec 03, 6:57 PM +10 credits credit_pack_purchase –

Payment records (pay gem)

The user has paid $444.99 total

Pay::Charge (7)
# {
                        :id => 4401,
               :customer_id => 6013,
           :subscription_id => nil,
              :processor_id => "2vob6Cw0-cF_L8h0ogFoN",
                    :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" => 12,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-12-03 18:57:31.811668000 UTC +00:00,
                :updated_at => 2026-12-03 18:57:31.811668000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4396,
               :customer_id => 6013,
           :subscription_id => nil,
              :processor_id => "3aYx4BlQfo5bkitDBJjql",
                    :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" => 12,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-12-03 04:23:01.564264000 UTC +00:00,
                :updated_at => 2026-12-03 04:23:01.564264000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4395,
               :customer_id => 6013,
           :subscription_id => nil,
              :processor_id => "79dDFIWNjeX6DGG9HDEhQ",
                    :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" => 12,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-12-03 04:23:01.536033000 UTC +00:00,
                :updated_at => 2026-12-03 04:23:01.536033000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4400,
               :customer_id => 6013,
           :subscription_id => nil,
              :processor_id => "LuwsUx4ryD5sTE5Qa1gJ2",
                    :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" => 12,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-12-03 13:02:46.493348000 UTC +00:00,
                :updated_at => 2026-12-03 13:02:46.493348000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4397,
               :customer_id => 6013,
           :subscription_id => nil,
              :processor_id => "Mb2e4J8dtV9-SBbzJ_J0J",
                    :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" => 12,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-12-03 10:50:35.205996000 UTC +00:00,
                :updated_at => 2026-12-03 10:50:35.205996000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4398,
               :customer_id => 6013,
           :subscription_id => nil,
              :processor_id => "tnagftd-aoeeAcwguPzZc",
                    :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" => 12,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-12-03 11:33:17.120442000 UTC +00:00,
                :updated_at => 2026-12-03 11:33:17.120442000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4399,
               :customer_id => 6013,
           :subscription_id => nil,
              :processor_id => "w0EhEz0GNQZfaGTM63RF1",
                    :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" => 12,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-12-03 12:10:16.046494000 UTC +00:00,
                :updated_at => 2026-12-03 12:10:16.046494000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (2)
# {
                         "id" => 1951,
                "customer_id" => 6013,
                       "name" => "default",
               "processor_id" => "8srAphPmOsXXQvUEafMOB",
             "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-12-03 04:23:01.444160000 UTC +00:00,
                 "updated_at" => 2026-12-03 04:23:01.444160000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1952,
                "customer_id" => 6013,
                       "name" => "default",
               "processor_id" => "M4koTjXgI_-DvXdAFGfMf",
             "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-12-03 13:17:10.164863000 UTC +00:00,
                 "updated_at" => 2026-12-03 13:17:10.164863000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (9)
# {
                          :id => 6345,
                   :wallet_id => 6021,
                 :source_type => "Pay::Subscription",
                   :source_id => 1951,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-12-03 04:23:01.447814000 UTC +00:00,
         :next_fulfillment_at => 2027-01-03 04:23:01.444160000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1951,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-12-03 04:23:01.448161000 UTC +00:00,
                  :updated_at => 2026-12-03 04:23:01.448161000 UTC +00:00
}
# {
                          :id => 6346,
                   :wallet_id => 6021,
                 :source_type => "Pay::Charge",
                   :source_id => 4395,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-12-03 04:23:01.541303000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4395,
              "purchased_at" => "2026-12-03T04:23:01.536Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-12-03 04:23:01.541633000 UTC +00:00,
                  :updated_at => 2026-12-03 04:23:01.541633000 UTC +00:00
}
# {
                          :id => 6347,
                   :wallet_id => 6021,
                 :source_type => "Pay::Charge",
                   :source_id => 4396,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-12-03 04:23:01.567460000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4396,
              "purchased_at" => "2026-12-03T04:23:01.564Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-12-03 04:23:01.567728000 UTC +00:00,
                  :updated_at => 2026-12-03 04:23:01.567728000 UTC +00:00
}
# {
                          :id => 6348,
                   :wallet_id => 6021,
                 :source_type => "Pay::Charge",
                   :source_id => 4397,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-12-03 10:50:35.210099000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4397,
              "purchased_at" => "2026-12-03T10:50:35.205Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-12-03 10:50:35.210543000 UTC +00:00,
                  :updated_at => 2026-12-03 10:50:35.210543000 UTC +00:00
}
# {
                          :id => 6349,
                   :wallet_id => 6021,
                 :source_type => "Pay::Charge",
                   :source_id => 4398,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-12-03 11:33:17.124719000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4398,
              "purchased_at" => "2026-12-03T11:33:17.120Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-12-03 11:33:17.125041000 UTC +00:00,
                  :updated_at => 2026-12-03 11:33:17.125041000 UTC +00:00
}
# {
                          :id => 6350,
                   :wallet_id => 6021,
                 :source_type => "Pay::Charge",
                   :source_id => 4399,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-12-03 12:10:16.050604000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4399,
              "purchased_at" => "2026-12-03T12:10:16.046Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-12-03 12:10:16.050915000 UTC +00:00,
                  :updated_at => 2026-12-03 12:10:16.050915000 UTC +00:00
}
# {
                          :id => 6351,
                   :wallet_id => 6021,
                 :source_type => "Pay::Charge",
                   :source_id => 4400,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-12-03 13:02:46.497843000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4400,
              "purchased_at" => "2026-12-03T13:02:46.493Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-12-03 13:02:46.498202000 UTC +00:00,
                  :updated_at => 2026-12-03 13:02:46.498202000 UTC +00:00
}
# {
                          :id => 6352,
                   :wallet_id => 6021,
                 :source_type => "Pay::Subscription",
                   :source_id => 1952,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-12-03 13:17:10.169855000 UTC +00:00,
         :next_fulfillment_at => 2027-01-03 13:17:10.164863000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1952,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-12-03 13:17:10.170344000 UTC +00:00,
                  :updated_at => 2026-12-03 13:17:10.170344000 UTC +00:00
}
# {
                          :id => 6353,
                   :wallet_id => 6021,
                 :source_type => "Pay::Charge",
                   :source_id => 4401,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-12-03 18:57:31.816243000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4401,
              "purchased_at" => "2026-12-03T18:57:31.811Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-12-03 18:57:31.816594000 UTC +00:00,
                  :updated_at => 2026-12-03 18:57:31.816594000 UTC +00:00
}
UsageCredits::Transaction (9)
# {
                :id => 10375,
         :wallet_id => 6021,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2027-01-03 04:28:01.444160000 UTC +00:00,
    :fulfillment_id => 6345,
          :metadata => {
        "subscription_id" => 1951,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-12-03T04:23:01.445Z"
    },
        :created_at => 2026-12-03 04:23:01.446408000 UTC +00:00,
        :updated_at => 2026-12-03 04:23:01.446408000 UTC +00:00
}
# {
                :id => 10376,
         :wallet_id => 6021,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4395,
              "purchased_at" => "2026-12-03T04:23:01.536Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-12-03T04:23:01.537Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-12-03 04:23:01.540031000 UTC +00:00,
        :updated_at => 2026-12-03 04:23:01.540031000 UTC +00:00
}
# {
                :id => 10377,
         :wallet_id => 6021,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4396,
              "purchased_at" => "2026-12-03T04:23:01.564Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-12-03T04:23:01.565Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-12-03 04:23:01.566287000 UTC +00:00,
        :updated_at => 2026-12-03 04:23:01.566287000 UTC +00:00
}
# {
                :id => 10378,
         :wallet_id => 6021,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4397,
              "purchased_at" => "2026-12-03T10:50:35.205Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-12-03T10:50:35.208Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-12-03 10:50:35.209003000 UTC +00:00,
        :updated_at => 2026-12-03 10:50:35.209003000 UTC +00:00
}
# {
                :id => 10379,
         :wallet_id => 6021,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4398,
              "purchased_at" => "2026-12-03T11:33:17.120Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-12-03T11:33:17.122Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-12-03 11:33:17.123716000 UTC +00:00,
        :updated_at => 2026-12-03 11:33:17.123716000 UTC +00:00
}
# {
                :id => 10380,
         :wallet_id => 6021,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4399,
              "purchased_at" => "2026-12-03T12:10:16.046Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-12-03T12:10:16.048Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-12-03 12:10:16.049624000 UTC +00:00,
        :updated_at => 2026-12-03 12:10:16.049624000 UTC +00:00
}
# {
                :id => 10381,
         :wallet_id => 6021,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4400,
              "purchased_at" => "2026-12-03T13:02:46.493Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-12-03T13:02:46.496Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-12-03 13:02:46.496877000 UTC +00:00,
        :updated_at => 2026-12-03 13:02:46.496877000 UTC +00:00
}
# {
                :id => 10382,
         :wallet_id => 6021,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2027-01-03 13:22:10.164863000 UTC +00:00,
    :fulfillment_id => 6352,
          :metadata => {
        "subscription_id" => 1952,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-12-03T13:17:10.167Z"
    },
        :created_at => 2026-12-03 13:17:10.168215000 UTC +00:00,
        :updated_at => 2026-12-03 13:17:10.168215000 UTC +00:00
}
# {
                :id => 10383,
         :wallet_id => 6021,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4401,
              "purchased_at" => "2026-12-03T18:57:31.811Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-12-03T18:57:31.814Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-12-03 18:57:31.815214000 UTC +00:00,
        :updated_at => 2026-12-03 18:57:31.815214000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [0] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1951,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-12-03T04:23:01.445Z"
        }
    ],
    [1] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 4395,
                  "purchased_at" => "2026-12-03T04:23:01.536Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-12-03T04:23:01.537Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [2] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4396,
                  "purchased_at" => "2026-12-03T04:23:01.564Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-12-03T04:23:01.565Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [3] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4397,
                  "purchased_at" => "2026-12-03T10:50:35.205Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-12-03T10:50:35.208Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [4] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4398,
                  "purchased_at" => "2026-12-03T11:33:17.120Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-12-03T11:33:17.122Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [5] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4399,
                  "purchased_at" => "2026-12-03T12:10:16.046Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-12-03T12:10:16.048Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [6] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4400,
                  "purchased_at" => "2026-12-03T13:02:46.493Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-12-03T13:02:46.496Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [7] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1952,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-12-03T13:17:10.167Z"
        }
    ],
    [8] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 4401,
                  "purchased_at" => "2026-12-03T18:57:31.811Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-12-03T18:57:31.814Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ]
]

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
}