Struct PiNetwork

Source
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

Source

pub fn new( api_key: String, wallet_private_seed: String, network_passphrase: Option<NetworkPassphrase>, options: Option<ReqwestClientOptions>, ) -> Result<Self, PiError>

Source

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).

Source

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).

Source

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.

Source

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.

Source

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

Source

pub async fn cancel_payment( &mut self, payment_id: String, ) -> Result<PaymentDTO, PiError>

This method cancels the payment in the Pi server.

Source

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.

Source

pub fn validate_seed_format(seed: &str) -> Result<(), PiError>

Validating the seed format, trying to filter out invalid wallet secret seeds

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T