List outgoing payments
Esta página aún no está disponible en tu idioma.
After one or more outgoing payments have been created on a wallet address, an authorized client can look up active and pending outgoing payments on that wallet address.
These code snippets retrieve the first ten outgoing payments on the 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” 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 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
Prerequisites View full 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); }} 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);
$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); 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) }
// 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))} 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 payments (by walletAddress)var outgoingPaymentsFetched = this.client.getOutgoingPayments(senderWallet, senderWallet.getId(), grantRequest);
// Outputlog.info("OUTGOING_PAYMENT_RESULT: {}", outgoingPaymentsFetched.getResult().size());outgoingPaymentsFetched.getResult().forEach(p -> log.info("OUTGOING_PAYMENT: {}", p));