Give access with access levels, receive webhooks, save your own data on subscriptions, sell upsells and keep the attribution with the Payments SDK.
A subscription from the Payments SDK is a normal web2wave subscription. The billing engine charges the renewals. web2wave sends your webhooks, emails and pixel events. The subscription shows in the cabinet analytics.
Read Payments SDK first.
Access levels
An access level is a key on a price, for example premium. Your app checks the key. It does not need to know the price IDs.
Add access levels to a price
- In Plans & Prices, open the price.
- In Access levels, select a key or enter a new one, for example
premium. - Click Save.
One price can give more than one access level. You can also send access_levels in the price API.
Check the access of a user
Your server sends a request with the secret project api_key:
GET https://api.web2wave.com/api/user/access?user=user_123
api_key: YOUR_PROJECT_API_KEY
{
"user_id": "user_123",
"access": {
"premium": {
"active": true,
"expires_at": "2026-12-24T22:33:18+00:00",
"will_renew": true,
"status": "active",
"subscription_id": 3064,
"price_id": 12
}
}
}user is the user ID or the email. An access level is active while a subscription with this level is active, trialing or past_due.
Do not put the
api_keyon your page. The publishable key cannot read access levels.
Right after the payment, the success event of the checkout has subscription.access_levels. Use it to open the access at once. Then check the access on your server.
Webhooks
Configure the webhooks of the project. See Get your API key and configure webhooks.
The subscription webhooks of SDK purchases have the same format as for paywall purchases. Each subscription in a webhook also has:
access_levels— the access levels of the price.metadata— your own data from the checkout.
See Webhook formats.
Metadata
Send your own data with the checkout:
const checkout = await W2WPay.checkout({
price: 12,
metadata: { order_id: 'A-17', team_id: '42' },
});web2wave saves metadata on the subscription. It shows in subscription webhooks, in GET /api/user/subscriptions and in the success event.
Your server can change it with PUT /api/subscription/{id} and { "metadata": { ... } }. This request replaces all the metadata.
| Limit | Value |
|---|---|
| Keys | 20 or fewer. Letters, digits, _, - and . |
| Values | Text up to 500 characters, numbers or true / false |
One-click upsell
After the payment, you can sell a second price. The SDK charges the same card. The user does not enter the card again.
checkout.on('success', () => showUpsellOffer());
upsellButton.onclick = async () => {
try {
const { subscription } = await W2WPay.upsell({ price: 15 });
// subscription.status, subscription.access_levels
} catch (error) {
// error.code, for example payment_failed or double_purchase
}
};These rules apply:
- The upsell price must be a Primer price.
- The upsell must start in 24 hours or less after a paid checkout of the same user.
- web2wave does not charge a price twice if the price has the double purchase check.
By default, the SDK uses the last paid checkout on the page. If the upsell offer is on another page, send session with the session_id from the success event.
For an upsell later than 24 hours, charge the user from your server with POST /api/subscription/user/charge.
| Error code | Description |
|---|---|
upsell_not_allowed | The user has no paid checkout in the last 24 hours. |
double_purchase | The user already has this price. |
no_saved_card | web2wave has no saved card of the user. |
payment_failed | The payment system declined the payment. |
User properties
The SDK can write and read user properties. These are the same user properties that quizzes write.
await W2WPay.user.set('goal', 'lose_weight');
await W2WPay.user.set({ company: 'Acme', seats: 5 });
const goal = await W2WPay.user.get('goal');
const all = await W2WPay.user.get();web2wave sends the user properties in your webhooks and shows them in the cabinet. web2wave saves all values as text.
Attribution
The SDK saves a visit with the ad tags of the page, for example utm_source, utm_campaign and fbclid. Then web2wave connects the subscription to the ad campaign. Server events to Meta and TikTok also get these tags.
Often the checkout page has no ad tags. Then send the tags that you saved on the landing page:
W2WPay.init({
key: 'w2w_pk_...',
user: { id: 'user_123' },
visit: {
utm_source: 'facebook',
utm_campaign: 'spring_sale',
fbclid: 'IwAR...',
url: 'https://example.com/landing',
referrer: 'https://facebook.com/',
},
});If you send visit, web2wave uses it instead of the tags of the page address.