usage_credits

Demo app for the 💳✨ usage_credits gem

The basics: get and spend credits

 

Subscribe to a plan: Buy credit packs: Get arbitrary bonuses: Spend credits:

Ledger status

Date Amount Category Expiration
Apr 07, 5:55 AM +10 credits subscription_credits first_cycle expires in 29 days
Apr 07, 5:56 AM +10 credits subscription_credits first_cycle expires in 29 days
Apr 07, 5:56 AM +10 credits credit_pack_purchase
Apr 07, 5:56 AM +10 credits credit_pack_purchase
Apr 07, 5:57 AM +1000 credits credit_pack_purchase
Apr 07, 5:57 AM +1000 credits credit_pack_purchase
Apr 07, 5:57 AM +5100 credits credit_pack_purchase
Apr 07, 5:57 AM +5100 credits credit_pack_purchase
Apr 07, 5:57 AM +10 credits signup_bonus signup
Apr 07, 5:58 AM +10 credits signup_bonus signup
Apr 07, 5:58 AM +20 credits referral_bonus referral
Apr 07, 5:58 AM +20 credits referral_bonus referral
Apr 07, 5:58 AM +10 credits bonus expiring_bonus_credits 🗑️ expired
Apr 07, 5:58 AM +10 credits bonus expiring_bonus_credits 🗑️ expired
Apr 07, 8:43 AM +10 credits subscription_credits first_cycle expires in 29 days
Apr 07, 8:46 AM +10 credits signup_bonus signup
Apr 07, 8:49 AM +10 credits credit_pack_purchase
Apr 07, 8:53 AM +1000 credits credit_pack_purchase
Apr 07, 8:56 AM +20 credits referral_bonus referral
Apr 07, 9:00 AM +10 credits bonus expiring_bonus_credits 🗑️ expired

Payment records (pay gem)

The user has paid $547.97 total

