Struct Paddle

Source
pub struct Paddle { /* private fields */ }
Expand description

Paddle API client

This struct is used to create a new Paddle client instance.

Implementations§

Source§

impl Paddle

Source

pub const PRODUCTION: &'static str = "https://api.paddle.com"

Source

pub const SANDBOX: &'static str = "https://sandbox-api.paddle.com"

Source

pub fn new( api_key: impl Into<String>, base_url: impl IntoUrl, ) -> Result<Self, Error>

Creates a new Paddle client instance.

Example:

use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
Source

pub fn products_list(&self) -> ProductsList<'_>

Returns a request builder for fetching products. Use the after method to page through results.

By default, Paddle returns products that are active. Use the status method to return products that are archived. Use the include method to include related price entities in the response.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let products = client.products_list().send().await.unwrap();
Source

pub fn product_create( &self, name: impl Into<String>, tax_category: TaxCategory, ) -> ProductCreate<'_>

Returns a request builder for creating a new product.

§Example:
use paddle::Paddle;
use paddle::enums::TaxCategory;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let product = client.products_create("My Product", TaxCategory::Standard).send().await.unwrap();
Source

pub fn product_get(&self, product_id: impl Into<ProductID>) -> ProductGet<'_>

Returns a request builder for fetching a specific product.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let product = client.product_get("pro_01jqx9rd...").send().await.unwrap();
Source

pub fn product_update( &self, product_id: impl Into<ProductID>, ) -> ProductUpdate<'_>

Returns a request builder for updating a specific product.

§Example:
use paddle::Paddle;
use paddle::enums::TaxCategory;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let product = client.product_update("pro_01jqx9rd...").name("My New Name").send().await.unwrap();
Source

pub fn prices_list(&self) -> PricesList<'_>

Returns a request builder listing prices

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let prices = client.prices_list().send().await.unwrap();
Source

pub fn price_create( &self, product_id: impl Into<ProductID>, description: impl Into<String>, amount: u64, currency: CurrencyCode, ) -> PricesCreate<'_>

Returns a request builder for creating a new price.

  • product_id - Paddle ID for the product that this price is for.
  • description - Internal description for this price, not shown to customers. Typically notes for your team.
  • amount - Amount of the price in the smallest unit of the currency (e.g. 1000 cents for 10 USD).
  • currency - Currency code for the price. Use the CurrencyCode enum to specify the currency.
§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let price = client.price_create("pro_01jqx9rd...", "Low price", 19.99, CurrencyCode::USD).send().await.unwrap();
Source

pub fn price_get(&self, price_id: impl Into<PriceID>) -> PriceGet<'_>

Returns a request builder for fetching a specific price by id.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let price = client.price_get("price_01jqx9rd...").send().await.unwrap();
Source

pub fn price_update(&self, price_id: impl Into<PriceID>) -> PriceUpdate<'_>

Returns a request builder for updating a specific price.

§Example:
use paddle::Paddle;
use paddle::enums::TaxCategory;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let price = client.price_update("pri_01jqxv...").name("Updated Name").send().await.unwrap();
Source

pub fn discounts_list(&self) -> DiscountsList<'_>

Returns a request builder for fetching discounts.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discounts = client.discounts_list().send().await.unwrap();
Source

pub fn discount_create( &self, amount: impl Into<String>, description: impl Into<String>, discount_type: DiscountType, ) -> DiscountCreate<'_>

Returns a request builder for creating discounts.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.discount_create("15", "Winter Holidays", DiscountType::Percentage).send().await.unwrap();
Source

pub fn discount_get( &self, discount_id: impl Into<DiscountID>, ) -> DiscountGet<'_>

Returns a request builder for fetching a specific discount by id.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.discount_get("dsc_01jqzpbmnq...").send().await.unwrap();
Source

pub fn discount_update( &self, discount_id: impl Into<DiscountID>, ) -> DiscountUpdate<'_>

Returns a request builder for creating discounts.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.discount_update("dsc_01jqzpbmnq...").amount("18").send().await.unwrap();
Source

pub fn customers_list(&self) -> CustomersList<'_>

Returns a request builder for fetching customers. Use the after method to page through results.

