Get a quote
The Get a Quote API lets you get the latest details for a quote resource. For example, its state (whether it’s valid or expired), the total amount that the recipient should receive, and the total amount to be debited from the sender.
The code snippets below let an authorized client receive the state and other details of a specific quote.
Before you begin
Section titled “Before you begin”We recommend creating a wallet account on the test wallet. Creating an account allows you to test your client against the Open Payments APIs by using an ILP-enabled wallet funded with play money.
Get a quote
Section titled “Get a quote”Initial configuration
If you’re using JavaScript, only do the first step.
-
Add
"type": "module"topackage.json. -
Add the following to
tsconfig.json{"compilerOptions": {"target": "ES2022","module": "ES2022"}}
// Import dependenciesimport { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize clientconst client = await createAuthenticatedClient({ walletAddressUrl: WALLET_ADDRESS, privateKey: PRIVATE_KEY_PATH, keyId: KEY_ID})
// Get quoteconst quote = await client.quote.get({ url: QUOTE_URL, accessToken: QUOTE_ACCESS_TOKEN})
// Outputconsole.log('QUOTE:', JSON.stringify(quote, null, 2))For TypeScript, run tsx path/to/directory/index.ts. View full TS source
For JavaScript, run node path/to/directory/index.js. View full JS source
// Import dependenciesuse open_payments::client::api::AuthenticatedResources;use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env};
// Initialize clientlet client = create_authenticated_client()?;
// Get quotelet access_token = get_env_var("QUOTE_ACCESS_TOKEN")?;let quote_url = get_env_var("QUOTE_URL")?;
let quote = client.quotes().get("e_url, Some(&access_token)).await?;
// Outputprintln!("Quote: {quote:#?}");// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config( $WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);$opClient = new AuthClient($config);
$wallet = $opClient->walletAddress()->get([ 'url' => $config->getWalletAddressUrl()]);
// Get quote$quote = $opClient->quote()->get( [ 'access_token' => $QUOTE_GRANT_ACCESS_TOKEN, 'url' => $QUOTE_URL ]);
// Outputecho 'QUOTE_URL ' . $quote->id . PHP_EOL;echo 'QUOTE ' . print_r($quote, true) . PHP_EOL;package main
// Import dependenciesimport ( "context" "encoding/json" "fmt" "log"
op "github.com/interledger/open-payments-go")
func main() { // Initialize client client, err := op.NewAuthenticatedClient(WALLET_ADDRESS_URL, PRIVATE_KEY_BASE_64, KEY_ID) if err != nil { log.Fatalf("Error creating authenticated client: %v\n", err) }
// Get quote quote, err := client.Quote.Get(context.TODO(), op.QuoteGetParams{ URL: QUOTE_URL, AccessToken: QUOTE_ACCESS_TOKEN, }) if err != nil { log.Fatalf("Error fetching quote: %v\n", err) }
// Output quoteJSON, err := json.MarshalIndent(quote, "", " ") if err != nil { log.Fatalf("Error marshaling quote: %v\n", err) } fmt.Println("QUOTE:", string(quoteJSON))}// Import dependenciesimport org.interledger.openpayments.httpclient.OpenPaymentsHttpClient;import org.interledger.openpayments.IOpenPaymentsClient;
// Initialize clientIOpenPaymentsClient client = OpenPaymentsHttpClient.defaultClient("WalletAddress","PrivateKeyPEM","KeyId");
// Get wallet address informationvar receiverWallet = client.walletAddress().get("https://cloudninebank.example.com/merchant");var senderWallet = client.walletAddress().get("https://cloudninebank.example.com/customer");
// Create incoming paymentvar grantRequest = client.auth().grant().incomingPayment(receiverWallet);var incomingPayment = client.payment().createIncoming(receiverWallet, grantRequest, BigDecimal.valueOf(11.25));
// Create quotevar quoteRequest = client.auth().grant().quote(senderWallet);var quote = client.quote().create(quoteRequest.getAccess().getToken(), senderWallet, incomingPayment, Optional.empty(), Optional.empty());
// Get the newly created quote (fetch by ID)var quoteFetched = client.quote().get(quote.getId(), grantRequest);
// Outputlog.info("QUOTE: {}", quoteFetched);// Import dependenciesusing Microsoft.Extensions.DependencyInjection;using Newtonsoft.Json;using OpenPayments.Sdk.Clients;using OpenPayments.Sdk.Extensions;using OpenPayments.Sdk.HttpSignatureUtils;
// Initialize clientvar client = new ServiceCollection() .UseOpenPayments(opts => { opts.UseAuthenticatedClient = true; opts.KeyId = CLIENT_ID; opts.PrivateKey = KeyUtils.LoadPem(CLIENT_SECRET); opts.ClientUrl = new Uri(CLIENT_WALLET_ADDRESS); }) .BuildServiceProvider() .GetRequiredService<IAuthenticatedClient>();
// Get quotevar quote = await client.GetQuoteAsync( new AuthRequestArgs { Url = new Uri(QUOTE_URL), AccessToken = QUOTE_ACCESS_TOKEN, });
// OutputConsole.WriteLine($"QUOTE: {JsonConvert.SerializeObject(quote, Formatting.Indented)}");