usage_credits 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/lib/usage_credits/models/wallet.rb +9 -2
- data/lib/usage_credits/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 710aa384672853be7b8711cffb537ad348761d0f8bf8c9df899565c7917522a8
|
|
4
|
+
data.tar.gz: de219e55c5442ce44bbdf9bc1843c5bdeaa1e32508e3ee3c193f5baef0b7c259
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ddd7d4f68a78f5608ded3984b277b6956ed1f849a72061a1816e1456252a164d87b771dd94337d653f28414932e349d31c88168085c1ead78e4083103920f356
|
|
7
|
+
data.tar.gz: cfaa71674966f0197675a0467cce70d5476b4dd161d838907567e286920590a3051463cb1583baab92e23e852942b6414812df23ed93dc2a421f613f9c853b8f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.0.1] - 2026-10-18
|
|
2
|
+
|
|
3
|
+
### Fixed
|
|
4
|
+
|
|
5
|
+
- **A refused `spend_credits_on` no longer poisons the wallet instance.** When the block had spent on the same wallet instance (or a caller's transaction rolled a command back), Rails left the cached balance and `ledger_revision` the command had written in memory as unsaved changes, and the next command on that instance raised `RuntimeError: Locking a record with unpersisted changes is not supported` instead of running. The fix is in `wallets` 0.4.2, which this release requires (`~> 0.4.2`); a regression test here pins the `spend_credits_on` shape.
|
|
6
|
+
- `InsufficientCredits` speaks of credits whichever command raised it: `deduct_credits` and transfers used to pass the core's "Insufficient balance (5 < 10)" through, while `spend_credits_on` said "Insufficient credits (5 < 10)".
|
|
7
|
+
|
|
1
8
|
## [1.0.0] - 2026-10-18
|
|
2
9
|
|
|
3
10
|
`usage_credits` is now built on top of [`wallets`](https://github.com/rameerez/wallets), our append-oriented, multi-asset ledger core. The credits-focused DX you know is unchanged — same `has_credits`, `spend_credits_on`, `give_credits`, packs, subscriptions, and Pay integration — but the expiration-aware allocation ledger, balance math, row-level locking, and transfer machinery now live in a shared, independently tested core.
|
data/README.md
CHANGED
|
@@ -22,7 +22,7 @@ All with a simple DSL that reads just like English.
|
|
|
22
22
|
- Ruby 3.2+ and Rails 7.2.3.1–8.x. Ruby 3.2 is the security floor because current patched versions of transitive Rails dependencies no longer support Ruby 3.1.
|
|
23
23
|
- An ActiveJob backend (Sidekiq, `solid_queue`, etc.) for subscription credit fulfillment
|
|
24
24
|
- [`pay`](https://github.com/pay-rails/pay) 11.6.2–11.x for payment integration. Pay 11.6.2 is the security floor because it fixes [GHSA-mjgf-xj26-9qf9](https://github.com/pay-rails/pay/security/advisories/GHSA-mjgf-xj26-9qf9).
|
|
25
|
-
- [`wallets`](https://github.com/rameerez/wallets) 0.4.x (installed automatically as the ledger core)
|
|
25
|
+
- [`wallets`](https://github.com/rameerez/wallets) 0.4.2 or any later 0.4.x (installed automatically as the ledger core)
|
|
26
26
|
|
|
27
27
|
## 👨💻 Example
|
|
28
28
|
|
|
@@ -208,7 +208,7 @@ module UsageCredits
|
|
|
208
208
|
def deduct_credits(amount, metadata: {}, category: :credit_deducted, fulfillment: nil)
|
|
209
209
|
debit(amount, metadata: metadata, category: category, fulfillment: fulfillment)
|
|
210
210
|
rescue Wallets::InsufficientBalance => e
|
|
211
|
-
raise InsufficientCredits, e.message
|
|
211
|
+
raise InsufficientCredits, in_credits_terms(e.message)
|
|
212
212
|
end
|
|
213
213
|
|
|
214
214
|
# Shorten the lifetime of credits minted by one fulfillment and reconcile
|
|
@@ -260,7 +260,7 @@ module UsageCredits
|
|
|
260
260
|
rescue Wallets::InvalidTransfer => e
|
|
261
261
|
raise InvalidTransfer, e.message
|
|
262
262
|
rescue Wallets::InsufficientBalance => e
|
|
263
|
-
raise InsufficientCredits, e.message
|
|
263
|
+
raise InsufficientCredits, in_credits_terms(e.message)
|
|
264
264
|
rescue Wallets::Error => e
|
|
265
265
|
raise UsageCredits::Error, e.message
|
|
266
266
|
end
|
|
@@ -304,6 +304,13 @@ module UsageCredits
|
|
|
304
304
|
|
|
305
305
|
private
|
|
306
306
|
|
|
307
|
+
# The wallets core refuses in its own words ("Insufficient balance (5 <
|
|
308
|
+
# 10)"); a credits wallet refuses in the words its own `InsufficientCredits`
|
|
309
|
+
# already uses, whichever command raised it.
|
|
310
|
+
def in_credits_terms(message)
|
|
311
|
+
message.sub(/\AInsufficient balance\b/, "Insufficient credits")
|
|
312
|
+
end
|
|
313
|
+
|
|
307
314
|
# =========================================
|
|
308
315
|
# Helper Methods
|
|
309
316
|
# =========================================
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: usage_credits
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- rameerez
|
|
@@ -55,14 +55,14 @@ dependencies:
|
|
|
55
55
|
requirements:
|
|
56
56
|
- - "~>"
|
|
57
57
|
- !ruby/object:Gem::Version
|
|
58
|
-
version: 0.4.
|
|
58
|
+
version: 0.4.2
|
|
59
59
|
type: :runtime
|
|
60
60
|
prerelease: false
|
|
61
61
|
version_requirements: !ruby/object:Gem::Requirement
|
|
62
62
|
requirements:
|
|
63
63
|
- - "~>"
|
|
64
64
|
- !ruby/object:Gem::Version
|
|
65
|
-
version: 0.4.
|
|
65
|
+
version: 0.4.2
|
|
66
66
|
description: Add a usage-based credit system to your Rails app, easily. Let users
|
|
67
67
|
buy and spend credits on usage-based actions. Refill Stripe subscriptions with credits,
|
|
68
68
|
sell one-time booster credit packs, implement PAYG (pay-as-you-go) billing, award
|