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
Aug 07, 5:38 PM +10 credits subscription_credits first_cycle expires in about 1 month
Aug 07, 5:39 PM +10 credits subscription_credits first_cycle expires in about 1 month
Aug 07, 5:39 PM +10 credits credit_pack_purchase
Aug 07, 5:39 PM +10 credits credit_pack_purchase
Aug 07, 5:40 PM +1000 credits credit_pack_purchase
Aug 07, 5:40 PM +1000 credits credit_pack_purchase
Aug 07, 5:40 PM +5100 credits credit_pack_purchase
Aug 07, 5:40 PM +5100 credits credit_pack_purchase
Aug 07, 5:41 PM +20 credits referral_bonus referral
Aug 07, 5:42 PM +20 credits referral_bonus referral
Aug 07, 5:42 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Aug 07, 5:42 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Aug 07, 9:17 PM +10 credits signup_bonus signup
Aug 07, 9:26 PM +1000 credits credit_pack_purchase
Aug 07, 9:38 PM +10 credits bonus expiring_bonus_credits 🗑️ expired

Payment records (pay gem)

The user has paid $546.98 total

Pay::Charge (7)
# {
                        :id => 3112,
               :customer_id => 4403,
           :subscription_id => nil,
              :processor_id => "2GFj-EPQue47h2nk-VcUD",
                    :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" => 8,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-08-07 17:40:33.503696000 UTC +00:00,
                :updated_at => 2026-08-07 17:40:33.503696000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 3109,
               :customer_id => 4403,
           :subscription_id => nil,
              :processor_id => "4OU5u90LM2VThD8zJjtx0",
                    :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" => 8,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-08-07 17:40:19.383251000 UTC +00:00,
                :updated_at => 2026-08-07 17:40:19.383251000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 3107,
               :customer_id => 4403,
           :subscription_id => nil,
              :processor_id => "IGny55_oOMA29ftGxvw0I",
                    :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" => 8,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-08-07 17:39:19.490724000 UTC +00:00,
                :updated_at => 2026-08-07 17:39:19.490724000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 3108,
               :customer_id => 4403,
           :subscription_id => nil,
              :processor_id => "_p2i5Lf6mGtts5I4FB7fE",
                    :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" => 8,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-08-07 17:39:57.625274000 UTC +00:00,
                :updated_at => 2026-08-07 17:39:57.625274000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 3111,
               :customer_id => 4403,
           :subscription_id => nil,
              :processor_id => "fDKIe4dzyQCmekPxcRJjf",
                    :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" => 8,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-08-07 17:40:32.625994000 UTC +00:00,
                :updated_at => 2026-08-07 17:40:32.625994000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 3110,
               :customer_id => 4403,
           :subscription_id => nil,
              :processor_id => "kZfyg-4_BfeY41vKDIPig",
                    :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" => 8,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-08-07 17:40:29.075403000 UTC +00:00,
                :updated_at => 2026-08-07 17:40:29.075403000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 3113,
               :customer_id => 4403,
           :subscription_id => nil,
              :processor_id => "zxeJKUaubaa9ys3Fx-ueN",
                    :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" => 8,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-08-07 21:26:48.306046000 UTC +00:00,
                :updated_at => 2026-08-07 21:26:48.306046000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (2)
# {
                         "id" => 1527,
                "customer_id" => 4403,
                       "name" => "default",
               "processor_id" => "7RZZ88xcn_xyo_7r53LxY",
             "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-08-07 17:39:17.644354000 UTC +00:00,
                 "updated_at" => 2026-08-07 17:39:17.644354000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1526,
                "customer_id" => 4403,
                       "name" => "default",
               "processor_id" => "YMNt01hT4fZFwujBSG8QH",
             "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-08-07 17:38:09.248096000 UTC +00:00,
                 "updated_at" => 2026-08-07 17:38:09.248096000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (9)
