{{indexmenu_n>40}}
====== Paid Content (Paywall) ======
A game can sell access to a single level, to a hint, or to any piece of the task text. The scheme is this: the author creates a **product**, puts a payment button into the task, and closes off the paid content with a [[en:authors_main:task_editor:advanced:edit_templates|template]] that checks whether the product has been paid for.
> **Before you start:** the payment system is switched on by the domain administrator, not by the game author. If payment is not configured on the domain, the payment button simply never appears on the page. The paywall can still be tested without configured payment — see the "How to Test It" section.
===== 1. Create a Product =====
In the game editor open **"Products / Paid access (Paywall)"**. The products screen has four fields:
* **Key** — the identifier you will use to reach the product from the task. Latin letters, digits and underscores only: a key with a hyphen, a space or Cyrillic letters will be saved, but the payment button will not find it. **The key cannot be changed after creation** — the only way is to delete the product and create it again.
* **Name** — goes to the payment system as the invoice description. It is not shown to the player on the button.
* **Price** — must be greater than zero.
* **Currency** — UAH, USD, EUR, GBP, CAD, PLN, CZK.
A game may have as many products as you like: a separate product for each paid level, for example.
===== 2. Place the Payment Button =====
At the spot in the task where the button should appear, write:
%pay_button product_key%
The engine replaces this with a **"Pay {price} {currency}"** button. Pressing it opens a separate payment system window.
What is worth knowing about the button:
* If the product has already been bought, the button **disappears by itself** — there is no need to hide it manually.
* If the key is misspelled and there is no such product, a grey **"Product not found"** message with that key appears instead of the button. Handy for checking yourself.
* The button can be placed in the task text, in hints, in bonuses and in the finish text — anywhere substitutions work. That includes **inside a template**: templates are evaluated first, so the button lives quite happily in the ''{%= no}'' branch.
===== 3. Close Off the Paid Content =====
The button on its own hides nothing — the paid text has to be closed off with the ''product_KEY'' template. It has three values:
* **''yes''** — the product is bought, access granted.
* **''pending''** — payment has started but the bank has not confirmed it yet. Rare, but the branch is better provided for.
* **''no''** — not paid.
{% match product_level_5 }:{
{%= yes}:{
Thank you for your purchase! The code to pass the level: ZOO
%}
{%= pending}:{
Your payment is being processed by the bank. Wait a moment and refresh the page.
%}
{%= no}:{
This level contains paid content.
%pay_button level_5%
%}
%}
The template is evaluated on the server, so unpaid content never reaches the page source — there is no way to peek at it.
> If the product name has a typo in it, the template does not complain — it simply always returns ''no''. Check the key against the button: in that case it will show "Product not found".
===== What Happens After Payment =====
When the player completes the payment, the payment system window closes by itself and the game page reloads — the paid content appears without the player having to do anything.
Access is granted **to the team**, not to the player: one pays, everyone gets it. In single-player games that is, naturally, the same person.
The list of purchases for the game is visible to the author on the game purchases screen — unfinished payment attempts are shown there too. Access can also be granted by hand from that screen: handy when a player paid you some other way, or when a payment got stuck and has to be closed manually.
===== How to Test It =====
Enter the game through **"Test Game"**. For a test team the engine substitutes a test payment system of its own, regardless of what is configured on the domain, or whether anything is configured at all. The payment button works like the real one, but instead of the bank it opens a form with a field for a code — the code you need is written right there in the form. No real money is charged.
That way the whole chain can be checked end to end: the ''no'' branch with the button, and the switch to the ''yes'' branch after "payment".
===== Not to Be Confused with Paid Entry to a Game =====
What is described here is selling content **inside** a game. Charging for **taking part** in a game is a separate mechanism: the price is set in the game settings, and teams are admitted to the game automatically once they have paid. See [[en:authors_main:game_management:game_settings|Game Settings]].
[[https://qeng.org/game.php?jump_to&gid=3493&task_id=81984|Example in game]]