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
Nov 10, 11:43 AM +10 credits bonus expiring_bonus_credits 🗑️ expired
Nov 10, 11:43 AM +10 credits credit_pack_purchase –
Nov 10, 11:43 AM +1000 credits credit_pack_purchase –
Nov 10, 11:43 AM +5100 credits credit_pack_purchase –
Nov 10, 11:43 AM +1000 credits credit_pack_purchase –
Nov 10, 11:43 AM +1000 credits credit_pack_purchase –
Nov 10, 3:11 PM +5100 credits credit_pack_purchase –
Nov 10, 3:12 PM +5100 credits credit_pack_purchase –

Payment records (pay gem)

The user has paid $744.99 total

Pay::Charge (7)
# {
                        :id => 4116,
               :customer_id => 5761,
           :subscription_id => nil,
              :processor_id => "2f9Ph-z0VDKh5OGFeihE3",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-10 11:43:48.175112000 UTC +00:00,
                :updated_at => 2026-11-10 11:43:48.175112000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4112,
               :customer_id => 5761,
           :subscription_id => nil,
              :processor_id => "CPgLVNjM1Wa394q8z17nE",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-10 11:43:24.486647000 UTC +00:00,
                :updated_at => 2026-11-10 11:43:24.486647000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4114,
               :customer_id => 5761,
           :subscription_id => nil,
              :processor_id => "Drl-3yqUx7dGkyGTrewx6",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-10 11:43:25.138478000 UTC +00:00,
                :updated_at => 2026-11-10 11:43:25.138478000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4117,
               :customer_id => 5761,
           :subscription_id => nil,
              :processor_id => "b1GBoZapIt5QCe-3aCWNR",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-10 15:11:57.654286000 UTC +00:00,
                :updated_at => 2026-11-10 15:11:57.654286000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4113,
               :customer_id => 5761,
           :subscription_id => nil,
              :processor_id => "cWzyJ5nwja1hQnrfIjN-c",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-10 11:43:24.628290000 UTC +00:00,
                :updated_at => 2026-11-10 11:43:24.628290000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4115,
               :customer_id => 5761,
           :subscription_id => nil,
              :processor_id => "mBDn8GW3lZFYhicpnAaFG",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-10 11:43:36.465282000 UTC +00:00,
                :updated_at => 2026-11-10 11:43:36.465282000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 4118,
               :customer_id => 5761,
           :subscription_id => nil,
              :processor_id => "o_5E2Ma-DT6qZygMYeLgk",
                    :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" => 11,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-11-10 15:12:11.633185000 UTC +00:00,
                :updated_at => 2026-11-10 15:12:11.633185000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (0) none

Model records

