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
Mar 07, 3:51 AM +10 credits credit_pack_purchase
Mar 07, 8:39 AM +10 credits subscription_credits first_cycle expires in 29 days
Mar 07, 8:39 AM +1000 credits credit_pack_purchase
Mar 07, 1:50 PM +20 credits referral_bonus referral
Mar 07, 5:53 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Mar 07, 11:15 PM +1000 credits credit_pack_purchase
Mar 07, 11:27 PM +20 credits referral_bonus referral
Mar 08, 2:54 AM +20 credits referral_bonus referral
Mar 08, 3:49 AM +1000 credits credit_pack_purchase
Mar 08, 11:24 AM +10 credits bonus expiring_bonus_credits 🗑️ expired
Mar 08, 11:42 PM +5100 credits credit_pack_purchase
Mar 09, 2:30 AM +5100 credits credit_pack_purchase
Mar 09, 8:29 AM +10 credits subscription_credits first_cycle expires in about 1 month
Mar 09, 10:34 AM +10 credits signup_bonus signup
Mar 09, 10:57 AM +10 credits subscription_credits first_cycle expires in about 1 month
Mar 09, 10:57 AM +10 credits signup_bonus signup
Mar 09, 10:58 AM +10 credits credit_pack_purchase
Mar 09, 10:58 AM +1000 credits credit_pack_purchase
Mar 09, 10:58 AM +20 credits referral_bonus referral
Mar 09, 10:59 AM +10 credits bonus expiring_bonus_credits 🗑️ expired
Mar 09, 1:23 PM +10 credits bonus expiring_bonus_credits 🗑️ expired

Payment records (pay gem)

The user has paid $595.98 total

Pay::Charge (8)
# {
                        :id => 2229,
               :customer_id => 3268,
           :subscription_id => nil,
              :processor_id => "BiCMDOvkUeE6Yx_7lKcTI",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-07 23:15:09.402770000 UTC +00:00,
                :updated_at => 2026-03-07 23:15:09.402770000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2234,
               :customer_id => 3268,
           :subscription_id => nil,
              :processor_id => "ToWPu12ufMi1MUaZSi2y7",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-09 10:58:31.781392000 UTC +00:00,
                :updated_at => 2026-03-09 10:58:31.781392000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2231,
               :customer_id => 3268,
           :subscription_id => nil,
              :processor_id => "cix-MySOtA9KSNZeZ0XPe",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-08 23:42:34.350110000 UTC +00:00,
                :updated_at => 2026-03-08 23:42:34.350110000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2230,
               :customer_id => 3268,
           :subscription_id => nil,
              :processor_id => "eouNnFETLDX7w4akDgJpT",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-08 03:49:57.938684000 UTC +00:00,
                :updated_at => 2026-03-08 03:49:57.938684000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2224,
               :customer_id => 3268,
           :subscription_id => nil,
              :processor_id => "o85SNZSlUTteFl3btnehX",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-07 03:51:43.325322000 UTC +00:00,
                :updated_at => 2026-03-07 03:51:43.325322000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2225,
               :customer_id => 3268,
           :subscription_id => nil,
              :processor_id => "qsCiXngAvBUWVbaxrHbz2",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-07 08:39:58.658178000 UTC +00:00,
                :updated_at => 2026-03-07 08:39:58.658178000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2232,
               :customer_id => 3268,
           :subscription_id => nil,
              :processor_id => "teQkbsMIe1g5g-46km2Ko",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-09 02:30:53.248282000 UTC +00:00,
                :updated_at => 2026-03-09 02:30:53.248282000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2233,
               :customer_id => 3268,
           :subscription_id => nil,
              :processor_id => "wV4rO36E0GvuxIxespcFh",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-09 10:58:06.697397000 UTC +00:00,
                :updated_at => 2026-03-09 10:58:06.697397000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (3)
