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
Mar 17, 9:18 PM +10 credits subscription_credits first_cycle expires in about 1 month
Mar 17, 9:19 PM +10 credits subscription_credits first_cycle expires in about 1 month
Mar 17, 9:21 PM +10 credits credit_pack_purchase
Mar 17, 9:24 PM +10 credits credit_pack_purchase
Mar 17, 9:26 PM +5100 credits credit_pack_purchase
Mar 17, 9:28 PM +5100 credits credit_pack_purchase
Mar 17, 9:28 PM +10 credits subscription_credits first_cycle expires in about 1 month
Mar 17, 9:28 PM +10 credits signup_bonus signup
Mar 17, 9:28 PM +10 credits signup_bonus signup
Mar 17, 9:31 PM +10 credits signup_bonus signup
Mar 17, 9:31 PM +20 credits referral_bonus referral
Mar 17, 9:31 PM +20 credits referral_bonus referral
Mar 17, 9:31 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Mar 17, 9:32 PM +10 credits bonus expiring_bonus_credits 🗑️ expired
Mar 17, 9:59 PM +10 credits subscription_credits first_cycle expires in about 1 month
Mar 17, 9:59 PM +10 credits signup_bonus signup
Mar 17, 10:21 PM +10 credits subscription_credits first_cycle expires in about 1 month
Mar 17, 10:21 PM +10 credits signup_bonus signup

Payment records (pay gem)

The user has paid $399.98 total

Pay::Charge (4)
# {
                        :id => 2273,
               :customer_id => 3319,
           :subscription_id => nil,
              :processor_id => "GwJFOTgKu5x-ybn_mEF-2",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-17 21:24:15.749581000 UTC +00:00,
                :updated_at => 2026-03-17 21:24:15.749581000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2275,
               :customer_id => 3319,
           :subscription_id => nil,
              :processor_id => "g_lK4ItpUC6m_JXt6VvUv",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-17 21:28:25.011764000 UTC +00:00,
                :updated_at => 2026-03-17 21:28:25.011764000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2274,
               :customer_id => 3319,
           :subscription_id => nil,
              :processor_id => "mVEV3vJ3sOkXOzzQej6Gd",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-17 21:26:45.828081000 UTC +00:00,
                :updated_at => 2026-03-17 21:26:45.828081000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
# {
                        :id => 2272,
               :customer_id => 3319,
           :subscription_id => nil,
              :processor_id => "whnBhacF2o4LLtFkpVPGl",
                    :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" => 3,
                   "exp_year" => 2026
    },
            :stripe_account => nil,
                :created_at => 2026-03-17 21:21:21.239862000 UTC +00:00,
                :updated_at => 2026-03-17 21:21:21.239862000 UTC +00:00,
                      :type => "Pay::FakeProcessor::Charge"
}
Pay::Subscription (5)
# {
                         "id" => 1213,
                "customer_id" => 3319,
                       "name" => "default",
               "processor_id" => "5MptFwKlHdcL340sA25XF",
             "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-03-17 21:59:38.672514000 UTC +00:00,
                 "updated_at" => 2026-03-17 21:59:38.672514000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1211,
                "customer_id" => 3319,
                       "name" => "default",
               "processor_id" => "ER9dvQC5Unq6tCPXoSmXj",
             "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-03-17 21:19:46.447095000 UTC +00:00,
                 "updated_at" => 2026-03-17 21:19:46.447095000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1214,
                "customer_id" => 3319,
                       "name" => "default",
               "processor_id" => "U_r_FeT3D1ccPGqC_yfip",
             "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-03-17 22:21:14.696762000 UTC +00:00,
                 "updated_at" => 2026-03-17 22:21:14.696762000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1212,
                "customer_id" => 3319,
                       "name" => "default",
               "processor_id" => "lPzlUa1pXIjGvsMQ9SXcg",
             "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-03-17 21:28:34.986643000 UTC +00:00,
                 "updated_at" => 2026-03-17 21:28:34.986643000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}
# {
                         "id" => 1210,
                "customer_id" => 3319,
                       "name" => "default",
               "processor_id" => "qgtQAJND7UTS7XTAUrUEn",
             "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-03-17 21:18:19.518774000 UTC +00:00,
                 "updated_at" => 2026-03-17 21:18:19.518774000 UTC +00:00,
                       "type" => "Pay::FakeProcessor::Subscription",
                    "prorate" => true
}

Model records

