API and webhooks
Affiliate sales
Sales through Plandalf checkouts and connected Stripe accounts are credited to partners automatically. When a sale happens somewhere else, report it here and Plandalf credits the partner and works out the commission. Report refunds, credit notes and disputes against it later and the commission follows. Setting up this kind of program is in Any platform.
Report a sale
Attribute the sale with the visitor's referral_token (the pf_rt value the SDK stores; see Referrals from code) or a partner's code.
curl -X POST https://admin.plandalf.dev/api/v1/affiliate/sales \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-10042" \
-d '{
"source": "my-shop",
"external_id": "order-10042",
"amount_cents": 9900,
"tax_cents": 900,
"currency": "usd",
"referral_token": "rt_…",
"billing_reason": "initial",
"customer": { "email": "ada@example.com", "external_id": "user-1815" }
}'
sourcenames your system andexternal_idis the sale's id in it. Together they identify the sale: the first report returns201, and the same pair again returns200with the sale as it is.- Send an
Idempotency-Keyheader so a retry after a timeout is safe. occurred_atmust be within the last 30 days. Settest: truefor test sales.
Refunds, credits and disputes
Each takes the source and sale_external_id of the sale, and its own external_id:
curl -X POST https://admin.plandalf.dev/api/v1/affiliate/refunds \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source": "my-shop", "sale_external_id": "order-10042", "external_id": "refund-311", "amount_cents": 4950}'
If the sale hasn't been reported yet, Plandalf returns 202 with {"status": "pending"} and applies the adjustment once you report the sale.
A dispute holds the sale's commission while it's open. To settle it, call won, lost or warning_closed with the dispute's id in the path. The body is the same as reporting the dispute and still needs external_id:
curl -X POST https://admin.plandalf.dev/api/v1/affiliate/disputes/dp_7731/won \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source": "my-shop", "sale_external_id": "order-10042", "external_id": "dp_7731", "amount_cents": 9900}'
Won releases the commission, lost reverses it, and warning_closed closes an inquiry that never became a chargeback.
Endpoints
Report a sale
POST /api/v1/affiliate/sales
Records a sale from your own checkout and attributes it to a partner by referral_token
(the visitor's referral cookie) or code (a partner's discount or referral code). Returns
the sale with its attribution and commission: 201 the first time, 200 when the same
source and external_id was already reported. Set test: true for test sales.
Send an Idempotency-Key header to make retries safe. occurred_at must be within the
last 30 days.
Body
| Field | Type | What it is |
|---|---|---|
source | string | |
external_id | string | |
currency | string | |
amount_cents | integer | |
tax_cents optional | integer | null | |
discount_cents optional | integer | null | |
occurred_at optional | string | null | |
referral_token optional | string | null | |
code optional | string | null | |
subscription_id optional | string | null | |
billing_reason optional | "initial" | "trial_start" | "trial_conversion" | "renewal" | "one_off" | "upgrade" | "downgrade" | "proration" | |
test optional | boolean | null | |
customer optional | object |
curl -X POST https://admin.plandalf.dev/api/v1/affiliate/sales \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source":"string","external_id":"string","currency":"string","amount_cents":0,"tax_cents":0,"discount_cents":0,"occurred_at":"string","referral_token":"string","code":"string","subscription_id":"string","billing_reason":"initial","test":true,"customer":{"email":"string","external_id":"string","payment_fingerprint":"string"}}'
Response
{
"id": "string",
"attribution": {
"method": "string",
"partner": {
"code": "string"
}
},
"commission": {
"status": "string",
"skip_reason": "string",
"amount_cents": 0,
"approves_at": "string"
},
"refunded_cents": 0
}
Errors
| Status | When |
|---|---|
401 | The API key or OAuth token is missing or invalid. |
403 | The credentials are valid but not allowed here: a site-connection token outside its scope, or the organization can't make this request. |
422 | The request failed validation; errors lists the problems by field. |
Report a refund
POST /api/v1/affiliate/refunds
Reduces the commission on a sale by the refunded amount. external_id is your refund's id.
Requires the source and sale_external_id of a sale reported earlier. Returns the updated
sale, or 202 with {"status": "pending"} when the sale hasn't been recorded yet (the
adjustment is applied once it is). Send an Idempotency-Key header to make retries safe.
Body
| Field | Type | What it is |
|---|---|---|
source | string | |
sale_external_id | string | |
external_id | string | |
amount_cents | integer | |
occurred_at optional | string | null | |
test optional | boolean | null |
curl -X POST https://admin.plandalf.dev/api/v1/affiliate/refunds \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source":"string","sale_external_id":"string","external_id":"string","amount_cents":0,"occurred_at":"string","test":true}'
Response
{
"id": "string",
"attribution": {
"method": "string",
"partner": {
"code": "string"
}
},
"commission": {
"status": "string",
"skip_reason": "string",
"amount_cents": 0,
"approves_at": "string"
},
"refunded_cents": 0
}
Errors
| Status | When |
|---|---|
401 | The API key or OAuth token is missing or invalid. |
403 | The credentials are valid but not allowed here: a site-connection token outside its scope, or the organization can't make this request. |
422 | The request failed validation; errors lists the problems by field. |
Report a credit note
POST /api/v1/affiliate/credits
Like a refund, for a credit issued against a sale. external_id is your credit note's id.
Requires the source and sale_external_id of a sale reported earlier. Returns the updated
sale, or 202 with {"status": "pending"} when the sale hasn't been recorded yet (the
adjustment is applied once it is). Send an Idempotency-Key header to make retries safe.
Body
| Field | Type | What it is |
|---|---|---|
source | string | |
sale_external_id | string | |
external_id | string | |
amount_cents | integer | |
tax_cents optional | integer | null | |
commission_basis_cents optional | integer | null | |
occurred_at optional | string | null | |
test optional | boolean | null |
curl -X POST https://admin.plandalf.dev/api/v1/affiliate/credits \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source":"string","sale_external_id":"string","external_id":"string","amount_cents":0,"tax_cents":0,"commission_basis_cents":0,"occurred_at":"string","test":true}'
Response
{
"id": "string",
"attribution": {
"method": "string",
"partner": {
"code": "string"
}
},
"commission": {
"status": "string",
"skip_reason": "string",
"amount_cents": 0,
"approves_at": "string"
},
"refunded_cents": 0
}
Errors
| Status | When |
|---|---|
401 | The API key or OAuth token is missing or invalid. |
403 | The credentials are valid but not allowed here: a site-connection token outside its scope, or the organization can't make this request. |
422 | The request failed validation; errors lists the problems by field. |
Report a dispute
POST /api/v1/affiliate/disputes
Records a chargeback or inquiry opened against a sale; its commission is held while the
dispute is open. status defaults to needs_response. external_id is your dispute's id.
Requires the source and sale_external_id of a sale reported earlier. Returns the updated
sale, or 202 with {"status": "pending"} when the sale hasn't been recorded yet (the
adjustment is applied once it is). Send an Idempotency-Key header to make retries safe.
Body
| Field | Type | What it is |
|---|---|---|
source | string | |
sale_external_id | string | |
external_id | string | |
charge_id optional | string | null | |
amount_cents | integer | |
currency optional | string | null | |
status optional | "needs_response" | "under_review" | "warning_needs_response" | "warning_under_review" | "warning_closed" | "won" | "lost" | |
occurred_at optional | string | null | |
test optional | boolean | null |
curl -X POST https://admin.plandalf.dev/api/v1/affiliate/disputes \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source":"string","sale_external_id":"string","external_id":"string","charge_id":"string","amount_cents":0,"currency":"string","status":"needs_response","occurred_at":"string","test":true}'
Response
{
"id": "string",
"attribution": {
"method": "string",
"partner": {
"code": "string"
}
},
"commission": {
"status": "string",
"skip_reason": "string",
"amount_cents": 0,
"approves_at": "string"
},
"refunded_cents": 0
}
Errors
| Status | When |
|---|---|
401 | The API key or OAuth token is missing or invalid. |
403 | The credentials are valid but not allowed here: a site-connection token outside its scope, or the organization can't make this request. |
422 | The request failed validation; errors lists the problems by field. |
Mark a dispute won
POST /api/v1/affiliate/disputes/{externalId}/won
The merchant won the dispute, so the sale's commission is released. externalId in the path
is the dispute's id; the body takes the same fields as reporting a dispute.
Parameters
| Name | In | Type | What it is |
|---|---|---|---|
externalId | path | string |
Body
| Field | Type | What it is |
|---|---|---|
source | string | |
sale_external_id | string | |
external_id | string | |
charge_id optional | string | null | |
amount_cents | integer | |
currency optional | string | null | |
status optional | "needs_response" | "under_review" | "warning_needs_response" | "warning_under_review" | "warning_closed" | "won" | "lost" | |
occurred_at optional | string | null | |
test optional | boolean | null |
curl -X POST https://admin.plandalf.dev/api/v1/affiliate/disputes/:externalId/won \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source":"string","sale_external_id":"string","external_id":"string","charge_id":"string","amount_cents":0,"currency":"string","status":"needs_response","occurred_at":"string","test":true}'
Response
{
"id": "string",
"attribution": {
"method": "string",
"partner": {
"code": "string"
}
},
"commission": {
"status": "string",
"skip_reason": "string",
"amount_cents": 0,
"approves_at": "string"
},
"refunded_cents": 0
}
Errors
| Status | When |
|---|---|
401 | The API key or OAuth token is missing or invalid. |
403 | The credentials are valid but not allowed here: a site-connection token outside its scope, or the organization can't make this request. |
422 | The request failed validation; errors lists the problems by field. |
Mark a dispute lost
POST /api/v1/affiliate/disputes/{externalId}/lost
The merchant lost the dispute, so the sale's commission is reversed. externalId in the path
is the dispute's id; the body takes the same fields as reporting a dispute.
Parameters
| Name | In | Type | What it is |
|---|---|---|---|
externalId | path | string |
Body
| Field | Type | What it is |
|---|---|---|
source | string | |
sale_external_id | string | |
external_id | string | |
charge_id optional | string | null | |
amount_cents | integer | |
currency optional | string | null | |
status optional | "needs_response" | "under_review" | "warning_needs_response" | "warning_under_review" | "warning_closed" | "won" | "lost" | |
occurred_at optional | string | null | |
test optional | boolean | null |
curl -X POST https://admin.plandalf.dev/api/v1/affiliate/disputes/:externalId/lost \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source":"string","sale_external_id":"string","external_id":"string","charge_id":"string","amount_cents":0,"currency":"string","status":"needs_response","occurred_at":"string","test":true}'
Response
{
"id": "string",
"attribution": {
"method": "string",
"partner": {
"code": "string"
}
},
"commission": {
"status": "string",
"skip_reason": "string",
"amount_cents": 0,
"approves_at": "string"
},
"refunded_cents": 0
}
Errors
| Status | When |
|---|---|
401 | The API key or OAuth token is missing or invalid. |
403 | The credentials are valid but not allowed here: a site-connection token outside its scope, or the organization can't make this request. |
422 | The request failed validation; errors lists the problems by field. |
Close a dispute warning
POST /api/v1/affiliate/disputes/{externalId}/warning_closed
An inquiry (warning) closed without becoming a chargeback. externalId in the path is the
dispute's id; the body takes the same fields as reporting a dispute.
Parameters
| Name | In | Type | What it is |
|---|---|---|---|
externalId | path | string |
Body
| Field | Type | What it is |
|---|---|---|
source | string | |
sale_external_id | string | |
external_id | string | |
charge_id optional | string | null | |
amount_cents | integer | |
currency optional | string | null | |
status optional | "needs_response" | "under_review" | "warning_needs_response" | "warning_under_review" | "warning_closed" | "won" | "lost" | |
occurred_at optional | string | null | |
test optional | boolean | null |
curl -X POST https://admin.plandalf.dev/api/v1/affiliate/disputes/:externalId/warning_closed \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source":"string","sale_external_id":"string","external_id":"string","charge_id":"string","amount_cents":0,"currency":"string","status":"needs_response","occurred_at":"string","test":true}'
Response
{
"id": "string",
"attribution": {
"method": "string",
"partner": {
"code": "string"
}
},
"commission": {
"status": "string",
"skip_reason": "string",
"amount_cents": 0,
"approves_at": "string"
},
"refunded_cents": 0
}
Errors
| Status | When |
|---|---|
401 | The API key or OAuth token is missing or invalid. |
403 | The credentials are valid but not allowed here: a site-connection token outside its scope, or the organization can't make this request. |
422 | The request failed validation; errors lists the problems by field. |