@hook-sdk/template 0.6.0 → 0.7.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.
package/dist/index.cjs CHANGED
@@ -32,12 +32,14 @@ __export(index_exports, {
32
32
  InstallSplash: () => InstallSplash,
33
33
  LoadingState: () => LoadingState,
34
34
  PushPrompt: () => PushPrompt2,
35
+ computeAnchorCents: () => computeAnchorCents,
35
36
  dailyFromYearly: () => dailyFromYearly,
36
37
  detectAndroidBrowser: () => detectAndroidBrowser,
37
38
  detectIOSBrowser: () => detectIOSBrowser,
38
39
  detectInAppApp: () => detectInAppApp,
39
40
  detectPlatform: () => detectPlatform,
40
41
  detectStandalone: () => detectStandalone,
42
+ discountPercent: () => discountPercent,
41
43
  formatBRL: () => formatBRL,
42
44
  monthlyFromYearly: () => monthlyFromYearly,
43
45
  shouldBlockInstall: () => shouldBlockInstall,
@@ -158,6 +160,7 @@ function usePaywallState() {
158
160
  const { subscription } = (0, import_sdk2.useHook)();
159
161
  const [opening, setOpening] = (0, import_react3.useState)(false);
160
162
  const [error, setError] = (0, import_react3.useState)(null);
163
+ const [pixPending, setPixPending] = (0, import_react3.useState)(null);
161
164
  const status = subscription.status();
162
165
  const daysLeftInTrial = subscription.daysLeftInTrial();
163
166
  const initialLoadComplete = subscription.initialLoadComplete;
@@ -165,12 +168,37 @@ function usePaywallState() {
165
168
  async (args) => {
166
169
  setOpening(true);
167
170
  setError(null);
171
+ setPixPending(null);
172
+ const method = args.method ?? "card";
173
+ const cycle = args.cycle ?? "MONTHLY";
168
174
  try {
169
- const result = await subscription.checkoutCard({
170
- cpf: args.cpf,
171
- cycle: args.cycle ?? "MONTHLY"
172
- });
173
- window.location.href = result.invoiceUrl;
175
+ if (method === "card") {
176
+ const result = await subscription.checkoutCard({ cpf: args.cpf, cycle });
177
+ window.location.href = result.invoiceUrl;
178
+ return;
179
+ }
180
+ if (method === "pix-auto") {
181
+ const result = await subscription.checkoutPixAuto({ cpf: args.cpf, cycle });
182
+ setPixPending({
183
+ method: "pix-auto",
184
+ qrCodePayload: result.qrCodePayload,
185
+ qrCodeBase64: result.qrCodeBase64,
186
+ expiresAt: null
187
+ });
188
+ setOpening(false);
189
+ return;
190
+ }
191
+ if (method === "pix-once") {
192
+ const result = await subscription.checkoutPixOnce({ cpf: args.cpf, cycle });
193
+ setPixPending({
194
+ method: "pix-once",
195
+ qrCodePayload: result.qrCodePayload,
196
+ qrCodeBase64: result.qrCodeBase64,
197
+ expiresAt: result.expiresAt
198
+ });
199
+ setOpening(false);
200
+ return;
201
+ }
174
202
  } catch (err) {
175
203
  setError(err);
176
204
  setOpening(false);
@@ -186,7 +214,18 @@ function usePaywallState() {
186
214
  setError(err);
187
215
  }
188
216
  }, [subscription]);
189
- return { status, daysLeftInTrial, initialLoadComplete, checkout, cancel, opening, error };
217
+ const dismissPix = (0, import_react3.useCallback)(() => setPixPending(null), []);
218
+ return {
219
+ status,
220
+ daysLeftInTrial,
221
+ initialLoadComplete,
222
+ checkout,
223
+ cancel,
224
+ opening,
225
+ error,
226
+ pixPending,
227
+ dismissPix
228
+ };
190
229
  }
191
230
 
192
231
  // src/internal/SubscriptionGate.tsx
@@ -2411,6 +2450,16 @@ function dailyFromYearly(yearlyCents) {
2411
2450
  if (yearlyCents === null || yearlyCents === void 0) return 0;
2412
2451
  return Math.round(yearlyCents / 365);
2413
2452
  }
2453
+ function computeAnchorCents(baseCents, multiplier) {
2454
+ if (multiplier === null || multiplier === void 0) return null;
2455
+ if (!Number.isFinite(multiplier)) return null;
2456
+ if (multiplier <= 1) return null;
2457
+ return Math.round(baseCents * multiplier);
2458
+ }
2459
+ function discountPercent(anchorCents, realCents) {
2460
+ if (anchorCents <= realCents) return 0;
2461
+ return Math.floor((anchorCents - realCents) / anchorCents * 100);
2462
+ }
2414
2463
 
2415
2464
  // src/hooks/useAuthPrimitives.ts
2416
2465
  var import_react17 = require("react");
@@ -2515,12 +2564,14 @@ function useToast() {
2515
2564
  InstallSplash,
2516
2565
  LoadingState,
2517
2566
  PushPrompt,
2567
+ computeAnchorCents,
2518
2568
  dailyFromYearly,
2519
2569
  detectAndroidBrowser,
2520
2570
  detectIOSBrowser,
2521
2571
  detectInAppApp,
2522
2572
  detectPlatform,
2523
2573
  detectStandalone,
2574
+ discountPercent,
2524
2575
  formatBRL,
2525
2576
  monthlyFromYearly,
2526
2577
  shouldBlockInstall,