pub struct PiNetwork {
pub api_key: String,
pub my_key_pair: Keypair,
pub network_passphrase: Option<NetworkPassphrase>,
pub current_payment: Option<PaymentDTO>,
pub reqwest_options: Option<ReqwestClientOptions>,
}
Expand description
The PiNetwork
struct containing every iformation for API authorization and the wallet handling
Have to initialized once and we can call all the methods on this struct.
If we want to handle more payments concurrently, we have to initialize one struct for every case.
The struct can store one payment flow and focus on that.
Fields§
§api_key: String
§my_key_pair: Keypair
§network_passphrase: Option<NetworkPassphrase>
§current_payment: Option<PaymentDTO>
§reqwest_options: Option<ReqwestClientOptions>
Implementations§
Source§impl PiNetwork
impl PiNetwork
pub fn new( api_key: String, wallet_private_seed: String, network_passphrase: Option<NetworkPassphrase>, options: Option<ReqwestClientOptions>, ) -> Result<Self, PiError>
Sourcepub async fn create_payment(
&mut self,
payment_data: PaymentArgs,
) -> Result<String, PiError>
pub async fn create_payment( &mut self, payment_data: PaymentArgs, ) -> Result<String, PiError>
You can create an A2U payment using create_payment method. This method returns a payment identifier (payment id).
Sourcepub async fn submit_payment(
&mut self,
payment_id: String,
) -> Result<String, PiError>
pub async fn submit_payment( &mut self, payment_id: String, ) -> Result<String, PiError>
You can submit the payment to the Pi Blockchain using submit_payment method. This method builds a payment transaction and submits it to the Pi Blockchain for you. Once submitted, the method returns a transaction identifier (txid).
Sourcepub async fn complete_payment(
&mut self,
payment_id: String,
tx_id: String,
) -> Result<PaymentDTO, PiError>
pub async fn complete_payment( &mut self, payment_id: String, tx_id: String, ) -> Result<PaymentDTO, PiError>
This method completes the payment in the Pi server.
Sourcepub async fn get_payment(
&mut self,
payment_id: String,
) -> Result<PaymentDTO, PiError>
pub async fn get_payment( &mut self, payment_id: String, ) -> Result<PaymentDTO, PiError>
This method returns a payment object based on the payment ID if it exists.
Sourcepub async fn approve_payment(
&mut self,
payment_id: String,
) -> Result<PaymentDTO, PiError>
pub async fn approve_payment( &mut self, payment_id: String, ) -> Result<PaymentDTO, PiError>
This method required to approve the user payment created on the frontend, after the backend is approved the user can pay
Sourcepub async fn cancel_payment(
&mut self,
payment_id: String,
) -> Result<PaymentDTO, PiError>
pub async fn cancel_payment( &mut self, payment_id: String, ) -> Result<PaymentDTO, PiError>
This method cancels the payment in the Pi server.
Sourcepub async fn get_incomplete_server_payments(
&self,
) -> Result<Vec<PaymentDTO>, PiError>
pub async fn get_incomplete_server_payments( &self, ) -> Result<Vec<PaymentDTO>, PiError>
This method returns the latest incomplete payment which your app has created, if present. Use this method to troubleshoot the following error: “You need to complete the ongoing payment first to create a new one.”
If a payment is returned by this method, you must follow one of the following 3 options:
- cancel the payment, if it is not linked with a blockchain transaction and you don’t want to submit the transaction anymore
- submit the transaction and complete the payment
- if a blockchain transaction has been made, complete the payment
If you do not know what this payment maps to in your business logic, you may use its metadata property to retrieve which business logic item it relates to. Remember that metadata is a required argument when creating a payment, and should be used as a way to link this payment to an item of your business logic.