Complete an incoming payment
The Complete an Incoming Payment API lets you complete an unexpired incoming payment.
When a client completes an unexpired payment, it tells the recipient’s account servicing entity that no further payments will be sent toward the incoming payment resource.
The code snippets below let an authorized client pass a wallet address and incoming payment URL to the recipient’s resource server and mark the payment as completed.
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.
Mark an incoming payment as complete
Section titled “Mark an incoming payment as complete”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})
// Complete incoming paymentconst incomingPayment = await client.incomingPayment.complete({ url: INCOMING_PAYMENT_URL, accessToken: INCOMING_PAYMENT_ACCESS_TOKEN})
// Outputconsole.log('INCOMING PAYMENT:', JSON.stringify(incomingPayment, 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::snippets::utils::{create_authenticated_client, get_env_var, load_env};
// Initialize clientlet client = create_authenticated_client()?;
// Complete 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() .complete(&incoming_payment_url, Some(&access_token)) .await?;
// Outputprintln!("Completed incoming payment: {payment:#?}");// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config( $WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);$opClient = new AuthClient($config);
// Complete incoming payment$incomingPayment = $opClient->incomingPayment()->complete( [ 'access_token' => $INCOMING_PAYMENT_GRANT_ACCESS_TOKEN, 'url' => $INCOMING_PAYMENT_URL ]);
// Outputecho 'COMPLETE INCOMING PAYMENT: '. PHP_EOL . print_r($incomingPayment, 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) }
// Complete incoming payment incomingPayment, err := client.IncomingPayment.Complete(context.TODO(), op.IncomingPaymentCompleteParams{ URL: INCOMING_PAYMENT_URL, AccessToken: ACCESS_TOKEN, }) if err != nil { log.Fatalf("Error completing 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))}// 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.walletAddress().get("https://cloudninebank.example.com/customer");
// Grant for incoming payment (default)var grantRequest = client.auth().grant().incomingPayment(receiverWallet);
// Create the incoming paymentvar incomingPayment = client.payment().createIncoming(receiverWallet, grantRequest, BigDecimal.valueOf(11.25));
// Complete the incoming paymentvar incomingPaymentComplete = client.payment().incomingPaymentComplete(incomingPayment, grantRequest);
// Outputlog.info("INCOMING_PAYMENT: {}", incomingPaymentComplete);// Import dependenciesusing Microsoft.Extensions.DependencyInjection;using Newtonsoft.Json;using OpenPayments.Sdk.Clients;using OpenPayments.Sdk.Extensions;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>();
// Create Incoming Paymentvar incomingPayment = await client.CompleteIncomingPaymentsAsync( new AuthRequestArgs { Url = new Uri(INCOMING_PAYMENT_URL), AccessToken = INCOMING_PAYMENT_ACCESS_TOKEN, });
// OutputConsole.WriteLine($"INCOMING PAYMENT: {JsonConvert.SerializeObject(incomingPayment, Formatting.Indented)}");