Coder Social home page Coder Social logo

edg-l / paypal-rs Goto Github PK

View Code? Open in Web Editor NEW
54.0 1.0 13.0 211 KB

A rust library that wraps the paypal api asynchronously in a strongly typed manner.

Home Page: https://docs.rs/paypal-rs/

License: Apache License 2.0

Rust 100.00%
api paypal async paypal-rest-api rust-lang rust rust-library

paypal-rs's Introduction

paypal-rs

Version Downloads License Rust Docs

A rust library that wraps the paypal api asynchronously in a strongly typed manner.

If there is a missing endpoint that you need, you may try to implement the Endpoint and pass it to Client::execute

Currently in early development.

Example

use paypal_rs::{
    Client,
    api::orders::*,
    data::orders::*,
    data::common::Currency,
    PaypalEnv,
};

#[tokio::main]
async fn main() {
    dotenvy::dotenv().ok();
    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();

    let order = OrderPayloadBuilder::default()
        .intent(Intent::Authorize)
        .purchase_units(vec![PurchaseUnit::new(Amount::new(Currency::EUR, "10.0"))])
        .build().unwrap();

    let create_order = CreateOrder::new(order);

    let _order_created = client
        .execute(&create_order).await.unwrap();
}

Testing

You need the enviroment variables PAYPAL_CLIENTID and PAYPAL_SECRET to be set.

cargo test

Roadmap

  • Orders API - 0.1.0
    • Create order
    • Update order
    • Show order details
    • Authorize payment for order
    • Capture payment for order
  • Invoicing API - 0.2.0
    • Generate Invoice number
    • Create Draft Invoice
    • Show Invoice Details (Get Invoice)
    • List Invoices
    • Delete Invoice
    • Update Invoice
    • Cancel Invoice
    • 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
  • Identity API - 0.6.0
  • Disputes API - 0.7.0
  • Catalog Products API - 0.8.0
  • Partner Referrals API - 0.9.0
  • Payouts API - 0.10.0
  • Transaction Search API - 0.11.0
  • Referenced Payouts API - 0.12.0
  • Vault API - 0.13.0
  • Webhooks Management API - 0.14.0
  • Payment Experience Web Profiles API - 1.0.0

License: MIT OR Apache-2.0

paypal-rs's People

Contributors

dependabot[bot] avatar edg-l avatar lexuge avatar twistedfall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

paypal-rs's Issues

Got `input is not enough for unique date and time` when a invoice is paid

Code is below:

let client = get_client().await?;
let get_invoice_req = GetInvoice::new(&invoice_id);
let get_invoice_res = client.execute(&get_invoice_req).await;

When the invoice is unpaid, it returns Ok, but when the invoice is paid, it turn outs to be HttpError(reqwest::Error { kind: Decode, source: Error("input is not enough for unique date and time", line: 1, column: 1544) }).

Fields missing for deserializing order::Order from response of order_capture

I am currently using 0.2.0-alpha.3 for my app as I am using tokio 1.x runtime. I encountered the problem of missing fields (which caused it to panic) when using Client::order_capture. I tried to check the code and PayPal's docs and found that:

  1. Capture does not necessary have a field status_details and it seems to appear only when status is PENDING, so it should probably be like:
pub struct Capture {
    /// The status of the captured payment.
    pub status: CaptureStatus,
    /// The details of the captured payment status.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status_details: Option<CaptureStatusDetails>,
}
  1. For PaymentCollection not all kind of collection appears, so it should have serde(default) to handle missing fields. For instance, order_capture has only captures in return when I did my testing. Changing it to this works:
pub struct PaymentCollection {
    /// An array of authorized payments for a purchase unit. A purchase unit can have zero or more authorized payments.
    #[serde(default)]
    pub authorizations: Vec<AuthorizationWithData>,
    /// An array of captured payments for a purchase unit. A purchase unit can have zero or more captured payments.
    #[serde(default)]
    pub captures: Vec<Capture>,
    /// An array of refunds for a purchase unit. A purchase unit can have zero or more refunds.
    #[serde(default)]
    pub refunds: Vec<Refund>,
}

Much appreciated for all your works that have been done! Probably there are more cases like this to be fixed and not being discovered yet.

Making the internal http client from `pub(crate)` to `pub`

Since this project is not complete, there are features I need to use (like the identity api) which haven't been implemented. This means I currently have to manually create the http client to send the requests, but still use the access token found in the actual client. For now, consider making the internal http client public to avoid this.

auth problem

client.get_access_token().await?;
Error:
   0: error sending request for url (https://api-m.sandbox.paypal.com/v1/oauth2/token): connection closed before message completed
   1: error sending request for url (https://api-m.sandbox.paypal.com/v1/oauth2/token): connection closed before message completed
   2: connection closed before message completed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.