The code in this repo shows how to integrate Access Protocol Payment Gate into your website. You can see the demo in action here: gate-demo.accessprotocol.co
The payment gate is accessible at gate.accessprotocol.co. To integrate it, you'll need:
- A pool address
- A callback URL for post-payment redirection
Use the getPaymentGateUrl
function to construct the URL:
const gateUrl = getPaymentGateUrl(poolAddress, callbackUrl);
All the needed functions and components are in the @accessprotocol/payment-gate
NPM package.
-
Wrap your app with
AccessSubscriptionProvider
-
Use
useSubscription
hook to check subscription status. -
For gated content:
- Check
token
existence - Show preview/locked state when
token
is null - Display full content when
token
exists
- Check
-
To verify the user subscription or buy a new one, forward the user to Access Protocol Payment Gate. You can get the appropriate address by calling:
getPaymentGateUrl(POOL_ADDRESS, callbackUrl ?? window.location.href)
-
After the user completes the process at Access Protocol Payment Gate, they get forwarded to the
callbackUrl
. This should be a page in your application that is wrapped inside theAccessSubscriptionProvider
. This automatically sets the user token, You can again access it usinguseSubscription
and enable user to get access to the restricted content.