This commit is contained in:
Edgar 2022-04-20 09:35:00 +02:00
parent 3f783a824f
commit d38ef6f80e
No known key found for this signature in database
GPG key ID: 8731E6C0166EAA85
10 changed files with 34 additions and 42 deletions

View file

@ -1,4 +1,4 @@
/*
/*
use paypal_rs::{common::*, errors::*, invoice::*, Client, HeaderParams};
#[tokio::main]
@ -73,4 +73,4 @@ async fn main() -> Result<(), ResponseError> {
}
*/
fn main() {}
fn main() {}

View file

@ -13,7 +13,7 @@ use serde::Serialize;
use crate::{
data::{
invoice::{Invoice, InvoiceList, InvoicePayload, CancelReason},
invoice::{CancelReason, Invoice, InvoiceList, InvoicePayload},
orders::InvoiceNumber,
},
endpoint::Endpoint,
@ -158,10 +158,10 @@ impl Endpoint for ListInvoices {
}
}
/// Deletes a draft or scheduled invoice, by ID. Deletes invoices in the draft or scheduled state only.
///
/// For invoices that have already been sent, you can cancel the invoice.
///
/// Deletes a draft or scheduled invoice, by ID. Deletes invoices in the draft or scheduled state only.
///
/// For invoices that have already been sent, you can cancel the invoice.
///
/// After you delete a draft or scheduled invoice, you can no longer use it or show its details. However, you can reuse its invoice number.
#[derive(Debug, Clone)]
pub struct DeleteInvoice {
@ -202,7 +202,7 @@ pub struct UpdateInvoiceQuery {
}
/// Update an invoice.
///
///
/// Fully updates an invoice, by ID. In the JSON request body, include a complete invoice object. This call does not support partial updates.
#[derive(Debug, Clone)]
pub struct UpdateInvoice {
@ -215,10 +215,7 @@ pub struct UpdateInvoice {
impl UpdateInvoice {
/// New constructor.
pub fn new(invoice: Invoice, query: UpdateInvoiceQuery) -> Self {
Self {
invoice,
query
}
Self { invoice, query }
}
}
@ -252,16 +249,13 @@ pub struct CancelInvoice {
/// The invoice id.
pub invoice_id: String,
/// The reason of the cancelation.
pub reason: CancelReason
pub reason: CancelReason,
}
impl CancelInvoice {
/// New constructor.
pub fn new(invoice_id: String, reason: CancelReason) -> Self {
Self {
invoice_id,
reason
}
Self { invoice_id, reason }
}
}

View file

@ -1,4 +1,4 @@
//! This module contains the api endpoints.
pub mod invoice;
pub mod orders;
pub mod invoice;

View file

@ -1,15 +1,14 @@
//! An order represents a payment between two or more parties. Use the Orders API to create, update, retrieve, authorize, and capture orders.
//!
//!
//! https://developer.paypal.com/docs/api/orders/v2/
use std::borrow::Cow;
use derive_builder::Builder;
use serde::Serialize;
use serde_json::json;
use crate::{
data::orders::{Order, OrderPayload, PaymentSourceResponse},
data::orders::{Order, OrderPayload},
endpoint::Endpoint,
};
@ -87,7 +86,7 @@ pub struct PaymentSourceToken {
/// The PayPal-generated ID for the token.
pub id: String,
/// The tokenization method that generated the ID.
///
///
/// Can only be BILLING_AGREEMENT.
pub r#type: String,
}
@ -106,15 +105,15 @@ pub struct PaymentSourceBody {
pub payment_source: PaymentSource,
}
/// Captures payment for an order. To successfully capture payment for an order,
/// the buyer must first approve the order or a valid payment_source must be provided in the request.
/// Captures payment for an order. To successfully capture payment for an order,
/// the buyer must first approve the order or a valid payment_source must be provided in the request.
/// A buyer can approve the order upon being redirected to the rel:approve URL that was returned in the HATEOAS links in the create order response.
#[derive(Debug, Clone, Builder)]
pub struct CaptureOrder {
/// The id of the order.
pub order_id: String,
/// The endpoint body.
pub body: Option<PaymentSourceBody>
pub body: Option<PaymentSourceBody>,
}
impl CaptureOrder {
@ -147,15 +146,15 @@ impl Endpoint for CaptureOrder {
}
}
/// Authorizes payment for an order. To successfully authorize payment for an order,
/// the buyer must first approve the order or a valid payment_source must be provided in the request.
/// Authorizes payment for an order. To successfully authorize payment for an order,
/// the buyer must first approve the order or a valid payment_source must be provided in the request.
/// A buyer can approve the order upon being redirected to the rel:approve URL that was returned in the HATEOAS links in the create order response.
#[derive(Debug)]
pub struct AuthorizeOrder {
/// The order id.
order_id: String,
/// The endpoint body.
pub body: Option<PaymentSourceBody>
pub body: Option<PaymentSourceBody>,
}
impl AuthorizeOrder {

View file

@ -218,7 +218,7 @@ impl Client {
}
/// Executes the given endpoints with the default headers.
///
///
/// You must remember to call `get_access_token` first or this may fail due to not being authed.
pub async fn execute<E>(&self, endpoint: E) -> Result<E::Response, ResponseError>
where

View file

@ -1,6 +1,6 @@
//! Paypal object definitions used in the invoice api.
use crate::{data::common::*, data::common::LinkDescription};
use crate::{data::common::LinkDescription, data::common::*};
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
@ -632,4 +632,4 @@ pub struct RecordPaymentPayload {
amount: Amount,
shipping_info: Option<ContactInformation>,
}
}

View file

@ -1,5 +1,5 @@
//! This module contains the data structures used in the api endpoints.
pub mod common;
pub mod invoice;
pub mod orders;
pub mod invoice;

View file

@ -1,8 +1,6 @@
//! Paypal object definitions used by the orders api.
use super::common::*;
use crate::errors::{PaypalError, ResponseError};
use crate::HeaderParams;
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
@ -726,4 +724,4 @@ pub struct Order {
pub struct InvoiceNumber {
/// The invoice number.
pub invoice_number: String,
}
}

View file

@ -1,8 +1,8 @@
//! This module contains the endpoint trait used to implemented api endpoints.
use crate::{LIVE_ENDPOINT, SANDBOX_ENDPOINT};
use serde::{de::DeserializeOwned, Serialize};
use std::borrow::Cow;
use serde::{Serialize, de::DeserializeOwned};
use crate::{SANDBOX_ENDPOINT, LIVE_ENDPOINT};
/// A trait implemented by api endpoints.
pub trait Endpoint {
@ -30,7 +30,7 @@ pub trait Endpoint {
}
/// The full path of this endpoint.
///
///
/// Automatically implemented.
fn full_path(&self, is_sandbox: bool) -> String {
if is_sandbox {
@ -39,4 +39,4 @@ pub trait Endpoint {
format!("{}{}", LIVE_ENDPOINT, self.relative_path())
}
}
}
}

View file

@ -75,13 +75,14 @@
//! - [ ] Payment Experience Web Profiles API - 1.0.0
#![deny(missing_docs)]
#![forbid(unsafe_code)]
pub mod api;
pub mod client;
pub mod countries;
pub mod data;
pub mod endpoint;
pub mod errors;
pub mod client;
pub use client::*;
use derive_builder::Builder;
@ -160,9 +161,9 @@ struct AuthAssertionClaims {
#[cfg(test)]
mod tests {
use crate::{countries::Country};
use crate::countries::Country;
use crate::data::common::Currency;
use crate::{Client};
use crate::Client;
use std::env;
use std::str::FromStr;