@funnelfox/billing 0.5.6 → 0.5.8

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/README.md CHANGED
@@ -133,6 +133,23 @@ const checkout = await createCheckout({
133
133
  - `customer.email` (string, required) - Customer email
134
134
  - `customer.countryCode` (string, optional) - ISO country code
135
135
  - `options.container` (string, required) - CSS selector for checkout container
136
+
137
+ **Container Styling Requirements (Default Skin):**
138
+
139
+ When using the default skin, the container element must have the following CSS properties for proper display of the loading indicator:
140
+
141
+ ```css
142
+ #checkout-container {
143
+ position: relative;
144
+ min-height: 200px; /* Adjust based on your layout */
145
+ }
146
+ ```
147
+
148
+ - `position: relative` - Required because the loading overlay uses `position: absolute` to cover the container
149
+ - `min-height` - Required to ensure the loader is visible during initialization. Recommended minimum is `200px`
150
+
151
+ **Additional Parameters:**
152
+
136
153
  - `options.orgId` (string, optional) - Org ID (if not configured globally)
137
154
  - `options.clientMetadata` (object, optional) - Custom metadata
138
155
  - `options.cardSelectors` (object, optional) - Custom card input selectors (defaults to auto-generated)
@@ -548,6 +565,112 @@ const checkout = await createCheckout({
548
565
 
549
566
  By default, payment methods are shown in the order: Card, PayPal, Google Pay, Apple Pay. You can reorder them to match your business priorities or regional preferences.
550
567
 
568
+ ### Using `initMethod` for Single Payment Methods
569
+
570
+ For scenarios where you want to render a single payment method with full control over placement and callbacks:
571
+
572
+ ```javascript
573
+ import { Billing, PaymentMethod } from '@funnelfox/billing';
574
+
575
+ const container = document.getElementById('payment-container');
576
+
577
+ const paymentMethod = await Billing.initMethod(
578
+ PaymentMethod.PAYMENT_CARD, // or PAYPAL, GOOGLE_PAY, APPLE_PAY
579
+ container,
580
+ {
581
+ // Required
582
+ orgId: 'your-org-id',
583
+ priceId: 'price_123',
584
+ externalId: 'user_456',
585
+ email: 'user@example.com',
586
+
587
+ // Optional - API configuration
588
+ baseUrl: 'https://custom.api', // Optional, defaults to https://billing.funnelfox.com
589
+ meta: { source: 'web' }, // Optional metadata
590
+
591
+ // Optional - Primer configuration (for customizing payment method behavior)
592
+ style: {
593
+ /* Primer style options */
594
+ },
595
+ card: {
596
+ /* Primer card options */
597
+ },
598
+ applePay: {
599
+ /* Primer Apple Pay options */
600
+ },
601
+ paypal: {
602
+ /* Primer PayPal options */
603
+ },
604
+ googlePay: {
605
+ /* Primer Google Pay options */
606
+ },
607
+
608
+ // Callbacks
609
+ onRenderSuccess: () => {
610
+ console.log('Payment method rendered successfully');
611
+ },
612
+ onRenderError: method => {
613
+ console.error('Failed to render:', method);
614
+ },
615
+ onLoaderChange: isLoading => {
616
+ console.log('Loading state:', isLoading);
617
+ },
618
+ onPaymentStarted: method => {
619
+ console.log('Payment started with:', method);
620
+ },
621
+ onPaymentSuccess: () => {
622
+ console.log('Payment completed successfully!');
623
+ },
624
+ onPaymentFail: error => {
625
+ console.error('Payment failed:', error.message);
626
+ },
627
+ onPaymentCancel: () => {
628
+ console.log('Payment was cancelled');
629
+ },
630
+ onErrorMessageChange: message => {
631
+ console.log('Error message:', message);
632
+ },
633
+ onMethodsAvailable: methods => {
634
+ console.log('Available methods:', methods);
635
+ },
636
+ }
637
+ );
638
+
639
+ // Control the payment method
640
+ paymentMethod.setDisabled(true); // Disable the payment method
641
+ paymentMethod.setDisabled(false); // Enable it
642
+
643
+ // For card payments, you can trigger submit programmatically
644
+ if (paymentMethod.submit) {
645
+ await paymentMethod.submit();
646
+ }
647
+
648
+ // Clean up when done
649
+ await paymentMethod.destroy();
650
+ ```
651
+
652
+ **Parameters:**
653
+
654
+ - `method` (PaymentMethod, required) - Payment method to initialize: `PAYMENT_CARD`, `PAYPAL`, `GOOGLE_PAY`, or `APPLE_PAY`
655
+ - `element` (HTMLElement, required) - DOM element where the payment method will be rendered
656
+ - `options` (InitMethodOptions, required):
657
+ - `orgId` (string, required) - Your organization identifier
658
+ - `priceId` (string, required) - Price identifier
659
+ - `externalId` (string, required) - Your user identifier
660
+ - `email` (string, required) - Customer email
661
+ - `baseUrl` (string, optional) - Custom API URL
662
+ - `meta` (object, optional) - Custom metadata
663
+ - `style`, `card`, `applePay`, `paypal`, `googlePay` (optional) - Primer SDK configuration options
664
+ - Callbacks (all optional): `onRenderSuccess`, `onRenderError`, `onLoaderChange`, `onPaymentStarted`, `onPaymentSuccess`, `onPaymentFail`, `onPaymentCancel`, `onErrorMessageChange`, `onMethodsAvailable`
665
+
666
+ **Returns:** `Promise<PaymentMethodInterface>` with methods:
667
+
668
+ - `setDisabled(disabled: boolean)` - Enable/disable the payment method
669
+ - `submit()` - Trigger form submission (available for card payments)
670
+ - `destroy()` - Clean up and remove the payment method
671
+
672
+ ---
673
+
551
674
  ### Manual Session Creation
552
675
 
553
676
  For advanced integrations where you want to control the Primer Headless Checkout directly: