Complete an incoming payment
An authorized client can complete an unexpired incoming payment to indicate it will not send any additional payments to the wallet address.
These code snippets pass the wallet address and incoming payment URL to the 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” 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})
// 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
Prerequisites View full 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:#?}"); 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);
// 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); 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) }
// 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))} 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));
// Complete the incoming paymentvar incomingPaymentComplete = this.client.createIncomingPaymentComplete(incomingPayment, grantRequest);
// Outputlog.info("INCOMING_PAYMENT: {}", incomingPaymentComplete);