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
impl Paddle
pub const PRODUCTION: &'static str = "https://api.paddle.com"
pub const SANDBOX: &'static str = "https://sandbox-api.paddle.com"
Sourcepub fn new(
api_key: impl Into<String>,
base_url: impl IntoUrl,
) -> Result<Self, Error>
pub fn new( api_key: impl Into<String>, base_url: impl IntoUrl, ) -> Result<Self, Error>
Creates a new Paddle client instance.
Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();Sourcepub fn products_list(&self) -> ProductsList<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let products = client.products_list().send().await.unwrap();Sourcepub fn product_create(
&self,
name: impl Into<String>,
tax_category: TaxCategory,
) -> ProductCreate<'_>
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_rust_sdk::Paddle;
use paddle_rust_sdk::enums::TaxCategory;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let product = client.products_create("My Product", TaxCategory::Standard).send().await.unwrap();Sourcepub fn product_get(&self, product_id: impl Into<ProductID>) -> ProductGet<'_>
pub fn product_get(&self, product_id: impl Into<ProductID>) -> ProductGet<'_>
Returns a request builder for fetching a specific product.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let product = client.product_get("pro_01jqx9rd...").send().await.unwrap();Sourcepub fn product_update(
&self,
product_id: impl Into<ProductID>,
) -> ProductUpdate<'_>
pub fn product_update( &self, product_id: impl Into<ProductID>, ) -> ProductUpdate<'_>
Returns a request builder for updating a specific product.
§Example:
use paddle_rust_sdk::Paddle;
use paddle_rust_sdk::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();Sourcepub fn prices_list(&self) -> PricesList<'_>
pub fn prices_list(&self) -> PricesList<'_>
Returns a request builder listing prices
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let prices = client.prices_list().send().await.unwrap();Sourcepub fn price_create(
&self,
product_id: impl Into<ProductID>,
description: impl Into<String>,
amount: u64,
currency: CurrencyCode,
) -> PricesCreate<'_>
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_rust_sdk::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();Sourcepub fn price_get(&self, price_id: impl Into<PriceID>) -> PriceGet<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let price = client.price_get("price_01jqx9rd...").send().await.unwrap();Sourcepub fn price_update(&self, price_id: impl Into<PriceID>) -> PriceUpdate<'_>
pub fn price_update(&self, price_id: impl Into<PriceID>) -> PriceUpdate<'_>
Returns a request builder for updating a specific price.
§Example:
use paddle_rust_sdk::Paddle;
use paddle_rust_sdk::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();Sourcepub fn discounts_list(&self) -> DiscountsList<'_>
pub fn discounts_list(&self) -> DiscountsList<'_>
Returns a request builder for fetching discounts.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discounts = client.discounts_list().send().await.unwrap();Sourcepub fn discount_create(
&self,
amount: impl Into<String>,
description: impl Into<String>,
discount_type: DiscountType,
) -> DiscountCreate<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.discount_create("15", "Winter Holidays", DiscountType::Percentage).send().await.unwrap();Sourcepub fn discount_get(
&self,
discount_id: impl Into<DiscountID>,
) -> DiscountGet<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.discount_get("dsc_01jqzpbmnq...").send().await.unwrap();Sourcepub fn discount_update(
&self,
discount_id: impl Into<DiscountID>,
) -> DiscountUpdate<'_>
pub fn discount_update( &self, discount_id: impl Into<DiscountID>, ) -> DiscountUpdate<'_>
Returns a request builder for creating discounts.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.discount_update("dsc_01jqzpbmnq...").amount("18").send().await.unwrap();Sourcepub fn customers_list(&self) -> CustomersList<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.customers_list().send().await.unwrap();Sourcepub fn customer_create(&self, email: impl Into<String>) -> CustomerCreate<'_>
pub fn customer_create(&self, email: impl Into<String>) -> CustomerCreate<'_>
Returns a request builder for creating a new customer.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.customer_create("test@example.com").send().await.unwrap();Sourcepub fn customer_get(
&self,
customer_id: impl Into<CustomerID>,
) -> CustomerGet<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.customer_get("ctm_01jqztc78e1xfdgwhcgjzdrvgd").send().await.unwrap();Sourcepub fn customer_update(
&self,
customer_id: impl Into<CustomerID>,
) -> CustomerUpdate<'_>
pub fn customer_update( &self, customer_id: impl Into<CustomerID>, ) -> CustomerUpdate<'_>
Returns a request builder for updating customer data.
§Example:
use paddle_rust_sdk::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();Sourcepub fn customer_credit_balances(
&self,
customer_id: impl Into<CustomerID>,
) -> CustomerCreditBalances<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let discount = client.customer_credit_balances("ctm_01jqztc78e1xfdgwhcgjzdrvgd").send().await.unwrap();Sourcepub async fn generate_auth_token(
&self,
customer_id: impl Display,
) -> Result<SuccessResponse<CustomerAuthenticationToken>, Error>
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.
Sourcepub fn addresses_list(
&self,
customer_id: impl Into<CustomerID>,
) -> AddressesList<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.addresses_list("ctm_01jqztc78e1xfdgwhcgjzdrvgd").send().await.unwrap();Sourcepub fn address_create(
&self,
customer_id: impl Into<CustomerID>,
country_code: CountryCodeSupported,
) -> AddressCreate<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.address_create("ctm_01jqztc78e1xfdgwhcgjzdrvgd", CountryCodeSupported::US).send().await.unwrap();Sourcepub fn address_get(
&self,
customer_id: impl Into<CustomerID>,
address_id: impl Into<AddressID>,
) -> AddressGet<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.address_get("ctm_01jqztc78e1xfdgwhcgjzdrvgd", "add_01hv8gwdfkw5z6d1yy6pa3xyrz").send().await.unwrap();Sourcepub fn address_update(
&self,
customer_id: impl Into<CustomerID>,
address_id: impl Into<AddressID>,
) -> AddressUpdate<'_>
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_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.address_update("ctm_01jqztc78e1xfdgwhcgjzdrvgd", "add_01hv8gwdfkw5z6d1yy6pa3xyrz").first_line("Test").send().await.unwrap();Sourcepub fn businesses_list(
&self,
customer_id: impl Into<CustomerID>,
) -> BusinessesList<'_>
pub fn businesses_list( &self, customer_id: impl Into<CustomerID>, ) -> BusinessesList<'_>
Returns a request builder for fetching customers businesses.
By default, Paddle returns addresses that are active. Use the status query parameter to return businesses that are archived.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.businesses_list("ctm_01jqztc78e1xfdgwhcgjzdrvgd").send().await.unwrap();Sourcepub fn business_create(
&self,
customer_id: impl Into<CustomerID>,
name: impl Into<String>,
) -> BusinessCreate<'_>
pub fn business_create( &self, customer_id: impl Into<CustomerID>, name: impl Into<String>, ) -> BusinessCreate<'_>
Returns a request builder for creating a new customer business.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.business_create("ctm_01jqztc78e1xfdgwhcgjzdrvgd", "Company Inc.").send().await.unwrap();Sourcepub fn business_get(
&self,
customer_id: impl Into<CustomerID>,
business_id: impl Into<BusinessID>,
) -> BusinessGet<'_>
pub fn business_get( &self, customer_id: impl Into<CustomerID>, business_id: impl Into<BusinessID>, ) -> BusinessGet<'_>
Returns a request builder for getting a business for a customer using its ID and related customer ID.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.business_get("ctm_01jqztc78e1xfdgwhcgjzdrvgd", "biz_01jr85bypq4d3w139m53zw2559").send().await.unwrap();Sourcepub fn business_update(
&self,
customer_id: impl Into<CustomerID>,
business_id: impl Into<BusinessID>,
) -> BusinessUpdate<'_>
pub fn business_update( &self, customer_id: impl Into<CustomerID>, business_id: impl Into<BusinessID>, ) -> BusinessUpdate<'_>
Returns a request builder for updating a business for a customer using its ID and related customer ID.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.business_update("ctm_01jqztc78e1xfdgwhcgjzdrvgd", "biz_01jr85bypq4d3w139m53zw2559").first_line("Test").send().await.unwrap();Sourcepub fn payment_methods_list(
&self,
customer_id: impl Into<CustomerID>,
) -> PaymentMethodsList<'_>
pub fn payment_methods_list( &self, customer_id: impl Into<CustomerID>, ) -> PaymentMethodsList<'_>
Returns a request builder for querying customer saved payment methods.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.payment_methods_list("ctm_01jqztc78e1xfdgwhcgjzdrvgd").send().await.unwrap();Sourcepub fn payment_method_get(
&self,
customer_id: impl Into<CustomerID>,
payment_method_id: impl Into<PaymentMethodID>,
) -> PaymentMethodGet<'_>
pub fn payment_method_get( &self, customer_id: impl Into<CustomerID>, payment_method_id: impl Into<PaymentMethodID>, ) -> PaymentMethodGet<'_>
Returns a request builder for getting a saved payment for a customer using its ID and related customer ID.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let customers = client.payment_method_get("ctm_01jqztc78e1xfdgwhcgjzdrvgd", "paymtd_01j2jff1m3es31sdkejpaym164").send().await.unwrap();Sourcepub async fn payment_method_delete(
&self,
customer_id: impl Into<CustomerID>,
payment_method_id: impl Into<PaymentMethodID>,
) -> Result<bool, Error>
pub async fn payment_method_delete( &self, customer_id: impl Into<CustomerID>, payment_method_id: impl Into<PaymentMethodID>, ) -> Result<bool, Error>
Deletes a customer payment method using its ID.
When you delete a customer payment method, it’s permanently removed from that customer.
There’s no way to recover a deleted payment method.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
client.payment_method_delete("ctm_01jqztc78e1xfdgwhcgjzdrvgd", "paymtd_01j2jff1m3es31sdkejpaym164").await.unwrap();Sourcepub fn create_portal_session(
&self,
customer_id: impl Into<CustomerID>,
) -> PortalSessionCreate<'_>
pub fn create_portal_session( &self, customer_id: impl Into<CustomerID>, ) -> PortalSessionCreate<'_>
Creates a customer portal session for a customer.
You can use this to generate authenticated links for a customer so that they’re automatically signed in to the portal. Typically used when linking to the customer portal from your app where customers are already authenticated.
You can include an array of subscription_ids to generate authenticated portal links that let customers make changes to their subscriptions. You can use these links as part of subscription management workflows rather than building your own billing screens.
Customer portal sessions are temporary and shouldn’t be cached.
The customer portal is fully hosted by Paddle. For security and the best customer experience, don’t embed the customer portal in an iframe.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let session = client.create_portal_session("ctm_01jqztc78e1xfdgwhcgjzdrvgd").send().await.unwrap();
dbg!(session.data.urls.general.overview);
dbg!(session.data.urls.subscriptions);Sourcepub fn transactions_list(&self) -> TransactionsList<'_>
pub fn transactions_list(&self) -> TransactionsList<'_>
Returns a request builder for querying transactions.
Use the include method on the builder to include related entities in the response.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let transactions = client.transactions_list().send().await.unwrap();Sourcepub fn transaction_create(&self) -> TransactionCreate<'_>
pub fn transaction_create(&self) -> TransactionCreate<'_>
Returns a request builder for creating a transaction.
See Create Transaction for more information.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let res = client.transaction_create()
.append_catalog_item("pri_01jqxvdyjkp961jzv4me7ezg4d", 1)
.send()
.await
.unwrap();
dbg!(res.data);Sourcepub fn transaction_get(
&self,
transaction_id: impl Into<TransactionID>,
) -> TransactionGet<'_>
pub fn transaction_get( &self, transaction_id: impl Into<TransactionID>, ) -> TransactionGet<'_>
Returns a request builder for fetching a transaction using its ID.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let res = client.transaction_get("txn_01hv8wptq8987qeep44cyrewp9").send().await.unwrap();
dbg!(res.data);Sourcepub fn transaction_update(
&self,
transaction_id: impl Into<TransactionID>,
) -> TransactionUpdate<'_>
pub fn transaction_update( &self, transaction_id: impl Into<TransactionID>, ) -> TransactionUpdate<'_>
Returns a request builder for updating a transaction.
§Example:
use paddle_rust_sdk::{enums::TransactionStatus, Paddle};
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
client.transaction_update("txn_01hv8wptq8987qeep44cyrewp9").status(TransactionStatus::Billed).send().await.unwrap();Sourcepub async fn transaction_invoice(
&self,
transaction_id: impl Into<TransactionID>,
disposition: Disposition,
) -> Result<SuccessResponse<TransactionInvoice>, Error>
pub async fn transaction_invoice( &self, transaction_id: impl Into<TransactionID>, disposition: Disposition, ) -> Result<SuccessResponse<TransactionInvoice>, Error>
Returns a link to an invoice PDF for a transaction.
Invoice PDFs are available for both automatically and manually-collected transactions:
- The PDF for manually-collected transactions includes payment terms, purchase order number, and notes for your customer. It’s a demand for payment from your customer. It’s available for transactions that are
billedorcompleted. - The PDF for automatically-collected transactions lets your customer know that payment was taken successfully. Customers may require this for for tax-reporting purposes. It’s available for transactions that are
completed.
Invoice PDFs aren’t available for zero-value transactions.
The link returned is not a permanent link. It expires after an hour.
§Example:
use paddle_rust_sdk::{enums::Disposition, Paddle};
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let res = client.transaction_invoice("txn_01hv8wptq8987qeep44cyrewp9", Disposition::Inline).await.unwrap();
dbg!(res.data.url)Sourcepub fn transaction_preview(&self) -> TransactionPreview<'_>
pub fn transaction_preview(&self) -> TransactionPreview<'_>
Returns a request builder for generating a transaction preview without creating a transaction entity. Typically used for creating more advanced, dynamic pricing pages where users can build their own plans.
You can provide location information when previewing a transaction. You must provide this if you want Paddle to calculate tax or automatically localize prices. You can provide one of:
customer_ip_address: Paddle fetches location using the IP address to calculate totals.address: Paddle uses the country and ZIP code (where supplied) to calculate totals.customer_id,address_id,business_id: Paddle uses existing customer data to calculate totals. Typically used for logged-in customers.
When supplying items, you can exclude items from the total calculation using the include_in_totals boolean.
By default, recurring items with trials are considered to have a zero charge when previewing. Set ignore_trials to true to ignore trial periods against prices for transaction preview calculations.
If successful, your response includes the data you sent with a details object that includes totals for the supplied prices.
Transaction previews don’t create transactions, so no id is returned.
Sourcepub fn transaction_revise(
&self,
transaction_id: impl Into<TransactionID>,
) -> TransactionRevise<'_>
pub fn transaction_revise( &self, transaction_id: impl Into<TransactionID>, ) -> TransactionRevise<'_>
Returns a request builder to revise customer information for a billed or completed transaction.
Revise a transaction to rectify incorrect customer, address, or business information on invoice documents generated by Paddle.
You can revise transaction details that don’t impact the tax rates on a transaction. This includes:
- Customer name
- Business name and tax or VAT number (
tax_identifier) - Address details, apart from the country
You can’t remove a valid tax or VAT number, only replace it with another valid one. If a valid tax or VAT number is added, Paddle automatically creates an adjustment to refund any tax where applicable.
Transactions can only be revised once.
If successful, your response includes a copy of the transaction entity. Get a transaction using the include parameter with the customer, address, and business values to see the revised customer information.
Only the customer information for this transaction is updated. The related customer, address, and business entities aren’t updated.
Sourcepub fn subscriptions_list(&self) -> SubscriptionsList<'_>
pub fn subscriptions_list(&self) -> SubscriptionsList<'_>
Returns a request builder for querying subscriptions.
§Example:
use paddle_rust_sdk::Paddle;
let client = Paddle::new("your_api_key", Paddle::SANDBOX).unwrap();
let subscriptions = client.subscriptions_list().send().await.unwrap();