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
May 17, 4:41 PM +10 credits signup_bonus signup
May 17, 4:41 PM +5100 credits credit_pack_purchase
May 17, 4:41 PM +10 credits subscription_credits first_cycle expires in about 1 month
May 17, 4:41 PM +10 credits credit_pack_purchase
May 17, 4:41 PM +1000 credits credit_pack_purchase
May 17, 4:41 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
May 17, 4:41 PM +20 credits referral_bonus referral
May 17, 4:41 PM +20 credits referral_bonus referral
May 17, 4:41 PM +10 credits subscription_credits first_cycle expires in about 1 month
May 17, 4:41 PM +10 credits credit_pack_purchase
May 17, 4:41 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
May 17, 4:41 PM +1000 credits credit_pack_purchase
May 18, 1:07 AM +10 credits signup_bonus signup

Payment records (pay gem)

The user has paid $298.98 total

Pay::Charge (5)
# {
                        :id => 2635,
               :customer_id => 3828,
           :subscription_id => nil,
              :processor_id => "FRfTvv3r2MzlEDHndU7Y0",
                    :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" => 5,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-05-17 16:41:20.249425000 UTC +00:00,
                :updated_at => 2026-05-17 16:41:20.249425000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2632,
               :customer_id => 3828,
           :subscription_id => nil,
              :processor_id => "W1OXu4H8Rws3Lz7soCqbd",
                    :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" => 5,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-05-17 16:41:10.942802000 UTC +00:00,
                :updated_at => 2026-05-17 16:41:10.942802000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2633,
               :customer_id => 3828,
           :subscription_id => nil,
              :processor_id => "WT4FLNMgKK_CnxTE1D3Mt",
                    :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" => 5,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-05-17 16:41:13.551084000 UTC +00:00,
                :updated_at => 2026-05-17 16:41:13.551084000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2636,
               :customer_id => 3828,
           :subscription_id => nil,
              :processor_id => "nVXDl3PxqguypRFOr8S4R",
                    :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" => 5,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-05-17 16:41:20.286450000 UTC +00:00,
                :updated_at => 2026-05-17 16:41:20.286450000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2634,
               :customer_id => 3828,
           :subscription_id => nil,
              :processor_id => "xeYzRvu0LzbIZ6X0MPCFY",
                    :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" => 5,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-05-17 16:41:13.788781000 UTC +00:00,
                :updated_at => 2026-05-17 16:41:13.788781000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (2)
# {
                         "id" => 1353,
                "customer_id" => 3828,
                       "name" => "default",
               "processor_id" => "GB3Scz3SwfpmN9r1guQiV",
             "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-05-17 16:41:13.535289000 UTC +00:00,
                 "updated_at" => 2026-05-17 16:41:13.535289000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1354,
                "customer_id" => 3828,
                       "name" => "default",
               "processor_id" => "q1cYzA7C5-QnOf6P3QyT4",
             "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-05-17 16:41:20.217015000 UTC +00:00,
                 "updated_at" => 2026-05-17 16:41:20.217015000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (7)
