⚒️[Admin] Monetize API with network app
Capture Network Action is a feature supported by the "network app" system which is a flexible and scalable system that handles all of the technical aspects of payment processing, making it easy for developers to easily monetize their API or plugin for users with Capture Wallet.
The Network App system is designed to be a pay-as-you-go solution, making it easy for users to control their budget and only pay for the services they use. By topping up their Capture Wallet with sufficient funds, users can easily make use of the paid plugins and APIs supported by the "network app" system. It is perfect for businesses to control usage and avoid overspending.
Step 1: Create a network app
In order to create a network app, you will need to have the Capture Token with admin permission.
Before making the request, you will also need to request an API key from the storage backend admin and make sure it is registered on the API Key spreadsheet. This is needed in Step 2 to create orders for users.
Use the following curl command to make the request:
Make sure to replace
ADMIN_TOKEN
with the actual token in your code. The price unit is NUM, replace the number with the price you desire.If you want the network app system to call webhook after the payment is successful, update the
webhook_url
.
Once it is created, use the following curl command to get the NETWORK_APP_ID
The response.data.results[0].id
is the NETWORK_APP_ID
you need for the next step.
Step 2: Create order for users
Add the network-app-orders
API endpoint in your code to create orders for users. The following is an example in curl:
Please note,
USER_TOKEN
should be used for the "Authorization" header instead ofADMIN_TOKEN
, as the order is being created under the user's account.Make sure to replace
YOUR_API_KEY
with the actual key.Replace
action_args
to the arguments needed by your webhook.If there is no need to call webhook after payment is successful, keep the
webhook_url
in the example and there is no need to inputaction_args
.The
response.data.id
is theORDER_ID
you need for the next step.
Step 3: Confirm the order
Once the order is created, the confirmation needs to be done within 15 minutes. It is recommended to confirm the order only after it has been created to avoid any potential errors or issues. If the user confirms their intent to proceed with the order before it is created, the API can be called to confirm the order immediately after it is created.
Once the order is confirmed, the user's wallet will be charged the price of the network app as specified in Step 1. To avoid any confusion or misunderstandings, it is best to clearly communicate the cost of the network app to the user before proceeding with the confirmation of the order.
Check user wallet balance
To ensure that users have sufficient funds to proceed with a request, you can check the user's wallet balance. Follow the instruction here, use auth/users
endpoint and authenticate with USER_TOKEN
to retrieve the NUM balance of users.
Here is a sample code in node.js to check the wallet balance:
Last updated