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
Apr 25, 5:54 PM +10 credits subscription_credits first_cycle expires in 30 days
Apr 25, 5:54 PM +10 credits signup_bonus signup
Apr 25, 5:54 PM +10 credits credit_pack_purchase
Apr 25, 5:55 PM +1000 credits credit_pack_purchase
Apr 25, 5:55 PM +5100 credits credit_pack_purchase
Apr 25, 5:55 PM +20 credits referral_bonus referral
Apr 25, 5:55 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Apr 25, 8:02 PM +10 credits credit_pack_purchase
Apr 25, 8:04 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Apr 25, 10:31 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Apr 25, 10:32 PM +10 credits signup_bonus signup
Apr 25, 10:32 PM +20 credits referral_bonus referral
Apr 25, 10:33 PM +5100 credits credit_pack_purchase
Apr 25, 10:33 PM +1000 credits credit_pack_purchase
Apr 25, 10:34 PM +10 credits subscription_credits first_cycle expires in 30 days

Payment records (pay gem)

The user has paid $497.98 total

Pay::Charge (6)
# {
                        :id => 2494,
               :customer_id => 3622,
           :subscription_id => nil,
              :processor_id => "5KfTTxQNeqT6RQnm3pqci",
                    :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" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-25 17:54:43.533551000 UTC +00:00,
                :updated_at => 2026-04-25 17:54:43.533551000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2498,
               :customer_id => 3622,
           :subscription_id => nil,
              :processor_id => "DSmeYfnfmsm-PjChMhsGg",
                    :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" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-25 22:33:42.152030000 UTC +00:00,
                :updated_at => 2026-04-25 22:33:42.152030000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2497,
               :customer_id => 3622,
           :subscription_id => nil,
              :processor_id => "al2B4DP_PNRO_Z2JQpBSh",
                    :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" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-25 20:02:53.473838000 UTC +00:00,
                :updated_at => 2026-04-25 20:02:53.473838000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2495,
               :customer_id => 3622,
           :subscription_id => nil,
              :processor_id => "blmkxn0D1pX__f-kNL3Wq",
                    :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" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-25 17:55:05.338060000 UTC +00:00,
                :updated_at => 2026-04-25 17:55:05.338060000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2499,
               :customer_id => 3622,
           :subscription_id => nil,
              :processor_id => "gfwjx7OzL0dTMZdrXis6G",
                    :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" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-25 22:33:52.355696000 UTC +00:00,
                :updated_at => 2026-04-25 22:33:52.355696000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2496,
               :customer_id => 3622,
           :subscription_id => nil,
              :processor_id => "kBxCw1rWKFZdVGqMWnqYM",
                    :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" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-25 17:55:38.606854000 UTC +00:00,
                :updated_at => 2026-04-25 17:55:38.606854000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (2)
# {
                         "id" => 1300,
                "customer_id" => 3622,
                       "name" => "default",
               "processor_id" => "o_G2ZbKGwk3Z1ZEKBlhut",
             "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-04-25 22:34:07.845267000 UTC +00:00,
                 "updated_at" => 2026-04-25 22:34:07.845267000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1299,
                "customer_id" => 3622,
                       "name" => "default",
               "processor_id" => "qqTweIia6hFDKNhsFxkYy",
             "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-04-25 17:54:26.932043000 UTC +00:00,
                 "updated_at" => 2026-04-25 17:54:26.932043000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (8)
