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
Feb 21, 8:05 AM +10 credits bonus expiring_bonus_credits 🗑️ expired
Feb 21, 8:05 AM +20 credits referral_bonus referral
Feb 21, 8:05 AM +10 credits signup_bonus signup
Feb 21, 8:05 AM +10 credits subscription_credits first_cycle expires in 27 days
Feb 21, 8:05 AM +5100 credits credit_pack_purchase
Feb 21, 8:07 AM +10 credits credit_pack_purchase
Feb 21, 8:07 AM +1000 credits credit_pack_purchase
Feb 21, 8:51 AM +1000 credits credit_pack_purchase
Feb 21, 8:51 AM +10 credits subscription_credits first_cycle expires in 28 days
Feb 21, 11:03 AM +5100 credits credit_pack_purchase

Payment records (pay gem)

The user has paid $496.99 total

Pay::Charge (5)
# {
                        :id => 2152,
               :customer_id => 3218,
           :subscription_id => nil,
              :processor_id => "-NQzleullNit7Fk48Cnz2",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-21 08:51:48.734346000 UTC +00:00,
                :updated_at => 2026-02-21 08:51:48.734346000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2150,
               :customer_id => 3218,
           :subscription_id => nil,
              :processor_id => "59XKjvlC6gDWfW2wTrX5F",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-21 08:07:09.805337000 UTC +00:00,
                :updated_at => 2026-02-21 08:07:09.805337000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2151,
               :customer_id => 3218,
           :subscription_id => nil,
              :processor_id => "QtKs7slLb3PcLWCcLdGiF",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-21 08:07:20.585116000 UTC +00:00,
                :updated_at => 2026-02-21 08:07:20.585116000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2149,
               :customer_id => 3218,
           :subscription_id => nil,
              :processor_id => "YLEnJSeLE2JNdusKwr6ZM",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-21 08:05:26.784033000 UTC +00:00,
                :updated_at => 2026-02-21 08:05:26.784033000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2153,
               :customer_id => 3218,
           :subscription_id => nil,
              :processor_id => "k5WDX5KH7r50vFXvSWeyB",
                    :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" => 2,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-02-21 11:03:24.469710000 UTC +00:00,
                :updated_at => 2026-02-21 11:03:24.469710000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (2)
# {
                         "id" => 1163,
                "customer_id" => 3218,
                       "name" => "default",
               "processor_id" => "XIraJoYL9We_t8i4GUtyL",
             "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-02-21 08:05:16.967076000 UTC +00:00,
                 "updated_at" => 2026-02-21 08:05:16.967076000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1164,
                "customer_id" => 3218,
                       "name" => "default",
               "processor_id" => "aXSEVLTNVM-VfrV3s43o6",
             "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-02-21 08:51:52.666972000 UTC +00:00,
                 "updated_at" => 2026-02-21 08:51:52.666972000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (7)
# {
                          :id => 3311,
                   :wallet_id => 3223,
                 :source_type => "Pay::Subscription",
                   :source_id => 1163,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-02-21 08:05:16.988302000 UTC +00:00,
         :next_fulfillment_at => 2026-03-21 08:05:16.967076000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1163,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-02-21 08:05:17.001353000 UTC +00:00,
                  :updated_at => 2026-02-21 08:05:17.001353000 UTC +00:00
}
# {
                          :id => 3312,
                   :wallet_id => 3223,
                 :source_type => "Pay::Charge",
                   :source_id => 2149,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-21 08:05:26.794545000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2149,
              "purchased_at" => "2026-02-21T08:05:26.784Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-21 08:05:26.795839000 UTC +00:00,
                  :updated_at => 2026-02-21 08:05:26.795839000 UTC +00:00
}
# {
                          :id => 3313,
                   :wallet_id => 3223,
                 :source_type => "Pay::Charge",
                   :source_id => 2150,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-21 08:07:09.820939000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2150,
              "purchased_at" => "2026-02-21T08:07:09.805Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-21 08:07:09.822795000 UTC +00:00,
                  :updated_at => 2026-02-21 08:07:09.822795000 UTC +00:00
}
# {
                          :id => 3314,
                   :wallet_id => 3223,
                 :source_type => "Pay::Charge",
                   :source_id => 2151,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-21 08:07:20.596027000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2151,
              "purchased_at" => "2026-02-21T08:07:20.585Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-21 08:07:20.596947000 UTC +00:00,
                  :updated_at => 2026-02-21 08:07:20.596947000 UTC +00:00
}
# {
                          :id => 3315,
                   :wallet_id => 3223,
                 :source_type => "Pay::Charge",
                   :source_id => 2152,
    :credits_last_fulfillment => 1000,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-21 08:51:48.752697000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2152,
              "purchased_at" => "2026-02-21T08:51:48.734Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-21 08:51:48.753588000 UTC +00:00,
                  :updated_at => 2026-02-21 08:51:48.753588000 UTC +00:00
}
# {
                          :id => 3316,
                   :wallet_id => 3223,
                 :source_type => "Pay::Subscription",
                   :source_id => 1164,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-02-21 08:51:52.671419000 UTC +00:00,
         :next_fulfillment_at => 2026-03-21 08:51:52.666972000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1164,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-02-21 08:51:52.672073000 UTC +00:00,
                  :updated_at => 2026-02-21 08:51:52.672073000 UTC +00:00
}
# {
                          :id => 3317,
                   :wallet_id => 3223,
                 :source_type => "Pay::Charge",
                   :source_id => 2153,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-02-21 11:03:24.476899000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2153,
              "purchased_at" => "2026-02-21T11:03:24.469Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-02-21 11:03:24.477364000 UTC +00:00,
                  :updated_at => 2026-02-21 11:03:24.477364000 UTC +00:00
}
UsageCredits::Transaction (10)
# {
                :id => 5441,
         :wallet_id => 3223,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-02-21 08:06:11.151876000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-02-21 08:05:11.213351000 UTC +00:00,
        :updated_at => 2026-02-21 08:05:11.213351000 UTC +00:00
}
# {
                :id => 5442,
         :wallet_id => 3223,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-02-21 08:05:12.986550000 UTC +00:00,
        :updated_at => 2026-02-21 08:05:12.986550000 UTC +00:00
}
# {
                :id => 5443,
         :wallet_id => 3223,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-02-21 08:05:14.859665000 UTC +00:00,
        :updated_at => 2026-02-21 08:05:14.859665000 UTC +00:00
}
# {
                :id => 5444,
         :wallet_id => 3223,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-03-21 08:10:16.967076000 UTC +00:00,
    :fulfillment_id => 3311,
          :metadata => {
        "subscription_id" => 1163,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-02-21T08:05:16.980Z"
    },
        :created_at => 2026-02-21 08:05:16.984283000 UTC +00:00,
        :updated_at => 2026-02-21 08:05:16.984283000 UTC +00:00
}
# {
                :id => 5445,
         :wallet_id => 3223,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2149,
              "purchased_at" => "2026-02-21T08:05:26.784Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-21T08:05:26.788Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-21 08:05:26.791449000 UTC +00:00,
        :updated_at => 2026-02-21 08:05:26.791449000 UTC +00:00
}
# {
                :id => 5446,
         :wallet_id => 3223,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2150,
              "purchased_at" => "2026-02-21T08:07:09.805Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-21T08:07:09.812Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-21 08:07:09.816409000 UTC +00:00,
        :updated_at => 2026-02-21 08:07:09.816409000 UTC +00:00
}
# {
                :id => 5447,
         :wallet_id => 3223,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2151,
              "purchased_at" => "2026-02-21T08:07:20.585Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-21T08:07:20.589Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-21 08:07:20.592020000 UTC +00:00,
        :updated_at => 2026-02-21 08:07:20.592020000 UTC +00:00
}
# {
                :id => 5448,
         :wallet_id => 3223,
            :amount => 1000,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2152,
              "purchased_at" => "2026-02-21T08:51:48.734Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-21T08:51:48.742Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "starter",
                   "credits" => 1000,
             "bonus_credits" => 0,
               "price_cents" => 4900,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-21 08:51:48.746727000 UTC +00:00,
        :updated_at => 2026-02-21 08:51:48.746727000 UTC +00:00
}
# {
                :id => 5449,
         :wallet_id => 3223,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-03-21 08:56:52.666972000 UTC +00:00,
    :fulfillment_id => 3316,
          :metadata => {
        "subscription_id" => 1164,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-02-21T08:51:52.668Z"
    },
        :created_at => 2026-02-21 08:51:52.669929000 UTC +00:00,
        :updated_at => 2026-02-21 08:51:52.669929000 UTC +00:00
}
# {
                :id => 5450,
         :wallet_id => 3223,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2153,
              "purchased_at" => "2026-02-21T11:03:24.469Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-02-21T11:03:24.473Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-02-21 11:03:24.475357000 UTC +00:00,
        :updated_at => 2026-02-21 11:03:24.475357000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [0] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [1] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [2] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [3] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1163,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-02-21T08:05:16.980Z"
        }
    ],
    [4] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2149,
                  "purchased_at" => "2026-02-21T08:05:26.784Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-21T08:05:26.788Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [5] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2150,
                  "purchased_at" => "2026-02-21T08:07:09.805Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-21T08:07:09.812Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [6] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2151,
                  "purchased_at" => "2026-02-21T08:07:20.585Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-21T08:07:20.589Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [7] [
        [0] "credit_pack_purchase",
        [1] 1000,
        [2] {
            "purchase_charge_id" => 2152,
                  "purchased_at" => "2026-02-21T08:51:48.734Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-21T08:51:48.742Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "starter",
                       "credits" => 1000,
                 "bonus_credits" => 0,
                   "price_cents" => 4900,
                "price_currency" => "USD"
        }
    ],
    [8] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1164,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-02-21T08:51:52.668Z"
        }
    ],
    [9] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2153,
                  "purchased_at" => "2026-02-21T11:03:24.469Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-02-21T11:03:24.473Z",
                 "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
}