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
Jul 27, 10:55 PM +10 credits signup_bonus signup
Jul 27, 10:56 PM +10 credits signup_bonus signup
Jul 28, 11:31 AM +10 credits subscription_credits first_cycle expires in about 1 month
Jul 28, 11:31 AM +10 credits subscription_credits first_cycle expires in about 1 month
Jul 28, 3:24 PM +10 credits credit_pack_purchase
Jul 28, 3:25 PM +1000 credits credit_pack_purchase
Jul 28, 3:25 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Jul 28, 3:26 PM +5100 credits credit_pack_purchase
Jul 28, 3:26 PM +10 credits subscription_credits first_cycle expires in about 1 month
Jul 28, 3:28 PM +20 credits referral_bonus referral
Jul 28, 3:32 PM +10 credits signup_bonus signup
Jul 28, 6:28 PM +10 credits subscription_credits first_cycle expires in about 1 month

Payment records (pay gem)

The user has paid $248.99 total

Pay::Charge (3)
# {
                        :id => 3058,
               :customer_id => 4334,
           :subscription_id => nil,
              :processor_id => "NPG13RXeq0kCuJhlG8VH8",
                    :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" => 7,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-07-28 15:24:34.443244000 UTC +00:00,
                :updated_at => 2026-07-28 15:24:34.443244000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 3060,
               :customer_id => 4334,
           :subscription_id => nil,
              :processor_id => "YaPLopFJ17WZljywFQQZC",
                    :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" => 7,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-07-28 15:26:57.969537000 UTC +00:00,
                :updated_at => 2026-07-28 15:26:57.969537000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 3059,
               :customer_id => 4334,
           :subscription_id => nil,
              :processor_id => "lO5UgphbHqNBPmndrNV2h",
                    :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" => 7,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-07-28 15:25:57.423052000 UTC +00:00,
                :updated_at => 2026-07-28 15:25:57.423052000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (4)
# {
                         "id" => 1508,
                "customer_id" => 4334,
                       "name" => "default",
               "processor_id" => "Wk0wxPFTi3aM-xWA5BQG8",
             "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-07-28 11:31:43.493600000 UTC +00:00,
                 "updated_at" => 2026-07-28 11:31:43.493600000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1509,
                "customer_id" => 4334,
                       "name" => "default",
               "processor_id" => "n1n7u11WVuyJMpgRiyCkW",
             "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-07-28 15:26:57.981259000 UTC +00:00,
                 "updated_at" => 2026-07-28 15:26:57.981259000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1510,
                "customer_id" => 4334,
                       "name" => "default",
               "processor_id" => "sMof47mf7gcD2OO1VrNAM",
             "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-07-28 18:28:16.229298000 UTC +00:00,
                 "updated_at" => 2026-07-28 18:28:16.229298000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1507,
                "customer_id" => 4334,
                       "name" => "default",
               "processor_id" => "uweTop-a-VLVwdE2jnhfD",
             "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-07-28 11:31:30.444735000 UTC +00:00,
                 "updated_at" => 2026-07-28 11:31:30.444735000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (7)
