List incoming payments
Esta página aún no está disponible en tu idioma.
The List Incoming Payments API lets you list all incoming payments on a wallet address.
After one or more incoming payment resources are created, a client can look up active and pending payments on the wallet address.
The code snippets below let an authorized client retrieve the first 10 incoming 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 incoming payments on a wallet address
Section titled “List all incoming 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 incoming paymentsconst incomingPayments = await client.incomingPayment.list( { url: walletAddress.resourceServer, walletAddress: WALLET_ADDRESS, accessToken: INCOMING_PAYMENT_ACCESS_TOKEN }, { first: 10, last: undefined, cursor: undefined, 'wallet-address': WALLET_ADDRESS })
// Outputconsole.log('INCOMING PAYMENTS:', JSON.stringify(incomingPayments, 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 incoming paymentslet access_token = get_env_var("INCOMING_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 .incoming_payments() .list( &resource_server_url, &wallet_address_url, None, Some(10), None, Some(&access_token), ) .await?;
// Outputprintln!("Incoming 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 .incoming_payments() .list( &resource_server_url, &wallet_address_url, Some(&end_cursor), Some(10), None, Some(&access_token), ) .await?; println!("Next page of incoming 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);
// Get wallet address information$wallet = $opClient->walletAddress()->get([ 'url' => $config->getWalletAddressUrl()]);
// List incoming payments$incomingPaymentsList = $opClient->incomingPayment()->list( [ 'url' => $wallet->resourceServer, 'access_token' => $INCOMING_PAYMENT_GRANT_ACCESS_TOKEN ], [ 'wallet-address' => $config->getWalletAddressUrl(), 'first' => 10, 'start'=> '96d964f0-3421-4df0-bb04-cb8d653bc571' ]);
// Outputecho 'INCOMING PAYMENTS ' . PHP_EOL . print_r($incomingPaymentsList, 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 incoming payments incomingPayments, err := client.IncomingPayment.List(context.TODO(), op.IncomingPaymentListParams{ BaseURL: RESOURCE_SERVER_URL, AccessToken: INCOMING_PAYMENT_ACCESS_TOKEN, WalletAddress: WALLET_ADDRESS_URL, Pagination: op.Pagination{ First: "10", }, }) if err != nil { log.Fatalf("Error listing incoming payments: %v\n", err) }
// Output incomingPaymentsJSON, err := json.MarshalIndent(incomingPayments, "", " ") if err != nil { log.Fatalf("Error marshaling incoming payments: %v\n", err) } fmt.Println("INCOMING PAYMENTS:", string(incomingPaymentsJSON))}// 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));
// Retrieve the created incoming payments (by walletAddress)var incomingPaymentsFetched = client.payment().getIncomingPayments(senderWallet, senderWallet.getId(), grantRequest);
// Outputlog.info("INCOMING_PAYMENT_RESULT: {}", incomingPaymentsFetched.getResult().size());incomingPaymentsFetched.getResult().forEach(p -> log.info("INCOMING_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 walletAddress = await client.GetWalletAddressAsync(WALLET_ADDRESS);
// Create Incoming Paymentvar list = await client.ListIncomingPaymentsAsync( new AuthRequestArgs { Url = walletAddress.ResourceServer, AccessToken = INCOMING_PAYMENT_ACCESS_TOKEN, }, new ListIncomingPaymentQuery { WalletAddress = walletAddress.Id.ToString(), First = 10, Last = null, Cursor = null, });
// OutputConsole.WriteLine($"INCOMING PAYMENTS: {JsonConvert.SerializeObject(list, Formatting.Indented)}");