UsageCredits::Fulfillment (9)
# {
                          :id => 3481,
                   :wallet_id => 3324,
                 :source_type => "Pay::Subscription",
                   :source_id => 1210,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-03-17 21:18:19.522786000 UTC +00:00,
         :next_fulfillment_at => 2026-04-17 21:18:19.518774000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1210,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-03-17 21:18:19.523350000 UTC +00:00,
                  :updated_at => 2026-03-17 21:18:19.523350000 UTC +00:00
}
# {
                          :id => 3482,
                   :wallet_id => 3324,
                 :source_type => "Pay::Subscription",
                   :source_id => 1211,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-03-17 21:19:46.451732000 UTC +00:00,
         :next_fulfillment_at => 2026-04-17 21:19:46.447095000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1211,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-03-17 21:19:46.452349000 UTC +00:00,
                  :updated_at => 2026-03-17 21:19:46.452349000 UTC +00:00
}
# {
                          :id => 3483,
                   :wallet_id => 3324,
                 :source_type => "Pay::Charge",
                   :source_id => 2272,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-17 21:21:21.244813000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2272,
              "purchased_at" => "2026-03-17T21:21:21.239Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-17 21:21:21.245408000 UTC +00:00,
                  :updated_at => 2026-03-17 21:21:21.245408000 UTC +00:00
}
# {
                          :id => 3484,
                   :wallet_id => 3324,
                 :source_type => "Pay::Charge",
                   :source_id => 2273,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-17 21:24:15.755995000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2273,
              "purchased_at" => "2026-03-17T21:24:15.749Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-17 21:24:15.756490000 UTC +00:00,
                  :updated_at => 2026-03-17 21:24:15.756490000 UTC +00:00
}
# {
                          :id => 3485,
                   :wallet_id => 3324,
                 :source_type => "Pay::Charge",
                   :source_id => 2274,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-17 21:26:45.832773000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2274,
              "purchased_at" => "2026-03-17T21:26:45.828Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-17 21:26:45.833308000 UTC +00:00,
                  :updated_at => 2026-03-17 21:26:45.833308000 UTC +00:00
}
# {
                          :id => 3486,
                   :wallet_id => 3324,
                 :source_type => "Pay::Charge",
                   :source_id => 2275,
    :credits_last_fulfillment => 5100,
            :fulfillment_type => "credit_pack",
           :last_fulfilled_at => 2026-03-17 21:28:25.020505000 UTC +00:00,
         :next_fulfillment_at => nil,
          :fulfillment_period => nil,
                    :stops_at => nil,
                    :metadata => {
        "purchase_charge_id" => 2275,
              "purchased_at" => "2026-03-17T21:28:25.011Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
                  :created_at => 2026-03-17 21:28:25.021071000 UTC +00:00,
                  :updated_at => 2026-03-17 21:28:25.021071000 UTC +00:00
}
# {
                          :id => 3487,
                   :wallet_id => 3324,
                 :source_type => "Pay::Subscription",
                   :source_id => 1212,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-03-17 21:28:34.990965000 UTC +00:00,
         :next_fulfillment_at => 2026-04-17 21:28:34.986643000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1212,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-03-17 21:28:34.991458000 UTC +00:00,
                  :updated_at => 2026-03-17 21:28:34.991458000 UTC +00:00
}
# {
                          :id => 3488,
                   :wallet_id => 3324,
                 :source_type => "Pay::Subscription",
                   :source_id => 1213,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-03-17 21:59:38.680112000 UTC +00:00,
         :next_fulfillment_at => 2026-04-17 21:59:38.672514000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1213,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-03-17 21:59:38.680771000 UTC +00:00,
                  :updated_at => 2026-03-17 21:59:38.680771000 UTC +00:00
}
# {
                          :id => 3489,
                   :wallet_id => 3324,
                 :source_type => "Pay::Subscription",
                   :source_id => 1214,
    :credits_last_fulfillment => 10,
            :fulfillment_type => "subscription",
           :last_fulfilled_at => 2026-03-17 22:21:14.704853000 UTC +00:00,
         :next_fulfillment_at => 2026-04-17 22:21:14.696762000 UTC +00:00,
          :fulfillment_period => "1 month",
                    :stops_at => nil,
                    :metadata => {
        "subscription_id" => 1214,
                   "plan" => "abcdef123456"
    },
                  :created_at => 2026-03-17 22:21:14.705588000 UTC +00:00,
                  :updated_at => 2026-03-17 22:21:14.705588000 UTC +00:00
}
UsageCredits::Transaction (18)
# {
                :id => 5719,
         :wallet_id => 3324,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-04-17 21:23:19.518774000 UTC +00:00,
    :fulfillment_id => 3481,
          :metadata => {
        "subscription_id" => 1210,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-03-17T21:18:19.520Z"
    },
        :created_at => 2026-03-17 21:18:19.521280000 UTC +00:00,
        :updated_at => 2026-03-17 21:18:19.521280000 UTC +00:00
}
# {
                :id => 5720,
         :wallet_id => 3324,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-04-17 21:24:46.447095000 UTC +00:00,
    :fulfillment_id => 3482,
          :metadata => {
        "subscription_id" => 1211,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-03-17T21:19:46.448Z"
    },
        :created_at => 2026-03-17 21:19:46.450161000 UTC +00:00,
        :updated_at => 2026-03-17 21:19:46.450161000 UTC +00:00
}
# {
                :id => 5721,
         :wallet_id => 3324,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2272,
              "purchased_at" => "2026-03-17T21:21:21.239Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-17T21:21:21.241Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-17 21:21:21.242962000 UTC +00:00,
        :updated_at => 2026-03-17 21:21:21.242962000 UTC +00:00
}
# {
                :id => 5722,
         :wallet_id => 3324,
            :amount => 10,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2273,
              "purchased_at" => "2026-03-17T21:24:15.749Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-17T21:24:15.753Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "tiny",
                   "credits" => 10,
             "bonus_credits" => 0,
               "price_cents" => 99,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-17 21:24:15.754438000 UTC +00:00,
        :updated_at => 2026-03-17 21:24:15.754438000 UTC +00:00
}
# {
                :id => 5723,
         :wallet_id => 3324,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2274,
              "purchased_at" => "2026-03-17T21:26:45.828Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-17T21:26:45.829Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-17 21:26:45.831128000 UTC +00:00,
        :updated_at => 2026-03-17 21:26:45.831128000 UTC +00:00
}
# {
                :id => 5724,
         :wallet_id => 3324,
            :amount => 5100,
          :category => "credit_pack_purchase",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "purchase_charge_id" => 2275,
              "purchased_at" => "2026-03-17T21:28:25.011Z",
         "credits_fulfilled" => true,
              "fulfilled_at" => "2026-03-17T21:28:25.017Z",
             "purchase_type" => "credit_pack",
                 "pack_name" => "pro",
                   "credits" => 5000,
             "bonus_credits" => 100,
               "price_cents" => 19900,
            "price_currency" => "USD"
    },
        :created_at => 2026-03-17 21:28:25.018764000 UTC +00:00,
        :updated_at => 2026-03-17 21:28:25.018764000 UTC +00:00
}
# {
                :id => 5725,
         :wallet_id => 3324,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-04-17 21:33:34.986643000 UTC +00:00,
    :fulfillment_id => 3487,
          :metadata => {
        "subscription_id" => 1212,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-03-17T21:28:34.988Z"
    },
        :created_at => 2026-03-17 21:28:34.989654000 UTC +00:00,
        :updated_at => 2026-03-17 21:28:34.989654000 UTC +00:00
}
# {
                :id => 5726,
         :wallet_id => 3324,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-03-17 21:28:35.462593000 UTC +00:00,
        :updated_at => 2026-03-17 21:28:35.462593000 UTC +00:00
}
# {
                :id => 5727,
         :wallet_id => 3324,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-03-17 21:28:40.756016000 UTC +00:00,
        :updated_at => 2026-03-17 21:28:40.756016000 UTC +00:00
}
# {
                :id => 5728,
         :wallet_id => 3324,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-03-17 21:31:32.955508000 UTC +00:00,
        :updated_at => 2026-03-17 21:31:32.955508000 UTC +00:00
}
# {
                :id => 5729,
         :wallet_id => 3324,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-03-17 21:31:34.776664000 UTC +00:00,
        :updated_at => 2026-03-17 21:31:34.776664000 UTC +00:00
}
# {
                :id => 5730,
         :wallet_id => 3324,
            :amount => 20,
          :category => "referral_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "referral"
    },
        :created_at => 2026-03-17 21:31:37.476945000 UTC +00:00,
        :updated_at => 2026-03-17 21:31:37.476945000 UTC +00:00
}
# {
                :id => 5731,
         :wallet_id => 3324,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-03-17 21:32:43.440500000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-03-17 21:31:43.443308000 UTC +00:00,
        :updated_at => 2026-03-17 21:31:43.443308000 UTC +00:00
}
# {
                :id => 5732,
         :wallet_id => 3324,
            :amount => 10,
          :category => "bonus",
        :expires_at => 2026-03-17 21:33:51.635008000 UTC +00:00,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "expiring_bonus_credits"
    },
        :created_at => 2026-03-17 21:32:51.637458000 UTC +00:00,
        :updated_at => 2026-03-17 21:32:51.637458000 UTC +00:00
}
# {
                :id => 5733,
         :wallet_id => 3324,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-04-17 22:04:38.672514000 UTC +00:00,
    :fulfillment_id => 3488,
          :metadata => {
        "subscription_id" => 1213,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-03-17T21:59:38.677Z"
    },
        :created_at => 2026-03-17 21:59:38.678772000 UTC +00:00,
        :updated_at => 2026-03-17 21:59:38.678772000 UTC +00:00
}
# {
                :id => 5734,
         :wallet_id => 3324,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-03-17 21:59:39.184968000 UTC +00:00,
        :updated_at => 2026-03-17 21:59:39.184968000 UTC +00:00
}
# {
                :id => 5735,
         :wallet_id => 3324,
            :amount => 10,
          :category => "subscription_credits",
        :expires_at => 2026-04-17 22:26:14.696762000 UTC +00:00,
    :fulfillment_id => 3489,
          :metadata => {
        "subscription_id" => 1214,
                 "reason" => "first_cycle",
                   "plan" => "abcdef123456",
           "fulfilled_at" => "2026-03-17T22:21:14.701Z"
    },
        :created_at => 2026-03-17 22:21:14.702953000 UTC +00:00,
        :updated_at => 2026-03-17 22:21:14.702953000 UTC +00:00
}
# {
                :id => 5736,
         :wallet_id => 3324,
            :amount => 10,
          :category => "signup_bonus",
        :expires_at => nil,
    :fulfillment_id => nil,
          :metadata => {
        "reason" => "signup"
    },
        :created_at => 2026-03-17 22:21:15.138828000 UTC +00:00,
        :updated_at => 2026-03-17 22:21:15.138828000 UTC +00:00
}
UsageCredits::Allocation (0) none

