Get a quote
A quote is a commitment from an account servicing entity to deliver a particular amount to a recipient when sending a particular amount from a sender. The quote is only valid for a limited time.
An authorized client can get a quote to check the quote’s state (for example, is the quote valid or expired), as well as other payment details, such as the total amount that should be received by the recipient and the total amount that should be sent by the sender.
These code snippets return the state and details of a specific quote, if found.
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 the state of a quote
Section titled “Get the state of 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.getWalletAddress("https://cloudninebank.example.com/merchant");var senderWallet = client.getWalletAddress("https://cloudninebank.example.com/customer");
// Create incoming paymentvar grantRequest = this.client.createGrantIncomingPayment(receiverWallet);var incomingPayment = this.client.createIncomingPayment(receiverWallet, grantRequest, BigDecimal.valueOf(11.25));
// Create quotevar quoteRequest = this.client.createGrantQuote(senderWallet);var quote = client.createQuote(quoteRequest.getAccess().getToken(), senderWallet, incomingPayment, Optional.empty(), Optional.empty());
// Get the newly created quote (fetch by ID)var quoteFetched = this.client.getQuote(quote.getId(), grantRequest);
// Outputlog.info("QUOTE: {}", quoteFetched);