|
| 1 | +# Implementing One-Time Purchases |
| 2 | + |
| 3 | +One-time purchases enable you to charge your users for premium functionality with in-app items. |
| 4 | + |
| 5 | +- Before you can add one-time purchases to your app, you must [Enable Monetization](/developers/docs/monetization/enabling-monetization) for your app. |
| 6 | +- Once you've confirmed eligibility for your app and team, you will be able to set up a [SKU](/developers/docs/resources/sku) (stock-keeping unit) to represent your one-time purchases. |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## Types of One-Time Purchases |
| 11 | + |
| 12 | +When creating items for one-time purchase, you can choose between durable and consumable items: |
| 13 | + |
| 14 | +- **Durable Items**: A one-time purchase that is permanent and is not subject to either renewal or consumption, such as lifetime access to an app's premium features. |
| 15 | +- **Consumable Items**: A one-time, non-renewable purchase that provides access, such as a temporary power-up or boost in a game. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## How One-Time Purchases Work |
| 20 | + |
| 21 | +#### For Durable SKUs |
| 22 | +- When a user purchases your durable SKU, Discord creates an [Entitlement](/developers/docs/resources/entitlement) for the purchasing user and that specific [SKU](/developers/docs/resources/sku). |
| 23 | +- You will receive an `ENTITLEMENT_CREATE` event via the Gateway. |
| 24 | +- This entitlement is now available via the `LIST Entitlements` API endpoint. |
| 25 | +- This entitlement will be available on `Interaction Payloads` initiated from the entitled user. |
| 26 | + |
| 27 | +#### For Consumable SKUs |
| 28 | +- When a user purchases your consumable SKU, Discord creates an [Entitlement](/developers/docs/resources/entitlement) for the purchasing user and that specific SKU. |
| 29 | +- You will receive an `ENTITLEMENT_CREATE` event via the Gateway. |
| 30 | +- This entitlement is now available via the `LIST Entitlements` API endpoint. |
| 31 | +- This entitlement will be available on `Interaction Payloads` initiated from the entitled user or users in a guild (for guild subscriptions). |
| 32 | +- Users cannot repurchase this SKU until you consume the entitlement using the [Consume Entitlement API](/developers/docs/resources/entitlement#consume-an-entitlement) endpoint. |
| 33 | + - In [Test Mode](/developers/docs/monetization/implementing-one-time-purchases#using-application-test-mode), repeated purchases are permitted without consumption for developer convenience. |
| 34 | +- When you receive an `ENTITLEMENT_CREATE` event for a consumable SKU, you should process the item purchase in your app and consume the entitlement as soon as possible. |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## Working with Entitlements |
| 39 | + |
| 40 | +When a user purchases a one-time purchase SKU, an entitlement is created. [Entitlements](/developers/docs/resources/entitlement) represent the user's access to your consumable or durable item. |
| 41 | + |
| 42 | +Depending on your app's features, you can use a combination of [Gateway events](/developers/docs/events/gateway-events#entitlements), the [Entitlement HTTP API](/developers/docs/resources/entitlement), and [interaction payloads](/developers/docs/interactions/receiving-and-responding) to keep track of entitlements to users who have purchased items in your app. |
| 43 | + |
| 44 | +### Accessing Entitlements with Gateway Events |
| 45 | + |
| 46 | +When a user purchases a SKU, Discord will emit an [`ENTITLEMENT_CREATE`](/developers/docs/events/gateway-events#entitlements) event. This event will contain the entitlement object that represents the user's access to the SKU. You can use this event to keep track of the user's entitlements in near-time. For One-Time Purchases, you may also receive an `ENTITLEMENT_DELETE` event if the user's entitlement is revoked. |
| 47 | + |
| 48 | +### Accessing Entitlements with the HTTP API |
| 49 | + |
| 50 | +Entitlements are available via the [List Entitlements](/developers/docs/resources/entitlement#list-entitlements) endpoint. You can filter entitlements by a specific user or set of SKUs by using the `?user_id=XYZ` or `?sku_ids=XYZ` query parameters. |
| 51 | + |
| 52 | +### Accessing Entitlements on Interaction Payloads |
| 53 | + |
| 54 | +Entitlements are also available on the `Interaction Payload` when a user interacts with your app. You can find the entitlements on the `entitlements` field of the `Interaction Payload` when [receiving and responding to interactions](/developers/docs/interactions/receiving-and-responding). |
| 55 | + |
| 56 | +### Accessing Entitlements with the Embedded App SDK |
| 57 | + |
| 58 | +When using the [Embedded App SDK](/developers/docs/developer-tools/embedded-app-sdk) to build an [Activity](/developers/docs/activities/overview), you can also [access a user's entitlements](/developers/docs/developer-tools/embedded-app-sdk#getentitlements). Check out the [Implementing In-App Purchases for Activities](/developers/docs/monetization/implementing-iap-for-activities) guide to learn more about monetization with the Embedded App SDK. |
| 59 | + |
| 60 | +Depending on your app's needs, you can use a combination of these methods to keep track of user entitlements. |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## One-Time Purchase Considerations |
| 65 | + |
| 66 | +When implementing one-time purchases, you should consider the following: |
| 67 | + |
| 68 | +### For Durable One-Time Purchases |
| 69 | + |
| 70 | +When offering durable items, users will have access to the SKU indefinitely. Durable items can't be consumed, so you don't need to worry about the user losing access to the item except in the case of a refund. |
| 71 | + |
| 72 | +### For Consumable One-Time Purchases |
| 73 | +When offering consumable items, users can only have one unconsumed entitlement at a time. To handle consumable items in your app or game, you should process and store the consumable item in your app and then make a call to the [Consume Entitlement](/developers/docs/resources/entitlement#consume-an-entitlement) endpoint so that the user can purchase more of this item in the future. |
| 74 | + |
| 75 | +Consuming the entitlement will update the entitlement to return a true value in the entitlement's `consumed` field. You will need to think through how your app keeps track of consumable items to decide on the best strategy for when to consume these entitlements and store the state of the consumable item and quantity in your app. |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Prompting Users to Purchase an Item |
| 80 | + |
| 81 | +### Responding with a Premium Button |
| 82 | + |
| 83 | +[Responding with a premium button](/developers/docs/monetization/managing-skus#responding-with-a-premium-button) gives you the ability to prompt users to subscribe to your app when they attempt to use a premium feature without a subscription. |
| 84 | + |
| 85 | +You can do this by sending a message with a [button](/developers/docs/components/reference#button) with a [premium style](/developers/docs/components/reference#button-button-styles) and a `sku_id` that allows the user to upgrade to your premium offering. |
| 86 | + |
| 87 | +### Starting a Purchase from an Activity |
| 88 | + |
| 89 | +If you are using the [Embedded App SDK](/developers/docs/developer-tools/embedded-app-sdk) to build an [Activity](/developers/docs/activities/overview), you can also launch the purchase flow for a specific SKU using the SDK. Check out the [Implementing In-App Purchases for Activities](/developers/docs/monetization/implementing-iap-for-activities) guide to learn more about monetization with the Embedded App SDK. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## Testing Your One-Time Purchase Implementation |
| 94 | + |
| 95 | +<Warning> |
| 96 | + |
| 97 | +The method of testing purchases for One-Time Purchases differs from the method for App Subscriptions. **Do NOT use Test Entitlements for One-Time Purchases.** |
| 98 | + |
| 99 | +</Warning> |
| 100 | + |
| 101 | +### Using Application Test Mode |
| 102 | + |
| 103 | +While in Application Test Mode, you can freely make "purchases" of One-Time Purchase SKUs tied to your application. That means you can test buying your consumable and durable items by going through the In-App Purchase flow without any credit card charges. |
| 104 | + |
| 105 | +<Info> |
| 106 | + |
| 107 | +You still need to have a valid payment method on file to "purchase" SKUs in Application Test Mode. It just won't be charged at checkout. |
| 108 | + |
| 109 | +</Info> |
| 110 | + |
| 111 | +To enable it, first, make sure you have a payment method on file in `User Settings -> Billing` and then: |
| 112 | + |
| 113 | +1. Open up the Discord app |
| 114 | +2. Click on the Settings cog in the bottom left corner |
| 115 | +3. Go to the `Advanced` page under App Settings |
| 116 | +4. Toggle "Developer Mode" **on** and "Application Test Mode" **on**, and enter your application ID. You can leave the other settings as-is. |
| 117 | +5. Exit user settings |
| 118 | + |
| 119 | +Once you enabled Application Test Mode successfully, you should see an orange bar across the top of your screen with the name of your app. |
| 120 | + |
| 121 | +You can now navigate to your Store page and purchase your one-time purchase items without being charged. |
| 122 | + |
| 123 | +The entitlements tied to items purchased in Application Test Mode can be identified by entitlements with a `type` value of 4 to represent `TEST_MODE_PURCHASE`. |
| 124 | + |
| 125 | +<Warning> |
| 126 | + |
| 127 | +The "Go To SKU" button does not currently work. To purchase your SKU in test mode, go to your Store page. |
| 128 | + |
| 129 | +</Warning> |
| 130 | + |
0 commit comments