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
Feb 09, 9:03 AM +10 credits subscription_credits first_cycle expires in 28 days
Feb 09, 9:09 AM +10 credits subscription_credits first_cycle expires in 28 days
Feb 09, 9:11 AM +10 credits credit_pack_purchase
Feb 09, 9:16 AM +10 credits credit_pack_purchase
Feb 09, 9:17 AM +10 credits credit_pack_purchase
Feb 09, 9:18 AM +20 credits referral_bonus referral
Feb 09, 9:23 AM +5100 credits credit_pack_purchase
Feb 09, 9:25 AM +5100 credits credit_pack_purchase
Feb 09, 9:25 AM +10 credits signup_bonus signup
Feb 09, 9:28 AM +10 credits signup_bonus signup
Feb 09, 9:31 AM +10 credits bonus expiring_bonus_credits 🗑️ expired
Feb 09, 9:35 AM +10 credits bonus expiring_bonus_credits 🗑️ expired
Feb 09, 9:45 AM +1000 credits credit_pack_purchase
Feb 09, 10:10 AM +20 credits referral_bonus referral
Feb 09, 10:39 AM +10 credits bonus expiring_bonus_credits 🗑️ expired

Payment records (pay gem)

The user has paid $449.97 total

Pay::Charge (6)
# {
                        :id => 2081,
               :customer_id => 3127,
           :subscription_id => nil,
              :processor_id => "PXdS6hCM1noN30MORmWCR",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-09 09:45:18.770360000 UTC +00:00,
                :updated_at => 2026-02-09 09:45:18.770360000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2076,
               :customer_id => 3127,
           :subscription_id => nil,
              :processor_id => "U_fDwivje4-Y90h0v7Qty",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-09 09:11:51.348451000 UTC +00:00,
                :updated_at => 2026-02-09 09:11:51.348451000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2077,
               :customer_id => 3127,
           :subscription_id => nil,
              :processor_id => "Uqd9WrMJyKxeOPefyJVgk",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-09 09:16:54.827058000 UTC +00:00,
                :updated_at => 2026-02-09 09:16:54.827058000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2078,
               :customer_id => 3127,
           :subscription_id => nil,
              :processor_id => "_wChE1ejXleTxFOeFQ0S9",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-09 09:17:15.583218000 UTC +00:00,
                :updated_at => 2026-02-09 09:17:15.583218000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2079,
               :customer_id => 3127,
           :subscription_id => nil,
              :processor_id => "bi_l4Kb0umizYKR8WYBY4",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-09 09:23:16.491852000 UTC +00:00,
                :updated_at => 2026-02-09 09:23:16.491852000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2080,
               :customer_id => 3127,
           :subscription_id => nil,
              :processor_id => "p7jr_MCP5WPg6EZbAP2tn",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-09 09:25:29.342341000 UTC +00:00,
                :updated_at => 2026-02-09 09:25:29.342341000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (2)
# {
                         "id" => 1137,
                "customer_id" => 3127,
                       "name" => "default",
               "processor_id" => "00F2rMovx6mx6hBfk4JPp",
             "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-02-09 09:09:28.563835000 UTC +00:00,
                 "updated_at" => 2026-02-09 09:09:28.563835000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1136,
                "customer_id" => 3127,
                       "name" => "default",
               "processor_id" => "knBH62YBR5cxPG26JJgbK",
             "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-02-09 09:03:54.186445000 UTC +00:00,
                 "updated_at" => 2026-02-09 09:03:54.186445000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (8)
