Skip to content

Commit b2b5c8d

Browse files
committed
February 2023 doc updates
1 parent 10f013d commit b2b5c8d

18 files changed

+264
-96
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ Pi.authenticate(scopes, onIncompletePaymentFound).then(function(auth) {
4141
});
4242
```
4343

44-
### Request a payment
44+
### Request a payment (User-To-App)
4545

4646
The `createPayment` method enables you to request a payment from the current user to your app's account.
4747

4848
The user will be prompted with a modal provided by the Pi Wallet, enabling them to sign the
49-
transaction and submit it to the Pi blockchain.
49+
transaction and submit it to the Pi Blockchain.
5050

5151
```javascript
5252

@@ -67,14 +67,21 @@ Pi.createPayment({
6767

6868
```
6969

70-
This code block is a **simplified example** to give you a sense of how it works.
70+
### Request a payment (App-To-User)
7171

72-
In order to make sure that all involved parties (your app, your server, the Pi servers, and the Pi blockchain) are in sync,
73-
the payment needs to go through a **Server-Side Approval** flow and a **Server-Side Completion** flow.
72+
If you want to send Pi from your app to a user, you need to use one of Pi Network's backend SDKs, depending
73+
on the language your backend is written in. Refer to the [Advanced payments guide](./payments_advanced.md)
74+
for more information.
75+
76+
77+
In order to make sure that all involved parties (your app, your server, the Pi servers, and the Pi Blockchain) are in sync,
78+
the payment needs to go through a **Server-Side Approval** flow (for User-to-App payment) and/or a **Server-Side Completion**
79+
flow (for all types of payments).
7480

7581
Please refer to:
7682
* [the full Payments documentation](./payments.md) to learn about the complete payment flow
83+
* [the Advanced Payments documentation](./payments_advanced.md) to learn about App-to-User payment flow
7784
* [the Platform API documentation](./platform_API.md) to learn how to confirm the payment and acknowledge it from your
7885
server
7986
* [the client SDK documentation](./SDK_reference.md) to learn about Pi Apps SDK and provided methods in detail
80-
* the Demo App (coming soon!) to view an example of how you can implement the various required flows in your app's code.
87+
* [the Demo App](https://github.com/pi-apps/demo) to view an example of how you can implement the various required flows in your app's code

SDK_reference.md

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Client SDK reference:
1+
# Client SDK reference
22

33
## Initialization
44

@@ -41,7 +41,7 @@ to configure this and view your Sandbox URL.
4141
4242

4343
```typescript
44-
Pi.authenticate(scopes: Array<string>, onIncompletePaymentFound: Function<PaymentDTO>): Promise<AuthResult>
44+
Pi.authenticate(scopes: Array<Scope>, onIncompletePaymentFound: Function<PaymentDTO>): Promise<AuthResult>
4545
```
4646

4747
Return value:
@@ -58,14 +58,7 @@ type AuthResult = {
5858
5959
### `scopes`
6060
61-
Available scopes: `username`, `payments`.
62-
63-
> **Not yet implemented**
64-
>
65-
> Currently, all calls to the `authenticate` method will assume all scopes have been requested - i.e all calls
66-
> are interpreted as though the first argument were `['username', 'payments']`.
67-
> However, you should implement your app by only adding the scopes you need when calling `authenticate`.
68-
> Scopes support will be added before the general release of the Pi platform.
61+
Available scopes: `username`, `payments`, `wallet_address`
6962
7063
Here is a breakdown of various keys available on the `AuthResult['user']` object, and the scopes required for those keys
7164
to be present:
@@ -74,14 +67,16 @@ to be present:
7467
| -------------: | ------------- | :-------------: |
7568
| `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) |
7669
| `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` |
7772
7873
### `onIncompletePaymentFound`
7974
8075
Signature: `(payment: PaymentDTO) => void`
8176
8277
Every time when the user is authenticated, and when they try to start a new payment flow, the SDK checks that there is no
8378
incomplete payment for this user. An incomplete payment, in this context, is a payment which has been submitted to
84-
the Pi blockchain, but where `status.developer_completed` is still `false` (i.e. the developer has not called the
79+
the Pi Blockchain, but where `status.developer_completed` is still `false` (i.e. the developer has not called the
8580
`/complete` endpoint on this payment).
8681
8782
If an incomplete payment is found, this callback will be invoked with the payment's `PaymentDTO`.
@@ -168,7 +163,7 @@ Read more about Server-Side Approval and the full payment flow in the dedicated
168163

169164
Signature: `(paymentId: string, txid: string) => void`
170165

171-
This is called when the user has submitted the transaction to the Pi blockchain. During the completion time period, this callback will be invoked multiple times in case of failure.
166+
This is called when the user has submitted the transaction to the Pi Blockchain. During the completion time period, this callback will be invoked multiple times in case of failure.
172167
If the initial trial fails, the Pi SDK will continue to invoke the function roughly every 10 seconds until the completion timer ends.
173168

174169
Use this callback to send the blockchain transaction identifier (txid), along with the paymentId
@@ -197,37 +192,63 @@ Otherwise, only the first argument will be provided.
197192

198193
### Type `PaymentDTO`
199194

200-
This type is used in the arguments that are passed to `onIncompletePaymentFound` and `onError`.
195+
This type is for the arguments that are passed to `onIncompletePaymentFound` and `onError`.
201196

202197
```typescript
203198
type PaymentDTO = {
204199
// Payment data:
205-
identifier: string, // The payment identifier
206-
user_uid: string, // The user's app-specific ID
207-
amount: number, // The payment amount
208-
memo: string, // A string provided by the developer, shown to the user
209-
metadata: Object, // An object provided by the developer for their own usage
210-
to_address: string, // The recipient address of the blockchain transaction
211-
created_at: string, // The payment's creation timestamp
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
212210

213211
// Status flags representing the current state of this payment
214212
status: {
215213
developer_approved: boolean, // Server-Side Approval
216-
transaction_verified: boolean, // Blockchain transaction verified
217-
developer_completed: boolean, // Server-Side Completion
218-
cancelled: boolean, // Cancelled by the developer or by Pi Network
219-
user_cancelled: boolean, // Cancelled by the user
214+
transaction_verified: boolean, // blockchain transaction verified
215+
developer_completed: boolean, // server-Side Completion
216+
cancelled: boolean, // cancelled by the developer or by Pi Network
217+
user_cancelled: boolean, // cancelled by the user
220218
},
221219

222220
// Blockchain transaction data:
223221
transaction: null | { // This is null if no transaction has been made yet
224-
txid: string, // The id of the blockchain transaction
225-
verified: boolean, // True if the transaction matches the payment, false otherwise
226-
_link: string, // A link to the operation on the Blockchain API
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
227225
},
228226
}
229227
```
230228
229+
### Type `Direction`
230+
231+
A developer can check the direction of the payment with this type.
232+
233+
```typescript
234+
type Direction = "user_to_app" | "app_to_user"
235+
```
236+
237+
### Type `AppNetwork`
238+
239+
Shows which network the payment is being made on.
240+
241+
```typescript
242+
type AppNetwork = "Pi Network" | "Pi Testnet"
243+
```
244+
245+
### Type `Scope`
246+
247+
Scopes you can request to users.
248+
249+
```typescript
250+
type Scope = "username" | "payments" | "wallet_address"
251+
```
231252
232253
## Share dialog
233254

authentication.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Authentication
2+
3+
This is a simple walkthrough on handling user authentication using Pi SDK and API endpoint. For a detailed explanation, please refer to [Pi.authenticate](./SDK_reference.md#authentication) for SDK reference and [/me](./platform_API.md#authentication) for API reference.
4+
## Guide
5+
6+
Here is a list of steps you can follow when you authenticate users for your app:
7+
### 1. Call `authenticate()` of Pi SDK
8+
9+
Using the Pi SDK `authenticate()`, you can obtain user information along with the access token.
10+
```javascript
11+
const authRes = await window.Pi.authenticate(scopes, onIncompletePaymentFound);
12+
```
13+
14+
### 2. Make a GET request to `/me` Pi API endpoint using the access token for verification
15+
To verify the data you got in step 1, you need to make a GET request to `/me` Pi API endpoint, with the access token included in the header. If the access token is valid, it will return a response with [UserDTO](./platform_API#UserDTO). However, if the token is invalid, it will return HTTP 401 Unauthorized code.
16+
```javascript
17+
const me = await axios.get('https://api.minepi.com/v2/me', {headers: {'Authorization': `Bearer ${accessToken}}});
18+
```

developer_portal.md

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,78 +4,88 @@ With the help of Pi SDK and Pi API, you can create applications that run within
44

55
## How to register your app
66

7-
1. The Pi Developer Portal can be accessed using the Pi Browser. Go to `pi://develop.pi` to visit the Pi Developer Portal. To register a new app, click on `New App` button at the bottom of the page.
7+
1. The Pi Developer Portal can be accessed using the Pi Browser. Go to `pi://develop.pi` to visit the Pi Developer Portal. When you first get to the main page, you won't see any app. To register your app, tab on the "New App" button.
88

99
<div style="text-align:center;">
10-
<img src="./img/dev_portal_main_1.png" alt="drawing" width="200"/>
10+
<img src="./img/dev_portal_main.png" alt="drawing" width="300" />
1111
</div>
12+
<br />
1213

13-
2. You can fill in the required fields. One important field is selecting the host network that the app is connecting to. Depending on this option, Pi SDK will automatically connect your app to the corresponding network. An app can only connect to one network at a time, and once you register the app, this option cannot be changed.
14+
2. Initially you're asked to fill in 3 required fields. The "App Network" option lets you select the host network that your app is connecting to. Depending on this option, Pi SDK will automatically connect your app to the corresponding network, either to Pi Mainnet or Pi Testnet. Note that an app can only connect to one network at a time, and once you register the app, this option cannot be changed. What this means is you're advised to create two different apps, one with testnet for testing purpose and one with mainnet for your production usage.
1415

1516
<div style="text-align:center;">
16-
<img src="./img/dev_portal_new_1.png" alt="drawing" width="200"/>
17+
<img src="./img/dev_portal_create_app.png" alt="drawing" width="300" />
1718
</div>
19+
<br />
1820

19-
> When the app is connecting to the Pi Testnet, you can maintain a list of whitelisted users. Your testnet app will only be accessible by users you allowed, and if you leave this field empty, anyone can access your test app.
21+
3. After you register your app, you can see your app in detail. Each app has its own "App Checklist", which helps you keep track of required steps to successfully set up your app. To see the checklist, tab on "App Checklist" button.
2022

2123
<div style="text-align:center;">
22-
<img src="./img/dev_portal_new_2.png" alt="drawing" width="200"/>
24+
<img src="./img/dev_portal_app_main_1.png" alt="drawing" width="300" />
2325
</div>
26+
<br />
2427

25-
> When the app is connecting to the Pi Mainnet, you can pair one of your testnet apps to the mainnet app. More specific usage is coming soon in the future.
28+
4. The checklist steps will be unlocked sequentially as you complete each step. The first step is to configure the hosting option.
2629

2730
<div style="text-align:center;">
28-
<img src="./img/dev_portal_new_3.png" alt="drawing" width="200"/>
31+
<img src="./img/dev_portal_checklist_1.png" alt="drawing" width="300" />
2932
</div>
33+
<br />
3034

31-
> When you're hosting the app on your server, you will also need to provide the url. Notice that you'll be asked to verify the ownership of the url after you register the app. After you filled in the required fields, you can submit to register your app by clicking on `Submit` button at the bottom of the page.
35+
5. Once you configure the hosting option, you'll see that "App Wallet" button is now enabled, and the next step for checklist is connecting a wallet to the app. Follow the instruction to create the app and connect it to your app.
3236

33-
3. After you register your app, you can see your apps in the main page. If you selected the paired app for your mainnet app, it will show like the following.
37+
<div style="text-align:center;">
38+
<img src="./img/dev_portal_app_main_2.png" alt="drawing" width="300" />
39+
</div>
40+
<br />
41+
42+
6. When you connect your app wallet to your app, the checklist will show you documentations that you can go over to get started. From here, you can have a look and follow the remaining steps to fully configure the app.
3443

3544
<div style="text-align:center;">
36-
<img src="./img/dev_portal_main_2.png" alt="drawing" width="200"/>
45+
<img src="./img/dev_portal_checklist_2.png" alt="drawing" width="300" />
3746
</div>
38-
<br>
47+
<br />
3948

4049
## Testnet app in the Pi Browser
4150

4251
If you registered your app to connect to the Pi Testnet and if you visit your app in the Pi Browser, it will show the black and yellow stripe at the top to indicate that this app is connected to the Pi Testnet.
4352

4453
<div style="text-align:center;">
45-
<img src="./img/testnet_indicator.png" alt="drawing" width="200"/>
54+
<img src="./img/testnet_indicator.png" alt="drawing" width="300" />
4655
</div>
4756

48-
49-
## Legacy Project created before 26/07/2022
57+
## Legacy Project created before 26/07/2022
5058

5159
Projects that existed prior to the launch of the Pi Mainnet SDK will point to the Pi Testnet
60+
5261
- This cannot be changed or updated
5362
- It is best practice to create new Developer Portal Projects
5463

5564
### Developers and Teams with previously created Legacy Projects
5665

57-
1. Create a new Developer Portal Project
58-
- Select Mainnet - This will be the Mainnet Version of the App
59-
- URL
60-
- This project should contain the desired URL that Pioneers will access the app with through the Pi Browser
61-
- URL ownership will be determined through verification process
62-
- Payment Wallet
63-
- Until developer/app wallets are created the wallet address of the developer who creates the new project page will be used to process all transactions
64-
- If the project page creator does not have a Pi Wallet Address which has been created in a Mainnet Migration all transactions will fail.
66+
1. Create a new Developer Portal Project
67+
- Select Mainnet - This will be the Mainnet Version of the App
68+
- URL
69+
- This project should contain the desired URL that Pioneers will access the app with through the Pi Browser
70+
- URL ownership will be determined through verification process
71+
- Payment Wallet
72+
- Until developer/app wallets are created the wallet address of the developer who creates the new project page will be used to process all transactions
73+
- If the project page creator does not have a Pi Wallet Address which has been created in a Mainnet Migration all transactions will fail.
6574
2. Create a second new Developer Project Page
66-
- Select Testnet - This will be for testing purposes
67-
- URL
68-
- Cannot be the same as the Mainnet URL
69-
- Must be owned by the developer as well
70-
- Set the desired access permissions
71-
- This project can be linked to the previously created Mainnet Project from step 1
75+
- Select Testnet - This will be for testing purposes
76+
- URL
77+
- Cannot be the same as the Mainnet URL
78+
- Must be owned by the developer as well
79+
- Set the desired access permissions
80+
- This project can be linked to the previously created Mainnet Project from step 1
7281
3. Link Mainnet Project to the Brainstorm project (if applicable)
73-
- As of July 2022 it is possible to link only one developer portal project to a brainstorm project
82+
- As of July 2022 it is possible to link only one developer portal project to a brainstorm project
7483

7584
### Special Considerations
85+
7686
- If an app team has no members with a Mainnet Wallet
77-
- Please reach out to the Pi CT through the <a href="https://pinetwork.atlassian.net/servicedesk/customer/portal/1/group/3/create/20" target="_blank">Pi Support Portal</a>
78-
- For the question “What does your question relate to? ”
79-
- Select “Pi Mainnet SDK Wallet”
80-
- Submit contact information
81-
- A member of the Pi CT will follow up
87+
- Please reach out to the Pi CT through the <a href="https://pinetwork.atlassian.net/servicedesk/customer/portal/1/group/3/create/20" target="_blank">Pi Support Portal</a>
88+
- For the question “What does your question relate to? ”
89+
- Select “Pi Mainnet SDK Wallet”
90+
- Submit contact information
91+
- A member of the Pi CT will follow up

img/dev_portal_app_main_1.png

496 KB
Loading

img/dev_portal_app_main_2.png

500 KB
Loading

img/dev_portal_checklist_1.png

227 KB
Loading

img/dev_portal_checklist_2.png

236 KB
Loading

img/dev_portal_create_app.png

115 KB
Loading

img/dev_portal_main.png

86.6 KB
Loading

0 commit comments

Comments
 (0)