# {
                          :id => 3792,
                   :wallet_id => 3628,
                 :source_type => "Pay::Subscription",
                   :source_id => 1299,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-04-25 17:54:26.937773000 UTC +00:00,
         :next_fulfillment_at => 2026-05-25 17:54:26.932043000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1299,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-04-25 17:54:26.938413000 UTC +00:00,
                  :updated_at => 2026-04-25 17:54:26.938413000 UTC +00:00
}
# {
                          :id => 3793,
                   :wallet_id => 3628,
                 :source_type => "Pay::Charge",
                   :source_id => 2494,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-25 17:54:43.538961000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2494,
              "purchased_at" => "2026-04-25T17:54:43.533Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-25 17:54:43.539553000 UTC +00:00,
                  :updated_at => 2026-04-25 17:54:43.539553000 UTC +00:00
}
# {
                          :id => 3794,
                   :wallet_id => 3628,
                 :source_type => "Pay::Charge",
                   :source_id => 2495,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-25 17:55:05.347146000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2495,
              "purchased_at" => "2026-04-25T17:55:05.338Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-25 17:55:05.348024000 UTC +00:00,
                  :updated_at => 2026-04-25 17:55:05.348024000 UTC +00:00
}
# {
                          :id => 3795,
                   :wallet_id => 3628,
                 :source_type => "Pay::Charge",
                   :source_id => 2496,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-25 17:55:38.618555000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2496,
              "purchased_at" => "2026-04-25T17:55:38.606Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-25 17:55:38.619504000 UTC +00:00,
                  :updated_at => 2026-04-25 17:55:38.619504000 UTC +00:00
}
# {
                          :id => 3796,
                   :wallet_id => 3628,
                 :source_type => "Pay::Charge",
                   :source_id => 2497,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-25 20:02:53.484766000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2497,
              "purchased_at" => "2026-04-25T20:02:53.473Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-25 20:02:53.485286000 UTC +00:00,
                  :updated_at => 2026-04-25 20:02:53.485286000 UTC +00:00
}
# {
                          :id => 3797,
                   :wallet_id => 3628,
                 :source_type => "Pay::Charge",
                   :source_id => 2498,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-25 22:33:42.159156000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2498,
              "purchased_at" => "2026-04-25T22:33:42.152Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-25 22:33:42.159696000 UTC +00:00,
                  :updated_at => 2026-04-25 22:33:42.159696000 UTC +00:00
}
# {
                          :id => 3798,
                   :wallet_id => 3628,
                 :source_type => "Pay::Charge",
                   :source_id => 2499,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-25 22:33:52.361407000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2499,
              "purchased_at" => "2026-04-25T22:33:52.355Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-25 22:33:52.361910000 UTC +00:00,
                  :updated_at => 2026-04-25 22:33:52.361910000 UTC +00:00
}
# {
                          :id => 3799,
                   :wallet_id => 3628,
                 :source_type => "Pay::Subscription",
                   :source_id => 1300,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-04-25 22:34:07.850888000 UTC +00:00,
         :next_fulfillment_at => 2026-05-25 22:34:07.845267000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1300,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-04-25 22:34:07.851779000 UTC +00:00,
                  :updated_at => 2026-04-25 22:34:07.851779000 UTC +00:00
}
UsageCredits::Transaction (15)
# {
                :id => 6246,
         :wallet_id => 3628,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-05-25 17:59:26.932043000 UTC +00:00,
    :fulfillment_id => 3792,
          :metadata => {
        "subscription_id" => 1299,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-04-25T17:54:26.934Z"
    },
        :created_at => 2026-04-25 17:54:26.935541000 UTC +00:00,
        :updated_at => 2026-04-25 17:54:26.935541000 UTC +00:00
}
# {
                :id => 6247,
         :wallet_id => 3628,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-04-25 17:54:28.507797000 UTC +00:00,
        :updated_at => 2026-04-25 17:54:28.507797000 UTC +00:00
}
# {
                :id => 6248,
         :wallet_id => 3628,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2494,
              "purchased_at" => "2026-04-25T17:54:43.533Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-25T17:54:43.536Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-25 17:54:43.537307000 UTC +00:00,
        :updated_at => 2026-04-25 17:54:43.537307000 UTC +00:00
}
# {
                :id => 6249,
         :wallet_id => 3628,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2495,
              "purchased_at" => "2026-04-25T17:55:05.338Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-25T17:55:05.342Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-25 17:55:05.344421000 UTC +00:00,
        :updated_at => 2026-04-25 17:55:05.344421000 UTC +00:00
}
# {
                :id => 6250,
         :wallet_id => 3628,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2496,
              "purchased_at" => "2026-04-25T17:55:38.606Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-25T17:55:38.609Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-25 17:55:38.615120000 UTC +00:00,
        :updated_at => 2026-04-25 17:55:38.615120000 UTC +00:00
}
# {
                :id => 6251,
         :wallet_id => 3628,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-04-25 17:55:41.751098000 UTC +00:00,
        :updated_at => 2026-04-25 17:55:41.751098000 UTC +00:00
}
# {
                :id => 6252,
         :wallet_id => 3628,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-04-25 17:56:56.503887000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-04-25 17:55:56.510891000 UTC +00:00,
        :updated_at => 2026-04-25 17:55:56.510891000 UTC +00:00
}
# {
                :id => 6253,
         :wallet_id => 3628,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2497,
              "purchased_at" => "2026-04-25T20:02:53.473Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-25T20:02:53.481Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-25 20:02:53.483191000 UTC +00:00,
        :updated_at => 2026-04-25 20:02:53.483191000 UTC +00:00
}
# {
                :id => 6254,
         :wallet_id => 3628,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-04-25 20:05:17.062555000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-04-25 20:04:17.066666000 UTC +00:00,
        :updated_at => 2026-04-25 20:04:17.066666000 UTC +00:00
}
# {
                :id => 6255,
         :wallet_id => 3628,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-04-25 22:32:53.876890000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-04-25 22:31:53.881023000 UTC +00:00,
        :updated_at => 2026-04-25 22:31:53.881023000 UTC +00:00
}
# {
                :id => 6256,
         :wallet_id => 3628,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-04-25 22:32:11.371364000 UTC +00:00,
        :updated_at => 2026-04-25 22:32:11.371364000 UTC +00:00
}
# {
                :id => 6257,
         :wallet_id => 3628,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-04-25 22:32:28.043402000 UTC +00:00,
        :updated_at => 2026-04-25 22:32:28.043402000 UTC +00:00
}
# {
                :id => 6258,
         :wallet_id => 3628,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2498,
              "purchased_at" => "2026-04-25T22:33:42.152Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-25T22:33:42.155Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-25 22:33:42.156939000 UTC +00:00,
        :updated_at => 2026-04-25 22:33:42.156939000 UTC +00:00
}
# {
                :id => 6259,
         :wallet_id => 3628,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2499,
              "purchased_at" => "2026-04-25T22:33:52.355Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-25T22:33:52.358Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-25 22:33:52.359835000 UTC +00:00,
        :updated_at => 2026-04-25 22:33:52.359835000 UTC +00:00
}
# {
                :id => 6260,
         :wallet_id => 3628,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-05-25 22:39:07.845267000 UTC +00:00,
    :fulfillment_id => 3799,
          :metadata => {
        "subscription_id" => 1300,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-04-25T22:34:07.847Z"
    },
        :created_at => 2026-04-25 22:34:07.848353000 UTC +00:00,
        :updated_at => 2026-04-25 22:34:07.848353000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1299,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-04-25T17:54:26.934Z"
        }
    ],
    [ 1] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [ 2] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2494,
                  "purchased_at" => "2026-04-25T17:54:43.533Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-25T17:54:43.536Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 3] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2495,
                  "purchased_at" => "2026-04-25T17:55:05.338Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-25T17:55:05.342Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 4] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2496,
                  "purchased_at" => "2026-04-25T17:55:38.606Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-25T17:55:38.609Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 5] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 6] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 7] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2497,
                  "purchased_at" => "2026-04-25T20:02:53.473Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-25T20:02:53.481Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 8] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 9] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [10] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [11] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [12] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2498,
                  "purchased_at" => "2026-04-25T22:33:42.152Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-25T22:33:42.155Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [13] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2499,
                  "purchased_at" => "2026-04-25T22:33:52.355Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-25T22:33:52.358Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [14] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1300,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-04-25T22:34:07.847Z"
        }
    ]
]

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
}