paypal-rs/examples/invoice.rs

42 lines
1.2 KiB
Rust
Raw Normal View History

2022-04-26 07:25:39 +00:00
use color_eyre::Result;
use paypal_rs::data::invoice::*;
use paypal_rs::{api::invoice::*, data::common::Money, PaypalEnv};
2022-04-26 07:25:39 +00:00
use paypal_rs::{data::common::Currency, Client};
2021-07-02 09:19:47 +00:00
#[tokio::main]
2022-04-26 07:25:39 +00:00
async fn main() -> Result<()> {
color_eyre::install()?;
2021-07-02 09:19:47 +00:00
dotenv::dotenv().ok();
2022-04-26 07:25:39 +00:00
let clientid = std::env::var("PAYPAL_CLIENTID")?;
let secret = std::env::var("PAYPAL_SECRET")?;
2021-07-02 09:19:47 +00:00
let mut client = Client::new(clientid, secret, PaypalEnv::Sandbox);
2022-04-26 07:25:39 +00:00
client.get_access_token().await?;
2021-07-02 09:19:47 +00:00
2022-04-26 07:25:39 +00:00
let payload = InvoicePayloadBuilder::default()
.detail(InvoiceDetailBuilder::default().currency_code(Currency::EUR).build()?)
.invoicer(
InvoicerInfoBuilder::default()
.name(NameBuilder::default().full_name("Test Person").build()?)
.build()?,
)
.items(vec![ItemBuilder::default()
.name("Some name")
.unit_amount(Money {
2021-07-02 09:21:20 +00:00
currency_code: Currency::EUR,
2022-04-26 07:25:39 +00:00
value: "10.0".to_string(),
})
.quantity("1")
.build()?])
.build()?;
2021-07-02 09:19:47 +00:00
2022-04-26 07:25:39 +00:00
let invoice = CreateDraftInvoice::new(payload);
2022-04-28 08:06:23 +00:00
let res = client.execute(&invoice).await?;
2022-04-26 07:25:39 +00:00
println!("{:#?}", res);
2021-07-02 09:19:47 +00:00
Ok(())
}