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
Jun 26, 4:50 AM +5100 credits credit_pack_purchase
Jun 26, 5:49 AM +1000 credits credit_pack_purchase
Jun 26, 5:57 AM +10 credits credit_pack_purchase
Jun 26, 7:45 AM +20 credits referral_bonus referral
Jun 26, 1:29 PM +20 credits referral_bonus referral
Jun 26, 5:10 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Jun 26, 5:21 PM +10 credits subscription_credits first_cycle expires in 29 days
Jun 26, 5:33 PM +20 credits referral_bonus referral
Jun 26, 5:40 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Jun 26, 5:51 PM +10 credits signup_bonus signup
Jun 26, 8:11 PM +10 credits credit_pack_purchase
Jun 27, 4:34 AM +10 credits signup_bonus signup
Jun 27, 7:31 AM +10 credits credit_pack_purchase
Jun 27, 9:22 AM +5100 credits credit_pack_purchase

Payment records (pay gem)

The user has paid $449.97 total

Pay::Charge (6)
# {
                        :id => 2880,
               :customer_id => 4131,
           :subscription_id => nil,
              :processor_id => "80EL-8KKoLSzB9ifTFDSj",
                    :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" => 6,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-06-26 04:50:54.709046000 UTC +00:00,
                :updated_at => 2026-06-26 04:50:54.709046000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2882,
               :customer_id => 4131,
           :subscription_id => nil,
              :processor_id => "VQBmRdRSZCy6kQBAlVN4F",
                    :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" => 6,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-06-26 05:57:54.712124000 UTC +00:00,
                :updated_at => 2026-06-26 05:57:54.712124000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2885,
               :customer_id => 4131,
           :subscription_id => nil,
              :processor_id => "XNNImcMPbny67RbgZQK72",
                    :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" => 6,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-06-27 07:31:30.590386000 UTC +00:00,
                :updated_at => 2026-06-27 07:31:30.590386000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2881,
               :customer_id => 4131,
           :subscription_id => nil,
              :processor_id => "YeqBr7JJ6NPd68C_cOP00",
                    :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" => 6,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-06-26 05:49:38.797878000 UTC +00:00,
                :updated_at => 2026-06-26 05:49:38.797878000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2884,
               :customer_id => 4131,
           :subscription_id => nil,
              :processor_id => "fuhWTojww5uUGPtufM9k6",
                    :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" => 6,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-06-26 20:11:56.136767000 UTC +00:00,
                :updated_at => 2026-06-26 20:11:56.136767000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2886,
               :customer_id => 4131,
           :subscription_id => nil,
              :processor_id => "xPTH6wcvZUeEAMpXseFsC",
                    :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" => 6,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-06-27 09:22:24.268718000 UTC +00:00,
                :updated_at => 2026-06-27 09:22:24.268718000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (1)
# {
                         "id" => 1447,
                "customer_id" => 4131,
                       "name" => "default",
               "processor_id" => "b8r1mDxhpjTva8vahyhZo",
             "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-06-26 17:21:48.831556000 UTC +00:00,
                 "updated_at" => 2026-06-26 17:21:48.831556000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (7)
