pub struct Client {
pub env: PaypalEnv,
pub auth: Auth,
/* private fields */
}
Expand description
Represents a client used to interact with the paypal api.
Fields§
§env: PaypalEnv
Whether you are or not in a sandbox enviroment.
auth: Auth
Api Auth information
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(client_id: String, secret: String, env: PaypalEnv) -> Client
pub fn new(client_id: String, secret: String, env: PaypalEnv) -> Client
Returns a new client, you must get_access_token afterwards to interact with the api.
§Examples
use paypal_rs::{Client, PaypalEnv};
#[tokio::main]
async fn main() {
let clientid = std::env::var("PAYPAL_CLIENTID").unwrap();
let secret = std::env::var("PAYPAL_SECRET").unwrap();
let mut client = Client::new(
clientid,
secret,
PaypalEnv::Sandbox,
);
client.get_access_token().await.unwrap();
}
Sourcepub async fn get_access_token(&mut self) -> Result<(), ResponseError>
pub async fn get_access_token(&mut self) -> Result<(), ResponseError>
Gets a access token used in all the api calls and saves it.
Sourcepub fn access_token_expired(&self) -> bool
pub fn access_token_expired(&self) -> bool
Checks if the access token expired.
Sourcepub async fn execute_ext<E>(
&self,
endpoint: &E,
headers: HeaderParams,
) -> Result<E::Response, ResponseError>where
E: Endpoint,
pub async fn execute_ext<E>(
&self,
endpoint: &E,
headers: HeaderParams,
) -> Result<E::Response, ResponseError>where
E: Endpoint,
Executes the given endpoint with the given headers.
Sourcepub async fn execute<E>(
&self,
endpoint: &E,
) -> Result<E::Response, ResponseError>where
E: Endpoint,
pub async fn execute<E>(
&self,
endpoint: &E,
) -> Result<E::Response, ResponseError>where
E: Endpoint,
Executes the given endpoints with the default headers.
You must remember to call Client::get_access_token first or this may fail due to not being authed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more