You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| `uid` | An app-local identifier for the user. This is specific to this user, and this app. It will change if the user revokes the permissions they granted to your app. | (none) |
69
-
| `username`| The user's Pi username. | `username` |
70
-
| `payments` | Required if your app needs to make payments between your app and the users | `payments` |
71
-
| `wallet_address` | The wallet address of the user who authenticates on your app. | `wallet_address` |
|`uid`| An app-local identifier for the user. This is specific to this user, and this app. It will change if the user revokes the permissions they granted to your app. |(none)|
72
+
|`username`| The user's Pi username. |`username`|
73
+
|`payments`| Required if your app needs to make payments between your app and the users |`payments`|
74
+
|`wallet_address`| The wallet address of the user who authenticates on your app. |`wallet_address`|
72
75
73
76
### `onIncompletePaymentFound`
74
77
@@ -85,7 +88,6 @@ When this callback is invoked, it is your responsibility to complete the corresp
85
88
likely send the payment DTO to your server, and process it according to your business logic). You'll need to do
86
89
so before you can request a new payment from the user.
87
90
88
-
89
91
## Payments
90
92
91
93
Create a new payment:
@@ -115,13 +117,12 @@ the payment and submit the blockchain transaction, or reject it.
115
117
> **Warning: concurrent payments:**
116
118
>
117
119
> When creating a new payment, if there is already an open payment with your app for the current user:
118
-
> * If the user has not yet made the blockchain transaction, the open payment will be cancelled.
119
-
> * If the user has already made the blockchain transaction, the new payment will be rejected
120
-
> (`onError` will be called) and the `onIncompletePaymentFound` callback that was passed to the `authenticate`
121
-
> method will be called with the existing payment (use this callback to resolve the situation, e.g by sending
122
-
> the previous payment to your server for server-side completion).
123
-
124
-
120
+
>
121
+
> - If the user has not yet made the blockchain transaction, the open payment will be cancelled.
122
+
> - If the user has already made the blockchain transaction, the new payment will be rejected
123
+
> (`onError` will be called) and the `onIncompletePaymentFound` callback that was passed to the `authenticate`
124
+
> method will be called with the existing payment (use this callback to resolve the situation, e.g by sending
125
+
> the previous payment to your server for server-side completion).
125
126
126
127
### `paymentData` keys:
127
128
@@ -189,65 +190,75 @@ This is called when an error occurs and the payment cannot be made. If the payme
189
190
created, the second argument will be present and you may use it to investigate the error.
190
191
Otherwise, only the first argument will be provided.
191
192
192
-
193
193
### Type `PaymentDTO`
194
194
195
195
This type is for the arguments that are passed to `onIncompletePaymentFound` and `onError`.
196
196
197
197
```typescript
198
198
typePaymentDTO= {
199
199
// Payment data:
200
-
identifier:string,// payment identifier
201
-
user_uid:string,// user's app-specific ID
202
-
amount:number,// payment amount
203
-
memo:string,// a string provided by the developer, shown to the user
204
-
metadata:Object,// an object provided by the developer for their own usage
205
-
from_address:string,// sender address of the blockchain transaction
206
-
to_address:string,// recipient address of the blockchain transaction
207
-
direction:Direction,// direction of the payment
208
-
created_at:string,// payment's creation timestamp
209
-
network:AppNetwork,// a network of the payment
210
-
200
+
identifier:string;// payment identifier
201
+
user_uid:string;// user's app-specific ID
202
+
amount:number;// payment amount
203
+
memo:string;// a string provided by the developer, shown to the user
204
+
metadata:Object;// an object provided by the developer for their own usage
205
+
from_address:string;// sender address of the blockchain transaction
206
+
to_address:string;// recipient address of the blockchain transaction
207
+
direction:Direction;// direction of the payment
208
+
created_at:string;// payment's creation timestamp
209
+
network:AppNetwork;// a network of the payment
210
+
211
211
// Status flags representing the current state of this payment
cancelled:boolean;// cancelled by the developer or by Pi Network
217
+
user_cancelled:boolean;// cancelled by the user
218
+
};
219
+
220
220
// Blockchain transaction data:
221
-
transaction:null| { // This is null if no transaction has been made yet
222
-
txid:string, // id of the blockchain transaction
223
-
verified:boolean, // true if the transaction matches the payment, false otherwise
224
-
_link:string, // a link to the operation on the Blockchain API
225
-
},
226
-
}
221
+
transaction:null| {
222
+
// This is null if no transaction has been made yet
223
+
txid:string; // id of the blockchain transaction
224
+
verified:boolean; // true if the transaction matches the payment, false otherwise
225
+
_link:string; // a link to the operation on the Blockchain API
226
+
};
227
+
};
227
228
```
228
229
229
230
### Type `Direction`
230
231
231
232
A developer can check the direction of the payment with this type.
232
233
233
234
```typescript
234
-
typeDirection="user_to_app"|"app_to_user"
235
+
typeDirection="user_to_app"|"app_to_user";
235
236
```
236
237
237
238
### Type `AppNetwork`
238
239
239
240
Shows which network the payment is being made on.
240
241
241
242
```typescript
242
-
typeAppNetwork="Pi Network"|"Pi Testnet"
243
+
typeAppNetwork="Pi Network"|"Pi Testnet";
243
244
```
244
245
245
246
### Type `Scope`
246
247
247
248
Scopes you can request to users.
248
249
249
250
```typescript
250
-
typeScope="username"|"payments"|"wallet_address"
251
+
typeScope="username"|"payments"|"wallet_address";
252
+
```
253
+
254
+
## Native features list
255
+
256
+
Use this method to get a list of native features available for specific version of Pi Browser your user is using. Some SDK features may require particular features to work properly.
Use this method to open a native Share dialog (provided by the phone's OS), enabling your users to share
262
273
content from your app with their friends.
263
274
264
-
*`title`: the title of the message being shared
265
-
*`message`: the message that will be sent when the user picks a target app in the Share flow
275
+
-`title`: the title of the message being shared
276
+
-`message`: the message that will be sent when the user picks a target app in the Share flow
277
+
278
+
## Ads
279
+
280
+
SDK contains the `Ads` module (object) which allows developers to display ads to the users. It provides several methods for both interstitial and rewarded ads. All of the methods take advantage of Promise-based asynchronicity.
281
+
282
+
```typescript
283
+
typeAdType="interstitial"|"rewarded";
284
+
```
285
+
286
+
### Show ad
287
+
288
+
Use `showAd(adType: "interstitial" | "rewarded")` method to display an ad to a user. It returns a promise which resolves with an object of type `ShowAdResponse`:
-`"AD_NOT_AVAILABLE"` indicates the ad failed to load,
307
+
-`"AD_CLOSED"` indicates the ad was successfully displayed and closed,
308
+
-`"AD_REWARDED"` indicates the ad was successfully displayed and rewarded (only applicable for `rewarded` ads),
309
+
-`"AD_DISPLAY_ERROR"` indicates the ad was successfully loaded but failed to be displayed,
310
+
-`"AD_NETWORK_ERROR"` indicates that a user might have encountered network connection issues,
311
+
-`"ADS_NOT_SUPPORTED"` - indicates that app version used by uesr does not support ads,
312
+
-`"USER_UNAUTHENTICATED"` - indicates that user is not authenticated therefore rewarded ad cannot be display (only for `rewarded` ads).
313
+
314
+
The Pi Browser internally manages the ads availability strategy, automatically loading initial ads and reloading them whenever displayed. This ensures that ads are consistently ready for display. However, in rare cases, loading ads may be interrupted or the third party app may use `showAd()` methods too quickly (even before the next ad is ready). To allow developers handle these cases, the Pi SDK provides additional methods: `isAdReady()` and `requestAd()`.
315
+
316
+
</br>
317
+
318
+
> **Notes:**
319
+
>
320
+
> - If your application was approved to Pi Developer Ad Network, the response from `Pi.Ads.showAd('rewarded')` will contain additional `adId` fields, which allows you to [verify the rewarded status using Pi Platform API](ads.md#rewarded-ads-status-verification-with-pi-platform-api).
321
+
> - If your application wasn't approved to Pi Developer Ad Network, the `adId` field will be missing from `Pi.Ads.showAd('rewarded')` response. You should not grant rewards to users without verifying the `adId` using [Pi Platform API](platform_API.md#verify-a-rewarded-ad-status).
322
+
323
+
### Check if ad is ready
324
+
325
+
Use `isAdReady(adType: "interstitial" | "rewarded")` method to check if an ad of specific type is available. This method returns a promise which resolves with object of type `IsAdReadyResponse`.
The Pi Browser internally manages the ads availability strategy, automatically loading initial ads and reloading them whenever displayed. This ensures that ads are consistently ready for display. However, in rare cases, loading ads may be interrupted or the third party app may use `showAd()` methods too quickly (even before the next ad is ready). To address such cases, the Pi SDK provides this method to allow developers to check the availability of ads explicitly.
337
+
338
+
### Request ad
339
+
340
+
Use `requestAd(adType: "interstitial" | "rewarded")` method to request an interstitial or a rewarded ad. It returns a promise which resolves with an object of type `RequestAdResponse`:
As with the Ads availability strategy, the Pi Browser internally manages the process of requesting new ads to replace the displayed ones. While it's not guaranteed that an ad will be available at all time, developers can use `requestAd()` method to manually retry the ad request in case a promise returned by the `isAdReady()` resolved with `false`.
0 commit comments