Create an outgoing payment
After a quote is accepted and the authorized client obtains the requisite grant from the authorization server of the sender’s ASE Account servicing entity , the client can create an outgoing payment resource against the sender’s wallet address.
These code snippets create an outgoing payment to a given wallet address. The amount of the outgoing payment is based on the amounts in the associated quote.
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.
Create an outgoing payment resource
Section titled “Create an outgoing payment resource”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 dependencies
import { createAuthenticatedClient } from "@interledger/open-payments";
Copied! Initialize Open Payments client
const client = await createAuthenticatedClient({
walletAddressUrl: WALLET_ADDRESS,
privateKey: PRIVATE_KEY_PATH,
keyId: KEY_ID,
});
Copied! Create outgoing payment
const outgoingPayment = await client.outgoingPayment.create(
{
url: new URL(WALLET_ADDRESS).origin,
accessToken: OUTGOING_PAYMENT_ACCESS_TOKEN,
},
{
walletAddress: WALLET_ADDRESS,
quoteId: QUOTE_URL,
},
);
Copied! Output
console.log("OUTGOING_PAYMENT_URL = ", outgoingPayment.id);
Copied! 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 dependencies
use OpenPayments\AuthClient;
use OpenPayments\Config\Config;
Copied! Initialize Open Payments client
$config = new Config($WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);
$opClient = new AuthClient($config);
Copied! Without amount
Section titled “Without amount”Create outgoing payment
$newOutgoingPayment = $opClient->outgoingPayment()->create(
[
"url" => $wallet->resourceServer,
"access_token" => $OUTGOING_PAYMENT_GRANT_ACCESS_TOKEN,
],
[
"walletAddress" => $config->getWalletAddressUrl(),
"quoteId" => $QUOTE_URL,
"metadata" => [
"description" => "Test outgoing payment",
"reference" => "1234567890",
"invoiceId" => "1234567890",
"customData" => [
"key1" => "value1",
"key2" => "value2",
],
],
]
);
Copied! With amount
Section titled “With amount”Create outgoing payment with amount
$newOutgoingPayment = $opClient->outgoingPayment()->create(
[
"url" => $wallet->resourceServer,
"access_token" => $OUTGOING_PAYMENT_GRANT_ACCESS_TOKEN,
],
[
"walletAddress" => $config->getWalletAddressUrl(),
"incomingPayment" => $INCOMING_PAYMENT_URL,
"debitAmount" => [
"value" => "121",
"assetCode" => "USD",
"assetScale" => 2,
],
"metadata" => [
"description" => "Test outgoing payment",
"reference" => "1234567890",
"invoiceId" => "1234567890",
"customData" => [
"key1" => "value1",
"key2" => "value2",
],
],
]
);
Copied! Output
$output->writeln("OUTGOING_PAYMENT_URL " . $newOutgoingPayment->id);
Copied!