Validate purchase in Stripe, provide access level, and import transaction history from Stripe with server-side API
Validates a purchase using the provided Stripe token using the credentials of Stripe in your App Settings inside Adapty Dashboard. If the purchase is valid, the transaction history is imported from Stripe to the profile in Adapty with the specified customer_user_id
. If there was no profile with this customer_user_id
before — it will be created.
Profile events are generated along the way and imported transactions are counted towards MTR.
Method and endpoint
POST https://api.adapty.io/api/v2/server-side-api/purchase/stripe/token/validate/
warning
This request requires different authorization parameters:
- Base URL: https://api.adapty.io/api/v1/sdk/purchase/stripe/token/validate/
- Authorization: API requests must be authenticated by including your secret API key as an Authorization header with value
Api-Key {secret_token}
to each request, for example,Api-Key secret_live_BEHrYLTr.ce5zuDEWz06lFRNiaJC8mrLtL8fUwswD
. You can find your secret API key in Adapty Dashboard -> App Settings -> General tab API -> API keys section. This key is secret, so be careful not to share it publicly. - Content-Type header: The API expects the request to use the Content-Type header set to
application/vnd.api+json
. - Body: The API expects the request to use the body as JSON.
Example request
- cURL
- Python
- JavaScript
--location 'https://api.adapty.io/api/v1/sdk/purchase/stripe/token/validate/' \
--header 'Content-Type: application/vnd.api+json' \
--header 'Authorization: Api-Key <PUBLIC_OR_PRIVATE_KEY>' \
--data-raw '{
"data": {
"type": "stripe_receipt_validation_result",
"attributes": {
"customer_user_id": "<CUSTOMER_USER_ID>",
"stripe_token": "sub_1OM8brJTlbIG45BdDRFOHWAU"
}
}
}'
import requests
import json
url = "https://api.adapty.io/api/v2/server-side-api/purchase/stripe/token/validate/"
payload = json.dumps({
"data": {
"type": "stripe_receipt_validation_result",
"attributes": {
"customer_user_id": "<CUSTOMER_USER_ID>",
"stripe_token": "<YOUR_STRIPE_TOKEN>"
}
}
})
headers = {
'Content-Type': 'application/vnd.api+json',
'Authorization': 'Api-Key <YOUR_SECRET_API_KEY>'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/vnd.api+json");
myHeaders.append("Authorization", "Api-Key <YOUR_SECRET_API_KEY>");
const raw = JSON.stringify({
"data": {
"type": "stripe_receipt_validation_result",
"attributes": {
"customer_user_id": "<CUSTOMER_USER_ID>",
"stripe_token": "<YOUR_STRIPE_TOKEN>"
}
}
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch("https://api.adapty.io/api/v2/server-side-api/purchase/stripe/token/validate/", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
Parameters
Param | Type | Required | Nullable | Description |
---|---|---|---|---|
customer_user_id | String | ➕ | ➖ | The ID of your user in your system. You can see it in the Customer user ID field on the Adapty Dashboard -> Profiles -> specific profile page. For it to work, you must identify the users in your mobile app code via Adapty SDK |
stripe_token | String | ➕ | ➖ | Token of a Stripe object that represents a unique purchase. Could either be a token of Stripe's Subscription (sub_XXX ) or Payment Intent (pi_XXX ). |
Successful response
{
"data": null
}
Errors
400 Bad request
Contain a list of errors with parameters.
Parameters
Parameter | Type | Description |
---|---|---|
detail | String | Descriptive information about the error. |
source | String | An object containing a "pointer" that references the exact location in the request document causing the issue |
Status | Integer | HTTP status. Always 400 |
Response example
{
"errors": [
{
"detail": "none is not an allowed value",
"source": {
"pointer": "/data/attributes/stripe_token"
},
"status": "400"
}
]
}
See also: