Create a Purchase

POST
/v2/purchases

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.

Authorization

Bearer-Auth
headerAuthorizationBearer <token>

Request Body

application/json
  1. body
pricing*string

The ID from the pricing endpoint

confirmation_document?
certificate_document?
expand?array<"files">

Receive either the file-id, or the file-object of a requested document. If omitted, only IDs are returned.

metadata?

A set of key-value pairs of yours that helps you link this record in your system. Never displayed to users.

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.

Response Body

Created

application/json
  1. response
id*string
Matchpurchase_[a-zA-Z0-9]*
files?array<|>

Contains for example the certificate document if it was requested during the purchase.

payment_method*Payment-Method

Mode of payment. The batch settlement means SQUAKE will invoice you regularly for a batch of purchases. The checkout page is SQUAKEs self-fulfillment solution where end-customers can purchase a product directly from SQUAKE as the merchant of record.

Default"batch_settlement"
Value in"batch_settlement""stripe"
state*Purchase State
Value in"reserved""confirmed""invoiced""settled""certificates_confirmed""certificates_retired""payment_initiated""canceled""voided""refunded""payment_aborted"
metadata?

A set of key-value pairs of yours that helps you link this record in your system. Never displayed to users.

checkout_page?

Present if the payment method is stripe, meaning self-fulfillment by the customer on SQUAKEs payment page.

carbon_quantity*number
carbon_unit*Carbon Unit

SQUAKE uses The International System of Units (SI), commonly referred to as "metric system".

Value in"tonne""kilogram""gram"
total*integer
currency*Currency

3-letter ISO 4217 alpha code of the currency.

Match^[A-Z]{3}$
Length3 <= length <= 3
Default"EUR"
Value in"AED""AMD""ARS""AUD""AZN""BAM""BGN""BHD""BRL""CAD""CHF""CLP""CNY""COP""CRC""CZK""DKK""DZD""EGP""ETB""EUR""GBP""GEL""HKD""HUF""IDR""INR""ISK""JMD""JOD""JPY""KES""KRW""KWD""KZT""LKR""LYD""MAD""MUR""MXN""MYR""NOK""NZD""OMR""PHP""PKR""PLN""QAR""RSD""RUB""SAR""SEK""SGD""SYP""THB""TND""TRY""TTD""TWD""UAH""USD""VND""XAF""XOF""ZAR"
external_reference?string

Unique identifier from your system; used as idempotency when creating this resource.

cancellable_until?string

The date until which purchase can be cancelled

Formatdate-time
Example Request
curl -X POST 'https://api.sandbox.squake.earth/v2/purchases' \  -H 'Content-Type: application/json' \  -d '{  "pricing": "string"}'
Example Response
{  "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": 0,  "carbon_unit": "tonne",  "total": 0,  "currency": "EUR",  "external_reference": "string",  "cancellable_until": "2019-08-24T14:15:22Z"}