# {
                          :id => 4632,
                   :wallet_id => 4410,
                 :source_type => "Pay::Subscription",
                   :source_id => 1526,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-08-07 17:38:09.257285000 UTC +00:00,
         :next_fulfillment_at => 2026-09-07 17:38:09.248096000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1526,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-08-07 17:38:09.257938000 UTC +00:00,
                  :updated_at => 2026-08-07 17:38:09.257938000 UTC +00:00
}
# {
                          :id => 4633,
                   :wallet_id => 4410,
                 :source_type => "Pay::Subscription",
                   :source_id => 1527,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-08-07 17:39:17.649038000 UTC +00:00,
         :next_fulfillment_at => 2026-09-07 17:39:17.644354000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1527,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-08-07 17:39:17.649687000 UTC +00:00,
                  :updated_at => 2026-08-07 17:39:17.649687000 UTC +00:00
}
# {
                          :id => 4634,
                   :wallet_id => 4410,
                 :source_type => "Pay::Charge",
                   :source_id => 3107,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-08-07 17:39:19.496016000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 3107,
              "purchased_at" => "2026-08-07T17:39:19.490Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-08-07 17:39:19.496477000 UTC +00:00,
                  :updated_at => 2026-08-07 17:39:19.496477000 UTC +00:00
}
# {
                          :id => 4635,
                   :wallet_id => 4410,
                 :source_type => "Pay::Charge",
                   :source_id => 3108,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-08-07 17:39:57.630065000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 3108,
              "purchased_at" => "2026-08-07T17:39:57.625Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-08-07 17:39:57.630558000 UTC +00:00,
                  :updated_at => 2026-08-07 17:39:57.630558000 UTC +00:00
}
# {
                          :id => 4636,
                   :wallet_id => 4410,
                 :source_type => "Pay::Charge",
                   :source_id => 3109,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-08-07 17:40:19.392528000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 3109,
              "purchased_at" => "2026-08-07T17:40:19.383Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-08-07 17:40:19.393440000 UTC +00:00,
                  :updated_at => 2026-08-07 17:40:19.393440000 UTC +00:00
}
# {
                          :id => 4637,
                   :wallet_id => 4410,
                 :source_type => "Pay::Charge",
                   :source_id => 3110,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-08-07 17:40:29.079759000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 3110,
              "purchased_at" => "2026-08-07T17:40:29.075Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-08-07 17:40:29.080182000 UTC +00:00,
                  :updated_at => 2026-08-07 17:40:29.080182000 UTC +00:00
}
# {
                          :id => 4638,
                   :wallet_id => 4410,
                 :source_type => "Pay::Charge",
                   :source_id => 3111,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-08-07 17:40:32.632802000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 3111,
              "purchased_at" => "2026-08-07T17:40:32.625Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-08-07 17:40:32.633428000 UTC +00:00,
                  :updated_at => 2026-08-07 17:40:32.633428000 UTC +00:00
}
# {
                          :id => 4639,
                   :wallet_id => 4410,
                 :source_type => "Pay::Charge",
                   :source_id => 3112,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-08-07 17:40:33.507512000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 3112,
              "purchased_at" => "2026-08-07T17:40:33.503Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-08-07 17:40:33.507927000 UTC +00:00,
                  :updated_at => 2026-08-07 17:40:33.507927000 UTC +00:00
}
# {
                          :id => 4640,
                   :wallet_id => 4410,
                 :source_type => "Pay::Charge",
                   :source_id => 3113,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-08-07 21:26:48.332416000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 3113,
              "purchased_at" => "2026-08-07T21:26:48.306Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-08-07 21:26:48.340413000 UTC +00:00,
                  :updated_at => 2026-08-07 21:26:48.340413000 UTC +00:00
}
UsageCredits::Transaction (15)
# {
                :id => 7665,
         :wallet_id => 4410,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-09-07 17:43:09.248096000 UTC +00:00,
    :fulfillment_id => 4632,
          :metadata => {
        "subscription_id" => 1526,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-08-07T17:38:09.249Z"
    },
        :created_at => 2026-08-07 17:38:09.250719000 UTC +00:00,
        :updated_at => 2026-08-07 17:38:09.250719000 UTC +00:00
}
# {
                :id => 7666,
         :wallet_id => 4410,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-09-07 17:44:17.644354000 UTC +00:00,
    :fulfillment_id => 4633,
          :metadata => {
        "subscription_id" => 1527,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-08-07T17:39:17.646Z"
    },
        :created_at => 2026-08-07 17:39:17.647364000 UTC +00:00,
        :updated_at => 2026-08-07 17:39:17.647364000 UTC +00:00
}
# {
                :id => 7667,
         :wallet_id => 4410,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 3107,
              "purchased_at" => "2026-08-07T17:39:19.490Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-08-07T17:39:19.492Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-08-07 17:39:19.494503000 UTC +00:00,
        :updated_at => 2026-08-07 17:39:19.494503000 UTC +00:00
}
# {
                :id => 7668,
         :wallet_id => 4410,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 3108,
              "purchased_at" => "2026-08-07T17:39:57.625Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-08-07T17:39:57.627Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-08-07 17:39:57.628652000 UTC +00:00,
        :updated_at => 2026-08-07 17:39:57.628652000 UTC +00:00
}
# {
                :id => 7669,
         :wallet_id => 4410,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 3109,
              "purchased_at" => "2026-08-07T17:40:19.383Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-08-07T17:40:19.386Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-08-07 17:40:19.388947000 UTC +00:00,
        :updated_at => 2026-08-07 17:40:19.388947000 UTC +00:00
}
# {
                :id => 7670,
         :wallet_id => 4410,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 3110,
              "purchased_at" => "2026-08-07T17:40:29.075Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-08-07T17:40:29.077Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-08-07 17:40:29.078292000 UTC +00:00,
        :updated_at => 2026-08-07 17:40:29.078292000 UTC +00:00
}
# {
                :id => 7671,
         :wallet_id => 4410,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 3111,
              "purchased_at" => "2026-08-07T17:40:32.625Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-08-07T17:40:32.628Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-08-07 17:40:32.629178000 UTC +00:00,
        :updated_at => 2026-08-07 17:40:32.629178000 UTC +00:00
}
# {
                :id => 7672,
         :wallet_id => 4410,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 3112,
              "purchased_at" => "2026-08-07T17:40:33.503Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-08-07T17:40:33.505Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-08-07 17:40:33.506337000 UTC +00:00,
        :updated_at => 2026-08-07 17:40:33.506337000 UTC +00:00
}
# {
                :id => 7673,
         :wallet_id => 4410,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-08-07 17:41:09.650751000 UTC +00:00,
        :updated_at => 2026-08-07 17:41:09.650751000 UTC +00:00
}
# {
                :id => 7674,
         :wallet_id => 4410,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-08-07 17:42:13.126228000 UTC +00:00,
        :updated_at => 2026-08-07 17:42:13.126228000 UTC +00:00
}
# {
                :id => 7675,
         :wallet_id => 4410,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-08-07 17:43:23.015655000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-08-07 17:42:23.018256000 UTC +00:00,
        :updated_at => 2026-08-07 17:42:23.018256000 UTC +00:00
}
# {
                :id => 7676,
         :wallet_id => 4410,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-08-07 17:43:34.210239000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-08-07 17:42:34.212458000 UTC +00:00,
        :updated_at => 2026-08-07 17:42:34.212458000 UTC +00:00
}
# {
                :id => 7677,
         :wallet_id => 4410,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-08-07 21:17:56.292661000 UTC +00:00,
        :updated_at => 2026-08-07 21:17:56.292661000 UTC +00:00
}
# {
                :id => 7678,
         :wallet_id => 4410,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 3113,
              "purchased_at" => "2026-08-07T21:26:48.306Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-08-07T21:26:48.323Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-08-07 21:26:48.327941000 UTC +00:00,
        :updated_at => 2026-08-07 21:26:48.327941000 UTC +00:00
}
# {
                :id => 7679,
         :wallet_id => 4410,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-08-07 21:39:00.489936000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-08-07 21:38:00.495089000 UTC +00:00,
        :updated_at => 2026-08-07 21:38:00.495089000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1526,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-08-07T17:38:09.249Z"
        }
    ],
    [ 1] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1527,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-08-07T17:39:17.646Z"
        }
    ],
    [ 2] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 3107,
                  "purchased_at" => "2026-08-07T17:39:19.490Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-08-07T17:39:19.492Z",
                 "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" => 3108,
                  "purchased_at" => "2026-08-07T17:39:57.625Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-08-07T17:39:57.627Z",
                 "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" => 3109,
                  "purchased_at" => "2026-08-07T17:40:19.383Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-08-07T17:40:19.386Z",
                 "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" => 3110,
                  "purchased_at" => "2026-08-07T17:40:29.075Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-08-07T17:40:29.077Z",
                 "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" => 3111,
                  "purchased_at" => "2026-08-07T17:40:32.625Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-08-07T17:40:32.628Z",
                 "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" => 3112,
                  "purchased_at" => "2026-08-07T17:40:33.503Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-08-07T17:40:33.505Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 8] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [ 9] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [10] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [11] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [12] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [13] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 3113,
                  "purchased_at" => "2026-08-07T21:26:48.306Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-08-07T21:26:48.323Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [14] [
        [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
}