# Use the Rust SDK > Learn how to install and use the Rust SDK to develop apps {/* vale Payabli.We = NO */} {/* First person rule off for Quickstart */} Payabli offers a Software Development Kit (SDK) for the Rust programming language. The Rust SDK can be installed in your projects to support app development and provide type safety when calling Payabli's APIs. Most development environments can use the SDK to generate code suggestions and inline documentation. See the [`payabli_api`](https://crates.io/crates/payabli_api) crate for more information. ## Dependencies {/* vale Payabli.PayabliSpelling = NO */} Before you begin, make sure you have the following installed on your machine: * [cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) * [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) {/* vale Payabli.PayabliSpelling = YES */} ## Use the SDK This section shows you how to install and use the Payabli SDK in a new Rust project. The example code shows how to use the SDK to make a transaction with the `money_in.getpaid` method. The `money_in.getpaid` method calls the [MoneyIn/getpaid](/api-reference/moneyin/make-a-transaction) endpoint. See the [SDK reference](https://github.com/payabli/sdk-rust/blob/main/reference.md) for a full list of methods. Method names in the SDK correspond to endpoint names in the API reference. For example: the `notification.add_notification` method calls the [POST Notification](/api-reference/notification/add-notification) endpoint. Open your terminal and run the following command to create a new Rust project: ```bash cargo new my-payabli-app cd my-payabli-app ``` Add the Payabli SDK to your project: ```bash cargo add payabli_api cargo add tokio --features full ``` Open the `src/main.rs` file that was created automatically in your code editor. The interactive walkthrough displays code examples alongside step-by-step explanations. Follow the walkthrough to use the SDK in your Rust code. {/* Hidden markdown content for server rendering and AI ingestion */}
/// Import the SDK Import the Payabli SDK to make it available in your code. ```rust // src/main.rs use payabli_api::prelude::*; ``` /// Define constants Define your API key and entrypoint as constants. Get these values from your Payabli account. ```rust focus=3-5 // src/main.rs use payabli_api::prelude::*; const API_KEY: &str = "REPLACE_WITH_YOUR_API_KEY"; const ENTRY_POINT: &str = "REPLACE_WITH_YOUR_ENTRYPOINT"; ``` /// Set up the async runtime Create the main async function using the `tokio` runtime. ```rust focus=7-8 // src/main.rs use payabli_api::prelude::*; const API_KEY: &str = "REPLACE_WITH_YOUR_API_KEY"; const ENTRY_POINT: &str = "REPLACE_WITH_YOUR_ENTRYPOINT"; #[tokio::main] async fn main() {} ``` /// Initialize the client Create an authenticated client instance with your API key. This client has methods that call Payabli's API endpoints. ```rust focus=9-14 // src/main.rs use payabli_api::prelude::*; const API_KEY: &str = "REPLACE_WITH_YOUR_API_KEY"; const ENTRY_POINT: &str = "REPLACE_WITH_YOUR_ENTRYPOINT"; #[tokio::main] async fn main() { let config = ClientConfig { api_key: Some(API_KEY.to_string()), ..Default::default() }; let client = ApiClient::new(config).expect("Failed to build client"); } ``` /// Build the payment request Construct a request object that contains all the necessary fields to process a transaction. Include payment details, a payment method, and customer data. ```rust focus=16-79 // src/main.rs use payabli_api::prelude::*; const API_KEY: &str = "REPLACE_WITH_YOUR_API_KEY"; const ENTRY_POINT: &str = "REPLACE_WITH_YOUR_ENTRYPOINT"; #[tokio::main] async fn main() { let config = ClientConfig { api_key: Some(API_KEY.to_string()), ..Default::default() }; let client = ApiClient::new(config).expect("Failed to build client"); let result = client .money_in .getpaid( &GetpaidRequest { body: TransRequestBody { account_id: None, customer_data: Some(PayorDataRequest { additional_data: None, billing_address_1: None, billing_address_2: None, billing_city: None, billing_country: None, billing_email: None, billing_phone: None, billing_state: None, billing_zip: None, company: None, customer_id: Some(CustomerId(4440)), customer_number: None, first_name: None, identifier_fields: None, last_name: None, shipping_address_1: None, shipping_address_2: None, shipping_city: None, shipping_country: None, shipping_state: None, shipping_zip: None, }), entry_point: Some(Entrypointfield(ENTRY_POINT.to_string())), invoice_data: None, ipaddress: Some(IpAddress("255.255.255.255".to_string())), order_description: None, order_id: None, payment_details: PaymentDetail { categories: None, check_image: None, check_number: None, currency: None, service_fee: Some(0.0), split_funding: None, total_amount: 100.0, }, payment_method: PaymentMethod::PayMethodCredit(PayMethodCredit { cardcvv: Some(Cardcvv("999".to_string())), cardexp: Cardexp("02/27".to_string()), card_holder: Some(Cardholder("John Cassian".to_string())), cardnumber: Cardnumber("4111111111111111".to_string()), cardzip: Some(Cardzip("12345".to_string())), initiator: Some(Initiator("payor".to_string())), method: "card".to_string(), save_if_success: None, }), source: None, subdomain: None, subscription_id: None, }, ach_validation: None, force_customer_creation: None, include_details: None, }, None, ) .await; } ``` /// Show the result Log the transaction response. Check the output to see if the transaction was successful. ```rust focus=81 // src/main.rs use payabli_api::prelude::*; const API_KEY: &str = "REPLACE_WITH_YOUR_API_KEY"; const ENTRY_POINT: &str = "REPLACE_WITH_YOUR_ENTRYPOINT"; #[tokio::main] async fn main() { let config = ClientConfig { api_key: Some(API_KEY.to_string()), ..Default::default() }; let client = ApiClient::new(config).expect("Failed to build client"); let result = client .money_in .getpaid( &GetpaidRequest { body: TransRequestBody { account_id: None, customer_data: Some(PayorDataRequest { additional_data: None, billing_address_1: None, billing_address_2: None, billing_city: None, billing_country: None, billing_email: None, billing_phone: None, billing_state: None, billing_zip: None, company: None, customer_id: Some(CustomerId(4440)), customer_number: None, first_name: None, identifier_fields: None, last_name: None, shipping_address_1: None, shipping_address_2: None, shipping_city: None, shipping_country: None, shipping_state: None, shipping_zip: None, }), entry_point: Some(Entrypointfield(ENTRY_POINT.to_string())), invoice_data: None, ipaddress: Some(IpAddress("255.255.255.255".to_string())), order_description: None, order_id: None, payment_details: PaymentDetail { categories: None, check_image: None, check_number: None, currency: None, service_fee: Some(0.0), split_funding: None, total_amount: 100.0, }, payment_method: PaymentMethod::PayMethodCredit(PayMethodCredit { cardcvv: Some(Cardcvv("999".to_string())), cardexp: Cardexp("02/27".to_string()), card_holder: Some(Cardholder("John Cassian".to_string())), cardnumber: Cardnumber("4111111111111111".to_string()), cardzip: Some(Cardzip("12345".to_string())), initiator: Some(Initiator("payor".to_string())), method: "card".to_string(), save_if_success: None, }), source: None, subdomain: None, subscription_id: None, }, ach_validation: None, force_customer_creation: None, include_details: None, }, None, ) .await; println!("{:?}", result); } ```
Run the app with the following command: ```bash cargo run ``` Check the console output for the result of the transaction. A successful transaction returns output like this: ```rust Ok( PayabliApiResponseGetPaid { response_text: ResponseText("Success"), is_success: IsSuccess(true), page_identifier: None, response_data: GetPaidResponseData { auth_code: Some(Authcode("TAS660")), transaction_details: None, reference_id: Referenceidtrans("255-2ea956014a6d42e9a3353d35d1cc2dae"), result_code: ResultCode(1), result_text: Resulttext("Approved"), avs_response_text: AvsResponseText("No Match, No address or ZIP match"), cvv_response_text: CvvResponseText("CVV2/CVC2 match"), customer_id: Customeridtrans(4440), method_reference_id: None } } ) ```
In production, we recommend that you pass a stored method ID to the `payment_method` object instead of card details. See more information in [Tokenization Overview](/developers/developer-guides/tokenization-overview). ## SDK example app The SDK example app is a basic web app built with the Payabli Rust SDK. It demonstrates how to manage customers and use the temporary token flow with the SDK. The code is publicly available in the [example repository](https://github.com/payabli/examples/tree/main/sdk/rust-sdk). customer creation page of SDK example app ### Set up the app Follow these steps to set up the SDK example app on your local machine: Open your terminal and run the following command to clone the SDK example app repository: ```bash git clone https://github.com/payabli/examples ``` In your terminal, navigate to the directory containing the SDK example app: ```bash cd examples/sdk/rust-sdk ``` Install the project dependencies with Cargo: ```bash cargo build ``` Copy the `.env.template` file to a new file called `.env`: ```bash cp .env.template .env ``` Open the `.env` file in your code editor. Set `PAYABLI_KEY` to a private API token, `PAYABLI_ENTRY` to your Payabli entrypoint, and `PAYABLI_PUBLIC_TOKEN` to a public API token: ```bash # your Payabli Private API token PAYABLI_KEY="o.Oim...Mekgjw=" # your Payabli entrypoint PAYABLI_ENTRY="41xxxxxa7e" # your Payabli Public API token PAYABLI_PUBLIC_TOKEN="o.Oim...Mekgjw=" ``` Run this command to start the development server, and open the app in your browser: ```bash cargo run ``` ### Use the app The SDK example app has three pages: 1. **Create Customer** - Create a new customer in the Payabli entrypoint. 2. **List Customers** - View a list of all customers in the Payabli entrypoint. 3. **Make Transaction** - Make a transaction using the temporary token flow. #### Create customer The **Create Customer** page has a form that allows you to create a new customer. Fill in the form with the customer's information and click the "Create" button. If the customer is created successfully, a green success message appears below the button. #### List customers The **List Customers** page has a table of all customers in the entrypoint. You can view the customer's information, including their name, email address, and ZIP Code. Click the "X" button on the right side of a customer's row to delete the customer. If the customer is deleted successfully, the row is removed from the table. #### Make transaction The **Make Transaction** page contains an EmbeddedMethod UI component using the temporary token flow. Fill in the form with payment information and click the "Process" button when the payment information is valid. The app performs these steps: 1. The embedded component saves the payment method as a temporary token and sends it to the server. 2. The server converts the temporary token to a permanent token with the **POST TokenStorage/add** endpoint. 3. The server uses the permanent token to make a transaction with the **POST MoneyIn/getpaid** endpoint. If everything is successful, a green success message appears below the embedded component. See [Extend embedded components with the temporary token flow](/developers/developer-guides/tokenization-temporary-flow) for more information.