@cedros/pay-react 1.0.4 → 1.0.5

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.
Files changed (51) hide show
  1. package/README.md +109 -3
  2. package/dist/CedrosContext-CFEXGwQg.mjs +2163 -0
  3. package/dist/CedrosContext-DbndTsTA.js +11 -0
  4. package/dist/components/CryptoSubscribeButton.d.ts +50 -0
  5. package/dist/components/CryptoSubscribeButton.d.ts.map +1 -0
  6. package/dist/components/SubscribeButton.d.ts +55 -0
  7. package/dist/components/SubscribeButton.d.ts.map +1 -0
  8. package/dist/components/SubscriptionManagementPanel.d.ts +67 -0
  9. package/dist/components/SubscriptionManagementPanel.d.ts.map +1 -0
  10. package/dist/components/subscriptionPanelStyles.d.ts +13 -0
  11. package/dist/components/subscriptionPanelStyles.d.ts.map +1 -0
  12. package/dist/context/CedrosContext.d.ts +4 -0
  13. package/dist/context/CedrosContext.d.ts.map +1 -1
  14. package/dist/crypto-only.js +1 -1
  15. package/dist/crypto-only.mjs +2 -2
  16. package/dist/en-C739WV_-.mjs +19 -0
  17. package/dist/en-Cz4OpvN-.js +1 -0
  18. package/dist/hooks/useCryptoSubscription.d.ts +42 -0
  19. package/dist/hooks/useCryptoSubscription.d.ts.map +1 -0
  20. package/dist/hooks/useSubscription.d.ts +42 -0
  21. package/dist/hooks/useSubscription.d.ts.map +1 -0
  22. package/dist/hooks/useSubscriptionManagement.d.ts +88 -0
  23. package/dist/hooks/useSubscriptionManagement.d.ts.map +1 -0
  24. package/dist/i18n/index.d.ts +7 -0
  25. package/dist/i18n/index.d.ts.map +1 -1
  26. package/dist/index.d.ts +11 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +1 -1
  29. package/dist/index.mjs +1658 -361
  30. package/dist/managers/ManagerCache.d.ts +4 -0
  31. package/dist/managers/ManagerCache.d.ts.map +1 -1
  32. package/dist/managers/SubscriptionChangeManager.d.ts +42 -0
  33. package/dist/managers/SubscriptionChangeManager.d.ts.map +1 -0
  34. package/dist/managers/SubscriptionManager.d.ts +113 -0
  35. package/dist/managers/SubscriptionManager.d.ts.map +1 -0
  36. package/dist/pay-react.css +1 -1
  37. package/dist/stripe-only.js +1 -1
  38. package/dist/stripe-only.mjs +2 -2
  39. package/dist/{styles-DI2LPVdQ.mjs → styles-DFcRS8Uu.mjs} +13 -12
  40. package/dist/{styles-61pRysGe.js → styles-Dup9uK6S.js} +1 -1
  41. package/dist/testing/index.js +1 -1
  42. package/dist/testing/index.mjs +1 -1
  43. package/dist/types/index.d.ts +1 -0
  44. package/dist/types/index.d.ts.map +1 -1
  45. package/dist/types/subscription.d.ts +300 -0
  46. package/dist/types/subscription.d.ts.map +1 -0
  47. package/package.json +1 -1
  48. package/dist/CedrosContext-B3iCqN6e.js +0 -11
  49. package/dist/CedrosContext-vX9uqZKp.mjs +0 -1796
  50. package/dist/en-CSsJl3nf.mjs +0 -19
  51. package/dist/en-D-uY3ltT.js +0 -1
package/README.md CHANGED
@@ -1115,6 +1115,112 @@ const newReq: v2.X402Requirement = { maxAmountRequired: 1000000n };
1115
1115
  />