# {
                          :id => 3211,
                   :wallet_id => 3132,
                 :source_type => "Pay::Subscription",
                   :source_id => 1136,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-02-09 09:03:54.199786000 UTC +00:00,
         :next_fulfillment_at => 2026-03-09 09:03:54.186445000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1136,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-02-09 09:03:54.200806000 UTC +00:00,
                  :updated_at => 2026-02-09 09:03:54.200806000 UTC +00:00
}
# {
                          :id => 3212,
                   :wallet_id => 3132,
                 :source_type => "Pay::Subscription",
                   :source_id => 1137,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-02-09 09:09:28.575978000 UTC +00:00,
         :next_fulfillment_at => 2026-03-09 09:09:28.563835000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1137,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-02-09 09:09:28.579430000 UTC +00:00,
                  :updated_at => 2026-02-09 09:09:28.579430000 UTC +00:00
}
# {
                          :id => 3213,
                   :wallet_id => 3132,
                 :source_type => "Pay::Charge",
                   :source_id => 2076,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-09 09:11:51.357411000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2076,
              "purchased_at" => "2026-02-09T09:11:51.348Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-09 09:11:51.358033000 UTC +00:00,
                  :updated_at => 2026-02-09 09:11:51.358033000 UTC +00:00
}
# {
                          :id => 3214,
                   :wallet_id => 3132,
                 :source_type => "Pay::Charge",
                   :source_id => 2077,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-09 09:16:54.836897000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2077,
              "purchased_at" => "2026-02-09T09:16:54.827Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-09 09:16:54.839019000 UTC +00:00,
                  :updated_at => 2026-02-09 09:16:54.839019000 UTC +00:00
}
# {
                          :id => 3215,
                   :wallet_id => 3132,
                 :source_type => "Pay::Charge",
                   :source_id => 2078,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-09 09:17:15.592752000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2078,
              "purchased_at" => "2026-02-09T09:17:15.583Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-09 09:17:15.593408000 UTC +00:00,
                  :updated_at => 2026-02-09 09:17:15.593408000 UTC +00:00
}
# {
                          :id => 3216,
                   :wallet_id => 3132,
                 :source_type => "Pay::Charge",
                   :source_id => 2079,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-09 09:23:16.500393000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2079,
              "purchased_at" => "2026-02-09T09:23:16.491Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-09 09:23:16.500928000 UTC +00:00,
                  :updated_at => 2026-02-09 09:23:16.500928000 UTC +00:00
}
# {
                          :id => 3217,
                   :wallet_id => 3132,
                 :source_type => "Pay::Charge",
                   :source_id => 2080,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-09 09:25:29.351494000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2080,
              "purchased_at" => "2026-02-09T09:25:29.342Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-09 09:25:29.352029000 UTC +00:00,
                  :updated_at => 2026-02-09 09:25:29.352029000 UTC +00:00
}
# {
                          :id => 3218,
                   :wallet_id => 3132,
                 :source_type => "Pay::Charge",
                   :source_id => 2081,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-09 09:45:18.780521000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2081,
              "purchased_at" => "2026-02-09T09:45:18.770Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-09 09:45:18.781240000 UTC +00:00,
                  :updated_at => 2026-02-09 09:45:18.781240000 UTC +00:00
}
UsageCredits::Transaction (15)
# {
                :id => 5272,
         :wallet_id => 3132,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-03-09 09:08:54.186445000 UTC +00:00,
    :fulfillment_id => 3211,
          :metadata => {
        "subscription_id" => 1136,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-02-09T09:03:54.192Z"
    },
        :created_at => 2026-02-09 09:03:54.196069000 UTC +00:00,
        :updated_at => 2026-02-09 09:03:54.196069000 UTC +00:00
}
# {
                :id => 5273,
         :wallet_id => 3132,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-03-09 09:14:28.563835000 UTC +00:00,
    :fulfillment_id => 3212,
          :metadata => {
        "subscription_id" => 1137,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-02-09T09:09:28.572Z"
    },
        :created_at => 2026-02-09 09:09:28.574055000 UTC +00:00,
        :updated_at => 2026-02-09 09:09:28.574055000 UTC +00:00
}
# {
                :id => 5274,
         :wallet_id => 3132,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2076,
              "purchased_at" => "2026-02-09T09:11:51.348Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-09T09:11:51.353Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-09 09:11:51.355531000 UTC +00:00,
        :updated_at => 2026-02-09 09:11:51.355531000 UTC +00:00
}
# {
                :id => 5275,
         :wallet_id => 3132,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2077,
              "purchased_at" => "2026-02-09T09:16:54.827Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-09T09:16:54.833Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-09 09:16:54.835351000 UTC +00:00,
        :updated_at => 2026-02-09 09:16:54.835351000 UTC +00:00
}
# {
                :id => 5276,
         :wallet_id => 3132,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2078,
              "purchased_at" => "2026-02-09T09:17:15.583Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-09T09:17:15.588Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-09 09:17:15.590830000 UTC +00:00,
        :updated_at => 2026-02-09 09:17:15.590830000 UTC +00:00
}
# {
                :id => 5277,
         :wallet_id => 3132,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-02-09 09:18:48.301641000 UTC +00:00,
        :updated_at => 2026-02-09 09:18:48.301641000 UTC +00:00
}
# {
                :id => 5278,
         :wallet_id => 3132,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2079,
              "purchased_at" => "2026-02-09T09:23:16.491Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-09T09:23:16.496Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-09 09:23:16.498727000 UTC +00:00,
        :updated_at => 2026-02-09 09:23:16.498727000 UTC +00:00
}
# {
                :id => 5279,
         :wallet_id => 3132,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2080,
              "purchased_at" => "2026-02-09T09:25:29.342Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-09T09:25:29.348Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-09 09:25:29.349892000 UTC +00:00,
        :updated_at => 2026-02-09 09:25:29.349892000 UTC +00:00
}
# {
                :id => 5280,
         :wallet_id => 3132,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-02-09 09:25:53.508306000 UTC +00:00,
        :updated_at => 2026-02-09 09:25:53.508306000 UTC +00:00
}
# {
                :id => 5281,
         :wallet_id => 3132,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-02-09 09:28:44.959490000 UTC +00:00,
        :updated_at => 2026-02-09 09:28:44.959490000 UTC +00:00
}
# {
                :id => 5282,
         :wallet_id => 3132,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-02-09 09:32:33.974931000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-02-09 09:31:34.008501000 UTC +00:00,
        :updated_at => 2026-02-09 09:31:34.008501000 UTC +00:00
}
# {
                :id => 5283,
         :wallet_id => 3132,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-02-09 09:36:27.310938000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-02-09 09:35:27.341258000 UTC +00:00,
        :updated_at => 2026-02-09 09:35:27.341258000 UTC +00:00
}
# {
                :id => 5284,
         :wallet_id => 3132,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2081,
              "purchased_at" => "2026-02-09T09:45:18.770Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-09T09:45:18.775Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-09 09:45:18.776982000 UTC +00:00,
        :updated_at => 2026-02-09 09:45:18.776982000 UTC +00:00
}
# {
                :id => 5285,
         :wallet_id => 3132,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-02-09 10:10:43.377731000 UTC +00:00,
        :updated_at => 2026-02-09 10:10:43.377731000 UTC +00:00
}
# {
                :id => 5292,
         :wallet_id => 3132,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-02-09 10:40:30.304480000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-02-09 10:39:30.344109000 UTC +00:00,
        :updated_at => 2026-02-09 10:39:30.344109000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1136,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-02-09T09:03:54.192Z"
        }
    ],
    [ 1] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1137,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-02-09T09:09:28.572Z"
        }
    ],
    [ 2] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2076,
                  "purchased_at" => "2026-02-09T09:11:51.348Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-09T09:11:51.353Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 3] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2077,
                  "purchased_at" => "2026-02-09T09:16:54.827Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-09T09:16:54.833Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 4] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2078,
                  "purchased_at" => "2026-02-09T09:17:15.583Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-09T09:17:15.588Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 5] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 6] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2079,
                  "purchased_at" => "2026-02-09T09:23:16.491Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-09T09:23:16.496Z",
                 "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" => 2080,
                  "purchased_at" => "2026-02-09T09:25:29.342Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-09T09:25:29.348Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 8] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [ 9] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [10] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [11] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [12] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2081,
                  "purchased_at" => "2026-02-09T09:45:18.770Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-09T09:45:18.775Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [13] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [14] [
        [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
}