usePaymentDetection

Detect new payments in real-time using polling

usePaymentDetection

Detect new payments in real-time

Returns

newPaymentsPayment[]

New payments since last check

isPollingboolean

Whether currently polling

startPolling() => void

Start polling for payments

stopPolling() => void

Stop polling for payments

Example

1import { usePaymentDetection } from 'pyhard-vendor-sdk';
2
3function PaymentMonitor({ subscriptionId, smartWalletAddress }: {
4  subscriptionId: string;
5  smartWalletAddress: string;
6}) {
7  const { 
8    newPayments, 
9    isPolling, 
10    startPolling, 
11    stopPolling 
12  } = usePaymentDetection(subscriptionId, smartWalletAddress, 3000);
13  
14  useEffect(() => {
15    if (newPayments.length > 0) {
16      console.log('New payments detected:', newPayments);
17      // Show notification or update UI
18    }
19  }, [newPayments]);
20  
21  return (
22    <div>
23      <button 
24        onClick={isPolling ? stopPolling : startPolling}
25        className={isPolling ? 'bg-red-500' : 'bg-green-500'}
26      >
27        {isPolling ? 'Stop Monitoring' : 'Start Monitoring'}
28      </button>
29      {newPayments.length > 0 && (
30        <div className="bg-green-100 p-2 rounded">
31          {newPayments.length} new payment(s) detected!
32        </div>
33      )}
34    </div>
35  );
36}