UsageCredits::Fulfillment (7)
# {
                          :id => 5958,
                   :wallet_id => 5769,
                 :source_type => "Pay::Charge",
                   :source_id => 4112,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-10 11:43:24.492021000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4112,
              "purchased_at" => "2026-11-10T11:43:24.486Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-10 11:43:24.492363000 UTC +00:00,
                  :updated_at => 2026-11-10 11:43:24.492363000 UTC +00:00
}
# {
                          :id => 5959,
                   :wallet_id => 5769,
                 :source_type => "Pay::Charge",
                   :source_id => 4113,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-10 11:43:24.631748000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4113,
              "purchased_at" => "2026-11-10T11:43:24.628Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-10 11:43:24.632034000 UTC +00:00,
                  :updated_at => 2026-11-10 11:43:24.632034000 UTC +00:00
}
# {
                          :id => 5960,
                   :wallet_id => 5769,
                 :source_type => "Pay::Charge",
                   :source_id => 4114,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-10 11:43:25.142527000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4114,
              "purchased_at" => "2026-11-10T11:43:25.138Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-10 11:43:25.142832000 UTC +00:00,
                  :updated_at => 2026-11-10 11:43:25.142832000 UTC +00:00
}
# {
                          :id => 5961,
                   :wallet_id => 5769,
                 :source_type => "Pay::Charge",
                   :source_id => 4115,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-10 11:43:36.468791000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4115,
              "purchased_at" => "2026-11-10T11:43:36.465Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-10 11:43:36.469195000 UTC +00:00,
                  :updated_at => 2026-11-10 11:43:36.469195000 UTC +00:00
}
# {
                          :id => 5962,
                   :wallet_id => 5769,
                 :source_type => "Pay::Charge",
                   :source_id => 4116,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-10 11:43:48.178435000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4116,
              "purchased_at" => "2026-11-10T11:43:48.175Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-10 11:43:48.178835000 UTC +00:00,
                  :updated_at => 2026-11-10 11:43:48.178835000 UTC +00:00
}
# {
                          :id => 5963,
                   :wallet_id => 5769,
                 :source_type => "Pay::Charge",
                   :source_id => 4117,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-10 15:11:57.659629000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4117,
              "purchased_at" => "2026-11-10T15:11:57.654Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-10 15:11:57.660103000 UTC +00:00,
                  :updated_at => 2026-11-10 15:11:57.660103000 UTC +00:00
}
# {
                          :id => 5964,
                   :wallet_id => 5769,
                 :source_type => "Pay::Charge",
                   :source_id => 4118,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-11-10 15:12:11.636566000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 4118,
              "purchased_at" => "2026-11-10T15:12:11.633Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-11-10 15:12:11.636868000 UTC +00:00,
                  :updated_at => 2026-11-10 15:12:11.636868000 UTC +00:00
}
UsageCredits::Transaction (8)
# {
                :id => 9755,
         :wallet_id => 5769,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-11-10 11:44:24.341490000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-11-10 11:43:24.344849000 UTC +00:00,
        :updated_at => 2026-11-10 11:43:24.344849000 UTC +00:00
}
# {
                :id => 9756,
         :wallet_id => 5769,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4112,
              "purchased_at" => "2026-11-10T11:43:24.486Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-10T11:43:24.487Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-10 11:43:24.491003000 UTC +00:00,
        :updated_at => 2026-11-10 11:43:24.491003000 UTC +00:00
}
# {
                :id => 9757,
         :wallet_id => 5769,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4113,
              "purchased_at" => "2026-11-10T11:43:24.628Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-10T11:43:24.629Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-10 11:43:24.630762000 UTC +00:00,
        :updated_at => 2026-11-10 11:43:24.630762000 UTC +00:00
}
# {
                :id => 9758,
         :wallet_id => 5769,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4114,
              "purchased_at" => "2026-11-10T11:43:25.138Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-10T11:43:25.139Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-10 11:43:25.140808000 UTC +00:00,
        :updated_at => 2026-11-10 11:43:25.140808000 UTC +00:00
}
# {
                :id => 9759,
         :wallet_id => 5769,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4115,
              "purchased_at" => "2026-11-10T11:43:36.465Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-10T11:43:36.466Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-10 11:43:36.467725000 UTC +00:00,
        :updated_at => 2026-11-10 11:43:36.467725000 UTC +00:00
}
# {
                :id => 9760,
         :wallet_id => 5769,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4116,
              "purchased_at" => "2026-11-10T11:43:48.175Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-10T11:43:48.176Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-10 11:43:48.177434000 UTC +00:00,
        :updated_at => 2026-11-10 11:43:48.177434000 UTC +00:00
}
# {
                :id => 9761,
         :wallet_id => 5769,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4117,
              "purchased_at" => "2026-11-10T15:11:57.654Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-10T15:11:57.657Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-10 15:11:57.658307000 UTC +00:00,
        :updated_at => 2026-11-10 15:11:57.658307000 UTC +00:00
}
# {
                :id => 9762,
         :wallet_id => 5769,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 4118,
              "purchased_at" => "2026-11-10T15:12:11.633Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-11-10T15:12:11.634Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-11-10 15:12:11.635579000 UTC +00:00,
        :updated_at => 2026-11-10 15:12:11.635579000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [0] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [1] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 4112,
                  "purchased_at" => "2026-11-10T11:43:24.486Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-10T11:43:24.487Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [2] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4113,
                  "purchased_at" => "2026-11-10T11:43:24.628Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-10T11:43:24.629Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [3] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 4114,
                  "purchased_at" => "2026-11-10T11:43:25.138Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-10T11:43:25.139Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [4] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 4115,
                  "purchased_at" => "2026-11-10T11:43:36.465Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-10T11:43:36.466Z",
                 "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" => 4116,
                  "purchased_at" => "2026-11-10T11:43:48.175Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-10T11:43:48.176Z",
                 "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" => 4117,
                  "purchased_at" => "2026-11-10T15:11:57.654Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-10T15:11:57.657Z",
                 "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" => 4118,
                  "purchased_at" => "2026-11-10T15:12:11.633Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-11-10T15:12:11.634Z",
                 "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
}