By default, Paddle returns customers that are active. Use the status query parameter to return customers that are archived.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.customers_list().send().await.unwrap();
Source

pub fn customer_create(&self, email: impl Into<String>) -> CustomerCreate<'_>

Returns a request builder for creating a new customer.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.customer_create("test@example.com").send().await.unwrap();
Source

pub fn customer_get( &self, customer_id: impl Into<CustomerID>, ) -> CustomerGet<'_>

Returns a request builder for fetching a specific customer by id.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.customer_get("ctm_01jqztc78e1xfdgwhcgjzdrvgd").send().await.unwrap();
Source

pub fn customer_update( &self, customer_id: impl Into<CustomerID>, ) -> CustomerUpdate<'_>

Returns a request builder for updating customer data.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.customer_update("ctm_01jqztc78e1xfdgwhcgjzdrvgd").email("new_email@example.com").send().await.unwrap();
Source

pub fn customer_credit_balances( &self, customer_id: impl Into<CustomerID>, ) -> CustomerCreditBalances<'_>

Returns a request builder for fetching a list of credit balances for each currency for a customer.

Each balance has three totals:

  • available - total available to use.
  • reserved - total temporarily reserved for billed transactions.
  • used - total amount of credit used.

Credit is added to the available total initially. When used, it moves to the used total.

The reserved total is used when a credit balance is applied to a transaction that’s marked as billed, like when working with an issued invoice. It’s not available for other transactions at this point, but isn’t considered used until the transaction is completed. If a billed transaction is canceled, any reserved credit moves back to available.

Credit balances are created automatically by Paddle when you take an action that results in Paddle creating a credit for a customer, like making prorated changes to a subscription. An empty data array is returned where a customer has no credit balances.

The response is not paginated.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.customer_credit_balances("ctm_01jqztc78e1xfdgwhcgjzdrvgd").send().await.unwrap();
Source

pub async fn generate_auth_token( &self, customer_id: impl Display, ) -> Result<SuccessResponse<CustomerAuthenticationToken>, Error>

Generates an authentication token for a customer.

You can pass a generated authentication token to Paddle.js when opening a checkout to let customers work with saved payment methods.

Authentication tokens are temporary and shouldn’t be cached. They’re valid until the expires_at date returned in the response.

Source

pub fn addresses_list( &self, customer_id: impl Into<CustomerID>, ) -> AddressesList<'_>

Returns a request builder for fetching customers addresses.

By default, Paddle returns addresses that are active. Use the status query parameter to return addresses that are archived.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.addresses_list("ctm_01jqztc78e1xfdgwhcgjzdrvgd").send().await.unwrap();
Source

pub fn address_create( &self, customer_id: impl Into<CustomerID>, country_code: CountryCodeSupported, ) -> AddressCreate<'_>

Returns a request builder for creating a new customer address.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.address_create("ctm_01jqztc78e1xfdgwhcgjzdrvgd", CountryCodeSupported::US).send().await.unwrap();
Source

pub fn address_get( &self, customer_id: impl Into<CustomerID>, address_id: impl Into<AddressID>, ) -> AddressGet<'_>

Returns a request builder for getting an address for a customer using its ID and related customer ID.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.address_get("ctm_01jqztc78e1xfdgwhcgjzdrvgd", "add_01hv8gwdfkw5z6d1yy6pa3xyrz").send().await.unwrap();
Source

pub fn address_update( &self, customer_id: impl Into<CustomerID>, address_id: impl Into<AddressID>, ) -> AddressUpdate<'_>

Returns a request builder for updating an address for a customer using its ID and related customer ID.

§Example:
use paddle::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.address_update("add_01hv8gwdfkw5z6d1yy6pa3xyrz", "add_01hv8gwdfkw5z6d1yy6pa3xyrz").first_line("Test").send().await.unwrap();

Trait Implementations§

Source§

impl Clone for Paddle

Source§

fn clone(&self) -> Paddle

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Paddle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Paddle

§

impl RefUnwindSafe for Paddle

§

impl Send for Paddle

§

impl Sync for Paddle

§

impl Unpin for Paddle

§

impl UnwindSafe for Paddle

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T