List outgoing payments
The List Outgoing Payments API lets you list all outgoing payments on a wallet address.
After one or more outgoing payment resources are created, a client and look up active and pending payments on the wallet address.
The code snippets below let an authorized client retrieve the first 10 outgoing payments on a given wallet address.
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.
List all outgoing payments on a wallet address
Section titled “List all outgoing payments on a wallet address”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 wallet address informationconst walletAddress = await client.walletAddress.get({ url: WALLET_ADDRESS})
// List outgoing paymentsconst outgoingPayments = await client.outgoingPayment.list( { url: walletAddress.resourceServer, walletAddress: WALLET_ADDRESS, accessToken: OUTGOING_PAYMENT_ACCESS_TOKEN }, { first: 10, last: undefined, cursor: undefined, 'wallet-address': WALLET_ADDRESS })
// Outputconsole.log('OUTGOING PAYMENTS:', JSON.stringify(outgoingPayments, 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::client::utils::get_resource_server_url;use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env};
// Initialize clientlet client = create_authenticated_client()?;
// List outgoing paymentslet access_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(&access_token), ) .await?;
// Outputprintln!("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(&access_token), ) .await?; println!("Next page of outgoing payments: {:#?}", next_page.result); }}// 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()]);
// List outgoing payments$outgoingPaymentList = $opClient->outgoingPayment()->list( [ 'url' => $wallet->resourceServer, 'access_token' => $OUTGOING_PAYMENT_GRANT_ACCESS_TOKEN ], [ 'wallet-address' => $config->getWalletAddressUrl(), 'first' => 3, 'start' => '96d964f0-3421-4df0-bb04-cb8d653bc571' ]);
// Outputecho 'OUTGOING PAYMENTS LIST ' . PHP_EOL . print_r($outgoingPaymentList, true);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) }
// List outgoing payments outgoingPayments, err := client.OutgoingPayment.List(context.TODO(), op.OutgoingPaymentListParams{ BaseURL: RESOURCE_SERVER_URL, AccessToken: OUTGOING_PAYMENT_ACCESS_TOKEN, WalletAddress: WALLET_ADDRESS_URL, Pagination: op.Pagination{ First: "10", }, }) if err != nil { log.Fatalf("Error listing outgoing payments: %v\n", err) }
// Output outgoingPaymentsJSON, err := json.MarshalIndent(outgoingPayments, "", " ") if err != nil { log.Fatalf("Error marshaling outgoing payments: %v\n", err) } fmt.Println("OUTGOING PAYMENTS:", string(outgoingPaymentsJSON))}// 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.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());
// Create outgoing payment from quotevar urlToOpen = "https://example.com/redirect?paymentId=1234";
var opContinueInteract = client.auth().grant().continuation(senderWallet,quote.getDebitAmount(),URI.create(urlToOpen),"test");
// USER APPROVES REQUEST
// Grant: Finalize/Continuevar finalized = client.auth().grant().finalize(opContinueInteract, "Reference from USER interaction.");
// Outgoing payment (The token will be extracted from [finalized])var finalizedOutgoingPayment = client.payment().createOutgoing(finalized, senderWallet, quote);
// Retrieve the created outgoing payments (by walletAddress)var outgoingPaymentsFetched = client.payment().getOutgoingPayments(senderWallet, senderWallet.getId(), grantRequest);
// Outputlog.info("OUTGOING_PAYMENT_RESULT: {}", outgoingPaymentsFetched.getResult().size());outgoingPaymentsFetched.getResult().forEach(p -> log.info("OUTGOING_PAYMENT: {}", p));// Import dependenciesusing Microsoft.Extensions.DependencyInjection;using Newtonsoft.Json;using OpenPayments.Sdk.Clients;using OpenPayments.Sdk.Extensions;using OpenPayments.Sdk.Generated.Resource;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 wallet address informationvar waInfo = await client.GetWalletAddressAsync(WALLET_ADDRESS);
// List outgoing paymentsvar list = await client.ListOutgoingPaymentsAsync( new AuthRequestArgs { Url = waInfo.ResourceServer, AccessToken = OUTGOING_PAYMENT_ACCESS_TOKEN, }, new ListOutgoingPaymentQuery { WalletAddress = waInfo.Id.ToString(), First = 10, Last = null, Cursor = null, });
// OutputConsole.WriteLine($"OUTGOING PAYMENTS: {JsonConvert.SerializeObject(list, Formatting.Indented)}");