Payments Overview and Workflow - alxspiker/Pi-Developer-Handbook GitHub Wiki

Pi Payments: Overview and Workflow

What are Pi Payments?

  • Pi Payments simplify interactions with the Pi blockchain for in-app transactions.
  • They ensure synchronization between your app, the Pi blockchain, and Pi servers.
  • They provide a secure framework for developers, confirming that Pioneers have actually completed transactions.

Payment Flow: Key Phases

  1. Creation and Server-Side Approval

    • Your app frontend creates the payment.
    • The JavaScript SDK obtains a PaymentID.
    • Your server approves the payment via the /approve API call, enabling the Pioneer to proceed.
  2. Pioneer Interaction and Blockchain Transaction

    • Pioneer confirms, signs, and submits the transaction.
    • The blockchain processes the transaction.
    • Pi Apps Platform and Pi Wallet handle this phase.
  3. Server-Side Completion

    • Pi Servers submit the transaction to the blockchain.
    • The SDK provides your app with a TxID (transaction ID).
    • Your server completes the payment via the /complete API endpoint, verifying the transaction's success.
    • The payment flow closes.

Payment Flow Diagram

Security

  • Crucial: Complete payments within your app only after successful Server-Side Completion, indicated by a 200 response code from the /complete API call.
  • Failure to do so opens your app to potential fraud by malicious users.

Developer Responsibilities

  • Implementing the frontend to server communication for PaymentID and TxID.
  • Using the Pi SDK's createPayment, onReadyForServerApproval, and onReadyForServerCompletion functions.
  • Making the necessary /approve and /complete API calls from your server.
  • Updating your app interface to reflect payment status for the Pioneer.