pix-api-client

You don't need to wrap the client into an Arc, since its inner reqwest client already is wrapped.

Note

You need to take care munually of renewing your oauth token. This is accomplished very easily with the helper functions provided by the PixClient.

Example: Create a new client and fetch the oauth token

```rust use pixapiclient::cob::CobrancaImediata; use pixapiclient::{Executor, PixClient}; use reqwest::header;

let mut certbuffer = Vec::new(); File::open("mycert.pem")?.readtoend(&mut cert_buffer)?;

// format your headers the way your PSP expects it // this is just an example let pixclient = PixClient::newwithcustomheaders("https://my-pix-h", |headers| { let username = "my-id"; let secret = "my-secret"; let formattedauthorization = format!("{}:{}", username, secret); let encodedauth = base64::encode(formatted_authorization);

// and then insert it
headers.insert(header::AUTHORIZATION, encoded_auth.parse().unwrap()).unwrap();

}, cert_buffer);

let oauthresponse = pixclient .oauth() .autenticar() .execute() .await?;

// retrieve your new access token, and store it as your new authorization header let token = oauthresponse.accesstoken; pixclient.swapauthorizationtoken(token.tostring());

// Your client is ready for any further api calls.

```

Example: Create a new QRCode from a create immediate transaction endpoint

```rust use pixapiclient::cob::{CobrancaImediata, Devedor}; use pixapiclient::{Executor, PixClient}; use pixbrcode::qrdinamico::PixDinamicoSchema; use pixapiclient::extensions::FromResponse;

let devedor = Devedor::newpessoafisica("00000000000".tostring(), "Fulano de tal".tostring()); let payload = CobrancaImediata::new(10.25, "my-key".to_string(), devedor);

let response: CobrancaImediata = pixclient .cob() .criarcobranca_imediata(payload) .execute() .await?;

let pix: String = PixDinamicoSchema::fromcobrancaimediatabasic(response, "minha loja", "minha cidade").serializewith_src();

```

License: MIT