|
| 1 | +--- |
| 2 | +id: enable-third-party-platform-payments |
| 3 | +title: Enable third-party platform payments |
| 4 | +slug: /enable-third-party-platform-payments |
| 5 | +--- |
| 6 | +JWP enables you to monetize your content through third-party platform payments. |
| 7 | + |
| 8 | +For your videos that require registration and payment, a new user must register or an existing user must log in. Then, the user must provide payment details. |
| 9 | + |
| 10 | +Your app makes an API call to create an account or authenticate an existing account. Then, a recurring subscription is initiated. Payment is processed. After a successful payment, the app validates the user's access and begins content playback. |
| 11 | + |
| 12 | +:::info |
| 13 | +Since this implementation uses both JWP and <a href="https://jwplayer.com/press-releases/jw-player-acquires-inplayer/" target="_blank">InPlayer</a> technologies, API calls will use the following namespaces and domains: |
| 14 | +- InPlayer |
| 15 | +- inplayer.com |
| 16 | +- jwplayer.com |
| 17 | +::: |
| 18 | + |
| 19 | +<br /> |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +<table> |
| 24 | + <thead> |
| 25 | + <tr> |
| 26 | + <th>Item</th> |
| 27 | + <th>Description</th> |
| 28 | + </tr> |
| 29 | + </thead> |
| 30 | + <tbody> |
| 31 | + <tr> |
| 32 | + <td><strong>New or existing app</strong></td> |
| 33 | + <td><a href="https://docs.jwplayer.com/platform/docs/apps-get-started" target="_blank">App</a> connected to a JWP property</td> |
| 34 | + </tr> |
| 35 | + <tr> |
| 36 | + <td><strong>Payment & Subscription Entitlement</strong></td> |
| 37 | + <td>Entitlement required to set up payments |
| 38 | + <br /><br /> |
| 39 | + <em>Contact your JWP representative for more information.</em> |
| 40 | + </td> |
| 41 | + </tr> |
| 42 | + <tr> |
| 43 | + <td><strong>Payment Plan</strong></td> |
| 44 | + <td>Plan that allows access to specified app content |
| 45 | + <br /><br /> |
| 46 | + You can <a href="https://docs.jwplayer.com/platform/docs/create-a-plan" target="_blank">create basic payment plans</a> or <a href="https://docs.jwplayer.com/platform/docs/apps-monetize-apps-with-a-subscription" target="_blank">complex payment plans</a> that include features such as <a href="https://docs.jwplayer.com/platform/docs/create-a-discount-code" target="_blank">discount codes</a>. |
| 47 | + </td> |
| 48 | + </tr> |
| 49 | + <tr> |
| 50 | + <td><strong>Asset ID</strong> & <strong>Client ID</strong></td> |
| 51 | + <td>IDs that enable access to content when combined: |
| 52 | + <ul> |
| 53 | + <li><strong>Asset ID</strong>: Subscription asset that must be purchased to watch content on the app</li> |
| 54 | + <li><strong>Client ID</strong>: Authentication realm where user account is created</li> |
| 55 | + </ul> |
| 56 | + <em>Contact your JWP representative for more information.</em> |
| 57 | + </td> |
| 58 | + </tr> |
| 59 | + </tbody> |
| 60 | +</table> |
| 61 | + |
| 62 | +<br /> |
| 63 | + |
| 64 | +## Set up third-party payments |
| 65 | + |
| 66 | +<br /> |
| 67 | + |
| 68 | +### New User |
| 69 | + |
| 70 | +Follow these steps to enable third-party payments for a new user: |
| 71 | + |
| 72 | +1. Create a new user account by calling <a href="https://docs.inplayer.com/api/accounts/#tag/V1/operation/createAccount" target="_blank">`POST /accounts`</a>. |
| 73 | + |
| 74 | + When the request **succeeds**, JWP creates a new user object and returns a unique user authentication token that is valid for **30 days**. When the request **fails**, JWP returns a failure response. |
| 75 | + ```cURL |
| 76 | + curl -L -X POST 'https://services.inplayer.com/accounts' \ |
| 77 | + -H 'Content-Type: application/x-www-form-urlencoded' \ |
| 78 | + --data-urlencode 'full_name=John Doe' \ |
| 79 | + --data-urlencode 'username=john@example.com' \ |
| 80 | + --data-urlencode 'password=foobar123' \ |
| 81 | + --data-urlencode 'password_confirmation=foobar123' \ |
| 82 | + --data-urlencode 'type=consumer' \ |
| 83 | + --data-urlencode 'grant_type=password' \ |
| 84 | + --data-urlencode 'client_id=12345678-90ab-1c23-4567-89d0e123f45' \ |
| 85 | + --data-urlencode 'metadata%5Bphone%5D=bar' |
| 86 | + ``` |
| 87 | +2. Use the app store's API to create an in-app purchase. This includes displaying the subscription price and setting up a subscription: |
| 88 | + - <a href="https://developer.amazon.com/docs/in-app-purchasing/iap-overview.html" target="_blank">Amazon</a> |
| 89 | + - <a href="https://developers.google.com/android-publisher#subscriptions" target="_blank">Android</a> |
| 90 | + - <a href="https://developer.apple.com/documentation/appstoreconnectapi/app_store/in-app_purchase/in-app_purchases" target="_blank">Apple</a> |
| 91 | + - <a href="https://developer.roku.com/docs/developer-program/roku-pay/implementation/channel-store.md" target="_blank">Roku</a> |
| 92 | +3. Validate the user's purchase by calling `POST /external-payments/<platform>/validate`. After making this API call, JWP verifies the payment on the third-party platform, stores transaction and subscription details, and grants the user access to the purchased content. |
| 93 | +
|
| 94 | + :::info |
| 95 | + See the following links for more information about each vendor-specific route: |
| 96 | + - <a href="https://docs.inplayer.com/api/payments/#tag/V2/operation/validateAmazonReceipt" target="_blank">Amazon</a> |
| 97 | + - <a href="https://docs.inplayer.com/api/payments/#tag/V2/operation/validateAndroidReceipt" target="_blank">Android</a> |
| 98 | + - <a href="https://docs.inplayer.com/api/payments/#tag/V2/operation/validateAppleReceipt" target="_blank">Apple</a> |
| 99 | + - <a href="https://docs.inplayer.com/api/payments/#tag/V2/operation/validateRokuReceipt" target="_blank">Roku</a> |
| 100 | + ::: |
| 101 | + |
| 102 | + ```cuRL |
| 103 | + curl POST https://services.inplayer.com/v2/external-payments/amazon/validate \ |
| 104 | + -H 'Authorization: <TOKEN>' \ |
| 105 | + --data-urlencode 'receipt=<AMZ_RVS_RECEIPT>' \ |
| 106 | + --data-urlencode 'product_name=<AMZ_PRODUCT_ID>' |
| 107 | + ``` |
| 108 | + ```cuRL |
| 109 | + curl POST https://services.inplayer.com/v2/external-payments/apple/validate \ |
| 110 | + -H 'Authorization: <TOKEN>' \ |
| 111 | + --data-urlencode 'receipt=<APP_STORE_JSON_PURCHASE_OBJECT>' \ |
| 112 | + --data-urlencode 'product_name=<APPLE_PRODUCT_ID>' |
| 113 | + ``` |
| 114 | + ```cuRL |
| 115 | + curl POST https://services.inplayer.com/v2/external-payments/google-play/validate \ |
| 116 | + -H 'Authorization: <TOKEN>' \ |
| 117 | + --data-urlencode 'receipt=<GOOGLE_JSON_PURCHASE_OBJECT>' \ |
| 118 | + --data-urlencode 'product_name=<GOOGLE_PRODUCT_ID>' |
| 119 | + ``` |
| 120 | + ```cuRL |
| 121 | + curl POST https://services.inplayer.com/v2/external-payments/roku/validate \ |
| 122 | + -H 'Authorization: <TOKEN>' \ |
| 123 | + --data-urlencode 'receipt=<ROKU_RECEIPT>' \ |
| 124 | + --data-urlencode 'product_name=<ROKU_PRODUCT_ID>' |
| 125 | + ``` |
| 126 | + |
| 127 | +5. Validate the user's access by calling <a href="https://docs.inplayer.com/api/assets/#tag/V1/operation/getAccess" target="_blank">`GET /items/{asset-ID}/access`</a>. |
| 128 | + |
| 129 | + If access to the asset **is verified**, the method returns the content in the response that you can display in your app. If access to the asset **cannot be verified**, your app should redirect the user to your payment page to re-enter payment details. |
| 130 | + ```cURL |
| 131 | + curl https://services.inplayer.com/items/{id}/access \ |
| 132 | + -H "Authorization:Bearer <TOKEN>" |
| 133 | + ``` |
| 134 | +
|
| 135 | +<br /> |
| 136 | +
|
| 137 | +After you have validated the user's access, you can fetch the content by media ID and begin playback. |
| 138 | +
|
| 139 | +If you use an app config to manage your content, you can obtain the media ID from the `contentId` parameter of the app config URL. |
| 140 | +
|
| 141 | +:::tip |
| 142 | +You can add <a href="https://docs.jwplayer.com/platform/docs/enable-protection-apps#url-signing-for-apps" target="_blank">URL signing</a> or <a href="https://docs.jwplayer.com/platform/docs/enable-protection-apps#drm" target="_blank">digital rights management (DRM)</a> for extra layers of content protection. |
| 143 | +::: |
| 144 | +
|
| 145 | +<br /><br /> |
| 146 | +
|
| 147 | +#### Existing User |
| 148 | +
|
| 149 | +Follow these steps to enable third-party payments for an existing user: |
| 150 | +
|
| 151 | +1. Log in an existing user account by calling <a href="https://docs.inplayer.com/api/accounts/#tag/V2/operation/v2authenticate" target="_blank">`POST /v2/accounts/authenticate`</a>. |
| 152 | +
|
| 153 | + When the request **succeeds**, JWP creates a new user object and returns a unique user authentication token. When the request **fails**, JWP returns a failure response. |
| 154 | + ```cURL |
| 155 | + curl -L -X POST 'https://services.inplayer.com/v2/accounts/authenticate' \ |
| 156 | + -H 'Content-Type: application/x-www-form-urlencoded' \ |
| 157 | + --data-urlencode 'username=test@test.com' \ |
| 158 | + --data-urlencode 'password=test123' \ |
| 159 | + --data-urlencode 'grant_type=password' \ |
| 160 | + --data-urlencode 'client_id=123-123-hf1hd1-12dhd1' \ |
| 161 | +
|
| 162 | + ``` |
| 163 | +2. Use the app store's API to create an in-app purchase. This includes displaying the subscription price and setting up a subscription: |
| 164 | + - <a href="https://developer.amazon.com/docs/in-app-purchasing/iap-overview.html" target="_blank">Amazon</a> |
| 165 | + - <a href="https://developers.google.com/android-publisher#subscriptions" target="_blank">Android</a> |
| 166 | + - <a href="https://developer.apple.com/documentation/appstoreconnectapi/app_store/in-app_purchase/in-app_purchases" target="_blank">Apple</a> |
| 167 | + - <a href="https://developer.roku.com/docs/developer-program/roku-pay/implementation/channel-store.md" target="_blank">Roku</a> |
| 168 | +3. Validate the user's purchase by calling `POST /external-payments/<platform>/validate`. After making this API call, JWP verifies the payment on the third-party platform, stores transaction and subscription details, and grants the user access to the purchased content. |
| 169 | +
|
| 170 | + :::info |
| 171 | + See the following links for more information about each vendor-specific route: |
| 172 | + - <a href="https://docs.inplayer.com/api/payments/#tag/V2/operation/validateAmazonReceipt" target="_blank">Amazon</a> |
| 173 | + - <a href="https://docs.inplayer.com/api/payments/#tag/V2/operation/validateAndroidReceipt" target="_blank">Android</a> |
| 174 | + - <a href="https://docs.inplayer.com/api/payments/#tag/V2/operation/validateAppleReceipt" target="_blank">Apple</a> |
| 175 | + - <a href="https://docs.inplayer.com/api/payments/#tag/V2/operation/validateRokuReceipt" target="_blank">Roku</a> |
| 176 | + ::: |
| 177 | + |
| 178 | + ```cuRL |
| 179 | + curl POST https://services.inplayer.com/v2/external-payments/amazon/validate \ |
| 180 | + -H 'Authorization: <TOKEN>' \ |
| 181 | + --data-urlencode 'receipt=<AMZ_RVS_RECEIPT>' \ |
| 182 | + --data-urlencode 'product_name=<AMZ_PRODUCT_ID>' |
| 183 | + ``` |
| 184 | + ```cuRL |
| 185 | + curl POST https://services.inplayer.com/v2/external-payments/apple/validate \ |
| 186 | + -H 'Authorization: <TOKEN>' \ |
| 187 | + --data-urlencode 'receipt=<APP_STORE_JSON_PURCHASE_OBJECT>' \ |
| 188 | + --data-urlencode 'product_name=<APPLE_PRODUCT_ID>' |
| 189 | + ``` |
| 190 | + ```cuRL |
| 191 | + curl POST https://services.inplayer.com/v2/external-payments/google-play/validate \ |
| 192 | + -H 'Authorization: <TOKEN>' \ |
| 193 | + --data-urlencode 'receipt=<GOOGLE_JSON_PURCHASE_OBJECT>' \ |
| 194 | + --data-urlencode 'product_name=<GOOGLE_PRODUCT_ID>' |
| 195 | + ``` |
| 196 | + ```cuRL |
| 197 | + curl POST https://services.inplayer.com/v2/external-payments/roku/validate \ |
| 198 | + -H 'Authorization: <TOKEN>' \ |
| 199 | + --data-urlencode 'receipt=<ROKU_RECEIPT>' \ |
| 200 | + --data-urlencode 'product_name=<ROKU_PRODUCT_ID>' |
| 201 | + ``` |
| 202 | + |
| 203 | +5. Validate the user's access by calling <a href="https://docs.inplayer.com/api/assets/#tag/V1/operation/getAccess" target="_blank">`GET /items/{asset-ID}/access`</a>. |
| 204 | + |
| 205 | + If access to the asset **is verified**, the method returns the content in the response that you can display in your app. If access to the asset **cannot be verified**, your app should redirect the user to your payment page to re-enter payment details. |
| 206 | + ```cURL |
| 207 | + curl https://services.inplayer.com/items/{id}/access \ |
| 208 | + -H "Authorization:Bearer <TOKEN>" |
| 209 | + ``` |
| 210 | + |
| 211 | +<br/> |
| 212 | +
|
| 213 | +After you have validated the user's access, you can fetch the content by media ID and begin playback. |
| 214 | +
|
| 215 | +If you use an app config to manage your content, you can obtain the media ID from the `contentId` parameter of the app config URL. |
| 216 | +
|
| 217 | +:::tip |
| 218 | +You can add <a href="https://docs.jwplayer.com/platform/docs/enable-protection-apps#url-signing-for-apps" target="_blank">URL signing</a> or <a href="https://docs.jwplayer.com/platform/docs/enable-protection-apps#drm" target="_blank">digital rights management (DRM)</a> for extra layers of content protection. |
| 219 | +::: |
0 commit comments