# {
                          :id => 3984,
                   :wallet_id => 3834,
                 :source_type => "Pay::Charge",
                   :source_id => 2632,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-05-17 16:41:10.948120000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2632,
              "purchased_at" => "2026-05-17T16:41:10.942Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-05-17 16:41:10.948574000 UTC +00:00,
                  :updated_at => 2026-05-17 16:41:10.948574000 UTC +00:00
}
# {
                          :id => 3985,
                   :wallet_id => 3834,
                 :source_type => "Pay::Subscription",
                   :source_id => 1353,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-05-17 16:41:13.540672000 UTC +00:00,
         :next_fulfillment_at => 2026-06-17 16:41:13.535289000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1353,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-05-17 16:41:13.541355000 UTC +00:00,
                  :updated_at => 2026-05-17 16:41:13.541355000 UTC +00:00
}
# {
                          :id => 3986,
                   :wallet_id => 3834,
                 :source_type => "Pay::Charge",
                   :source_id => 2633,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-05-17 16:41:13.556431000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2633,
              "purchased_at" => "2026-05-17T16:41:13.551Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-05-17 16:41:13.556905000 UTC +00:00,
                  :updated_at => 2026-05-17 16:41:13.556905000 UTC +00:00
}
# {
                          :id => 3987,
                   :wallet_id => 3834,
                 :source_type => "Pay::Charge",
                   :source_id => 2634,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-05-17 16:41:13.793667000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2634,
              "purchased_at" => "2026-05-17T16:41:13.788Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-05-17 16:41:13.794137000 UTC +00:00,
                  :updated_at => 2026-05-17 16:41:13.794137000 UTC +00:00
}
# {
                          :id => 3988,
                   :wallet_id => 3834,
                 :source_type => "Pay::Subscription",
                   :source_id => 1354,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-05-17 16:41:20.221778000 UTC +00:00,
         :next_fulfillment_at => 2026-06-17 16:41:20.217015000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1354,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-05-17 16:41:20.222435000 UTC +00:00,
                  :updated_at => 2026-05-17 16:41:20.222435000 UTC +00:00
}
# {
                          :id => 3989,
                   :wallet_id => 3834,
                 :source_type => "Pay::Charge",
                   :source_id => 2635,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-05-17 16:41:20.255107000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2635,
              "purchased_at" => "2026-05-17T16:41:20.249Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-05-17 16:41:20.255729000 UTC +00:00,
                  :updated_at => 2026-05-17 16:41:20.255729000 UTC +00:00
}
# {
                          :id => 3990,
                   :wallet_id => 3834,
                 :source_type => "Pay::Charge",
                   :source_id => 2636,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-05-17 16:41:20.294242000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2636,
              "purchased_at" => "2026-05-17T16:41:20.286Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-05-17 16:41:20.294920000 UTC +00:00,
                  :updated_at => 2026-05-17 16:41:20.294920000 UTC +00:00
}
UsageCredits::Transaction (13)
# {
                :id => 6569,
         :wallet_id => 3834,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-05-17 16:41:10.911463000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:10.911463000 UTC +00:00
}
# {
                :id => 6570,
         :wallet_id => 3834,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2632,
              "purchased_at" => "2026-05-17T16:41:10.942Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-05-17T16:41:10.944Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-05-17 16:41:10.946551000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:10.946551000 UTC +00:00
}
# {
                :id => 6571,
         :wallet_id => 3834,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-06-17 16:46:13.535289000 UTC +00:00,
    :fulfillment_id => 3985,
          :metadata => {
        "subscription_id" => 1353,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-05-17T16:41:13.537Z"
    },
        :created_at => 2026-05-17 16:41:13.538792000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:13.538792000 UTC +00:00
}
# {
                :id => 6572,
         :wallet_id => 3834,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2633,
              "purchased_at" => "2026-05-17T16:41:13.551Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-05-17T16:41:13.553Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-05-17 16:41:13.554996000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:13.554996000 UTC +00:00
}
# {
                :id => 6573,
         :wallet_id => 3834,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2634,
              "purchased_at" => "2026-05-17T16:41:13.788Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-05-17T16:41:13.791Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-05-17 16:41:13.792148000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:13.792148000 UTC +00:00
}
# {
                :id => 6574,
         :wallet_id => 3834,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-05-17 16:42:13.796671000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-05-17 16:41:13.799225000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:13.799225000 UTC +00:00
}
# {
                :id => 6575,
         :wallet_id => 3834,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-05-17 16:41:13.811280000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:13.811280000 UTC +00:00
}
# {
                :id => 6576,
         :wallet_id => 3834,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-05-17 16:41:20.209240000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:20.209240000 UTC +00:00
}
# {
                :id => 6577,
         :wallet_id => 3834,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-06-17 16:46:20.217015000 UTC +00:00,
    :fulfillment_id => 3988,
          :metadata => {
        "subscription_id" => 1354,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-05-17T16:41:20.218Z"
    },
        :created_at => 2026-05-17 16:41:20.220048000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:20.220048000 UTC +00:00
}
# {
                :id => 6578,
         :wallet_id => 3834,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2635,
              "purchased_at" => "2026-05-17T16:41:20.249Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-05-17T16:41:20.251Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-05-17 16:41:20.253358000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:20.253358000 UTC +00:00
}
# {
                :id => 6579,
         :wallet_id => 3834,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-05-17 16:42:20.270033000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-05-17 16:41:20.273404000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:20.273404000 UTC +00:00
}
# {
                :id => 6580,
         :wallet_id => 3834,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2636,
              "purchased_at" => "2026-05-17T16:41:20.286Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-05-17T16:41:20.289Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-05-17 16:41:20.290418000 UTC +00:00,
        :updated_at => 2026-05-17 16:41:20.290418000 UTC +00:00
}
# {
                :id => 6588,
         :wallet_id => 3834,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-05-18 01:07:09.659705000 UTC +00:00,
        :updated_at => 2026-05-18 01:07:09.659705000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [ 1] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2632,
                  "purchased_at" => "2026-05-17T16:41:10.942Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-05-17T16:41:10.944Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 2] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1353,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-05-17T16:41:13.537Z"
        }
    ],
    [ 3] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2633,
                  "purchased_at" => "2026-05-17T16:41:13.551Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-05-17T16:41:13.553Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 4] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2634,
                  "purchased_at" => "2026-05-17T16:41:13.788Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-05-17T16:41:13.791Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 5] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 6] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 7] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 8] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1354,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-05-17T16:41:20.218Z"
        }
    ],
    [ 9] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2635,
                  "purchased_at" => "2026-05-17T16:41:20.249Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-05-17T16:41:20.251Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [10] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [11] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2636,
                  "purchased_at" => "2026-05-17T16:41:20.286Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-05-17T16:41:20.289Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [12] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ]
]

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
}