# {
                          :id => 4564,
                   :wallet_id => 4341,
                 :source_type => "Pay::Subscription",
                   :source_id => 1507,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-07-28 11:31:30.523573000 UTC +00:00,
         :next_fulfillment_at => 2026-08-28 11:31:30.444735000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1507,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-07-28 11:31:30.543129000 UTC +00:00,
                  :updated_at => 2026-07-28 11:31:30.543129000 UTC +00:00
}
# {
                          :id => 4565,
                   :wallet_id => 4341,
                 :source_type => "Pay::Subscription",
                   :source_id => 1508,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-07-28 11:31:43.512348000 UTC +00:00,
         :next_fulfillment_at => 2026-08-28 11:31:43.493600000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1508,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-07-28 11:31:43.514020000 UTC +00:00,
                  :updated_at => 2026-07-28 11:31:43.514020000 UTC +00:00
}
# {
                          :id => 4566,
                   :wallet_id => 4341,
                 :source_type => "Pay::Charge",
                   :source_id => 3058,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-07-28 15:24:34.472690000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 3058,
              "purchased_at" => "2026-07-28T15:24:34.443Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-07-28 15:24:34.476051000 UTC +00:00,
                  :updated_at => 2026-07-28 15:24:34.476051000 UTC +00:00
}
# {
                          :id => 4567,
                   :wallet_id => 4341,
                 :source_type => "Pay::Charge",
                   :source_id => 3059,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-07-28 15:25:57.430097000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 3059,
              "purchased_at" => "2026-07-28T15:25:57.423Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-07-28 15:25:57.430546000 UTC +00:00,
                  :updated_at => 2026-07-28 15:25:57.430546000 UTC +00:00
}
# {
                          :id => 4568,
                   :wallet_id => 4341,
                 :source_type => "Pay::Charge",
                   :source_id => 3060,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-07-28 15:26:57.974304000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 3060,
              "purchased_at" => "2026-07-28T15:26:57.969Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-07-28 15:26:57.975313000 UTC +00:00,
                  :updated_at => 2026-07-28 15:26:57.975313000 UTC +00:00
}
# {
                          :id => 4569,
                   :wallet_id => 4341,
                 :source_type => "Pay::Subscription",
                   :source_id => 1509,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-07-28 15:26:57.988317000 UTC +00:00,
         :next_fulfillment_at => 2026-08-28 15:26:57.981259000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1509,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-07-28 15:26:57.989458000 UTC +00:00,
                  :updated_at => 2026-07-28 15:26:57.989458000 UTC +00:00
}
# {
                          :id => 4570,
                   :wallet_id => 4341,
                 :source_type => "Pay::Subscription",
                   :source_id => 1510,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-07-28 18:28:16.292748000 UTC +00:00,
         :next_fulfillment_at => 2026-08-28 18:28:16.229298000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1510,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-07-28 18:28:16.303446000 UTC +00:00,
                  :updated_at => 2026-07-28 18:28:16.303446000 UTC +00:00
}
UsageCredits::Transaction (12)
# {
                :id => 7550,
         :wallet_id => 4341,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-07-27 22:55:52.474316000 UTC +00:00,
        :updated_at => 2026-07-27 22:55:52.474316000 UTC +00:00
}
# {
                :id => 7551,
         :wallet_id => 4341,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-07-27 22:56:04.066375000 UTC +00:00,
        :updated_at => 2026-07-27 22:56:04.066375000 UTC +00:00
}
# {
                :id => 7552,
         :wallet_id => 4341,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-08-28 11:36:30.444735000 UTC +00:00,
    :fulfillment_id => 4564,
          :metadata => {
        "subscription_id" => 1507,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-07-28T11:31:30.481Z"
    },
        :created_at => 2026-07-28 11:31:30.505287000 UTC +00:00,
        :updated_at => 2026-07-28 11:31:30.505287000 UTC +00:00
}
# {
                :id => 7553,
         :wallet_id => 4341,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-08-28 11:36:43.493600000 UTC +00:00,
    :fulfillment_id => 4565,
          :metadata => {
        "subscription_id" => 1508,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-07-28T11:31:43.499Z"
    },
        :created_at => 2026-07-28 11:31:43.505877000 UTC +00:00,
        :updated_at => 2026-07-28 11:31:43.505877000 UTC +00:00
}
# {
                :id => 7554,
         :wallet_id => 4341,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 3058,
              "purchased_at" => "2026-07-28T15:24:34.443Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-07-28T15:24:34.459Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-07-28 15:24:34.465834000 UTC +00:00,
        :updated_at => 2026-07-28 15:24:34.465834000 UTC +00:00
}
# {
                :id => 7555,
         :wallet_id => 4341,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 3059,
              "purchased_at" => "2026-07-28T15:25:57.423Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-07-28T15:25:57.427Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-07-28 15:25:57.428707000 UTC +00:00,
        :updated_at => 2026-07-28 15:25:57.428707000 UTC +00:00
}
# {
                :id => 7556,
         :wallet_id => 4341,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-07-28 15:26:57.455693000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-07-28 15:25:57.458832000 UTC +00:00,
        :updated_at => 2026-07-28 15:25:57.458832000 UTC +00:00
}
# {
                :id => 7557,
         :wallet_id => 4341,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 3060,
              "purchased_at" => "2026-07-28T15:26:57.969Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-07-28T15:26:57.971Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-07-28 15:26:57.972836000 UTC +00:00,
        :updated_at => 2026-07-28 15:26:57.972836000 UTC +00:00
}
# {
                :id => 7558,
         :wallet_id => 4341,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-08-28 15:31:57.981259000 UTC +00:00,
    :fulfillment_id => 4569,
          :metadata => {
        "subscription_id" => 1509,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-07-28T15:26:57.982Z"
    },
        :created_at => 2026-07-28 15:26:57.986809000 UTC +00:00,
        :updated_at => 2026-07-28 15:26:57.986809000 UTC +00:00
}
# {
                :id => 7559,
         :wallet_id => 4341,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-07-28 15:28:14.068348000 UTC +00:00,
        :updated_at => 2026-07-28 15:28:14.068348000 UTC +00:00
}
# {
                :id => 7560,
         :wallet_id => 4341,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-07-28 15:32:47.171858000 UTC +00:00,
        :updated_at => 2026-07-28 15:32:47.171858000 UTC +00:00
}
# {
                :id => 7561,
         :wallet_id => 4341,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-08-28 18:33:16.229298000 UTC +00:00,
    :fulfillment_id => 4570,
          :metadata => {
        "subscription_id" => 1510,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-07-28T18:28:16.263Z"
    },
        :created_at => 2026-07-28 18:28:16.278301000 UTC +00:00,
        :updated_at => 2026-07-28 18:28:16.278301000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [ 1] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [ 2] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1507,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-07-28T11:31:30.481Z"
        }
    ],
    [ 3] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1508,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-07-28T11:31:43.499Z"
        }
    ],
    [ 4] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 3058,
                  "purchased_at" => "2026-07-28T15:24:34.443Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-07-28T15:24:34.459Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 5] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 3059,
                  "purchased_at" => "2026-07-28T15:25:57.423Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-07-28T15:25:57.427Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 6] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 7] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 3060,
                  "purchased_at" => "2026-07-28T15:26:57.969Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-07-28T15:26:57.971Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 8] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1509,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-07-28T15:26:57.982Z"
        }
    ],
    [ 9] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [10] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [11] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1510,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-07-28T18:28:16.263Z"
        }
    ]
]

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
}