# {
                          :id => 4326,
                   :wallet_id => 4138,
                 :source_type => "Pay::Charge",
                   :source_id => 2880,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-06-26 04:50:54.725463000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2880,
              "purchased_at" => "2026-06-26T04:50:54.709Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-06-26 04:50:54.726295000 UTC +00:00,
                  :updated_at => 2026-06-26 04:50:54.726295000 UTC +00:00
}
# {
                          :id => 4327,
                   :wallet_id => 4138,
                 :source_type => "Pay::Charge",
                   :source_id => 2881,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-06-26 05:49:38.810540000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2881,
              "purchased_at" => "2026-06-26T05:49:38.797Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-06-26 05:49:38.811090000 UTC +00:00,
                  :updated_at => 2026-06-26 05:49:38.811090000 UTC +00:00
}
# {
                          :id => 4328,
                   :wallet_id => 4138,
                 :source_type => "Pay::Charge",
                   :source_id => 2882,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-06-26 05:57:54.724426000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2882,
              "purchased_at" => "2026-06-26T05:57:54.712Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-06-26 05:57:54.726046000 UTC +00:00,
                  :updated_at => 2026-06-26 05:57:54.726046000 UTC +00:00
}
# {
                          :id => 4330,
                   :wallet_id => 4138,
                 :source_type => "Pay::Subscription",
                   :source_id => 1447,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-06-26 17:21:48.845235000 UTC +00:00,
         :next_fulfillment_at => 2026-07-26 17:21:48.831556000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1447,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-06-26 17:21:48.848922000 UTC +00:00,
                  :updated_at => 2026-06-26 17:21:48.848922000 UTC +00:00
}
# {
                          :id => 4331,
                   :wallet_id => 4138,
                 :source_type => "Pay::Charge",
                   :source_id => 2884,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-06-26 20:11:56.146354000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2884,
              "purchased_at" => "2026-06-26T20:11:56.136Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-06-26 20:11:56.146757000 UTC +00:00,
                  :updated_at => 2026-06-26 20:11:56.146757000 UTC +00:00
}
# {
                          :id => 4332,
                   :wallet_id => 4138,
                 :source_type => "Pay::Charge",
                   :source_id => 2885,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-06-27 07:31:30.608092000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2885,
              "purchased_at" => "2026-06-27T07:31:30.590Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-06-27 07:31:30.613446000 UTC +00:00,
                  :updated_at => 2026-06-27 07:31:30.613446000 UTC +00:00
}
# {
                          :id => 4333,
                   :wallet_id => 4138,
                 :source_type => "Pay::Charge",
                   :source_id => 2886,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-06-27 09:22:24.283956000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2886,
              "purchased_at" => "2026-06-27T09:22:24.268Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-06-27 09:22:24.284798000 UTC +00:00,
                  :updated_at => 2026-06-27 09:22:24.284798000 UTC +00:00
}
UsageCredits::Transaction (14)
# {
                :id => 7153,
         :wallet_id => 4138,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2880,
              "purchased_at" => "2026-06-26T04:50:54.709Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-06-26T04:50:54.716Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-06-26 04:50:54.720319000 UTC +00:00,
        :updated_at => 2026-06-26 04:50:54.720319000 UTC +00:00
}
# {
                :id => 7154,
         :wallet_id => 4138,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2881,
              "purchased_at" => "2026-06-26T05:49:38.797Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-06-26T05:49:38.805Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-06-26 05:49:38.807430000 UTC +00:00,
        :updated_at => 2026-06-26 05:49:38.807430000 UTC +00:00
}
# {
                :id => 7155,
         :wallet_id => 4138,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2882,
              "purchased_at" => "2026-06-26T05:57:54.712Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-06-26T05:57:54.719Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-06-26 05:57:54.721321000 UTC +00:00,
        :updated_at => 2026-06-26 05:57:54.721321000 UTC +00:00
}
# {
                :id => 7156,
         :wallet_id => 4138,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-06-26 07:45:41.598495000 UTC +00:00,
        :updated_at => 2026-06-26 07:45:41.598495000 UTC +00:00
}
# {
                :id => 7157,
         :wallet_id => 4138,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-06-26 13:29:29.722895000 UTC +00:00,
        :updated_at => 2026-06-26 13:29:29.722895000 UTC +00:00
}
# {
                :id => 7159,
         :wallet_id => 4138,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-06-26 17:11:10.767395000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-06-26 17:10:10.772124000 UTC +00:00,
        :updated_at => 2026-06-26 17:10:10.772124000 UTC +00:00
}
# {
                :id => 7160,
         :wallet_id => 4138,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-07-26 17:26:48.831556000 UTC +00:00,
    :fulfillment_id => 4330,
          :metadata => {
        "subscription_id" => 1447,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-06-26T17:21:48.840Z"
    },
        :created_at => 2026-06-26 17:21:48.842766000 UTC +00:00,
        :updated_at => 2026-06-26 17:21:48.842766000 UTC +00:00
}
# {
                :id => 7161,
         :wallet_id => 4138,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-06-26 17:33:04.309025000 UTC +00:00,
        :updated_at => 2026-06-26 17:33:04.309025000 UTC +00:00
}
# {
                :id => 7162,
         :wallet_id => 4138,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-06-26 17:41:17.467881000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-06-26 17:40:17.472344000 UTC +00:00,
        :updated_at => 2026-06-26 17:40:17.472344000 UTC +00:00
}
# {
                :id => 7163,
         :wallet_id => 4138,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-06-26 17:51:26.282413000 UTC +00:00,
        :updated_at => 2026-06-26 17:51:26.282413000 UTC +00:00
}
# {
                :id => 7164,
         :wallet_id => 4138,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2884,
              "purchased_at" => "2026-06-26T20:11:56.136Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-06-26T20:11:56.143Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-06-26 20:11:56.144986000 UTC +00:00,
        :updated_at => 2026-06-26 20:11:56.144986000 UTC +00:00
}
# {
                :id => 7165,
         :wallet_id => 4138,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-06-27 04:34:54.033579000 UTC +00:00,
        :updated_at => 2026-06-27 04:34:54.033579000 UTC +00:00
}
# {
                :id => 7166,
         :wallet_id => 4138,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2885,
              "purchased_at" => "2026-06-27T07:31:30.590Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-06-27T07:31:30.601Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-06-27 07:31:30.604692000 UTC +00:00,
        :updated_at => 2026-06-27 07:31:30.604692000 UTC +00:00
}
# {
                :id => 7167,
         :wallet_id => 4138,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2886,
              "purchased_at" => "2026-06-27T09:22:24.268Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-06-27T09:22:24.276Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-06-27 09:22:24.280135000 UTC +00:00,
        :updated_at => 2026-06-27 09:22:24.280135000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2880,
                  "purchased_at" => "2026-06-26T04:50:54.709Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-06-26T04:50:54.716Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 1] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2881,
                  "purchased_at" => "2026-06-26T05:49:38.797Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-06-26T05:49:38.805Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [ 2] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2882,
                  "purchased_at" => "2026-06-26T05:57:54.712Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-06-26T05:57:54.719Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 3] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 4] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 5] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 6] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1447,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-06-26T17:21:48.840Z"
        }
    ],
    [ 7] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 8] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [ 9] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [10] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2884,
                  "purchased_at" => "2026-06-26T20:11:56.136Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-06-26T20:11:56.143Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [11] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [12] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2885,
                  "purchased_at" => "2026-06-27T07:31:30.590Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-06-27T07:31:30.601Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [13] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2886,
                  "purchased_at" => "2026-06-27T09:22:24.268Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-06-27T09:22:24.276Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ]
]

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
}