azirid-react 0.9.5 → 0.9.7
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 +109 -0
- package/dist/index.cjs +457 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -9
- package/dist/index.d.ts +48 -9
- package/dist/index.js +456 -85
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -715,6 +715,115 @@ The hook handles both phases automatically:
|
|
|
715
715
|
1. **Widget phase**: Calls checkout API, loads Payphone SDK, widget renders via `<PayphoneWidget />`.
|
|
716
716
|
2. **Confirmation phase**: After Payphone redirects back (same page), detects URL params and confirms the payment.
|
|
717
717
|
|
|
718
|
+
### `usePayButton`
|
|
719
|
+
|
|
720
|
+
Hook that returns **renderable components** and **state** for a complete payment flow. Supports all providers (Stripe, PayPal, Payphone, Manual Transfer, Nuvei). You control the layout.
|
|
721
|
+
|
|
722
|
+
```tsx
|
|
723
|
+
import { usePayButton } from 'azirid-react'
|
|
724
|
+
|
|
725
|
+
function CheckoutPage({ intentId }: { intentId: string }) {
|
|
726
|
+
const {
|
|
727
|
+
providers, checkout, ProviderSelector,
|
|
728
|
+
TransferDetails, PayphoneWidget, status, error,
|
|
729
|
+
} = usePayButton({
|
|
730
|
+
intentId,
|
|
731
|
+
onSuccess: (data) => console.log('Paid!', data),
|
|
732
|
+
onError: (err) => console.error(err),
|
|
733
|
+
})
|
|
734
|
+
|
|
735
|
+
return (
|
|
736
|
+
<div>
|
|
737
|
+
{/* Option A: built-in provider selector */}
|
|
738
|
+
<ProviderSelector />
|
|
739
|
+
|
|
740
|
+
{/* Option B: custom UI with providers array */}
|
|
741
|
+
{providers.map(p => (
|
|
742
|
+
<button key={p.provider} onClick={() => checkout(p.provider)}>
|
|
743
|
+
{p.provider}
|
|
744
|
+
</button>
|
|
745
|
+
))}
|
|
746
|
+
|
|
747
|
+
{/* Renders automatically based on selected provider */}
|
|
748
|
+
<PayphoneWidget />
|
|
749
|
+
<TransferDetails />
|
|
750
|
+
|
|
751
|
+
{status === 'processing' && <p>Processing...</p>}
|
|
752
|
+
{status === 'redirecting' && <p>Redirecting to payment...</p>}
|
|
753
|
+
{status === 'error' && <p>Error: {error?.message}</p>}
|
|
754
|
+
</div>
|
|
755
|
+
)
|
|
756
|
+
}
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
| Option | Type | Description |
|
|
760
|
+
|--------|------|-------------|
|
|
761
|
+
| `intentId` | `string` | Payment intent ID |
|
|
762
|
+
| `planId` | `string` | Plan ID (alternative to intentId) |
|
|
763
|
+
| `onSuccess` | `(data) => void` | Called after successful payment |
|
|
764
|
+
| `onError` | `(error) => void` | Called on any error |
|
|
765
|
+
|
|
766
|
+
| Return | Type | Description |
|
|
767
|
+
|--------|------|-------------|
|
|
768
|
+
| `providers` | `AvailableProvider[]` | Enabled payment providers |
|
|
769
|
+
| `checkout` | `(provider) => void` | Trigger checkout for a specific provider |
|
|
770
|
+
| `ProviderSelector` | Component | Built-in provider selection list |
|
|
771
|
+
| `TransferDetails` | Component | Bank transfer details (after MANUAL_TRANSFER checkout) |
|
|
772
|
+
| `PayphoneWidget` | Component | Payphone widget (after PAYPHONE checkout) |
|
|
773
|
+
| `status` | `PayButtonStatus` | `'idle' \| 'loading_providers' \| 'ready' \| 'processing' \| 'redirecting' \| 'success' \| 'error'` |
|
|
774
|
+
| `selectedProvider` | `PaymentProviderType \| null` | Currently selected provider |
|
|
775
|
+
| `checkoutData` | `CheckoutResponse \| null` | Full checkout response |
|
|
776
|
+
| `isPending` | `boolean` | Checkout API call in progress |
|
|
777
|
+
| `error` | `Error \| null` | Error details |
|
|
778
|
+
|
|
779
|
+
### `useTransferPayment`
|
|
780
|
+
|
|
781
|
+
Hook for manual bank transfer payments. Pass an `intentId` and get a component with bank details + a function to submit proof of payment.
|
|
782
|
+
|
|
783
|
+
```tsx
|
|
784
|
+
import { useTransferPayment } from 'azirid-react'
|
|
785
|
+
|
|
786
|
+
function TransferPage({ intentId }: { intentId: string }) {
|
|
787
|
+
const { TransferDetails, submitProof, status, error } = useTransferPayment({
|
|
788
|
+
intentId,
|
|
789
|
+
onProofSubmitted: (proof) => console.log('Proof sent:', proof.id),
|
|
790
|
+
onError: (err) => console.error(err),
|
|
791
|
+
})
|
|
792
|
+
|
|
793
|
+
return (
|
|
794
|
+
<div>
|
|
795
|
+
<TransferDetails />
|
|
796
|
+
{status === 'ready' && (
|
|
797
|
+
<button onClick={() => submitProof({
|
|
798
|
+
fileUrl: 'https://...', amount: 29.99, notes: 'Transfer ref #123'
|
|
799
|
+
})}>
|
|
800
|
+
Submit proof
|
|
801
|
+
</button>
|
|
802
|
+
)}
|
|
803
|
+
{status === 'submitting' && <p>Submitting...</p>}
|
|
804
|
+
{status === 'submitted' && <p>Proof submitted!</p>}
|
|
805
|
+
{status === 'error' && <p>Error: {error?.message}</p>}
|
|
806
|
+
</div>
|
|
807
|
+
)
|
|
808
|
+
}
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
| Option | Type | Description |
|
|
812
|
+
|--------|------|-------------|
|
|
813
|
+
| `intentId` | `string` | **Required.** Payment intent ID |
|
|
814
|
+
| `onSuccess` | `(data) => void` | Called after checkout completes |
|
|
815
|
+
| `onProofSubmitted` | `(proof) => void` | Called after proof is submitted |
|
|
816
|
+
| `onError` | `(error) => void` | Called on any error |
|
|
817
|
+
|
|
818
|
+
| Return | Type | Description |
|
|
819
|
+
|--------|------|-------------|
|
|
820
|
+
| `TransferDetails` | Component | Amount, bank details, and transfer instructions |
|
|
821
|
+
| `submitProof` | `(data) => void` | Submit transfer proof (fileUrl, amount, notes, etc.) |
|
|
822
|
+
| `status` | `TransferPaymentStatus` | `'idle' \| 'loading' \| 'ready' \| 'submitting' \| 'submitted' \| 'error'` |
|
|
823
|
+
| `checkoutData` | `CheckoutResponse \| null` | Full checkout response |
|
|
824
|
+
| `isSubmitting` | `boolean` | Proof submission in progress |
|
|
825
|
+
| `error` | `Error \| null` | Error details |
|
|
826
|
+
|
|
718
827
|
### `usePayphoneConfirm`
|
|
719
828
|
|
|
720
829
|
Confirm a Payphone payment callback. Used on the Payphone return URL page.
|