Audit trail

Audit trail
[
    [ 0] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1210,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-03-17T21:18:19.520Z"
        }
    ],
    [ 1] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1211,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-03-17T21:19:46.448Z"
        }
    ],
    [ 2] [
        [0] "credit_pack_purchase",
        [1] 10,
        [2] {
            "purchase_charge_id" => 2272,
                  "purchased_at" => "2026-03-17T21:21:21.239Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-17T21:21:21.241Z",
                 "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" => 2273,
                  "purchased_at" => "2026-03-17T21:24:15.749Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-17T21:24:15.753Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "tiny",
                       "credits" => 10,
                 "bonus_credits" => 0,
                   "price_cents" => 99,
                "price_currency" => "USD"
        }
    ],
    [ 4] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2274,
                  "purchased_at" => "2026-03-17T21:26:45.828Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-17T21:26:45.829Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 5] [
        [0] "credit_pack_purchase",
        [1] 5100,
        [2] {
            "purchase_charge_id" => 2275,
                  "purchased_at" => "2026-03-17T21:28:25.011Z",
             "credits_fulfilled" => true,
                  "fulfilled_at" => "2026-03-17T21:28:25.017Z",
                 "purchase_type" => "credit_pack",
                     "pack_name" => "pro",
                       "credits" => 5000,
                 "bonus_credits" => 100,
                   "price_cents" => 19900,
                "price_currency" => "USD"
        }
    ],
    [ 6] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1212,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-03-17T21:28:34.988Z"
        }
    ],
    [ 7] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [ 8] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [ 9] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [10] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [11] [
        [0] "referral_bonus",
        [1] 20,
        [2] {
            "reason" => "referral"
        }
    ],
    [12] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [13] [
        [0] "bonus",
        [1] 10,
        [2] {
            "reason" => "expiring_bonus_credits"
        }
    ],
    [14] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1213,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-03-17T21:59:38.677Z"
        }
    ],
    [15] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ],
    [16] [
        [0] "subscription_credits",
        [1] 10,
        [2] {
            "subscription_id" => 1214,
                     "reason" => "first_cycle",
                       "plan" => "abcdef123456",
               "fulfilled_at" => "2026-03-17T22:21:14.701Z"
        }
    ],
    [17] [
        [0] "signup_bonus",
        [1] 10,
        [2] {
            "reason" => "signup"
        }
    ]
]

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
}