Create a Purchase
You can register a purchase programmatically to compensate for carbon emissions on this endpoint. You must quote for pricing beforehand and pass the returned pricing ID as a parameter.
Alternatively, you can use the payment_link
from the pricing endpoint to finalize the purchase using SQUAKE's provided checkout page.
Lifecycle
When purchasing via API (this endpoint)
- reserved: A successful purchase starts in the state "reserved"; SQUAKE registered your purchase and reserved carbon credits accordingly.
- canceled: SQUAKE offers 14 days to cancel a purchase worry-free. This is a terminal state.
- confirmed: The refundable period has passed. If you need to cancel the purchase beyond this point, please request a refund on the refunds endpoint.
- invoiced: Without further action, a purchase is invoiced after the grace period and transitions to "invoiced".
When purchasing via the checkout page
- payment_initiated: the end customer entered the payment flow on the checkout page
- payment_aborted: the payment failed permanently, for example, because the customer exited the page without finalizing the payment and didn't return before the pricing's validity ended. This is a terminal state.
- confirmed: the payment provider informed SQUAKE about the successful payment. In this flow, this state exists only for a short time; the purchase immediately continues to "settled".
Both
- settled: SQUAKE has received the payment.
- refunded: a refund request was successfully processed. This is a terminal state.
- certificates_confirmed: all certificates for the carbon credits have been confirmed from all project partners related to the purchase.
- certificates_retired: all certificates have been retired in the corresponding registries. This is a terminal state.
Body
-
The ID from the pricing endpoint
-
confirmation_document object
Additional properties are allowed.
-
certificate_document object
Additional properties are allowed.
-
expand array[string]
Receive either the file-id, or the file-object of a requested document. If omitted, only IDs are returned.
Value is
files
. -
metadata object
A set of key-value pairs of yours that helps you link this record in your system. Never displayed to users.
Additional properties are allowed.
-
external_reference string
If given, this reference must be unique. Suppose you need idempotency on the purchase endpoint: in that case, the external reference must be provided, meaning you can retry a purchase call with the same pricing id multiple times without registering multiple purchases, e.g., to recover from a network failure. Remember: with a valid pricing id, you can register as many purchases as you need. The reference should have enough entropy; a great choice is a V4 UUID.
curl \
-X POST https://api.squake.earth/v2/purchases \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"pricing":"string","confirmation_document":{"full_name":"string","address":{"city":"string","country":"DE","line1":"string","line2":"string","postal_code":"string","state":"string"},"email":"hello@example.com","on_behalf_of":{"full_name":"string","address":{"city":"string","country":"DE","line1":"string","line2":"string","postal_code":"string","state":"string"}},"locale":"en"},"certificate_document":{"full_name":"string","address":{"city":"string","country":"DE","line1":"string","line2":"string","postal_code":"string","state":"string"},"email":"hello@example.com","flags":["with_attribution"],"locale":"en"},"expand":["files"],"metadata":{},"external_reference":"string"}'
{
"pricing": "string",
"confirmation_document": {
"full_name": "string",
"address": {
"city": "string",
"country": "DE",
"line1": "string",
"line2": "string",
"postal_code": "string",
"state": "string"
},
"email": "hello@example.com",
"on_behalf_of": {
"full_name": "string",
"address": {
"city": "string",
"country": "DE",
"line1": "string",
"line2": "string",
"postal_code": "string",
"state": "string"
}
},
"locale": "en"
},
"certificate_document": {
"full_name": "string",
"address": {
"city": "string",
"country": "DE",
"line1": "string",
"line2": "string",
"postal_code": "string",
"state": "string"
},
"email": "hello@example.com",
"flags": [
"with_attribution"
],
"locale": "en"
},
"expand": [
"files"
],
"metadata": {},
"external_reference": "string"
}
# Headers
# Payload
{
"id": "purchase_sd234asdfl23",
"files": [
"file_34sdfgJH9df4g35"
],
"payment_method": "batch_settlement",
"state": "reserved",
"metadata": {},
"checkout_page": {
"url": "https://checkout.squake.earth",
"return_url": "https://example.com"
},
"carbon_quantity": 42.0,
"carbon_unit": "tonne",
"total": 42,
"currency": "EUR",
"external_reference": "string"
}
# Headers
SQUAKE-Request-Id: req_70394c00-728e-4d70-90bc-2b589c9ebdf8
# Payload
[
{
"code": "field_validation_error",
"detail": "string",
"source": {
"id": "string",
"attribute": "string",
"model": "string"
}
}
]
# Headers
SQUAKE-Request-Id: req_70394c00-728e-4d70-90bc-2b589c9ebdf8
# Payload
[
{
"code": "field_validation_error",
"detail": "string",
"source": {
"id": "string",
"attribute": "string",
"model": "string"
}
}
]