# {
                         "id" => 1195,
                "customer_id" => 3268,
                       "name" => "default",
               "processor_id" => "2OWdKOFXPdHDoSHELhN71",
             "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-03-07 08:39:54.699818000 UTC +00:00,
                 "updated_at" => 2026-03-07 08:39:54.699818000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1197,
                "customer_id" => 3268,
                       "name" => "default",
               "processor_id" => "C97PuAww2isj3-maClGhV",
             "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-03-09 08:29:45.269064000 UTC +00:00,
                 "updated_at" => 2026-03-09 08:29:45.269064000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1198,
                "customer_id" => 3268,
                       "name" => "default",
               "processor_id" => "FUN2XMMoxRunV5G3Hc6OT",
             "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-03-09 10:57:11.956550000 UTC +00:00,
                 "updated_at" => 2026-03-09 10:57:11.956550000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (11)
# {
                          :id => 3418,
                   :wallet_id => 3273,
                 :source_type => "Pay::Charge",
                   :source_id => 2224,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-07 03:51:43.333834000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2224,
              "purchased_at" => "2026-03-07T03:51:43.325Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-07 03:51:43.334821000 UTC +00:00,
                  :updated_at => 2026-03-07 03:51:43.334821000 UTC +00:00
}
# {
                          :id => 3419,
                   :wallet_id => 3273,
                 :source_type => "Pay::Subscription",
                   :source_id => 1195,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-03-07 08:39:54.760814000 UTC +00:00,
         :next_fulfillment_at => 2026-04-07 08:39:54.699818000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1195,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-03-07 08:39:54.768930000 UTC +00:00,
                  :updated_at => 2026-03-07 08:39:54.768930000 UTC +00:00
}
# {
                          :id => 3420,
                   :wallet_id => 3273,
                 :source_type => "Pay::Charge",
                   :source_id => 2225,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-07 08:39:58.682321000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2225,
              "purchased_at" => "2026-03-07T08:39:58.658Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-07 08:39:58.683087000 UTC +00:00,
                  :updated_at => 2026-03-07 08:39:58.683087000 UTC +00:00
}
# {
                          :id => 3425,
                   :wallet_id => 3273,
                 :source_type => "Pay::Charge",
                   :source_id => 2229,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-07 23:15:09.413108000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2229,
              "purchased_at" => "2026-03-07T23:15:09.402Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-07 23:15:09.413660000 UTC +00:00,
                  :updated_at => 2026-03-07 23:15:09.413660000 UTC +00:00
}
# {
                          :id => 3426,
                   :wallet_id => 3273,
                 :source_type => "Pay::Charge",
                   :source_id => 2230,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-08 03:49:58.156798000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2230,
              "purchased_at" => "2026-03-08T03:49:57.938Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-08 03:49:58.177232000 UTC +00:00,
                  :updated_at => 2026-03-08 03:49:58.177232000 UTC +00:00
}
# {
                          :id => 3427,
                   :wallet_id => 3273,
                 :source_type => "Pay::Charge",
                   :source_id => 2231,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-08 23:42:34.368113000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2231,
              "purchased_at" => "2026-03-08T23:42:34.350Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-08 23:42:34.374048000 UTC +00:00,
                  :updated_at => 2026-03-08 23:42:34.374048000 UTC +00:00
}
# {
                          :id => 3428,
                   :wallet_id => 3273,
                 :source_type => "Pay::Charge",
                   :source_id => 2232,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-09 02:30:53.429189000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2232,
              "purchased_at" => "2026-03-09T02:30:53.248Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-09 02:30:53.443674000 UTC +00:00,
                  :updated_at => 2026-03-09 02:30:53.443674000 UTC +00:00
}
# {
                          :id => 3429,
                   :wallet_id => 3273,
                 :source_type => "Pay::Subscription",
                   :source_id => 1197,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-03-09 08:29:45.334602000 UTC +00:00,
         :next_fulfillment_at => 2026-04-09 08:29:45.269064000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1197,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-03-09 08:29:45.345023000 UTC +00:00,
                  :updated_at => 2026-03-09 08:29:45.345023000 UTC +00:00
}
# {
                          :id => 3430,
                   :wallet_id => 3273,
                 :source_type => "Pay::Subscription",
                   :source_id => 1198,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-03-09 10:57:11.963888000 UTC +00:00,
         :next_fulfillment_at => 2026-04-09 10:57:11.956550000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1198,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-03-09 10:57:11.964545000 UTC +00:00,
                  :updated_at => 2026-03-09 10:57:11.964545000 UTC +00:00
}
# {
                          :id => 3431,
                   :wallet_id => 3273,
                 :source_type => "Pay::Charge",
                   :source_id => 2233,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-09 10:58:06.706245000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2233,
              "purchased_at" => "2026-03-09T10:58:06.697Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-09 10:58:06.706745000 UTC +00:00,
                  :updated_at => 2026-03-09 10:58:06.706745000 UTC +00:00
}
# {
                          :id => 3432,
                   :wallet_id => 3273,
                 :source_type => "Pay::Charge",
                   :source_id => 2234,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-09 10:58:31.788953000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2234,
              "purchased_at" => "2026-03-09T10:58:31.781Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-09 10:58:31.789606000 UTC +00:00,
                  :updated_at => 2026-03-09 10:58:31.789606000 UTC +00:00
}
UsageCredits::Transaction (21)
# {
                :id => 5603,
         :wallet_id => 3273,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2224,
              "purchased_at" => "2026-03-07T03:51:43.325Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-07T03:51:43.329Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-07 03:51:43.331488000 UTC +00:00,
        :updated_at => 2026-03-07 03:51:43.331488000 UTC +00:00
}
# {
                :id => 5604,
         :wallet_id => 3273,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-04-07 08:44:54.699818000 UTC +00:00,
    :fulfillment_id => 3419,
          :metadata => {
        "subscription_id" => 1195,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-03-07T08:39:54.737Z"
    },
        :created_at => 2026-03-07 08:39:54.750770000 UTC +00:00,
        :updated_at => 2026-03-07 08:39:54.750770000 UTC +00:00
}
# {
                :id => 5605,
         :wallet_id => 3273,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2225,
              "purchased_at" => "2026-03-07T08:39:58.658Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-07T08:39:58.674Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-07 08:39:58.676349000 UTC +00:00,
        :updated_at => 2026-03-07 08:39:58.676349000 UTC +00:00
}
# {
                :id => 5606,
         :wallet_id => 3273,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-03-07 13:50:24.904077000 UTC +00:00,
        :updated_at => 2026-03-07 13:50:24.904077000 UTC +00:00
}
# {
                :id => 5614,
         :wallet_id => 3273,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-03-07 17:54:51.176469000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-03-07 17:53:51.180538000 UTC +00:00,
        :updated_at => 2026-03-07 17:53:51.180538000 UTC +00:00
}
# {
                :id => 5615,
         :wallet_id => 3273,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2229,
              "purchased_at" => "2026-03-07T23:15:09.402Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-07T23:15:09.408Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-07 23:15:09.410438000 UTC +00:00,
        :updated_at => 2026-03-07 23:15:09.410438000 UTC +00:00
}
# {
                :id => 5616,
         :wallet_id => 3273,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-03-07 23:27:23.452735000 UTC +00:00,
        :updated_at => 2026-03-07 23:27:23.452735000 UTC +00:00
}
# {
                :id => 5617,
         :wallet_id => 3273,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-03-08 02:54:12.023949000 UTC +00:00,
        :updated_at => 2026-03-08 02:54:12.023949000 UTC +00:00
}
# {
                :id => 5618,
         :wallet_id => 3273,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2230,
              "purchased_at" => "2026-03-08T03:49:57.938Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-08T03:49:58.054Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-08 03:49:58.116493000 UTC +00:00,
        :updated_at => 2026-03-08 03:49:58.116493000 UTC +00:00
}
# {
                :id => 5619,
         :wallet_id => 3273,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-03-08 11:25:46.571231000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-03-08 11:24:46.616259000 UTC +00:00,
        :updated_at => 2026-03-08 11:24:46.616259000 UTC +00:00
}
# {
                :id => 5620,
         :wallet_id => 3273,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2231,
              "purchased_at" => "2026-03-08T23:42:34.350Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-08T23:42:34.363Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-08 23:42:34.366522000 UTC +00:00,
        :updated_at => 2026-03-08 23:42:34.366522000 UTC +00:00
}
# {
                :id => 5621,
         :wallet_id => 3273,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2232,
              "purchased_at" => "2026-03-09T02:30:53.248Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-09T02:30:53.315Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-09 02:30:53.345756000 UTC +00:00,
        :updated_at => 2026-03-09 02:30:53.345756000 UTC +00:00
}
# {
                :id => 5622,
         :wallet_id => 3273,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-04-09 08:34:45.269064000 UTC +00:00,
    :fulfillment_id => 3429,
          :metadata => {
        "subscription_id" => 1197,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-03-09T08:29:45.305Z"
    },
        :created_at => 2026-03-09 08:29:45.319980000 UTC +00:00,
        :updated_at => 2026-03-09 08:29:45.319980000 UTC +00:00
}
# {
                :id => 5623,
         :wallet_id => 3273,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-03-09 10:34:42.398213000 UTC +00:00,
        :updated_at => 2026-03-09 10:34:42.398213000 UTC +00:00
}
# {
                :id => 5624,
         :wallet_id => 3273,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-04-09 11:02:11.956550000 UTC +00:00,
    :fulfillment_id => 3430,
          :metadata => {
        "subscription_id" => 1198,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-03-09T10:57:11.960Z"
    },
        :created_at => 2026-03-09 10:57:11.962039000 UTC +00:00,
        :updated_at => 2026-03-09 10:57:11.962039000 UTC +00:00
}
# {
                :id => 5625,
         :wallet_id => 3273,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-03-09 10:57:40.584067000 UTC +00:00,
        :updated_at => 2026-03-09 10:57:40.584067000 UTC +00:00
}
# {
                :id => 5626,
         :wallet_id => 3273,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2233,
              "purchased_at" => "2026-03-09T10:58:06.697Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-09T10:58:06.702Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-09 10:58:06.704557000 UTC +00:00,
        :updated_at => 2026-03-09 10:58:06.704557000 UTC +00:00
}
# {
                :id => 5627,
         :wallet_id => 3273,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2234,
              "purchased_at" => "2026-03-09T10:58:31.781Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-09T10:58:31.783Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-09 10:58:31.787214000 UTC +00:00,
        :updated_at => 2026-03-09 10:58:31.787214000 UTC +00:00
}
# {
                :id => 5628,
         :wallet_id => 3273,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-03-09 10:58:54.670782000 UTC +00:00,
        :updated_at => 2026-03-09 10:58:54.670782000 UTC +00:00
}
# {
                :id => 5629,
         :wallet_id => 3273,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-03-09 11:00:20.012287000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-03-09 10:59:20.015232000 UTC +00:00,
        :updated_at => 2026-03-09 10:59:20.015232000 UTC +00:00
}
# {
                :id => 5630,
         :wallet_id => 3273,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-03-09 13:24:53.257172000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-03-09 13:23:53.261213000 UTC +00:00,
        :updated_at => 2026-03-09 13:23:53.261213000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2224,
                  "purchased_at" => "2026-03-07T03:51:43.325Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-07T03:51:43.329Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 1] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1195,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-03-07T08:39:54.737Z"
        }
    ],
    [ 2] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2225,
                  "purchased_at" => "2026-03-07T08:39:58.658Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-07T08:39:58.674Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 3] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 4] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 5] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2229,
                  "purchased_at" => "2026-03-07T23:15:09.402Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-07T23:15:09.408Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 6] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 7] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 8] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2230,
                  "purchased_at" => "2026-03-08T03:49:57.938Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-08T03:49:58.054Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 9] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [10] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2231,
                  "purchased_at" => "2026-03-08T23:42:34.350Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-08T23:42:34.363Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [11] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2232,
                  "purchased_at" => "2026-03-09T02:30:53.248Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-09T02:30:53.315Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [12] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1197,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-03-09T08:29:45.305Z"
        }
    ],
    [13] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [14] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1198,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-03-09T10:57:11.960Z"
        }
    ],
    [15] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [16] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2233,
                  "purchased_at" => "2026-03-09T10:58:06.697Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-09T10:58:06.702Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [17] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2234,
                  "purchased_at" => "2026-03-09T10:58:31.781Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-09T10:58:31.783Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [18] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [19] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [20] [
        [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
}