Get an incoming payment
Esta página aún no está disponible en tu idioma.
An authorized client can look up the state of an incoming payment on a wallet address. This is useful when a client must determine if an incoming payment is still active and pending payment.
These code snippets return the state and details of a specific incoming 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 incoming payment
Section titled “Get the state of an incoming 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"}}
Get with authentication
Section titled “Get with authentication”// Import dependenciesimport { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize clientconst client = await createAuthenticatedClient({ walletAddressUrl: WALLET_ADDRESS, privateKey: PRIVATE_KEY_PATH, keyId: KEY_ID})
// Get incoming paymentconst incomingPayment = await client.incomingPayment.get({ url: INCOMING_PAYMENT_URL, accessToken: INCOMING_PAYMENT_ACCESS_TOKEN})
// Outputconsole.log('INCOMING PAYMENT:', incomingPayment)Get without authentication
Section titled “Get without authentication”// Import dependenciesimport { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize clientconst client = await createAuthenticatedClient({ walletAddressUrl: WALLET_ADDRESS, privateKey: PRIVATE_KEY_PATH, keyId: KEY_ID})
// Get incoming paymentconst incomingPayment = await client.incomingPayment.get({ url: INCOMING_PAYMENT_URL})
// Outputconsole.log('INCOMING PAYMENT:', incomingPayment)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
Get with authentication
Section titled “Get with authentication”// 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 incoming paymentlet access_token = get_env_var("INCOMING_PAYMENT_ACCESS_TOKEN")?;let incoming_payment_url = get_env_var("INCOMING_PAYMENT_URL")?;
let payment = client .incoming_payments() .get(&incoming_payment_url, Some(&access_token)) .await?;
// Outputprintln!("Incoming payment: {payment:#?}");Get without authentication
Section titled “Get without authentication”// 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 incoming paymentlet incoming_payment_url = get_env_var("INCOMING_PAYMENT_URL")?;
let payment = client .public_incoming_payments() .get(&incoming_payment_url) .await?;
// Outputprintln!("Public incoming payment: {payment:#?}"); Prerequisites View full source with authentication View full source without authentication
Get with authentication
Section titled “Get with authentication”// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config( $WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);$opClient = new AuthClient($config);
// Get incoming payment$incomingPayment = $opClient->incomingPayment()->get( [ 'access_token' => $INCOMING_PAYMENT_GRANT_ACCESS_TOKEN, 'url' => $INCOMING_PAYMENT_URL ]);
// Outputecho 'INCOMING PAYMENT: ' . PHP_EOL . print_r($incomingPayment, true);Get without authentication
Section titled “Get without authentication”// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config( $WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);$opClient = new AuthClient($config);
// Get incoming payment$incomingPayment = $opClient->incomingPayment()->get( [ 'url' => $INCOMING_PAYMENT_URL ]);
// Outputecho 'INCOMING PAYMENT: ' . PHP_EOL . print_r($incomingPayment, 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 incoming payment incomingPayment, err := client.IncomingPayment.Get(context.TODO(), op.IncomingPaymentGetParams{ URL: INCOMING_PAYMENT_URL, AccessToken: ACCESS_TOKEN, })
// Or, get public incoming payment without authenticating // incomingPayment, err := client.IncomingPayment.GetPublic(context.TODO(), op.IncomingPaymentGetPublicParams{ // URL: INCOMING_PAYMENT_URL, // })
if err != nil { log.Fatalf("Error fetching incoming payment: %v\n", err) }
// Output incomingPaymentJSON, err := json.MarshalIndent(incomingPayment, "", " ") if err != nil { log.Fatalf("Error marshaling incoming payment: %v\n", err) } fmt.Println("INCOMING PAYMENT:", string(incomingPaymentJSON))} Prerequisites
// Import dependenciesimport org.interledger.openpayments.httpclient.OpenPaymentsHttpClient;import org.interledger.openpayments.IOpenPaymentsClient;
// Initialize clientIOpenPaymentsClient client = OpenPaymentsHttpClient.defaultClient("WalletAddress","PrivateKeyPEM","KeyId");
// Retrieve the walletvar receiverWallet = client.getWalletAddress("https://cloudninebank.example.com/customer");
// Grant for incoming payment (default)var grantRequest = this.client.createGrantIncomingPayment(receiverWallet);
// Create the incoming paymentvar incomingPayment = this.client.createIncomingPayment(receiverWallet, grantRequest, BigDecimal.valueOf(11.25));
// Get the newly created incoming payment (fetch by ID)var incomingPaymentFetched = this.client.getIncomingPayment(incomingPayment.getId(), grantRequest);
// Outputlog.info("INCOMING_PAYMENT: {}", incomingPaymentFetched);