Build your first integration
Install an integration, get an access token, and create a payment link from your server.
In this tutorial, you connect a server to your MyTPE account and create a payment link. It takes about 15 minutes.
Before you begin
You need:
- To be the owner of the MyTPE account.
- A plan that includes the external API.
- A payment instance that's ready to accept payments. If you don't have one, follow Submit KYC and Request a payment instance first.
curlon the computer you're working from.
Create the integration
- In the MyTPE dashboard, go to the Developers page and open the Integrations tab.
- Click New integration.
- Enter a name, such as
My first server. - Select these permissions: read payment instances, and create and change payment links.
- Click Create integration.
- Copy the client ID and the client secret. MyTPE shows the secret only once.
Store both values as environment variables on your server:
export MYTPE_CLIENT_ID="your-client-id"
export MYTPE_CLIENT_SECRET="your-client-secret"Get an access token
Exchange the credentials for a token. Request only the scopes this program needs:
curl -X POST https://api.mytpe.app/oauth/token \
-d grant_type=client_credentials \
-d client_id="$MYTPE_CLIENT_ID" \
-d client_secret="$MYTPE_CLIENT_SECRET" \
-d scope="instances:read links:write"The response holds the token and its lifetime in seconds:
{
"token_type": "Bearer",
"expires_in": 3600,
"access_token": "eyJ0eXAiOiJKV1Qi..."
}Store the token for the next steps:
export MYTPE_ACCESS_TOKEN="the-access-token"Find your payment instance
curl https://api.mytpe.app/api/ext/instances \
-H "Authorization: Bearer $MYTPE_ACCESS_TOKEN"Copy the id of an instance whose acceptance_status is ready.
Create a payment link
Send an Idempotency-Key that's unique to this operation. If your request times out and you retry
with the same key, MyTPE returns the first link instead of creating a second one.
curl -X POST https://api.mytpe.app/api/ext/links \
-H "Authorization: Bearer $MYTPE_ACCESS_TOKEN" \
-H "Idempotency-Key: first-link-0001" \
-H "Content-Type: application/json" \
-d '{
"payment_instance_id": "your-instance-id",
"title": "My first link",
"amount_mode": "fixed",
"amount": 1000,
"usage_mode": "reusable"
}'Copy the id and the slug from the response. The link's status is draft.
Publish the link
curl -X POST https://api.mytpe.app/api/ext/links/your-link-id/publish \
-H "Authorization: Bearer $MYTPE_ACCESS_TOKEN"The link's status is now active. Customers can pay it at this address:
https://mytpe.app/pay/your-link-slugWhat you built
Your server now authenticates as an integration on one account and creates payment links for it.
What's next
- Receive webhooks so you know when a customer pays.
- Restrict an integration by IP address.
- Read How access tokens work.