From 76c169781c6eca45fa4d711c3bb39f3841a92321 Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Tue, 5 Jul 2022 08:16:07 +0200 Subject: [PATCH] release 0.2 even if not all features are implemented --- Cargo.toml | 2 +- README.md | 22 +++++++++++++++++----- src/api/invoice.rs | 41 ++++++++++++++++++++++++++++++++++++++++- src/data/invoice.rs | 40 ++++++++++++++++++++++++++++++---------- src/lib.rs | 16 +++++++++++++++- 5 files changed, 103 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e5e1594..5dadb93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "paypal-rs" -version = "0.2.0-alpha.7" +version = "0.2.0" authors = ["Edgar "] description = "A library that wraps the paypal api asynchronously." repository = "https://github.com/edg-l/paypal-rs/" diff --git a/README.md b/README.md index c3006d3..66a7c78 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,7 @@ A rust library that wraps the [paypal api](https://developer.paypal.com/docs/api) asynchronously in a strongly typed manner. -Crate: https://crates.io/crates/paypal-rs - -Documentation: https://docs.rs/paypal-rs +If there is a missing endpoint that you need, you may try to implement the [Endpoint](endpoint::Endpoint) and pass it to [Client::execute](client::Client::execute) Currently in early development. @@ -43,7 +41,7 @@ async fn main() { let create_order = CreateOrder::new(order); let _order_created = client - .execute(create_order).await.unwrap(); + .execute(&create_order).await.unwrap(); } ``` @@ -60,7 +58,21 @@ You need the enviroment variables PAYPAL_CLIENTID and PAYPAL_SECRET to be set. - - [x] Show order details - - [x] Authorize payment for order - - [x] Capture payment for order -- [ ] Invoicing API - 0.2.0 +- [x] Invoicing API - 0.2.0 +- - [x] Generate Invoice number +- - [x] Create Draft Invoice +- - [x] Show Invoice Details (Get Invoice) +- - [x] List Invoices +- - [x] Delete Invoice +- - [x] Update Invoice +- - [x] Cancel Invoice +- - [x] Send Invoice +- - [ ] Send Invoice Reminder +- - [ ] List Templates +- - [ ] Create Template +- - [ ] Delete Template +- - [ ] Fully Update Template +- - [ ] Show Template Template - [ ] Payments API - 0.3.0 - [ ] Tracking API - 0.4.0 - [ ] Subscriptions API - 0.5.0 diff --git a/src/api/invoice.rs b/src/api/invoice.rs index 9f1d2ad..8ef16ba 100644 --- a/src/api/invoice.rs +++ b/src/api/invoice.rs @@ -13,7 +13,7 @@ use serde::Serialize; use crate::{ data::{ - invoice::{CancelReason, Invoice, InvoiceList, InvoicePayload}, + invoice::{CancelReason, Invoice, InvoiceList, InvoicePayload, SendInvoicePayload}, orders::InvoiceNumber, }, endpoint::Endpoint, @@ -286,6 +286,45 @@ impl Endpoint for CancelInvoice { } } +/// Cancels a sent invoice, by ID, and, optionally, sends a notification about the cancellation to the payer, merchant, and CC: emails. +#[derive(Debug, Clone)] +pub struct SendInvoice { + /// The invoice id. + pub invoice_id: String, + /// The payload. + pub payload: SendInvoicePayload, +} + +impl SendInvoice { + /// New constructor. + pub fn new(invoice_id: impl ToString, payload: SendInvoicePayload) -> Self { + Self { + invoice_id: invoice_id.to_string(), + payload, + } + } +} + +impl Endpoint for SendInvoice { + type Query = (); + + type Body = SendInvoicePayload; + + type Response = (); + + fn relative_path(&self) -> Cow { + Cow::Owned(format!("/v2/invoicing/invoices/{}/send", self.invoice_id)) + } + + fn method(&self) -> reqwest::Method { + reqwest::Method::POST + } + + fn body(&self) -> Option { + Some(self.payload.clone()) + } +} + /* impl super::Client { diff --git a/src/data/invoice.rs b/src/data/invoice.rs index f0839e0..75521bd 100644 --- a/src/data/invoice.rs +++ b/src/data/invoice.rs @@ -656,7 +656,7 @@ pub const QR_ACTION_PAY: &str = "pay"; pub const QR_ACTION_DETAILS: &str = "details"; /// QR creation parameters -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder)] pub struct QRCodeParams { /// The width, in pixels, of the QR code image. Value is from 150 to 500. pub width: i32, @@ -670,15 +670,35 @@ pub struct QRCodeParams { /// Used to record a payment. #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder)] pub struct RecordPaymentPayload { - payment_id: Option, - - payment_date: Option>, - method: PaymentMethod, - - note: Option, - amount: Amount, + /// The payment id. + pub payment_id: Option, + /// The payment date + pub payment_date: Option>, + /// The payment method. + pub method: PaymentMethod, + /// A note. + pub note: Option, + /// The amount. + pub amount: Amount, + /// The shipping info. + pub shipping_info: Option, +} - shipping_info: Option, +/// Send Invoice Payload +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Default, Builder, Clone)] +pub struct SendInvoicePayload { + /// An array of one or more CC: emails to which notifications are sent. + /// If you omit this parameter, a notification is sent to all CC: email addresses that are part of the invoice. + pub additional_recipients: Option>, + /// A note to the payer. + pub note: Option, + /// Indicates whether to send a copy of the email to the merchant. + pub send_to_invoicer: Option, + /// Indicates whether to send a copy of the email to the recipient. + pub send_to_recipient: Option, + /// The subject of the email that is sent as a notification to the recipient. + pub subject: Option, } diff --git a/src/lib.rs b/src/lib.rs index 2d2f703..5efbf6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,7 +57,21 @@ //! - - [x] Show order details //! - - [x] Authorize payment for order //! - - [x] Capture payment for order -//! - [ ] Invoicing API - 0.2.0 +//! - [x] Invoicing API - 0.2.0 +//! - - [x] Generate Invoice number +//! - - [x] Create Draft Invoice +//! - - [x] Show Invoice Details (Get Invoice) +//! - - [x] List Invoices +//! - - [x] Delete Invoice +//! - - [x] Update Invoice +//! - - [x] Cancel Invoice +//! - - [x] Send Invoice +//! - - [ ] Send Invoice Reminder +//! - - [ ] List Templates +//! - - [ ] Create Template +//! - - [ ] Delete Template +//! - - [ ] Fully Update Template +//! - - [ ] Show Template Template //! - [ ] Payments API - 0.3.0 //! - [ ] Tracking API - 0.4.0 //! - [ ] Subscriptions API - 0.5.0