Get an outgoing payment
An authorized client can look up the state of an outgoing payment on a wallet address. This is useful when a client must determine if an outgoing payment is still active and pending payment.
These code snippets return the state and details of a specific outgoing payment, 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 an outgoing payment
Section titled “Get the state of an outgoing payment” Prerequisites
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 outgoing paymentconst outgoingPayment = await client.outgoingPayment.get({ url: OUTGOING_PAYMENT_URL, accessToken: OUTGOING_PAYMENT_ACCESS_TOKEN})
// Outputconsole.log('OUTGOING PAYMENT:', outgoingPayment)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
Prerequisites View full 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 outgoing paymentlet access_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(&access_token)) .await?;
// Outputprintln!("Outgoing payment: {payment:#?}"); Prerequisites View full source
// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config( $WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);$opClient = new AuthClient($config);
// Get outgoing payment$outgoingPayment = $opClient->outgoingPayment()->get( [ 'access_token' => $OUTGOING_PAYMENT_GRANT_ACCESS_TOKEN, 'url' => $OUTGOING_PAYMENT_URL ]);
// Outputecho 'OUTGOING PAYMENT: ' . PHP_EOL . print_r($outgoingPayment, true); Prerequisites
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 outgoing payment outgoingPayment, err := client.OutgoingPayment.Get(context.TODO(), op.OutgoingPaymentGetParams{ URL: OUTGOING_PAYMENT_URL, AccessToken: OUTGOING_PAYMENT_ACCESS_TOKEN, }) if err != nil { log.Fatalf("Error fetching outgoing payment: %v\n", err) }
// Output outgoingPaymentJSON, err := json.MarshalIndent(outgoingPayment, "", " ") if err != nil { log.Fatalf("Error marshaling outgoing payment: %v\n", err) } fmt.Println("OUTGOING PAYMENT:", string(outgoingPaymentJSON))} Prerequisites
// Import dependenciesimport org.interledger.openpayments.httpclient.OpenPaymentsHttpClient;import org.interledger.openpayments.IOpenPaymentsClient;
// Initialize clientvar 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());
// Create outing payment from quotevar urlToOpen = "http://localhost:%d?paymentId=1234".formatted(port);
var opContinueInteract = this.client.createGrantContinuation(senderWallet,quote.getDebitAmount(),URI.create(urlToOpen),"test");
// USER APPROVES REQUEST
// Grant: Finalize/Continuevar finalized = this.client.createGrantFinalize(opContinueInteract, "Reference from USER interaction.");
// Outgoing payment (The token will be extracted from [finalized])var finalizedOutgoingPayment = this.client.createFinalizePayment(finalized, senderWallet, quote);
// Retrieve the created outgoing payment (fetch by ID)var outgoingPaymentFetched = this.client.getOutgoingPayment(finalizedOutgoingPayment.getId(), grantRequest);
// Outputlog.info("OUTGOING_PAYMENT: {}", outgoingPaymentFetched);