From 25ebc31600a8f30639edf9e24e545da742ef3b77 Mon Sep 17 00:00:00 2001 From: sanducb Date: Tue, 25 Nov 2025 17:39:20 +0200 Subject: [PATCH] chore: remove snippets --- Cargo.toml | 108 ------------------ README.md | 16 +-- src/lib.rs | 8 -- src/snippets/.env.example | 35 ------ src/snippets/README.md | 52 ++++----- src/snippets/examples/payment-flow.md | 83 -------------- src/snippets/grant/cancel.rs | 20 ---- src/snippets/grant/continuation.rs | 33 ------ src/snippets/grant/incoming_payment.rs | 59 ---------- src/snippets/grant/outgoing_payment.rs | 86 -------------- src/snippets/grant/quote.rs | 53 --------- src/snippets/incoming_payment/complete.rs | 20 ---- src/snippets/incoming_payment/create.rs | 47 -------- src/snippets/incoming_payment/get.rs | 20 ---- src/snippets/incoming_payment/list.rs | 48 -------- src/snippets/mod.rs | 1 - src/snippets/outgoing_payment/create.rs | 35 ------ src/snippets/outgoing_payment/get.rs | 20 ---- src/snippets/outgoing_payment/list.rs | 49 -------- src/snippets/quote/create.rs | 35 ------ .../quote/create_with_debit_amount.rs | 40 ------- .../quote/create_with_receive_amount.rs | 40 ------- src/snippets/quote/get.rs | 17 --- src/snippets/token/revoke.rs | 20 ---- src/snippets/token/rotate.rs | 20 ---- src/snippets/utils/mod.rs | 38 ------ src/snippets/wallet_address/get.rs | 16 --- src/snippets/wallet_address/get_keys.rs | 19 --- 28 files changed, 31 insertions(+), 1007 deletions(-) delete mode 100644 src/snippets/.env.example delete mode 100644 src/snippets/examples/payment-flow.md delete mode 100644 src/snippets/grant/cancel.rs delete mode 100644 src/snippets/grant/continuation.rs delete mode 100644 src/snippets/grant/incoming_payment.rs delete mode 100644 src/snippets/grant/outgoing_payment.rs delete mode 100644 src/snippets/grant/quote.rs delete mode 100644 src/snippets/incoming_payment/complete.rs delete mode 100644 src/snippets/incoming_payment/create.rs delete mode 100644 src/snippets/incoming_payment/get.rs delete mode 100644 src/snippets/incoming_payment/list.rs delete mode 100644 src/snippets/mod.rs delete mode 100644 src/snippets/outgoing_payment/create.rs delete mode 100644 src/snippets/outgoing_payment/get.rs delete mode 100644 src/snippets/outgoing_payment/list.rs delete mode 100644 src/snippets/quote/create.rs delete mode 100644 src/snippets/quote/create_with_debit_amount.rs delete mode 100644 src/snippets/quote/create_with_receive_amount.rs delete mode 100644 src/snippets/quote/get.rs delete mode 100644 src/snippets/token/revoke.rs delete mode 100644 src/snippets/token/rotate.rs delete mode 100644 src/snippets/utils/mod.rs delete mode 100644 src/snippets/wallet_address/get.rs delete mode 100644 src/snippets/wallet_address/get_keys.rs diff --git a/Cargo.toml b/Cargo.toml index b794f65..2945a12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ homepage = "https://github.com/interledger/open-payments-rust" [features] default = [] -snippets = ["tokio", "dotenv", "tempfile", "uuid"] [dependencies] serde = { version = "1.0", features = ["derive"] } @@ -36,117 +35,10 @@ pem = "3.0" log = "0.4" rand = "0.8" -# Optional dependencies for snippets -tokio = { version = "1.45.0", features = ["full"], optional = true } -dotenv = { version = "0.15", optional = true } -tempfile = { version = "3.20.0", optional = true } -uuid = { version = "1.16", features = ["v4", "serde"], optional = true } - [lib] name = "open_payments" path = "src/lib.rs" -# Binary targets for snippets -[[bin]] -name = "grant-cancel" -path = "src/snippets/grant/cancel.rs" -required-features = ["snippets"] - -[[bin]] -name = "grant-continuation" -path = "src/snippets/grant/continuation.rs" -required-features = ["snippets"] - -[[bin]] -name = "grant-incoming-payment" -path = "src/snippets/grant/incoming_payment.rs" -required-features = ["snippets"] - -[[bin]] -name = "grant-outgoing-payment" -path = "src/snippets/grant/outgoing_payment.rs" -required-features = ["snippets"] - -[[bin]] -name = "grant-quote" -path = "src/snippets/grant/quote.rs" -required-features = ["snippets"] - -[[bin]] -name = "incoming-payment-complete" -path = "src/snippets/incoming_payment/complete.rs" -required-features = ["snippets"] - -[[bin]] -name = "incoming-payment-create" -path = "src/snippets/incoming_payment/create.rs" -required-features = ["snippets"] - -[[bin]] -name = "incoming-payment-get" -path = "src/snippets/incoming_payment/get.rs" -required-features = ["snippets"] - -[[bin]] -name = "incoming-payment-list" -path = "src/snippets/incoming_payment/list.rs" -required-features = ["snippets"] - -[[bin]] -name = "outgoing-payment-create" -path = "src/snippets/outgoing_payment/create.rs" -required-features = ["snippets"] - -[[bin]] -name = "outgoing-payment-get" -path = "src/snippets/outgoing_payment/get.rs" -required-features = ["snippets"] - -[[bin]] -name = "outgoing-payment-list" -path = "src/snippets/outgoing_payment/list.rs" -required-features = ["snippets"] - -[[bin]] -name = "quote-create" -path = "src/snippets/quote/create.rs" -required-features = ["snippets"] - -[[bin]] -name = "quote-create-with-debit-amount" -path = "src/snippets/quote/create_with_debit_amount.rs" -required-features = ["snippets"] - -[[bin]] -name = "quote-create-with-receive-amount" -path = "src/snippets/quote/create_with_receive_amount.rs" -required-features = ["snippets"] - -[[bin]] -name = "quote-get" -path = "src/snippets/quote/get.rs" -required-features = ["snippets"] - -[[bin]] -name = "token-revoke" -path = "src/snippets/token/revoke.rs" -required-features = ["snippets"] - -[[bin]] -name = "token-rotate" -path = "src/snippets/token/rotate.rs" -required-features = ["snippets"] - -[[bin]] -name = "wallet-address-get" -path = "src/snippets/wallet_address/get.rs" -required-features = ["snippets"] - -[[bin]] -name = "wallet-address-get-keys" -path = "src/snippets/wallet_address/get_keys.rs" -required-features = ["snippets"] - [[bin]] name = "http-signature-example" path = "src/http_signature/examples/generate_signature.rs" diff --git a/README.md b/README.md index a46ae34..f49cddd 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,6 @@ Additionally, this crate contains several modules: - [`client`](./src/client) contains a Rust client to make requests via the Open Payments API. - [`types`](./src/types) contains Rust types for the API. -- [`snippets`](./src/snippets) contains examples of Rust client usage for getting accustomed to the Open Payments flow. - [`http_signature`](./src/http_signature) provides tools for working with [HTTP Message Signatures](https://datatracker.ietf.org/doc/draft-ietf-httpbis-message-signatures). ## Dependencies @@ -77,14 +76,14 @@ cd open-payments-rust cargo build ``` -### Running Examples +### Running Snippets -See [src/snippets/README.md](./src/snippets/README.md) for details on running code snippets and payment flows. For example, to run a snippet: +Rust snippets are no longer shipped in this repository. Please use the Open Payments docs to view and run the latest examples: -```sh -cd src/snippets -cargo run --features snippets --bin grant-incoming-payment -``` +- Docs: https://openpayments.dev +- Rust snippet sources: https://github.com/interledger/open-payments/tree/main/snippets/rust + +See [src/snippets/README.md](./src/snippets/README.md) for a short pointer. ### Useful commands @@ -106,9 +105,6 @@ cargo doc --no-deps # Generate documentation and open in browser: cargo doc --no-deps --open - -# Generate documentation with snippets feature: -cargo doc --features snippets --no-deps ``` ## Adding crate as dependency diff --git a/src/lib.rs b/src/lib.rs index c10162c..e8d7d86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,6 @@ //! - **Types**: Complete type definitions for all Open Payments resources and operations //! - **HTTP Client**: Async HTTP client with authentication and signature support //! - **HTTP Signatures**: Utilities for creating and validating HTTP message signatures -//! - **Snippets**: Ready-to-use code examples for common operations (optional feature) //! //! ## Quick Start //! @@ -41,11 +40,6 @@ //! - [`client`] - HTTP client for making unauthenticated and authenticated requests to Open Payments servers //! - [`types`] - Type definitions for all Open Payments resources and operations //! - [`http_signature`] - Utilities for HTTP message signature creation and validation -//! - \[`snippets`\] - Code examples for common operations (requires `snippets` feature) -//! -//! ## Cargo Features -//! -//! - `snippets` - Enables snippet binaries with example code for common operations //! //! ## Examples //! @@ -120,8 +114,6 @@ pub mod client; pub mod http_signature; -#[cfg(feature = "snippets")] -pub mod snippets; pub mod types; // Re-export everything public from client at the crate root diff --git a/src/snippets/.env.example b/src/snippets/.env.example deleted file mode 100644 index 070f5b4..0000000 --- a/src/snippets/.env.example +++ /dev/null @@ -1,35 +0,0 @@ -# Client -PRIVATE_KEY_PATH= -KEY_ID= -JWKS_PATH= -WALLET_ADDRESS_URL= - -# Incoming payment -INCOMING_PAYMENT_ACCESS_TOKEN= -INCOMING_PAYMENT_ACCESS_TOKEN_MANAGE_URL= -INCOMING_PAYMENT_URL= - -# Quote -QUOTE_ACCESS_TOKEN= -QUOTE_ACCESS_TOKEN_MANAGE_URL= -QUOTE_URL= - -# Grant continuation -CONTINUE_ACCESS_TOKEN= -CONTINUE_URI= -INTERACT_REF= - -# Outgoing payment -OUTGOING_PAYMENT_ACCESS_TOKEN= -OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL= -OUTGOING_PAYMENT_URL= - -# Token -ACCESS_TOKEN= -TOKEN_MANAGE_URL= - - - - - - diff --git a/src/snippets/README.md b/src/snippets/README.md index 7ce52bb..e6b9a78 100644 --- a/src/snippets/README.md +++ b/src/snippets/README.md @@ -4,11 +4,13 @@ These code snippets are intended for use with openpayments.dev +- Rust snippet sources: interledger/open-payments/snippets/rust -- Rust (>=1.43.1) +- Rust (>=1.85) - Cargo (comes with Rust) - [Rust Open Payments SDK](https://github.com/interledger/open-payments-rust) @@ -51,33 +53,29 @@ From the repository's root you can execute the following commands: | Command | Description | | ------------------ | ---------------------------------------------- | -| `cargo run --features snippets --bin grant-cancel` | Cancel a grant | -| `cargo run --features snippets --bin grant-continuation` | Continuation request for a grant (interactive) | -| `cargo run --features snippets --bin grant-incoming-payment` | Request a grant for an incoming payment | -| `cargo run --features snippets --bin grant-outgoing-payment` | Request a grant for an outgoing payment | -| `cargo run --features snippets --bin grant-quote` | Request a grant for a quote | -| `cargo run --features snippets --bin incoming-payment-create` | Create an incoming payment | -| `cargo run --features snippets --bin incoming-payment-complete` | Complete an incoming payment | -| `cargo run --features snippets --bin incoming-payment-get` | Retrieve an incoming payment | -| `cargo run --features snippets --bin incoming-payment-list` | List incoming payments | -| `cargo run --features snippets --bin outgoing-payment-create` | Create an outgoing payment | -| `cargo run --features snippets --bin outgoing-payment-get` | Retrieve an outgoing payment | -| `cargo run --features snippets --bin outgoing-payment-list` | List outgoing payments | -| `cargo run --features snippets --bin quote-create` | Create a quote | -| `cargo run --features snippets --bin quote-create-debit-amount` | Create a quote with debit amount | -| `cargo run --features snippets --bin quote-create-receive-amount` | Create a quote with receive amount | -| `cargo run --features snippets --bin quote-get` | Retrieve a quote | -| `cargo run --features snippets --bin wallet-address-get` | Retrieve wallet address' information | -| `cargo run --features snippets --bin wallet-address-get-keys` | Retrieve wallet address' JWKs | -| `cargo run --features snippets --bin token-revoke` | Revoke a token | -| `cargo run --features snippets --bin token-rotate` | Rotate a token | +| `cargo run --bin grant-cancel` | Cancel a grant | +| `cargo run --bin grant-continuation` | Continuation request for a grant (interactive) | +| `cargo run --bin grant-incoming-payment` | Request a grant for an incoming payment | +| `cargo run --bin grant-outgoing-payment` | Request a grant for an outgoing payment | +| `cargo run --bin grant-quote` | Request a grant for a quote | +| `cargo run --bin incoming-payment-create` | Create an incoming payment | +| `cargo run --bin incoming-payment-complete` | Complete an incoming payment | +| `cargo run --bin incoming-payment-get` | Retrieve an incoming payment | +| `cargo run --bin incoming-payment-list` | List incoming payments | +| `cargo run --bin outgoing-payment-create` | Create an outgoing payment | +| `cargo run --bin outgoing-payment-get` | Retrieve an outgoing payment | +| `cargo run --bin outgoing-payment-list` | List outgoing payments | +| `cargo run --bin quote-create` | Create a quote | +| `cargo run --bin quote-create-debit-amount` | Create a quote with debit amount | +| `cargo run --bin quote-create-receive-amount` | Create a quote with receive amount | +| `cargo run --bin quote-get` | Retrieve a quote | +| `cargo run --bin wallet-address-get` | Retrieve wallet address' information | +| `cargo run --bin wallet-address-get-keys` | Retrieve wallet address' JWKs | +| `cargo run --bin token-revoke` | Revoke a token | +| `cargo run --bin token-rotate` | Rotate a token | Example: ```sh -cargo run --features snippets --bin grant-incoming-payment +cargo run --bin grant-incoming-payment ``` - -### Examples - -- [Payment flow example](./examples/payment-flow.md) \ No newline at end of file diff --git a/src/snippets/examples/payment-flow.md b/src/snippets/examples/payment-flow.md deleted file mode 100644 index fa1744c..0000000 --- a/src/snippets/examples/payment-flow.md +++ /dev/null @@ -1,83 +0,0 @@ -# Payment flow - -Before proceeding with this example, ensure you have met the necessary [prerequisites](../README.md#prerequisites). - -1. **Request a Grant for an Incoming Payment** - -```sh -cargo run --features snippets --bin grant-incoming-payment -``` - -The script will output an `INCOMING_PAYMENT_ACCESS_TOKEN`. Copy its value and fill the corresponding variable in your -`.env` file. - -```sh -# Output example -INCOMING_PAYMENT_ACCESS_TOKEN = 123456ABD... -``` - -2. **Create an Incoming Payment** - -```sh -cargo run --features snippets --bin incoming-payment-create -``` - -Copy the `INCOMING_PAYMENT_URL` value and update the corresponding variable in your `.env` file. - -3. **Request a Grant for Quoting** - -```sh -cargo run --features snippets --bin grant-quote -``` - -Copy the `QUOTE_ACCESS_TOKEN` value and update the corresponding variable in your `.env` file. - -4. **Create a quote** - -```sh -cargo run --features snippets --bin quote-create -``` - -Copy the `QUOTE_URL` value and update the corresponding variable in your `.env` file. - -5. **Request a Grant for an Outgoing Payment** - -```sh -cargo run --features snippets --bin grant-outgoing-payment -``` - -This will output three values: The interaction URL, `CONTINUE_ACCESS_TOKEN`, and `CONTINUE_URI`. Update the `CONTINUE_*` -variables in your `.env` file with these values (only `CONTINUE_ACCESS_TOKEN` and `CONTINUE_URI`). - -Note: In Rafiki, this is the only grant that requires user interaction, necessitating two steps to retrieve an access -token with permission to create an outgoing payment. - -6. **Accepting the Grant** - -- Click on the interaction URL outputted in the previous step; -- Accept or decline the grant on Rafiki Money; -- After accepting, click the Finish button in the dialog that appears; -- Copy the redirected URL, it should look something like this: `http://localhost/?hash=...&interact_ref=....` -- Update the `INTERACT_REF` variable in your `.env` file with the `interact_ref` value in this URL - -7. **Continuation request** (notify Rafiki that the user has interacted with the grant) - -```sh -cargo run --features snippets --bin grant-continuation -``` - -Copy the `OUTGOING_PAYMENT_ACCESS_TOKEN` value and update the corresponding variable in your `.env` file. - -8. **Create the Outgoing Payment** - -```sh -cargo run --features snippets --bin outgoing-payment-create -``` - -Copy the `OUTGOING_PAYMENT_URL` value and update the corresponding variable in your `.env` file. - -9. **Retrieve Outgoing Payment Information** (Optional) - -```sh -cargo run --features snippets --bin outgoing-payment-get -``` \ No newline at end of file diff --git a/src/snippets/grant/cancel.rs b/src/snippets/grant/cancel.rs deleted file mode 100644 index 08e058b..0000000 --- a/src/snippets/grant/cancel.rs +++ /dev/null @@ -1,20 +0,0 @@ -use open_payments::client::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("CONTINUE_ACCESS_TOKEN")?; - let continue_uri = get_env_var("CONTINUE_URI")?; - - client - .grant() - .cancel(&continue_uri, Some(&gnap_token)) - .await?; - - println!("Grant cancelled successfully"); - Ok(()) -} diff --git a/src/snippets/grant/continuation.rs b/src/snippets/grant/continuation.rs deleted file mode 100644 index b1a2e32..0000000 --- a/src/snippets/grant/continuation.rs +++ /dev/null @@ -1,33 +0,0 @@ -use open_payments::client::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; -use open_payments::types::auth::ContinueResponse; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("CONTINUE_ACCESS_TOKEN")?; - let continue_uri = get_env_var("CONTINUE_URI")?; - let interact_ref = get_env_var("INTERACT_REF")?; - - let response = client - .grant() - .continue_grant(&continue_uri, &interact_ref, Some(&gnap_token)) - .await?; - - match response { - ContinueResponse::WithToken { access_token, .. } => { - println!("Received access token: {:#?}", access_token.value); - println!( - "Received access token manage URL: {:#?}", - access_token.manage - ); - } - ContinueResponse::Pending { .. } => { - println!("Pending"); - } - } - Ok(()) -} diff --git a/src/snippets/grant/incoming_payment.rs b/src/snippets/grant/incoming_payment.rs deleted file mode 100644 index 73422b8..0000000 --- a/src/snippets/grant/incoming_payment.rs +++ /dev/null @@ -1,59 +0,0 @@ -use open_payments::client::api::UnauthenticatedResources; -use open_payments::client::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; -use open_payments::types::auth::{ - AccessItem, AccessTokenRequest, GrantRequest, GrantResponse, IncomingPaymentAction, -}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - // Authenticated client can be also used for unauthenticated resources - let client = create_authenticated_client()?; - - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - let wallet_address = client.wallet_address().get(&wallet_address_url).await?; - - let grant_request = GrantRequest { - access_token: AccessTokenRequest { - access: vec![AccessItem::IncomingPayment { - actions: vec![ - IncomingPaymentAction::Create, - IncomingPaymentAction::Read, - IncomingPaymentAction::ReadAll, - IncomingPaymentAction::List, - IncomingPaymentAction::Complete, - ], - identifier: None, - }], - }, - client: wallet_address.id, - interact: None, - }; - - println!( - "Grant request JSON: {}", - serde_json::to_string_pretty(&grant_request)? - ); - - let response = client - .grant() - .request(&wallet_address.auth_server, &grant_request) - .await?; - - match response { - GrantResponse::WithToken { access_token, .. } => { - println!("Received access token: {:#?}", access_token.value); - println!( - "Received access token manage URL: {:#?}", - access_token.manage - ); - } - GrantResponse::WithInteraction { .. } => { - unreachable!("Interaction not required for incoming payments"); - } - } - - Ok(()) -} diff --git a/src/snippets/grant/outgoing_payment.rs b/src/snippets/grant/outgoing_payment.rs deleted file mode 100644 index 1274e97..0000000 --- a/src/snippets/grant/outgoing_payment.rs +++ /dev/null @@ -1,86 +0,0 @@ -use open_payments::client::api::UnauthenticatedResources; -use open_payments::client::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; -use open_payments::types::{ - auth::{ - AccessItem, AccessTokenRequest, GrantRequest, InteractFinish, InteractRequest, - LimitsOutgoing, OutgoingPaymentAction, - }, - GrantResponse, -}; -use uuid::Uuid; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - // Authenticated client can be also used for unauthenticated resources - let client = create_authenticated_client()?; - - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - let quote_url = get_env_var("QUOTE_URL")?; - let gnap_token = get_env_var("QUOTE_ACCESS_TOKEN")?; - - let wallet_address = client.wallet_address().get(&wallet_address_url).await?; - - let quote = client.quotes().get("e_url, Some(&gnap_token)).await?; - - let wallet_id = &wallet_address.id; - let grant_request = GrantRequest { - access_token: AccessTokenRequest { - access: vec![AccessItem::OutgoingPayment { - actions: vec![ - OutgoingPaymentAction::Read, - OutgoingPaymentAction::ReadAll, - OutgoingPaymentAction::List, - OutgoingPaymentAction::Create, - ], - identifier: wallet_id.to_string(), - limits: Some(LimitsOutgoing { - receiver: None, - debit_amount: Some(quote.debit_amount), - receive_amount: None, - interval: None, - }), - }], - }, - client: wallet_id.to_string(), - interact: Some(InteractRequest { - start: vec!["redirect".to_string()], - finish: Some(InteractFinish { - method: "redirect".to_string(), - uri: "http://localhost".to_string(), - nonce: Uuid::new_v4().to_string(), - }), - }), - }; - - println!( - "Grant request JSON: {}", - serde_json::to_string_pretty(&grant_request)? - ); - - let response = client - .grant() - .request(&wallet_address.auth_server, &grant_request) - .await?; - - match response { - GrantResponse::WithToken { access_token, .. } => { - println!("Received access token: {:#?}", access_token.value); - println!( - "Received access token manage URL: {:#?}", - access_token.manage - ); - } - GrantResponse::WithInteraction { - interact, - continue_, - } => { - println!("Received interact: {:#?}", interact); - println!("Received continue: {:#?}", continue_); - } - } - - Ok(()) -} diff --git a/src/snippets/grant/quote.rs b/src/snippets/grant/quote.rs deleted file mode 100644 index 5260bdf..0000000 --- a/src/snippets/grant/quote.rs +++ /dev/null @@ -1,53 +0,0 @@ -use open_payments::client::api::UnauthenticatedResources; -use open_payments::client::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; -use open_payments::types::{ - auth::{AccessItem, AccessTokenRequest, GrantRequest, QuoteAction}, - GrantResponse, -}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - // Authenticated client can be also used for unauthenticated resources - let client = create_authenticated_client()?; - - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - let wallet_address = client.wallet_address().get(&wallet_address_url).await?; - - let grant_request = GrantRequest { - access_token: AccessTokenRequest { - access: vec![AccessItem::Quote { - actions: vec![QuoteAction::Create, QuoteAction::Read, QuoteAction::ReadAll], - }], - }, - client: wallet_address.id, - interact: None, - }; - - println!( - "Grant request JSON: {}", - serde_json::to_string_pretty(&grant_request)? - ); - - let response = client - .grant() - .request(&wallet_address.auth_server, &grant_request) - .await?; - - match response { - GrantResponse::WithToken { access_token, .. } => { - println!("Received access token: {:#?}", access_token.value); - println!( - "Received access token manage URL: {:#?}", - access_token.manage - ); - } - GrantResponse::WithInteraction { .. } => { - unreachable!("Interaction not required for quotes"); - } - } - - Ok(()) -} diff --git a/src/snippets/incoming_payment/complete.rs b/src/snippets/incoming_payment/complete.rs deleted file mode 100644 index 3ec78df..0000000 --- a/src/snippets/incoming_payment/complete.rs +++ /dev/null @@ -1,20 +0,0 @@ -use open_payments::client::api::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let gnap_token = get_env_var("INCOMING_PAYMENT_ACCESS_TOKEN")?; - let incoming_payment_url = get_env_var("INCOMING_PAYMENT_URL")?; - - let client = create_authenticated_client()?; - - let payment = client - .incoming_payments() - .complete(&incoming_payment_url, Some(&gnap_token)) - .await?; - - println!("Completed incoming payment: {:#?}", payment); - Ok(()) -} diff --git a/src/snippets/incoming_payment/create.rs b/src/snippets/incoming_payment/create.rs deleted file mode 100644 index c7b7d86..0000000 --- a/src/snippets/incoming_payment/create.rs +++ /dev/null @@ -1,47 +0,0 @@ -use chrono::{Duration, Utc}; -use open_payments::client::api::AuthenticatedResources; -use open_payments::client::utils::get_resource_server_url; -use open_payments::client::OpClientError; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; -use open_payments::types::{resource::CreateIncomingPaymentRequest, Amount}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env().map_err(|e| OpClientError::Other(e.to_string()))?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("INCOMING_PAYMENT_ACCESS_TOKEN")?; - - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - let resource_server_url = get_resource_server_url(&wallet_address_url)?; - - // Remove unwrap - let expires_at = Utc::now() - .checked_add_signed(Duration::minutes(10000)) - .unwrap(); - - let request = CreateIncomingPaymentRequest { - wallet_address: wallet_address_url, - incoming_amount: Some(Amount { - value: "1000".to_string(), - asset_code: "EUR".to_string(), - asset_scale: 2u8, - }), - expires_at: Some(expires_at), - metadata: None, - }; - - println!( - "Incoming payment create request JSON: {}", - serde_json::to_string_pretty(&request)? - ); - - let payment = client - .incoming_payments() - .create(&resource_server_url, &request, Some(&gnap_token)) - .await?; - - println!("Created incoming payment: {:#?}", payment); - Ok(()) -} diff --git a/src/snippets/incoming_payment/get.rs b/src/snippets/incoming_payment/get.rs deleted file mode 100644 index 4c31217..0000000 --- a/src/snippets/incoming_payment/get.rs +++ /dev/null @@ -1,20 +0,0 @@ -use open_payments::client::api::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("INCOMING_PAYMENT_ACCESS_TOKEN")?; - let incoming_payment_url = get_env_var("INCOMING_PAYMENT_URL")?; - - let payment = client - .incoming_payments() - .get(&incoming_payment_url, Some(&gnap_token)) - .await?; - - println!("Incoming payment: {:#?}", payment); - Ok(()) -} diff --git a/src/snippets/incoming_payment/list.rs b/src/snippets/incoming_payment/list.rs deleted file mode 100644 index 251e047..0000000 --- a/src/snippets/incoming_payment/list.rs +++ /dev/null @@ -1,48 +0,0 @@ -use open_payments::client::api::AuthenticatedResources; -use open_payments::client::utils::get_resource_server_url; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("INCOMING_PAYMENT_ACCESS_TOKEN")?; - - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - let resource_server_url = get_resource_server_url(&wallet_address_url)?; - let response = client - .incoming_payments() - .list( - &resource_server_url, - &wallet_address_url, - None, - Some(10), - None, - Some(&gnap_token), - ) - .await?; - - println!("Incoming payments: {:#?}", response.result); - println!("Pagination info: {:#?}", response.pagination); - - if response.pagination.has_next_page { - if let Some(end_cursor) = response.pagination.end_cursor { - let next_page = client - .incoming_payments() - .list( - &resource_server_url, - &wallet_address_url, - Some(&end_cursor), - Some(10), - None, - Some(&gnap_token), - ) - .await?; - println!("Next page of incoming payments: {:#?}", next_page.result); - } - } - - Ok(()) -} diff --git a/src/snippets/mod.rs b/src/snippets/mod.rs deleted file mode 100644 index b5614dd..0000000 --- a/src/snippets/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod utils; diff --git a/src/snippets/outgoing_payment/create.rs b/src/snippets/outgoing_payment/create.rs deleted file mode 100644 index f179013..0000000 --- a/src/snippets/outgoing_payment/create.rs +++ /dev/null @@ -1,35 +0,0 @@ -use open_payments::client::api::AuthenticatedResources; -use open_payments::client::utils::get_resource_server_url; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; -use open_payments::types::OutgoingPaymentRequest; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("OUTGOING_PAYMENT_ACCESS_TOKEN")?; - let quote_url = get_env_var("QUOTE_URL")?; - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - let resource_server_url = get_resource_server_url(&wallet_address_url)?; - - let request = OutgoingPaymentRequest::FromQuote { - wallet_address: wallet_address_url, - quote_id: quote_url, - metadata: None, - }; - - println!( - "Outgoing payment create request JSON: {}", - serde_json::to_string_pretty(&request)? - ); - - let payment = client - .outgoing_payments() - .create(&resource_server_url, &request, Some(&gnap_token)) - .await?; - - println!("Created outgoing payment: {:#?}", payment); - Ok(()) -} diff --git a/src/snippets/outgoing_payment/get.rs b/src/snippets/outgoing_payment/get.rs deleted file mode 100644 index d7dbcaf..0000000 --- a/src/snippets/outgoing_payment/get.rs +++ /dev/null @@ -1,20 +0,0 @@ -use open_payments::client::api::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("OUTGOING_PAYMENT_ACCESS_TOKEN")?; - let outgoing_payment_url = get_env_var("OUTGOING_PAYMENT_URL")?; - - let payment = client - .outgoing_payments() - .get(&outgoing_payment_url, Some(&gnap_token)) - .await?; - - println!("Outgoing payment: {:#?}", payment); - Ok(()) -} diff --git a/src/snippets/outgoing_payment/list.rs b/src/snippets/outgoing_payment/list.rs deleted file mode 100644 index 7855a4f..0000000 --- a/src/snippets/outgoing_payment/list.rs +++ /dev/null @@ -1,49 +0,0 @@ -use open_payments::client::api::AuthenticatedResources; -use open_payments::client::utils::get_resource_server_url; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("OUTGOING_PAYMENT_ACCESS_TOKEN")?; - - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - let resource_server_url = get_resource_server_url(&wallet_address_url)?; - - let response = client - .outgoing_payments() - .list( - &resource_server_url, - &wallet_address_url, - None, - Some(10), - None, - Some(&gnap_token), - ) - .await?; - - println!("Outgoing payments: {:#?}", response.result); - println!("Pagination info: {:#?}", response.pagination); - - if response.pagination.has_next_page { - if let Some(end_cursor) = response.pagination.end_cursor { - let next_page = client - .outgoing_payments() - .list( - &resource_server_url, - &wallet_address_url, - Some(&end_cursor), - Some(10), - None, - Some(&gnap_token), - ) - .await?; - println!("Next page of outgoing payments: {:#?}", next_page.result); - } - } - - Ok(()) -} diff --git a/src/snippets/quote/create.rs b/src/snippets/quote/create.rs deleted file mode 100644 index 8036988..0000000 --- a/src/snippets/quote/create.rs +++ /dev/null @@ -1,35 +0,0 @@ -use open_payments::client::api::AuthenticatedResources; -use open_payments::client::utils::get_resource_server_url; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; -use open_payments::types::{resource::CreateQuoteRequest, PaymentMethodType, Receiver}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("QUOTE_ACCESS_TOKEN")?; - let incoming_payment_url = get_env_var("INCOMING_PAYMENT_URL")?; - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - let resource_server_url = get_resource_server_url(&wallet_address_url)?; - - let request = CreateQuoteRequest::NoAmountQuote { - wallet_address: wallet_address_url, - receiver: Receiver(incoming_payment_url), - method: PaymentMethodType::Ilp, - }; - - println!( - "Quote create request JSON: {}", - serde_json::to_string_pretty(&request)? - ); - - let quote = client - .quotes() - .create(&resource_server_url, &request, Some(&gnap_token)) - .await?; - - println!("Created quote: {:#?}", quote); - Ok(()) -} diff --git a/src/snippets/quote/create_with_debit_amount.rs b/src/snippets/quote/create_with_debit_amount.rs deleted file mode 100644 index 589d25e..0000000 --- a/src/snippets/quote/create_with_debit_amount.rs +++ /dev/null @@ -1,40 +0,0 @@ -use open_payments::client::api::AuthenticatedResources; -use open_payments::client::utils::get_resource_server_url; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; -use open_payments::types::{resource::CreateQuoteRequest, Amount, PaymentMethodType, Receiver}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("QUOTE_ACCESS_TOKEN")?; - let incoming_payment_url = get_env_var("INCOMING_PAYMENT_URL")?; - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - let resource_server_url = get_resource_server_url(&wallet_address_url)?; - - let request = CreateQuoteRequest::FixedSendAmountQuote { - wallet_address: wallet_address_url, - receiver: Receiver(incoming_payment_url), - method: PaymentMethodType::Ilp, - debit_amount: Amount { - value: "1000".to_string(), - asset_code: "EUR".to_string(), - asset_scale: 2u8, - }, - }; - - println!( - "Quote create request JSON: {}", - serde_json::to_string_pretty(&request)? - ); - - let quote = client - .quotes() - .create(&resource_server_url, &request, Some(&gnap_token)) - .await?; - - println!("Created quote: {:#?}", quote); - Ok(()) -} diff --git a/src/snippets/quote/create_with_receive_amount.rs b/src/snippets/quote/create_with_receive_amount.rs deleted file mode 100644 index ee0f14c..0000000 --- a/src/snippets/quote/create_with_receive_amount.rs +++ /dev/null @@ -1,40 +0,0 @@ -use open_payments::client::api::AuthenticatedResources; -use open_payments::client::utils::get_resource_server_url; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; -use open_payments::types::{resource::CreateQuoteRequest, Amount, PaymentMethodType, Receiver}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("QUOTE_ACCESS_TOKEN")?; - let incoming_payment_url = get_env_var("INCOMING_PAYMENT_URL")?; - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - let resource_server_url = get_resource_server_url(&wallet_address_url)?; - - let request = CreateQuoteRequest::FixedReceiveAmountQuote { - wallet_address: wallet_address_url, - receiver: Receiver(incoming_payment_url), - method: PaymentMethodType::Ilp, - receive_amount: Amount { - value: "1000".to_string(), - asset_code: "EUR".to_string(), - asset_scale: 2u8, - }, - }; - - println!( - "Quote create request JSON: {}", - serde_json::to_string_pretty(&request)? - ); - - let quote = client - .quotes() - .create(&resource_server_url, &request, Some(&gnap_token)) - .await?; - - println!("Created quote: {:#?}", quote); - Ok(()) -} diff --git a/src/snippets/quote/get.rs b/src/snippets/quote/get.rs deleted file mode 100644 index bcedf43..0000000 --- a/src/snippets/quote/get.rs +++ /dev/null @@ -1,17 +0,0 @@ -use open_payments::client::api::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("QUOTE_ACCESS_TOKEN")?; - let quote_url = get_env_var("QUOTE_URL")?; - - let quote = client.quotes().get("e_url, Some(&gnap_token)).await?; - - println!("Quote: {:#?}", quote); - Ok(()) -} diff --git a/src/snippets/token/revoke.rs b/src/snippets/token/revoke.rs deleted file mode 100644 index 07dbfea..0000000 --- a/src/snippets/token/revoke.rs +++ /dev/null @@ -1,20 +0,0 @@ -use open_payments::client::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("ACCESS_TOKEN")?; - let token_manage_url = get_env_var("TOKEN_MANAGE_URL")?; - - client - .token() - .revoke(&token_manage_url, Some(&gnap_token)) - .await?; - - println!("Access token revoked successfully"); - Ok(()) -} diff --git a/src/snippets/token/rotate.rs b/src/snippets/token/rotate.rs deleted file mode 100644 index 215f282..0000000 --- a/src/snippets/token/rotate.rs +++ /dev/null @@ -1,20 +0,0 @@ -use open_payments::client::AuthenticatedResources; -use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let client = create_authenticated_client()?; - - let gnap_token = get_env_var("ACCESS_TOKEN")?; - let token_manage_url = get_env_var("TOKEN_MANAGE_URL")?; - - let response = client - .token() - .rotate(&token_manage_url, Some(&gnap_token)) - .await?; - - println!("Rotated access token: {:#?}", response.access_token); - Ok(()) -} diff --git a/src/snippets/utils/mod.rs b/src/snippets/utils/mod.rs deleted file mode 100644 index 3788d5b..0000000 --- a/src/snippets/utils/mod.rs +++ /dev/null @@ -1,38 +0,0 @@ -use crate::client::{ - AuthenticatedClient, ClientConfig, OpClientError, Result, UnauthenticatedClient, -}; -use crate::http_signature::jwk::Jwk; -use dotenv::dotenv; -use std::{env, path::PathBuf}; - -pub fn load_env() -> Result<()> { - dotenv().ok(); - Ok(()) -} - -pub fn get_env_var(key: &str) -> Result { - env::var(key).map_err(|_| OpClientError::Other(format!("{} environment variable not set", key))) -} - -pub fn create_authenticated_client() -> Result { - let private_key_path = PathBuf::from(get_env_var("PRIVATE_KEY_PATH")?); - let key_id = get_env_var("KEY_ID")?; - let key_id_clone = key_id.clone(); - let jwks_path = get_env_var("JWKS_PATH").map(PathBuf::from).ok(); - - let config = ClientConfig { - private_key_path, - key_id, - jwks_path, - }; - - let client = AuthenticatedClient::new(config) - .map_err(|e| OpClientError::Other(format!("Client creation error: {e}")))?; - Jwk::new(key_id_clone, Some(&client.signing_key)) - .map_err(|e| OpClientError::Other(format!("JWK error: {e}")))?; - Ok(client) -} - -pub fn create_unauthenticated_client() -> UnauthenticatedClient { - UnauthenticatedClient::new() -} diff --git a/src/snippets/wallet_address/get.rs b/src/snippets/wallet_address/get.rs deleted file mode 100644 index c4915f4..0000000 --- a/src/snippets/wallet_address/get.rs +++ /dev/null @@ -1,16 +0,0 @@ -use open_payments::client::api::UnauthenticatedResources; -use open_payments::snippets::utils::{create_unauthenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - - let client = create_unauthenticated_client(); - - let wallet_address = client.wallet_address().get(&wallet_address_url).await?; - - println!("Retrieved wallet address: {:#?}", wallet_address); - Ok(()) -} diff --git a/src/snippets/wallet_address/get_keys.rs b/src/snippets/wallet_address/get_keys.rs deleted file mode 100644 index 19e5bc7..0000000 --- a/src/snippets/wallet_address/get_keys.rs +++ /dev/null @@ -1,19 +0,0 @@ -use open_payments::client::api::UnauthenticatedResources; -use open_payments::snippets::utils::{create_unauthenticated_client, get_env_var, load_env}; - -#[tokio::main] -async fn main() -> open_payments::client::Result<()> { - load_env()?; - - let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?; - - let client = create_unauthenticated_client(); - - let wallet_address = client.wallet_address().get(&wallet_address_url).await?; - - let keys = client.wallet_address().get_keys(&wallet_address).await?; - - println!("Retrieved wallet address: {:#?}", wallet_address); - println!("Retrieved keys: {:#?}", keys); - Ok(()) -}