Sell subscriptions on your own website with the web2wave checkout and billing engine. No web2wave quiz is needed.
The Payments SDK puts the web2wave checkout on your own website. You do not need a web2wave quiz or paywall. Renewals, analytics, pixels, webhooks and emails work the same as for a purchase on a web2wave paywall.
The SDK is a JavaScript file. It shows a card form and Apple Pay, Google Pay and PayPal buttons on your page. You can also show a full web2wave paywall in a frame.
When to use the Payments SDK
Use the Payments SDK in these cases:
- You build your own landing pages, quizzes or app screens and want to sell subscriptions there.
- You use a site builder, for example Webflow, Framer or Typeform, and need a checkout after it.
- You have a web app and want web subscriptions without your own billing code.
If you use web2wave quizzes and paywalls, you do not need the SDK.
Modes
| Mode | What you get | Payment systems |
|---|---|---|
| Elements | A card form and wallet buttons as separate blocks in your layout. You control the design. | Primer |
| Embedded paywall | A full web2wave paywall in a frame on your page. A/B tests of the paywall work. | All payment systems of the paywall |
| Pay API | The HTTP API that the SDK uses. Use it to build your own client. | Primer |
Elements use Primer. Primer connects the payment systems behind it, for example Stripe, Adyen or Airwallex. For other payment systems, for example Paddle or Finby, use the embedded paywall.
Terms
| Term | Meaning |
|---|---|
| publishable key | A key that starts with w2w_pk_. It identifies the project in the browser. It is safe to put on your page. |
| allowed sites | The websites that can use the publishable key. If the list is empty, all websites can use it. |
| access level | A key on a price, for example premium. It tells your app what the user paid for. |
| checkout | One attempt to buy one price. The SDK creates it with W2WPay.checkout(). |
The publishable key can read prices and start payments. It cannot read subscriptions or access levels. Your server reads them with the secret project api_key.
Before you start
You must have:
- A project with Primer keys. See Primer.io integration.
- Primer prices in Plans & Prices. See Creation and test of Primer prices.
If the project has no Primer keys, the Payments SDK page shows Request activation. Click it. The web2wave team configures Primer and the payment systems for you.
Enable the SDK
- In the cabinet, open Payments SDK.
- In the top bar, select the project.
- Copy the Publishable key.
- In Allowed sites, enter the addresses of your websites. Enter one address on each line, for example
https://example.com. - Click Save sites.
- Copy the script tag from Quick start.
Copy the script address from the cabinet. It has a version parameter
?v=. A new SDK version comes with a new address.
To test the SDK with your key, click Open test page.
Quick start
This example shows a card form and an Apple Pay or Google Pay button. Replace the key and the price ID with your values.
<script src="SCRIPT_ADDRESS_FROM_THE_CABINET"></script>
<div id="wallets"></div>
<div id="card"></div>
<button id="pay">Pay</button>
<script>
W2WPay.init({
key: 'w2w_pk_...',
user: { id: 'user_123', email: '[email protected]' },
});
(async () => {
const checkout = await W2WPay.checkout({ price: 12 });
checkout.mount('wallets', '#wallets');
checkout.mount('card', '#card');
document.getElementById('pay').onclick = () => checkout.submit();
checkout.on('success', ({ subscription }) => {
// subscription.access_levels, for example ['premium']
window.location.href = '/welcome';
});
checkout.on('error', (error) => alert(error.message));
})();
</script>user.id is the ID of the user in your system. web2wave saves the subscription for this user. If you do not send it, the SDK creates an ID and keeps it in the browser.
Use user IDs that nobody can guess. The SDK reads user properties by the user ID.
Pages
- Checkout with elements — prices, the card form, wallet buttons, events and styling.
- Embedded paywall — a full web2wave paywall on your page.
- After the payment — access levels, webhooks, metadata, upsells, user properties and attribution.
Limits
- The checkout shows a price that your page sends. Price sets and A/B tests of prices are not available in elements. They work in the embedded paywall.
- One visitor can open 30 checkouts in 1 hour from one IP address and 10 checkouts for one user ID. After the limit, the SDK returns the error
too_many_attempts.