Pay::Charge (8)
# {
                        :id => 2386,
               :customer_id => 3474,
           :subscription_id => nil,
              :processor_id => "1Otpn5iWBmplq1AMTUmCl",
                    :amount => 4900,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "starter",
               "credits" => 1000,
         "bonus_credits" => 0,
           "price_cents" => 4900,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-07 05:57:19.986762000 UTC +00:00,
                :updated_at => 2026-04-07 05:57:19.986762000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2383,
               :customer_id => 3474,
           :subscription_id => nil,
              :processor_id => "9BjodM4MgKYjisiQVA6zE",
                    :amount => 99,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "tiny",
               "credits" => 10,
         "bonus_credits" => 0,
           "price_cents" => 99,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-07 05:56:45.263464000 UTC +00:00,
                :updated_at => 2026-04-07 05:56:45.263464000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2387,
               :customer_id => 3474,
           :subscription_id => nil,
              :processor_id => "D_yQ0zlVVpu-klzswYZN1",
                    :amount => 19900,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "pro",
               "credits" => 5000,
         "bonus_credits" => 100,
           "price_cents" => 19900,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-07 05:57:23.611178000 UTC +00:00,
                :updated_at => 2026-04-07 05:57:23.611178000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2385,
               :customer_id => 3474,
           :subscription_id => nil,
              :processor_id => "FnLgIgJ5vh8g-l7hYMEAA",
                    :amount => 4900,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "starter",
               "credits" => 1000,
         "bonus_credits" => 0,
           "price_cents" => 4900,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-07 05:57:17.424411000 UTC +00:00,
                :updated_at => 2026-04-07 05:57:17.424411000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2389,
               :customer_id => 3474,
           :subscription_id => nil,
              :processor_id => "WS8XWJDKzJzRaLW7dS9CH",
                    :amount => 99,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "tiny",
               "credits" => 10,
         "bonus_credits" => 0,
           "price_cents" => 99,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-07 08:49:50.370674000 UTC +00:00,
                :updated_at => 2026-04-07 08:49:50.370674000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2384,
               :customer_id => 3474,
           :subscription_id => nil,
              :processor_id => "_jnl7DsBPmYe8h580blkz",
                    :amount => 99,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "tiny",
               "credits" => 10,
         "bonus_credits" => 0,
           "price_cents" => 99,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-07 05:56:46.854747000 UTC +00:00,
                :updated_at => 2026-04-07 05:56:46.854747000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2388,
               :customer_id => 3474,
           :subscription_id => nil,
              :processor_id => "lTqfzEIRNLDg142JjuHo6",
                    :amount => 19900,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "pro",
               "credits" => 5000,
         "bonus_credits" => 100,
           "price_cents" => 19900,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-07 05:57:32.562415000 UTC +00:00,
                :updated_at => 2026-04-07 05:57:32.562415000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2390,
               :customer_id => 3474,
           :subscription_id => nil,
              :processor_id => "qtOkDNGf05n8PfBJ96KSK",
                    :amount => 4900,
                  :currency => nil,
    :application_fee_amount => nil,
           :amount_refunded => nil,
                  :metadata => {
         "purchase_type" => "credit_pack",
             "pack_name" => "starter",
               "credits" => 1000,
         "bonus_credits" => 0,
           "price_cents" => 4900,
        "price_currency" => "USD"
    },
                      :data => {
        "payment_method_type" => "card",
                      "brand" => "Fake",
                      "last4" => 1234,
                  "exp_month" => 4,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-04-07 08:53:22.943787000 UTC +00:00,
                :updated_at => 2026-04-07 08:53:22.943787000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (3)
# {
                         "id" => 1260,
                "customer_id" => 3474,
                       "name" => "default",
               "processor_id" => "Fm0A2a3JSdiHI_VSSzga-",
             "processor_plan" => "abcdef123456",
                   "quantity" => 1,
                     "status" => "active",
       "current_period_start" => nil,
         "current_period_end" => nil,
              "trial_ends_at" => nil,
                    "ends_at" => nil,
                    "metered" => nil,
             "pause_behavior" => nil,
            "pause_starts_at" => nil,
           "pause_resumes_at" => nil,
    "application_fee_percent" => nil,
                   "metadata" => {
                   "purchase_type" => "credit_subscription",
               "subscription_name" => "test_plan",
              "fulfillment_period" => "1 month",
              "credits_per_period" => 10,
            "signup_bonus_credits" => 0,
                   "trial_credits" => 0,
                "rollover_enabled" => false,
        "expire_credits_on_cancel" => false,
        "credit_expiration_period" => nil,
                        "metadata" => {}
    },
                       "data" => nil,
             "stripe_account" => nil,
          "payment_method_id" => nil,
                 "created_at" => 2026-04-07 05:55:50.242731000 UTC +00:00,
                 "updated_at" => 2026-04-07 05:55:50.242731000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1261,
                "customer_id" => 3474,
                       "name" => "default",
               "processor_id" => "WxdfIb7GJSNnzfNv_QwYW",
             "processor_plan" => "abcdef123456",
                   "quantity" => 1,
                     "status" => "active",
       "current_period_start" => nil,
         "current_period_end" => nil,
              "trial_ends_at" => nil,
                    "ends_at" => nil,
                    "metered" => nil,
             "pause_behavior" => nil,
            "pause_starts_at" => nil,
           "pause_resumes_at" => nil,
    "application_fee_percent" => nil,
                   "metadata" => {
                   "purchase_type" => "credit_subscription",
               "subscription_name" => "test_plan",
              "fulfillment_period" => "1 month",
              "credits_per_period" => 10,
            "signup_bonus_credits" => 0,
                   "trial_credits" => 0,
                "rollover_enabled" => false,
        "expire_credits_on_cancel" => false,
        "credit_expiration_period" => nil,
                        "metadata" => {}
    },
                       "data" => nil,
             "stripe_account" => nil,
          "payment_method_id" => nil,
                 "created_at" => 2026-04-07 05:56:04.522799000 UTC +00:00,
                 "updated_at" => 2026-04-07 05:56:04.522799000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1262,
                "customer_id" => 3474,
                       "name" => "default",
               "processor_id" => "x7SgOvy5G-Q-XTcxHO0u6",
             "processor_plan" => "abcdef123456",
                   "quantity" => 1,
                     "status" => "active",
       "current_period_start" => nil,
         "current_period_end" => nil,
              "trial_ends_at" => nil,
                    "ends_at" => nil,
                    "metered" => nil,
             "pause_behavior" => nil,
            "pause_starts_at" => nil,
           "pause_resumes_at" => nil,
    "application_fee_percent" => nil,
                   "metadata" => {
                   "purchase_type" => "credit_subscription",
               "subscription_name" => "test_plan",
              "fulfillment_period" => "1 month",
              "credits_per_period" => 10,
            "signup_bonus_credits" => 0,
                   "trial_credits" => 0,
                "rollover_enabled" => false,
        "expire_credits_on_cancel" => false,
        "credit_expiration_period" => nil,
                        "metadata" => {}
    },
                       "data" => nil,
             "stripe_account" => nil,
          "payment_method_id" => nil,
                 "created_at" => 2026-04-07 08:43:00.441087000 UTC +00:00,
                 "updated_at" => 2026-04-07 08:43:00.441087000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (11)
# {
                          :id => 3642,
                   :wallet_id => 3480,
                 :source_type => "Pay::Subscription",
                   :source_id => 1260,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-04-07 05:55:50.247806000 UTC +00:00,
         :next_fulfillment_at => 2026-05-07 05:55:50.242731000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1260,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-04-07 05:55:50.248482000 UTC +00:00,
                  :updated_at => 2026-04-07 05:55:50.248482000 UTC +00:00
}
# {
                          :id => 3643,
                   :wallet_id => 3480,
                 :source_type => "Pay::Subscription",
                   :source_id => 1261,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-04-07 05:56:04.529016000 UTC +00:00,
         :next_fulfillment_at => 2026-05-07 05:56:04.522799000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1261,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-04-07 05:56:04.529691000 UTC +00:00,
                  :updated_at => 2026-04-07 05:56:04.529691000 UTC +00:00
}
# {
                          :id => 3644,
                   :wallet_id => 3480,
                 :source_type => "Pay::Charge",
                   :source_id => 2383,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-07 05:56:45.267713000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2383,
              "purchased_at" => "2026-04-07T05:56:45.263Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-07 05:56:45.268142000 UTC +00:00,
                  :updated_at => 2026-04-07 05:56:45.268142000 UTC +00:00
}
# {
                          :id => 3645,
                   :wallet_id => 3480,
                 :source_type => "Pay::Charge",
                   :source_id => 2384,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-07 05:56:46.861832000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2384,
              "purchased_at" => "2026-04-07T05:56:46.854Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-07 05:56:46.862378000 UTC +00:00,
                  :updated_at => 2026-04-07 05:56:46.862378000 UTC +00:00
}
# {
                          :id => 3646,
                   :wallet_id => 3480,
                 :source_type => "Pay::Charge",
                   :source_id => 2385,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-07 05:57:17.431018000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2385,
              "purchased_at" => "2026-04-07T05:57:17.424Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-07 05:57:17.431685000 UTC +00:00,
                  :updated_at => 2026-04-07 05:57:17.431685000 UTC +00:00
}
# {
                          :id => 3647,
                   :wallet_id => 3480,
                 :source_type => "Pay::Charge",
                   :source_id => 2386,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-07 05:57:19.992516000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2386,
              "purchased_at" => "2026-04-07T05:57:19.986Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-07 05:57:19.993000000 UTC +00:00,
                  :updated_at => 2026-04-07 05:57:19.993000000 UTC +00:00
}
# {
                          :id => 3648,
                   :wallet_id => 3480,
                 :source_type => "Pay::Charge",
                   :source_id => 2387,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-07 05:57:23.617167000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2387,
              "purchased_at" => "2026-04-07T05:57:23.611Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-07 05:57:23.617804000 UTC +00:00,
                  :updated_at => 2026-04-07 05:57:23.617804000 UTC +00:00
}
# {
                          :id => 3649,
                   :wallet_id => 3480,
                 :source_type => "Pay::Charge",
                   :source_id => 2388,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-07 05:57:32.567883000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2388,
              "purchased_at" => "2026-04-07T05:57:32.562Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-07 05:57:32.568349000 UTC +00:00,
                  :updated_at => 2026-04-07 05:57:32.568349000 UTC +00:00
}
# {
                          :id => 3650,
                   :wallet_id => 3480,
                 :source_type => "Pay::Subscription",
                   :source_id => 1262,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-04-07 08:43:00.448796000 UTC +00:00,
         :next_fulfillment_at => 2026-05-07 08:43:00.441087000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1262,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-04-07 08:43:00.449574000 UTC +00:00,
                  :updated_at => 2026-04-07 08:43:00.449574000 UTC +00:00
}
# {
                          :id => 3651,
                   :wallet_id => 3480,
                 :source_type => "Pay::Charge",
                   :source_id => 2389,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-07 08:49:50.376338000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2389,
              "purchased_at" => "2026-04-07T08:49:50.370Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-07 08:49:50.376820000 UTC +00:00,
                  :updated_at => 2026-04-07 08:49:50.376820000 UTC +00:00
}
# {
                          :id => 3652,
                   :wallet_id => 3480,
                 :source_type => "Pay::Charge",
                   :source_id => 2390,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-04-07 08:53:22.949201000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2390,
              "purchased_at" => "2026-04-07T08:53:22.943Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-04-07 08:53:22.949769000 UTC +00:00,
                  :updated_at => 2026-04-07 08:53:22.949769000 UTC +00:00
}
UsageCredits::Transaction (20)
# {
                :id => 5990,
         :wallet_id => 3480,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-05-07 06:00:50.242731000 UTC +00:00,
    :fulfillment_id => 3642,
          :metadata => {
        "subscription_id" => 1260,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-04-07T05:55:50.244Z"
    },
        :created_at => 2026-04-07 05:55:50.245949000 UTC +00:00,
        :updated_at => 2026-04-07 05:55:50.245949000 UTC +00:00
}
# {
                :id => 5991,
         :wallet_id => 3480,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-05-07 06:01:04.522799000 UTC +00:00,
    :fulfillment_id => 3643,
          :metadata => {
        "subscription_id" => 1261,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-04-07T05:56:04.525Z"
    },
        :created_at => 2026-04-07 05:56:04.527292000 UTC +00:00,
        :updated_at => 2026-04-07 05:56:04.527292000 UTC +00:00
}
# {
                :id => 5992,
         :wallet_id => 3480,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2383,
              "purchased_at" => "2026-04-07T05:56:45.263Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-07T05:56:45.265Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-07 05:56:45.266312000 UTC +00:00,
        :updated_at => 2026-04-07 05:56:45.266312000 UTC +00:00
}
# {
                :id => 5993,
         :wallet_id => 3480,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2384,
              "purchased_at" => "2026-04-07T05:56:46.854Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-07T05:56:46.856Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-07 05:56:46.858168000 UTC +00:00,
        :updated_at => 2026-04-07 05:56:46.858168000 UTC +00:00
}
# {
                :id => 5994,
         :wallet_id => 3480,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2385,
              "purchased_at" => "2026-04-07T05:57:17.424Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-07T05:57:17.427Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-07 05:57:17.429018000 UTC +00:00,
        :updated_at => 2026-04-07 05:57:17.429018000 UTC +00:00
}
# {
                :id => 5995,
         :wallet_id => 3480,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2386,
              "purchased_at" => "2026-04-07T05:57:19.986Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-07T05:57:19.989Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-07 05:57:19.990994000 UTC +00:00,
        :updated_at => 2026-04-07 05:57:19.990994000 UTC +00:00
}
# {
                :id => 5996,
         :wallet_id => 3480,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2387,
              "purchased_at" => "2026-04-07T05:57:23.611Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-07T05:57:23.613Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-07 05:57:23.615303000 UTC +00:00,
        :updated_at => 2026-04-07 05:57:23.615303000 UTC +00:00
}
# {
                :id => 5997,
         :wallet_id => 3480,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2388,
              "purchased_at" => "2026-04-07T05:57:32.562Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-07T05:57:32.564Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-07 05:57:32.565729000 UTC +00:00,
        :updated_at => 2026-04-07 05:57:32.565729000 UTC +00:00
}
# {
                :id => 5998,
         :wallet_id => 3480,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-04-07 05:57:51.748975000 UTC +00:00,
        :updated_at => 2026-04-07 05:57:51.748975000 UTC +00:00
}
# {
                :id => 5999,
         :wallet_id => 3480,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-04-07 05:58:09.711217000 UTC +00:00,
        :updated_at => 2026-04-07 05:58:09.711217000 UTC +00:00
}
# {
                :id => 6000,
         :wallet_id => 3480,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-04-07 05:58:19.254161000 UTC +00:00,
        :updated_at => 2026-04-07 05:58:19.254161000 UTC +00:00
}
# {
                :id => 6001,
         :wallet_id => 3480,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-04-07 05:58:29.775544000 UTC +00:00,
        :updated_at => 2026-04-07 05:58:29.775544000 UTC +00:00
}
# {
                :id => 6002,
         :wallet_id => 3480,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-04-07 05:59:49.007906000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-04-07 05:58:49.010588000 UTC +00:00,
        :updated_at => 2026-04-07 05:58:49.010588000 UTC +00:00
}
# {
                :id => 6003,
         :wallet_id => 3480,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-04-07 05:59:56.206266000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-04-07 05:58:56.209221000 UTC +00:00,
        :updated_at => 2026-04-07 05:58:56.209221000 UTC +00:00
}
# {
                :id => 6004,
         :wallet_id => 3480,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-05-07 08:48:00.441087000 UTC +00:00,
    :fulfillment_id => 3650,
          :metadata => {
        "subscription_id" => 1262,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-04-07T08:43:00.445Z"
    },
        :created_at => 2026-04-07 08:43:00.446827000 UTC +00:00,
        :updated_at => 2026-04-07 08:43:00.446827000 UTC +00:00
}
# {
                :id => 6005,
         :wallet_id => 3480,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-04-07 08:46:20.466906000 UTC +00:00,
        :updated_at => 2026-04-07 08:46:20.466906000 UTC +00:00
}
# {
                :id => 6006,
         :wallet_id => 3480,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2389,
              "purchased_at" => "2026-04-07T08:49:50.370Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-07T08:49:50.373Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-07 08:49:50.374531000 UTC +00:00,
        :updated_at => 2026-04-07 08:49:50.374531000 UTC +00:00
}
# {
                :id => 6007,
         :wallet_id => 3480,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2390,
              "purchased_at" => "2026-04-07T08:53:22.943Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-04-07T08:53:22.946Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-04-07 08:53:22.947542000 UTC +00:00,
        :updated_at => 2026-04-07 08:53:22.947542000 UTC +00:00
}
# {
                :id => 6008,
         :wallet_id => 3480,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-04-07 08:56:53.406580000 UTC +00:00,
        :updated_at => 2026-04-07 08:56:53.406580000 UTC +00:00
}
# {
                :id => 6009,
         :wallet_id => 3480,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-04-07 09:01:16.489687000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-04-07 09:00:16.492487000 UTC +00:00,
        :updated_at => 2026-04-07 09:00:16.492487000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1260,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-04-07T05:55:50.244Z"
        }
    ],
    [ 1] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1261,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-04-07T05:56:04.525Z"
        }
    ],
    [ 2] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2383,
                  "purchased_at" => "2026-04-07T05:56:45.263Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-07T05:56:45.265Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 3] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2384,
                  "purchased_at" => "2026-04-07T05:56:46.854Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-07T05:56:46.856Z",
                 "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" => 2385,
                  "purchased_at" => "2026-04-07T05:57:17.424Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-07T05:57:17.427Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 5] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2386,
                  "purchased_at" => "2026-04-07T05:57:19.986Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-07T05:57:19.989Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 6] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2387,
                  "purchased_at" => "2026-04-07T05:57:23.611Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-07T05:57:23.613Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 7] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2388,
                  "purchased_at" => "2026-04-07T05:57:32.562Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-07T05:57:32.564Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 8] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [ 9] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [10] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [11] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [12] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [13] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [14] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1262,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-04-07T08:43:00.445Z"
        }
    ],
    [15] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [16] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2389,
                  "purchased_at" => "2026-04-07T08:49:50.370Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-07T08:49:50.373Z",
                 "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" => 2390,
                  "purchased_at" => "2026-04-07T08:53:22.943Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-04-07T08:53:22.946Z",
                 "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"
        }
    ]
]

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
}