1116
1116
  ```
1117
1117
 
1118
+ ### Subscriptions
1119
+
1120
+ Cedros Pay supports recurring subscriptions with both Stripe and crypto (x402) payments.
1121
+
1122
+ **Stripe Subscription Checkout:**
1123
+
1124
+ ```tsx
1125
+ import { SubscribeButton } from "@cedros/pay-react";
1126
+
1127
+ <SubscribeButton
1128
+ resource="plan-pro"
1129
+ interval="monthly"
1130
+ trialDays={14}
1131
+ onSubscriptionSuccess={(result) => {
1132
+ console.log("Subscribed:", result.subscriptionStatus);
1133
+ }}
1134
+ />;
1135
+ ```
1136
+
1137
+ **Crypto Subscription (x402):**
1138
+
1139
+ ```tsx
1140
+ import { CryptoSubscribeButton } from "@cedros/pay-react";
1141
+
1142
+ <CryptoSubscribeButton
1143
+ resource="plan-pro"
1144
+ interval="monthly"
1145
+ onSubscriptionSuccess={(result) => {
1146
+ console.log("Subscription active until:", result.expiresAt);
1147
+ }}
1148
+ />;
1149
+ ```
1150
+
1151
+ **Subscription Management (Upgrade/Downgrade/Cancel):**
1152
+
1153
+ ```tsx
1154
+ import { SubscriptionManagementPanel } from "@cedros/pay-react";
1155
+
1156
+ <SubscriptionManagementPanel
1157
+ resource="plan-pro"
1158
+ userId="user@example.com"
1159
+ availablePlans={[
1160
+ { resource: "plan-basic", name: "Basic", price: 999, currency: "USD", interval: "monthly" },
1161
+ { resource: "plan-pro", name: "Pro", price: 1999, currency: "USD", interval: "monthly" },
1162
+ { resource: "plan-enterprise", name: "Enterprise", price: 4999, currency: "USD", interval: "monthly" },
1163
+ ]}
1164
+ onSubscriptionChanged={(newResource) => console.log("Changed to:", newResource)}
1165
+ onSubscriptionCanceled={() => console.log("Subscription canceled")}
1166
+ showBillingPortal
1167
+ />;
1168
+ ```
1169
+
1170
+ **Programmatic Subscription Management:**
1171
+
1172
+ ```tsx
1173
+ import { useSubscriptionManagement } from "@cedros/pay-react";
1174
+
1175
+ function SubscriptionSettings({ userId }: { userId: string }) {
1176
+ const {
1177
+ subscription,
1178
+ status,
1179
+ loadSubscription,
1180
+ previewChange,
1181
+ changeSubscription,
1182
+ cancelSubscription,
1183
+ openBillingPortal,
1184
+ } = useSubscriptionManagement();
1185
+
1186
+ useEffect(() => {
1187
+ loadSubscription("plan-pro", userId);
1188
+ }, [userId]);
1189
+
1190
+ const handleUpgrade = async () => {
1191
+ // Preview proration before confirming
1192
+ const preview = await previewChange("plan-pro", "plan-enterprise", userId);
1193
+ if (preview && confirm(`Upgrade for $${preview.immediateAmount / 100}?`)) {
1194
+ await changeSubscription({ newResource: "plan-enterprise" });
1195
+ }
1196
+ };
1197
+
1198
+ return (
1199
+ <div>
1200
+ {subscription && (
1201
+ <>
1202
+ <p>Plan: {subscription.resource}</p>
1203
+ <p>Status: {subscription.status}</p>
1204
+ <button onClick={handleUpgrade}>Upgrade to Enterprise</button>
1205
+ <button onClick={() => cancelSubscription(false)}>Cancel at Period End</button>
1206
+ <button onClick={() => openBillingPortal(userId)}>Manage Billing</button>
1207
+ </>
1208
+ )}
1209
+ </div>
1210
+ );
1211
+ }
1212
+ ```
1213
+
1214
+ **Billing Intervals:** `weekly`, `monthly`, `yearly`, `custom`
1215
+
1216
+ **Subscription Features:**
1217
+
1218
+ - Trial periods (Stripe)
1219
+ - Proration on plan changes
1220
+ - Immediate or period-end cancellation
1221
+ - Stripe billing portal integration
1222
+ - Backend-verified subscription status for x402 gating
1223
+
1118
1224
  ### Coupon Codes
1119
1225
 
1120
1226
  ```tsx
@@ -1572,9 +1678,9 @@ We follow [Semantic Versioning](https://semver.org/):
1572
1678
 
1573
1679
  **These exports are guaranteed stable** and follow semantic versioning:
1574
1680
 
1575
- - ✅ **Components** - All exported React components (CedrosPay, StripeButton, CryptoButton, etc.)
1576
- - ✅ **Hooks** - useCedrosContext, useStripeCheckout, useX402Payment, etc.
1577
- - ✅ **Manager Interfaces** - IStripeManager, IX402Manager, IWalletManager, IRouteDiscoveryManager
1681
+ - ✅ **Components** - All exported React components (CedrosPay, StripeButton, CryptoButton, SubscribeButton, CryptoSubscribeButton, SubscriptionManagementPanel, etc.)
1682
+ - ✅ **Hooks** - useCedrosContext, useStripeCheckout, useX402Payment, useSubscription, useCryptoSubscription, useSubscriptionManagement, etc.
1683
+ - ✅ **Manager Interfaces** - IStripeManager, IX402Manager, IWalletManager, ISubscriptionManager, ISubscriptionChangeManager, IRouteDiscoveryManager
1578
1684
  - ✅ **Types** - All types exported via versioned namespaces (v1, v2, etc.)
1579
1685
  - ✅ **Utilities** - validateConfig, parseCouponCodes, rate limiters, logging, events
1580
1686