azirid-react 0.9.4 → 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 +158 -0
- package/dist/index.cjs +550 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -9
- package/dist/index.d.ts +81 -9
- package/dist/index.js +547 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -667,6 +667,163 @@ const { data: proofs } = useTransferProofs()
|
|
|
667
667
|
// [{ id, status: 'PENDING_REVIEW' | 'APPROVED' | 'REJECTED', ... }]
|
|
668
668
|
```
|
|
669
669
|
|
|
670
|
+
### `usePayphoneCheckout`
|
|
671
|
+
|
|
672
|
+
Hook that returns a **renderable widget component** and **payment status**. Pass an `intentId` and get full control over where the widget renders and how to react to the payment result.
|
|
673
|
+
|
|
674
|
+
```tsx
|
|
675
|
+
import { usePayphoneCheckout } from 'azirid-react'
|
|
676
|
+
|
|
677
|
+
function CheckoutPage({ intentId }: { intentId: string }) {
|
|
678
|
+
const { PayphoneWidget, status, error } = usePayphoneCheckout({
|
|
679
|
+
intentId,
|
|
680
|
+
onSuccess: (data) => {
|
|
681
|
+
// data: { status: 'confirmed' | 'cancelled' | 'already_confirmed', intentId: string }
|
|
682
|
+
console.log('Payment result:', data.status)
|
|
683
|
+
},
|
|
684
|
+
onError: (err) => console.error(err),
|
|
685
|
+
})
|
|
686
|
+
|
|
687
|
+
return (
|
|
688
|
+
<div>
|
|
689
|
+
<h1>Pay</h1>
|
|
690
|
+
<PayphoneWidget />
|
|
691
|
+
{status === 'loading' && <p>Preparing checkout...</p>}
|
|
692
|
+
{status === 'confirming' && <p>Confirming payment...</p>}
|
|
693
|
+
{status === 'confirmed' && <p>Payment confirmed!</p>}
|
|
694
|
+
{status === 'cancelled' && <p>Payment was cancelled</p>}
|
|
695
|
+
{status === 'error' && <p>Error: {error?.message}</p>}
|
|
696
|
+
</div>
|
|
697
|
+
)
|
|
698
|
+
}
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
| Option | Type | Description |
|
|
702
|
+
|--------|------|-------------|
|
|
703
|
+
| `intentId` | `string` | **Required.** Payment intent ID |
|
|
704
|
+
| `onSuccess` | `(data) => void` | Called after payment confirmation |
|
|
705
|
+
| `onError` | `(error) => void` | Called on any error |
|
|
706
|
+
|
|
707
|
+
| Return | Type | Description |
|
|
708
|
+
|--------|------|-------------|
|
|
709
|
+
| `PayphoneWidget` | `() => ReactElement \| null` | Component to render the Payphone widget |
|
|
710
|
+
| `status` | `PayphoneCheckoutStatus` | `'idle' \| 'loading' \| 'ready' \| 'confirming' \| 'confirmed' \| 'cancelled' \| 'error'` |
|
|
711
|
+
| `intentId` | `string` | The intent ID passed in |
|
|
712
|
+
| `error` | `Error \| null` | Error details if status is `'error'` |
|
|
713
|
+
|
|
714
|
+
The hook handles both phases automatically:
|
|
715
|
+
1. **Widget phase**: Calls checkout API, loads Payphone SDK, widget renders via `<PayphoneWidget />`.
|
|
716
|
+
2. **Confirmation phase**: After Payphone redirects back (same page), detects URL params and confirms the payment.
|
|
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
|
+
|
|
670
827
|
### `usePayphoneConfirm`
|
|
671
828
|
|
|
672
829
|
Confirm a Payphone payment callback. Used on the Payphone return URL page.
|
|
@@ -1564,6 +1721,7 @@ import type {
|
|
|
1564
1721
|
| `UsePasswordResetOptions` / `UsePasswordResetReturn` | Options and return type for `usePasswordReset()` |
|
|
1565
1722
|
| `UseCheckoutOptions` / `CheckoutParams` | Options and params for `useCheckout()` |
|
|
1566
1723
|
| `UsePayphoneConfirmOptions` / `PayphoneConfirmParams` | Options and params for `usePayphoneConfirm()` |
|
|
1724
|
+
| `PayphoneCheckoutProps` | Props for `PayphoneCheckout` component |
|
|
1567
1725
|
| `SimpleMutationOptions<T>` | Options for hooks created via `createMutationHook` |
|
|
1568
1726
|
| `MutationHookConfig<TData, TInput>` | Configuration for `createMutationHook()` |
|
|
1569
1727
|
|