@cedros/pay-react 1.0.3 → 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 (61) hide show
  1. package/README.md +110 -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/i18n/useTranslation.d.ts.map +1 -1
  27. package/dist/index.d.ts +12 -2
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/index.mjs +1658 -360
  31. package/dist/managers/ManagerCache.d.ts +4 -0
  32. package/dist/managers/ManagerCache.d.ts.map +1 -1
  33. package/dist/managers/SubscriptionChangeManager.d.ts +42 -0
  34. package/dist/managers/SubscriptionChangeManager.d.ts.map +1 -0
  35. package/dist/managers/SubscriptionManager.d.ts +113 -0
  36. package/dist/managers/SubscriptionManager.d.ts.map +1 -0
  37. package/dist/pay-react.css +1 -1
  38. package/dist/stripe-only.js +1 -1
  39. package/dist/stripe-only.mjs +2 -2
  40. package/dist/{styles-zgmHs6Hs.mjs → styles-DFcRS8Uu.mjs} +303 -278
  41. package/dist/styles-Dup9uK6S.js +1 -0
  42. package/dist/testing/index.js +1 -1
  43. package/dist/testing/index.mjs +1 -1
  44. package/dist/types/index.d.ts +1 -0
  45. package/dist/types/index.d.ts.map +1 -1
  46. package/dist/types/subscription.d.ts +300 -0
  47. package/dist/types/subscription.d.ts.map +1 -0
  48. package/dist/utils/__tests__/couponHelpers.test.d.ts +2 -0
  49. package/dist/utils/__tests__/couponHelpers.test.d.ts.map +1 -0
  50. package/dist/utils/couponHelpers.d.ts +46 -0
  51. package/dist/utils/couponHelpers.d.ts.map +1 -1
  52. package/dist/utils/index.d.ts +1 -1
  53. package/dist/utils/index.d.ts.map +1 -1
  54. package/dist/utils/uuid-shim.d.ts +9 -0
  55. package/dist/utils/uuid-shim.d.ts.map +1 -0
  56. package/package.json +1 -1
  57. package/dist/CedrosContext-B3iCqN6e.js +0 -11
  58. package/dist/CedrosContext-vX9uqZKp.mjs +0 -1796
  59. package/dist/en-CSsJl3nf.mjs +0 -19
  60. package/dist/en-D-uY3ltT.js +0 -1
  61. package/dist/styles-D3XGpsqb.js +0 -1
package/README.md CHANGED
@@ -338,6 +338,7 @@ go get github.com/cedros-pay/server
338
338
  - `POST /paywall/v1/quote` - x402 payment quote (resource ID in body)
339
339
  - `POST /paywall/v1/verify` - Payment verification (resource ID in X-PAYMENT header)
340
340
  - `POST /paywall/v1/stripe-session` - Create Stripe checkout (single item)
341
+ - `GET /paywall/v1/stripe-session/verify` - Verify Stripe payment session (security-critical)
341
342
  - `POST /paywall/v1/cart/checkout` - Create Stripe checkout (cart)
342
343
  - `POST /paywall/v1/cart/quote` - Get x402 quote for cart items
343
344
  - `POST /paywall/v1/gasless-transaction` - Build gasless transaction (optional)
@@ -1114,6 +1115,112 @@ const newReq: v2.X402Requirement = { maxAmountRequired: 1000000n };
1114
1115
  />
1115
1116
  ```
1116
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
+
1117
1224
  ### Coupon Codes
1118
1225
 
1119
1226
  ```tsx
@@ -1571,9 +1678,9 @@ We follow [Semantic Versioning](https://semver.org/):
1571
1678
 
1572
1679
  **These exports are guaranteed stable** and follow semantic versioning:
1573
1680
 
1574
- - ✅ **Components** - All exported React components (CedrosPay, StripeButton, CryptoButton, etc.)
1575
- - ✅ **Hooks** - useCedrosContext, useStripeCheckout, useX402Payment, etc.
1576
- - ✅ **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
1577
1684
  - ✅ **Types** - All types exported via versioned namespaces (v1, v2, etc.)
1578
1685
  - ✅ **Utilities** - validateConfig, parseCouponCodes, rate limiters, logging, events
1579
1686