Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Generate json schemas (#17760)

Iga Karbowiakc924abf309d0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c9f5fcbb6..5576cd352b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ All notable, unreleased changes to this project will be documented in this file.
### Webhooks
### Other changes
+- Add JSON schemas for synchronous webhooks, now available in `saleor/json_schemas.py`. These schemas define the expected structure of webhook payloads, enabling improved validation and tooling support for webhook integrations. This change helps ensure that webhook consumers can reliably parse and validate incoming data.
- deps: upgraded urllib3 from v1.x to v2.x
- Fix PAGE_DELETE webhook to include pageType in payload - #17697 by @Jennyyyy0212 and @CherineCho2016
- Stripe Plugin has been deprecated. It will be removed in the future. Please use [the Stripe App](https://docs.saleor.io/developer/app-store/apps/stripe/overview) instead
diff --git a/saleor/core/management/commands/generate_json_schemas.py b/saleor/core/management/commands/generate_json_schemas.py
new file mode 100644
index 0000000000..4709789c7c
--- /dev/null
+++ b/saleor/core/management/commands/generate_json_schemas.py
@@ -0,0 +1,77 @@
+import json
+import os
+import shutil
+from typing import cast
+
+from django.core.management.base import BaseCommand
+from pydantic import BaseModel
+
+from ....webhook.response_schemas import COMBINED_SCHEMAS_TO_EXPORT, SCHEMAS_TO_EXPORT
+
+SCHEMA_OUTPUT_DIR = "saleor/json_schemas"
+
+
+class Command(BaseCommand):
+ help = "Generate JSON schemas for synchronous webhooks responses."
+
+ def handle(self, *args, **options):
+ self.clear_dir()
+ os.makedirs(SCHEMA_OUTPUT_DIR, exist_ok=True)
+ self.export_single_schemas()
+ self.export_combined_schemas()
+
+ def export_single_schemas(self):
+ for schema_data in SCHEMAS_TO_EXPORT:
+ title, schema_cls = schema_data["title"], schema_data["schema"]
+ title = cast(str, title)
+ schema_cls = cast(type[BaseModel], schema_cls)
+ schema = schema_cls.model_json_schema()
+ schema["title"] = self.get_schema_title(schema_cls)
+ self.write_schema_to_file(schema, title)
+
+ def export_combined_schemas(self):
+ for combined_schema in COMBINED_SCHEMAS_TO_EXPORT:
+ title, schemas_cls = combined_schema["title"], combined_schema["schemas"]
+ title = cast(str, title)
+ defs: dict[str, dict] = {}
+ schemas = self.get_schemas(schemas_cls, defs)
+ combined_schema_dict = {
+ "title": title,
+ "anyOf": schemas,
+ }
+ if defs:
+ combined_schema_dict["$defs"] = defs
+ self.write_schema_to_file(combined_schema_dict, title)
+
+ def get_schemas(self, schemas_cls, merged_defs):
+ schemas = []
+ for cls in schemas_cls:
+ schema = cls.model_json_schema()
+
+ # move $defs to the top level
+ defs = schema.pop("$defs", {})
+ merged_defs.update(defs)
+
+ schema["title"] = self.get_schema_title(cls)
+ schemas.append(schema)
+ return schemas
+
+ @staticmethod
+ def get_schema_title(schema_cls: type[BaseModel]) -> str:
+ """Get rid of `Schema` suffix from title."""
+ title = schema_cls.__name__
+ if title.endswith("Schema"):
+ title = title.removesuffix("Schema")
+ return title
+
+ def write_schema_to_file(self, schema: dict, title: str):
+ file_name = f"{title}.json"
+ path = os.path.join(SCHEMA_OUTPUT_DIR, file_name)
+ with open(path, "w") as f:
+ json.dump(schema, f, indent=2)
+ self.stdout.write(self.style.SUCCESS(f"Generated {path}"))
+
+ @staticmethod
+ def clear_dir():
+ if os.path.exists(SCHEMA_OUTPUT_DIR):
+ shutil.rmtree(SCHEMA_OUTPUT_DIR)
diff --git a/saleor/json_schemas/CheckoutCalculateTaxes.json b/saleor/json_schemas/CheckoutCalculateTaxes.json
new file mode 100644
index 0000000000..9a6efcc427
--- /dev/null
+++ b/saleor/json_schemas/CheckoutCalculateTaxes.json
@@ -0,0 +1,108 @@
+{
+ "$defs": {
+ "LineCalculateTaxesSchema": {
+ "properties": {
+ "tax_rate": {
+ "anyOf": [
+ {
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Tax Rate"
+ },
+ "total_gross_amount": {
+ "anyOf": [
+ {
+ "maximum": 1e+17,
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Total Gross Amount"
+ },
+ "total_net_amount": {
+ "anyOf": [
+ {
+ "maximum": 1e+17,
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Total Net Amount"
+ }
+ },
+ "required": [
+ "tax_rate",
+ "total_gross_amount",
+ "total_net_amount"
+ ],
+ "title": "LineCalculateTaxesSchema",
+ "type": "object"
+ }
+ },
+ "properties": {
+ "shipping_tax_rate": {
+ "anyOf": [
+ {
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Shipping Tax Rate"
+ },
+ "shipping_price_gross_amount": {
+ "anyOf": [
+ {
+ "maximum": 1e+17,
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Shipping Price Gross Amount"
+ },
+ "shipping_price_net_amount": {
+ "anyOf": [
+ {
+ "maximum": 1e+17,
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Shipping Price Net Amount"
+ },
+ "lines": {
+ "default": [],
+ "items": {
+ "$ref": "#/$defs/LineCalculateTaxesSchema"
+ },
+ "title": "Lines",
+ "type": "array"
+ }
+ },
+ "required": [
+ "shipping_tax_rate",
+ "shipping_price_gross_amount",
+ "shipping_price_net_amount"
+ ],
+ "title": "CalculateTaxes",
+ "type": "object"
+}
diff --git a/saleor/json_schemas/CheckoutFilterShippingMethods.json b/saleor/json_schemas/CheckoutFilterShippingMethods.json
new file mode 100644
index 0000000000..65865f416f
--- /dev/null
+++ b/saleor/json_schemas/CheckoutFilterShippingMethods.json
@@ -0,0 +1,34 @@
+{
+ "$defs": {
+ "ExcludedShippingMethodSchema": {
+ "properties": {
+ "id": {
+ "title": "Id",
+ "type": "string"
+ },
+ "reason": {
+ "default": "",
+ "title": "Reason",
+ "type": "string"
+ }
+ },
+ "required": [
+ "id"
+ ],
+ "title": "ExcludedShippingMethodSchema",
+ "type": "object"
+ }
+ },
+ "properties": {
+ "excluded_methods": {
+ "default": [],
+ "items": {
+ "$ref": "#/$defs/ExcludedShippingMethodSchema"
+ },
+ "title": "Excluded Methods",
+ "type": "array"
+ }
+ },
+ "title": "FilterShippingMethods",
+ "type": "object"
+}
diff --git a/saleor/json_schemas/ListStoredPaymentMethods.json b/saleor/json_schemas/ListStoredPaymentMethods.json
new file mode 100644
index 0000000000..638fb413e6
--- /dev/null
+++ b/saleor/json_schemas/ListStoredPaymentMethods.json
@@ -0,0 +1,127 @@
+{
+ "$defs": {
+ "CreditCardInfoSchema": {
+ "properties": {
+ "brand": {
+ "description": "Brand of the credit card.",
+ "title": "Brand",
+ "type": "string"
+ },
+ "lastDigits": {
+ "description": "Last digits of the credit card.",
+ "title": "Lastdigits",
+ "type": "string"
+ },
+ "expYear": {
+ "description": "Expiration year of the credit card.",
+ "title": "Expyear",
+ "type": "integer"
+ },
+ "expMonth": {
+ "description": "Expiration month of the credit card.",
+ "title": "Expmonth",
+ "type": "integer"
+ },
+ "firstDigits": {
+ "default": null,
+ "description": "First digits of the credit card.",
+ "title": "Firstdigits",
+ "type": "string"
+ }
+ },
+ "required": [
+ "brand",
+ "lastDigits",
+ "expYear",
+ "expMonth"
+ ],
+ "title": "CreditCardInfoSchema",
+ "type": "object"
+ },
+ "JsonValue": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "integer"
+ },
+ {
+ "type": "number"
+ },
+ {
+ "type": "boolean"
+ },
+ {
+ "additionalProperties": true,
+ "type": "object"
+ },
+ {
+ "items": {},
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "JsonValue"
+ },
+ "StoredPaymentMethodSchema": {
+ "properties": {
+ "id": {
+ "description": "ID of stored payment method.",
+ "title": "Id",
+ "type": "string"
+ },
+ "supportedPaymentFlows": {
+ "description": "Supported flows that can be performed with this payment method.",
+ "items": {
+ "const": "INTERACTIVE",
+ "type": "string"
+ },
+ "title": "Supportedpaymentflows",
+ "type": "array"
+ },
+ "type": {
+ "description": "Type of stored payment method. For example: Credit Card.",
+ "title": "Type",
+ "type": "string"
+ },
+ "name": {
+ "default": null,
+ "description": "Name of the payment method. For example: last 4 digits of credit card, obfuscated email.",
+ "title": "Name",
+ "type": "string"
+ },
+ "data": {
+ "$ref": "#/$defs/JsonValue",
+ "default": null,
+ "description": "JSON data that will be returned to client."
+ },
+ "creditCardInfo": {
+ "$ref": "#/$defs/CreditCardInfoSchema",
+ "default": null,
+ "description": "Credit card information."
+ }
+ },
+ "required": [
+ "id",
+ "type"
+ ],
+ "title": "StoredPaymentMethodSchema",
+ "type": "object"
+ }
+ },
+ "properties": {
+ "paymentMethods": {
+ "description": "List of stored payment methods.",
+ "items": {
+ "$ref": "#/$defs/StoredPaymentMethodSchema"
+ },
+ "title": "Paymentmethods",
+ "type": "array"
+ }
+ },
+ "title": "ListStoredPaymentMethods",
+ "type": "object"
+}
diff --git a/saleor/json_schemas/OrderCalculateTaxes.json b/saleor/json_schemas/OrderCalculateTaxes.json
new file mode 100644
index 0000000000..9a6efcc427
--- /dev/null
+++ b/saleor/json_schemas/OrderCalculateTaxes.json
@@ -0,0 +1,108 @@
+{
+ "$defs": {
+ "LineCalculateTaxesSchema": {
+ "properties": {
+ "tax_rate": {
+ "anyOf": [
+ {
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Tax Rate"
+ },
+ "total_gross_amount": {
+ "anyOf": [
+ {
+ "maximum": 1e+17,
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Total Gross Amount"
+ },
+ "total_net_amount": {
+ "anyOf": [
+ {
+ "maximum": 1e+17,
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Total Net Amount"
+ }
+ },
+ "required": [
+ "tax_rate",
+ "total_gross_amount",
+ "total_net_amount"
+ ],
+ "title": "LineCalculateTaxesSchema",
+ "type": "object"
+ }
+ },
+ "properties": {
+ "shipping_tax_rate": {
+ "anyOf": [
+ {
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Shipping Tax Rate"
+ },
+ "shipping_price_gross_amount": {
+ "anyOf": [
+ {
+ "maximum": 1e+17,
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Shipping Price Gross Amount"
+ },
+ "shipping_price_net_amount": {
+ "anyOf": [
+ {
+ "maximum": 1e+17,
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Shipping Price Net Amount"
+ },
+ "lines": {
+ "default": [],
+ "items": {
+ "$ref": "#/$defs/LineCalculateTaxesSchema"
+ },
+ "title": "Lines",
+ "type": "array"
+ }
+ },
+ "required": [
+ "shipping_tax_rate",
+ "shipping_price_gross_amount",
+ "shipping_price_net_amount"
+ ],
+ "title": "CalculateTaxes",
+ "type": "object"
+}
diff --git a/saleor/json_schemas/OrderFilterShippingMethods.json b/saleor/json_schemas/OrderFilterShippingMethods.json
new file mode 100644
index 0000000000..65865f416f
--- /dev/null
+++ b/saleor/json_schemas/OrderFilterShippingMethods.json
@@ -0,0 +1,34 @@
+{
+ "$defs": {
+ "ExcludedShippingMethodSchema": {
+ "properties": {
+ "id": {
+ "title": "Id",
+ "type": "string"
+ },
+ "reason": {
+ "default": "",
+ "title": "Reason",
+ "type": "string"
+ }
+ },
+ "required": [
+ "id"
+ ],
+ "title": "ExcludedShippingMethodSchema",
+ "type": "object"
+ }
+ },
+ "properties": {
+ "excluded_methods": {
+ "default": [],
+ "items": {
+ "$ref": "#/$defs/ExcludedShippingMethodSchema"
+ },
+ "title": "Excluded Methods",
+ "type": "array"
+ }
+ },
+ "title": "FilterShippingMethods",
+ "type": "object"
+}
diff --git a/saleor/json_schemas/PaymentGatewayInitializeSession.json b/saleor/json_schemas/PaymentGatewayInitializeSession.json
new file mode 100644
index 0000000000..034d5e0c02
--- /dev/null
+++ b/saleor/json_schemas/PaymentGatewayInitializeSession.json
@@ -0,0 +1,42 @@
+{
+ "$defs": {
+ "JsonValue": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "integer"
+ },
+ {
+ "type": "number"
+ },
+ {
+ "type": "boolean"
+ },
+ {
+ "additionalProperties": true,
+ "type": "object"
+ },
+ {
+ "items": {},
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "JsonValue"
+ }
+ },
+ "properties": {
+ "data": {
+ "$ref": "#/$defs/JsonValue"
+ }
+ },
+ "required": [
+ "data"
+ ],
+ "title": "PaymentGatewayInitializeSession",
+ "type": "object"
+}
diff --git a/saleor/json_schemas/PaymentGatewayInitializeTokenizationSession.json b/saleor/json_schemas/PaymentGatewayInitializeTokenizationSession.json
new file mode 100644
index 0000000000..887f03e779
--- /dev/null
+++ b/saleor/json_schemas/PaymentGatewayInitializeTokenizationSession.json
@@ -0,0 +1,128 @@
+{
+ "title": "PaymentGatewayInitializeTokenizationSession",
+ "anyOf": [
+ {
+ "properties": {
+ "id": {
+ "description": "ID of the payment method.",
+ "title": "Id",
+ "type": "string"
+ },
+ "result": {
+ "description": "Result of the payment method tokenization.",
+ "enum": [
+ "SUCCESSFULLY_TOKENIZED",
+ "ADDITIONAL_ACTION_REQUIRED"
+ ],
+ "title": "Result",
+ "type": "string"
+ },
+ "data": {
+ "$ref": "#/$defs/JsonValue",
+ "default": null,
+ "description": "A data passes to the client."
+ }
+ },
+ "required": [
+ "id",
+ "result"
+ ],
+ "title": "PaymentMethodTokenizationSuccess",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "ID of the payment method.",
+ "title": "Id"
+ },
+ "result": {
+ "const": "PENDING",
+ "description": "Result of the payment method tokenization.",
+ "title": "Result",
+ "type": "string"
+ },
+ "data": {
+ "$ref": "#/$defs/JsonValue",
+ "default": null,
+ "description": "A data passes to the client."
+ }
+ },
+ "required": [
+ "result"
+ ],
+ "title": "PaymentMethodTokenizationPending",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "result": {
+ "description": "Result of the payment method tokenization.",
+ "enum": [
+ "FAILED_TO_TOKENIZE",
+ "FAILED_TO_DELIVER"
+ ],
+ "title": "Result",
+ "type": "string"
+ },
+ "error": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Error message that will be passed to the frontend.",
+ "title": "Error"
+ }
+ },
+ "required": [
+ "result"
+ ],
+ "title": "PaymentMethodTokenizationFailed",
+ "type": "object"
+ }
+ ],
+ "$defs": {
+ "JsonValue": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "integer"
+ },
+ {
+ "type": "number"
+ },
+ {
+ "type": "boolean"
+ },
+ {
+ "additionalProperties": true,
+ "type": "object"
+ },
+ {
+ "items": {},
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "JsonValue"
+ }
+ }
+}
diff --git a/saleor/json_schemas/ShippingListMethodsForCheckout.json b/saleor/json_schemas/ShippingListMethodsForCheckout.json
new file mode 100644
index 0000000000..28b82e6cf8
--- /dev/null
+++ b/saleor/json_schemas/ShippingListMethodsForCheckout.json
@@ -0,0 +1,93 @@
+{
+ "$defs": {
+ "ShippingMethodSchema": {
+ "properties": {
+ "id": {
+ "title": "Id",
+ "type": "string"
+ },
+ "name": {
+ "maxLength": 100,
+ "title": "Name",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Amount"
+ },
+ "currency": {
+ "title": "Currency",
+ "type": "string"
+ },
+ "maximum_delivery_days": {
+ "anyOf": [
+ {
+ "minimum": 0,
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Maximum Delivery Days"
+ },
+ "minimum_delivery_days": {
+ "anyOf": [
+ {
+ "minimum": 0,
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Minimum Delivery Days"
+ },
+ "description": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Description"
+ },
+ "metadata": {
+ "additionalProperties": {
+ "type": "string"
+ },
+ "default": {},
+ "title": "Metadata",
+ "type": "object"
+ }
+ },
+ "required": [
+ "id",
+ "name",
+ "amount",
+ "currency"
+ ],
+ "title": "ShippingMethodSchema",
+ "type": "object"
+ }
+ },
+ "default": [],
+ "items": {
+ "$ref": "#/$defs/ShippingMethodSchema"
+ },
+ "title": "ListShippingMethods",
+ "type": "array"
+}
diff --git a/saleor/json_schemas/ShippingListMethodsForOrder.json b/saleor/json_schemas/ShippingListMethodsForOrder.json
new file mode 100644
index 0000000000..28b82e6cf8
--- /dev/null
+++ b/saleor/json_schemas/ShippingListMethodsForOrder.json
@@ -0,0 +1,93 @@
+{
+ "$defs": {
+ "ShippingMethodSchema": {
+ "properties": {
+ "id": {
+ "title": "Id",
+ "type": "string"
+ },
+ "name": {
+ "maxLength": 100,
+ "title": "Name",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "minimum": 0.0,
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "title": "Amount"
+ },
+ "currency": {
+ "title": "Currency",
+ "type": "string"
+ },
+ "maximum_delivery_days": {
+ "anyOf": [
+ {
+ "minimum": 0,
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Maximum Delivery Days"
+ },
+ "minimum_delivery_days": {
+ "anyOf": [
+ {
+ "minimum": 0,
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Minimum Delivery Days"
+ },
+ "description": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Description"
+ },
+ "metadata": {
+ "additionalProperties": {
+ "type": "string"
+ },
+ "default": {},
+ "title": "Metadata",
+ "type": "object"
+ }
+ },
+ "required": [
+ "id",
+ "name",
+ "amount",
+ "currency"
+ ],
+ "title": "ShippingMethodSchema",
+ "type": "object"
+ }
+ },
+ "default": [],
+ "items": {
+ "$ref": "#/$defs/ShippingMethodSchema"
+ },
+ "title": "ListShippingMethods",
+ "type": "array"
+}
diff --git a/saleor/json_schemas/StoredPaymentMethodDeleteRequested.json b/saleor/json_schemas/StoredPaymentMethodDeleteRequested.json
new file mode 100644
index 0000000000..a8a2959d30
--- /dev/null
+++ b/saleor/json_schemas/StoredPaymentMethodDeleteRequested.json
@@ -0,0 +1,38 @@
+{
+ "$defs": {
+ "StoredPaymentMethodRequestDeleteResult": {
+ "description": "Result of deleting a stored payment method.\n\nThis enum is used to determine the result of deleting a stored payment method.\nSUCCESSFULLY_DELETED - The stored payment method was successfully deleted.\nFAILED_TO_DELETE - The stored payment method was not deleted.\nFAILED_TO_DELIVER - The request to delete the stored payment method was not\ndelivered.",
+ "enum": [
+ "SUCCESSFULLY_DELETED",
+ "FAILED_TO_DELETE",
+ "FAILED_TO_DELIVER"
+ ],
+ "title": "StoredPaymentMethodRequestDeleteResult",
+ "type": "string"
+ }
+ },
+ "properties": {
+ "result": {
+ "$ref": "#/$defs/StoredPaymentMethodRequestDeleteResult",
+ "description": "Result of the request to delete the stored payment method."
+ },
+ "error": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Error message if the request to delete the stored payment method failed that will be passed to the frontend.",
+ "title": "Error"
+ }
+ },
+ "required": [
+ "result"
+ ],
+ "title": "StoredPaymentMethodDeleteRequested",
+ "type": "object"
+}
diff --git a/saleor/json_schemas/TransactionCancelationRequested.json b/saleor/json_schemas/TransactionCancelationRequested.json
new file mode 100644
index 0000000000..216cde89a3
--- /dev/null
+++ b/saleor/json_schemas/TransactionCancelationRequested.json
@@ -0,0 +1,192 @@
+{
+ "title": "TransactionCancelationRequested",
+ "anyOf": [
+ {
+ "properties": {
+ "pspReference": {
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "const": "CANCEL_SUCCESS",
+ "description": "Result of the action",
+ "title": "Result",
+ "type": "string"
+ }
+ },
+ "required": [
+ "pspReference",
+ "result"
+ ],
+ "title": "TransactionCancelationRequestedSyncSuccess",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "pspReference": {
+ "default": null,
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "const": "CANCEL_FAILURE",
+ "description": "Result of the action",
+ "title": "Result",
+ "type": "string"
+ }
+ },
+ "required": [
+ "result"
+ ],
+ "title": "TransactionCancelationRequestedSyncFailure",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "pspReference": {
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ }
+ },
+ "required": [
+ "pspReference"
+ ],
+ "title": "TransactionCancelationRequestedAsync",
+ "type": "object"
+ }
+ ]
+}
diff --git a/saleor/json_schemas/TransactionChargeRequested.json b/saleor/json_schemas/TransactionChargeRequested.json
new file mode 100644
index 0000000000..9fc3e117cc
--- /dev/null
+++ b/saleor/json_schemas/TransactionChargeRequested.json
@@ -0,0 +1,192 @@
+{
+ "title": "TransactionChargeRequested",
+ "anyOf": [
+ {
+ "properties": {
+ "pspReference": {
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "const": "CHARGE_SUCCESS",
+ "description": "Result of the action",
+ "title": "Result",
+ "type": "string"
+ }
+ },
+ "required": [
+ "pspReference",
+ "result"
+ ],
+ "title": "TransactionChargeRequestedSyncSuccess",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "pspReference": {
+ "default": null,
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "const": "CHARGE_FAILURE",
+ "description": "Result of the action",
+ "title": "Result",
+ "type": "string"
+ }
+ },
+ "required": [
+ "result"
+ ],
+ "title": "TransactionChargeRequestedSyncFailure",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "pspReference": {
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ }
+ },
+ "required": [
+ "pspReference"
+ ],
+ "title": "TransactionChargeRequestedAsync",
+ "type": "object"
+ }
+ ]
+}
diff --git a/saleor/json_schemas/TransactionInitializeSession.json b/saleor/json_schemas/TransactionInitializeSession.json
new file mode 100644
index 0000000000..e51abdaf9e
--- /dev/null
+++ b/saleor/json_schemas/TransactionInitializeSession.json
@@ -0,0 +1,289 @@
+{
+ "title": "TransactionInitializeSession",
+ "anyOf": [
+ {
+ "properties": {
+ "pspReference": {
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "description": "Result of the action",
+ "enum": [
+ "AUTHORIZATION_SUCCESS",
+ "CHARGE_SUCCESS",
+ "AUTHORIZATION_REQUEST",
+ "CHARGE_REQUEST"
+ ],
+ "title": "Result",
+ "type": "string"
+ },
+ "data": {
+ "$ref": "#/$defs/JsonValue",
+ "default": null,
+ "description": "The JSON data that will be returned to storefront"
+ }
+ },
+ "required": [
+ "pspReference",
+ "result"
+ ],
+ "title": "TransactionSessionSuccess",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "pspReference": {
+ "default": null,
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "description": "Result of the action",
+ "enum": [
+ "AUTHORIZATION_FAILURE",
+ "CHARGE_FAILURE"
+ ],
+ "title": "Result",
+ "type": "string"
+ },
+ "data": {
+ "$ref": "#/$defs/JsonValue",
+ "default": null,
+ "description": "The JSON data that will be returned to storefront"
+ }
+ },
+ "required": [
+ "result"
+ ],
+ "title": "TransactionSessionFailure",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "pspReference": {
+ "default": null,
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "description": "Result of the action",
+ "enum": [
+ "AUTHORIZATION_ACTION_REQUIRED",
+ "CHARGE_ACTION_REQUIRED"
+ ],
+ "title": "Result",
+ "type": "string"
+ },
+ "data": {
+ "$ref": "#/$defs/JsonValue",
+ "default": null,
+ "description": "The JSON data that will be returned to storefront"
+ }
+ },
+ "required": [
+ "result"
+ ],
+ "title": "TransactionSessionActionRequired",
+ "type": "object"
+ }
+ ],
+ "$defs": {
+ "JsonValue": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "integer"
+ },
+ {
+ "type": "number"
+ },
+ {
+ "type": "boolean"
+ },
+ {
+ "additionalProperties": true,
+ "type": "object"
+ },
+ {
+ "items": {},
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "JsonValue"
+ }
+ }
+}
diff --git a/saleor/json_schemas/TransactionProcessSession.json b/saleor/json_schemas/TransactionProcessSession.json
new file mode 100644
index 0000000000..2dda4f2b60
--- /dev/null
+++ b/saleor/json_schemas/TransactionProcessSession.json
@@ -0,0 +1,289 @@
+{
+ "title": "TransactionProcessSession",
+ "anyOf": [
+ {
+ "properties": {
+ "pspReference": {
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "description": "Result of the action",
+ "enum": [
+ "AUTHORIZATION_SUCCESS",
+ "CHARGE_SUCCESS",
+ "AUTHORIZATION_REQUEST",
+ "CHARGE_REQUEST"
+ ],
+ "title": "Result",
+ "type": "string"
+ },
+ "data": {
+ "$ref": "#/$defs/JsonValue",
+ "default": null,
+ "description": "The JSON data that will be returned to storefront"
+ }
+ },
+ "required": [
+ "pspReference",
+ "result"
+ ],
+ "title": "TransactionSessionSuccess",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "pspReference": {
+ "default": null,
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "description": "Result of the action",
+ "enum": [
+ "AUTHORIZATION_FAILURE",
+ "CHARGE_FAILURE"
+ ],
+ "title": "Result",
+ "type": "string"
+ },
+ "data": {
+ "$ref": "#/$defs/JsonValue",
+ "default": null,
+ "description": "The JSON data that will be returned to storefront"
+ }
+ },
+ "required": [
+ "result"
+ ],
+ "title": "TransactionSessionFailure",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "pspReference": {
+ "default": null,
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "description": "Result of the action",
+ "enum": [
+ "AUTHORIZATION_ACTION_REQUIRED",
+ "CHARGE_ACTION_REQUIRED"
+ ],
+ "title": "Result",
+ "type": "string"
+ },
+ "data": {
+ "$ref": "#/$defs/JsonValue",
+ "default": null,
+ "description": "The JSON data that will be returned to storefront"
+ }
+ },
+ "required": [
+ "result"
+ ],
+ "title": "TransactionSessionActionRequired",
+ "type": "object"
+ }
+ ],
+ "$defs": {
+ "JsonValue": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "integer"
+ },
+ {
+ "type": "number"
+ },
+ {
+ "type": "boolean"
+ },
+ {
+ "additionalProperties": true,
+ "type": "object"
+ },
+ {
+ "items": {},
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "JsonValue"
+ }
+ }
+}
diff --git a/saleor/json_schemas/TransactionRefundRequested.json b/saleor/json_schemas/TransactionRefundRequested.json
new file mode 100644
index 0000000000..da61161d4c
--- /dev/null
+++ b/saleor/json_schemas/TransactionRefundRequested.json
@@ -0,0 +1,192 @@
+{
+ "title": "TransactionRefundRequested",
+ "anyOf": [
+ {
+ "properties": {
+ "pspReference": {
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "const": "REFUND_SUCCESS",
+ "description": "Result of the action",
+ "title": "Result",
+ "type": "string"
+ }
+ },
+ "required": [
+ "pspReference",
+ "result"
+ ],
+ "title": "TransactionRefundRequestedSyncSuccess",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "pspReference": {
+ "default": null,
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "amount": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "string"
+ }
+ ],
+ "default": null,
+ "description": "Decimal amount of the processed action",
+ "title": "Amount"
+ },
+ "time": {
+ "description": "Time of the action in ISO 8601 format",
+ "format": "date-time",
+ "title": "Time",
+ "type": "string"
+ },
+ "externalUrl": {
+ "default": "",
+ "description": "External url with action details",
+ "format": "uri",
+ "maxLength": 2083,
+ "minLength": 1,
+ "title": "Externalurl",
+ "type": "string"
+ },
+ "message": {
+ "default": "",
+ "description": "Message related to the action. The maximum length is 512 characters; any text exceeding this limit will be truncated",
+ "title": "Message",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ },
+ "result": {
+ "const": "REFUND_FAILURE",
+ "description": "Result of the action",
+ "title": "Result",
+ "type": "string"
+ }
+ },
+ "required": [
+ "result"
+ ],
+ "title": "TransactionRefundRequestedSyncFailure",
+ "type": "object"
+ },
+ {
+ "properties": {
+ "pspReference": {
+ "description": "Psp reference received from payment provider.",
+ "title": "Pspreference",
+ "type": "string"
+ },
+ "actions": {
+ "anyOf": [
+ {
+ "description": "List of actions available for the transaction.",
+ "items": {
+ "enum": [
+ "CHARGE",
+ "REFUND",
+ "CANCEL"
+ ],
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Actions"
+ }
+ },
+ "required": [
+ "pspReference"
+ ],
+ "title": "TransactionRefundRequestedAsync",
+ "type": "object"
+ }
+ ]
+}
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.py
index 4c06deb3bc..481b6762d6 100644
--- a/saleor/payment/utils.py
+++ b/saleor/payment/utils.py
@@ -914,9 +914,9 @@ def _validate_transaction_action_data(
transaction_schemas.TransactionRefundRequestedAsyncSchema,
),
TransactionEventType.CANCEL_REQUEST: (
- transaction_schemas.TransactionCancelRequestedSyncSuccessSchema,
- transaction_schemas.TransactionCancelRequestedSyncFailureSchema,
- transaction_schemas.TransactionCancelRequestedAsyncSchema,
+ transaction_schemas.TransactionCancelationRequestedSyncSuccessSchema,
+ transaction_schemas.TransactionCancelationRequestedSyncFailureSchema,
+ transaction_schemas.TransactionCancelationRequestedAsyncSchema,
),
}
success_schema, failure_schema, async_schema = request_type_to_schemas_map[
diff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.py
index 3d47c961e2..090ec440d3 100644
--- a/saleor/plugins/webhook/plugin.py
+++ b/saleor/plugins/webhook/plugin.py
@@ -4,7 +4,7 @@ from collections import defaultdict
from collections.abc import Callable, Iterable
from decimal import Decimal
from functools import partial
-from typing import TYPE_CHECKING, Any, Final, Optional, Union
+from typing import TYPE_CHECKING, Any, Final, Optional, Union, cast
import graphene
from django.conf import settings
@@ -36,6 +36,7 @@ from ...order.models import Order
from ...payment import PaymentError, TransactionKind
from ...payment.interface import (
GatewayResponse,
+ JSONValue,
ListStoredPaymentMethodsRequestData,
PaymentData,
PaymentGateway,
@@ -3149,9 +3150,11 @@ class WebhookPlugin(BasePlugin):
response_data = None
error_msg = str(e)
+ data = response_data_model.data if response_data_model else None
+ data = cast(JSONValue, data)
response_gateway[webhook.app.identifier] = PaymentGatewayData(
app_identifier=webhook.app.identifier,
- data=response_data_model.data if response_data_model else None,
+ data=data,
error=error_msg,
)
diff --git a/saleor/plugins/webhook/tests/test_tax_webhook.py b/saleor/plugins/webhook/tests/test_tax_webhook.py
index fb9d848ca8..91faa47f15 100644
--- a/saleor/plugins/webhook/tests/test_tax_webhook.py
+++ b/saleor/plugins/webhook/tests/test_tax_webhook.py
@@ -355,8 +355,8 @@ def test_get_taxes_for_checkout_with_app_identifier_invalid_response(
checkout_info = fetch_checkout_info(
checkout, [], get_plugins_manager(allow_replica=False)
)
- # mock returning invalid data - tax_rate above 100
- mock_request.return_value = tax_data_response_factory(shipping_tax_rate=120)
+ # mock returning invalid data - tax_rate with negative value
+ mock_request.return_value = tax_data_response_factory(shipping_tax_rate=-10)
mock_generate_payload.return_value = expected_payload
plugin = webhook_plugin()
webhook = tax_app.webhooks.get(name="tax-webhook-1")
@@ -462,8 +462,8 @@ def test_get_taxes_for_order_with_app_identifier_invalid_response(
# given
subscription_query = "subscription{event{... on CalculateTaxes{taxBase{currency}}}}"
expected_payload = {"taxBase": {"currency": "USD"}}
- # mock returning invalid data - tax_rate above 100
- mock_request.return_value = tax_data_response_factory(shipping_tax_rate=120)
+ # mock returning invalid data - tax_rate with negative value
+ mock_request.return_value = tax_data_response_factory(shipping_tax_rate=-10)
mock_generate_payload.return_value = expected_payload
plugin = webhook_plugin()
webhook = tax_app.webhooks.get(name="tax-webhook-1")
diff --git a/saleor/webhook/response_schemas/__init__.py b/saleor/webhook/response_schemas/__init__.py
index e69de29bb2..8682130bde 100644
--- a/saleor/webhook/response_schemas/__init__.py
+++ b/saleor/webhook/response_schemas/__init__.py
@@ -0,0 +1,126 @@
+from .payment import (
+ ListStoredPaymentMethodsSchema,
+ PaymentGatewayInitializeTokenizationSessionSchema,
+ PaymentMethodTokenizationFailedSchema,
+ PaymentMethodTokenizationPendingSchema,
+ PaymentMethodTokenizationSuccessSchema,
+ StoredPaymentMethodDeleteRequestedSchema,
+)
+from .shipping import FilterShippingMethodsSchema, ListShippingMethodsSchema
+from .taxes import CalculateTaxesSchema
+from .transaction import (
+ PaymentGatewayInitializeSessionSchema,
+ TransactionCancelationRequestedAsyncSchema,
+ TransactionCancelationRequestedSyncFailureSchema,
+ TransactionCancelationRequestedSyncSuccessSchema,
+ TransactionChargeRequestedAsyncSchema,
+ TransactionChargeRequestedSyncFailureSchema,
+ TransactionChargeRequestedSyncSuccessSchema,
+ TransactionRefundRequestedAsyncSchema,
+ TransactionRefundRequestedSyncFailureSchema,
+ TransactionRefundRequestedSyncSuccessSchema,
+ TransactionSessionActionRequiredSchema,
+ TransactionSessionFailureSchema,
+ TransactionSessionSuccessSchema,
+)
+
+# The list with schemas that should be exported to JSON files.
+SCHEMAS_TO_EXPORT = [
+ # taxes
+ {
+ "title": "CheckoutCalculateTaxes",
+ "schema": CalculateTaxesSchema,
+ },
+ {
+ "title": "OrderCalculateTaxes",
+ "schema": CalculateTaxesSchema,
+ },
+ {
+ "title": "ShippingListMethodsForCheckout",
+ "schema": ListShippingMethodsSchema,
+ },
+ # shipping
+ {
+ "title": "ShippingListMethodsForOrder",
+ "schema": ListShippingMethodsSchema,
+ },
+ {
+ "title": "CheckoutFilterShippingMethods",
+ "schema": FilterShippingMethodsSchema,
+ },
+ {
+ "title": "OrderFilterShippingMethods",
+ "schema": FilterShippingMethodsSchema,
+ },
+ # payment
+ {
+ "title": "ListStoredPaymentMethods",
+ "schema": ListStoredPaymentMethodsSchema,
+ },
+ {
+ "title": "StoredPaymentMethodDeleteRequested",
+ "schema": StoredPaymentMethodDeleteRequestedSchema,
+ },
+ {
+ "title": "PaymentGatewayInitializeTokenizationSession",
+ "schema": PaymentGatewayInitializeTokenizationSessionSchema,
+ },
+ # transaction
+ {
+ "title": "PaymentGatewayInitializeSession",
+ "schema": PaymentGatewayInitializeSessionSchema,
+ },
+]
+
+COMBINED_SCHEMAS_TO_EXPORT = [
+ # transaction
+ {
+ "title": "TransactionChargeRequested",
+ "schemas": [
+ TransactionChargeRequestedSyncSuccessSchema,
+ TransactionChargeRequestedSyncFailureSchema,
+ TransactionChargeRequestedAsyncSchema,
+ ],
+ },
+ {
+ "title": "TransactionRefundRequested",
+ "schemas": [
+ TransactionRefundRequestedSyncSuccessSchema,
+ TransactionRefundRequestedSyncFailureSchema,
+ TransactionRefundRequestedAsyncSchema,
+ ],
+ },
+ {
+ "title": "TransactionCancelationRequested",
+ "schemas": [
+ TransactionCancelationRequestedSyncSuccessSchema,
+ TransactionCancelationRequestedSyncFailureSchema,
+ TransactionCancelationRequestedAsyncSchema,
+ ],
+ },
+ {
+ "title": "TransactionInitializeSession",
+ "schemas": [
+ TransactionSessionSuccessSchema,
+ TransactionSessionFailureSchema,
+ TransactionSessionActionRequiredSchema,
+ ],
+ },
+ {
+ "title": "TransactionProcessSession",
+ "schemas": [
+ TransactionSessionSuccessSchema,
+ TransactionSessionFailureSchema,
+ TransactionSessionActionRequiredSchema,
+ ],
+ },
+ # payment
+ {
+ "title": "PaymentGatewayInitializeTokenizationSession",
+ "schemas": [
+ PaymentMethodTokenizationSuccessSchema,
+ PaymentMethodTokenizationPendingSchema,
+ PaymentMethodTokenizationFailedSchema,
+ ],
+ },
+]
diff --git a/saleor/webhook/response_schemas/payment.py b/saleor/webhook/response_schemas/payment.py
index bc221b6f1e..6fe80f263b 100644
--- a/saleor/webhook/response_schemas/payment.py
+++ b/saleor/webhook/response_schemas/payment.py
@@ -5,7 +5,6 @@ from pydantic import (
AfterValidator,
BaseModel,
Field,
- JsonValue,
ValidationInfo,
field_validator,
model_validator,
@@ -19,8 +18,13 @@ from ...payment.interface import (
PaymentMethodTokenizationResult,
StoredPaymentMethodRequestDeleteResult,
)
-from ..transport.utils import to_payment_app_id
-from .utils.annotations import DefaultIfNone, EnumByName, OnErrorDefault, OnErrorSkip
+from .utils.annotations import (
+ DefaultIfNone,
+ EnumByName,
+ JSONValue,
+ OnErrorDefault,
+ OnErrorSkip,
+)
from .utils.validators import lower_values
TokenizedPaymentFlowEnum = Enum( # type: ignore[misc]
@@ -89,7 +93,7 @@ class StoredPaymentMethodSchema(BaseModel):
),
]
data: Annotated[
- DefaultIfNone[JsonValue],
+ DefaultIfNone[JSONValue],
Field(
description="JSON data that will be returned to client.",
default=None,
@@ -140,7 +144,7 @@ class PaymentGatewayInitializeTokenizationSessionSchema(BaseModel):
),
]
data: Annotated[
- DefaultIfNone[JsonValue],
+ DefaultIfNone[JSONValue],
Field(
default=None,
description="A data required to finalize the initialization.",
@@ -156,6 +160,8 @@ class PaymentGatewayInitializeTokenizationSessionSchema(BaseModel):
def clean_id(payment_method_id: str, info: ValidationInfo) -> str:
+ from ..transport.utils import to_payment_app_id
+
app: App | None = info.context.get("app", None) if info.context else None
if not app:
raise RuntimeError("Missing app in context")
@@ -179,7 +185,7 @@ class PaymentMethodTokenizationSuccessSchema(BaseModel):
AfterValidator(clean_result),
]
data: Annotated[
- DefaultIfNone[JsonValue],
+ DefaultIfNone[JSONValue],
Field(
description="A data passes to the client.",
default=None,
@@ -205,7 +211,7 @@ class PaymentMethodTokenizationPendingSchema(BaseModel):
AfterValidator(clean_result),
]
data: Annotated[
- DefaultIfNone[JsonValue],
+ DefaultIfNone[JSONValue],
Field(
description="A data passes to the client.",
default=None,
diff --git a/saleor/webhook/response_schemas/taxes.py b/saleor/webhook/response_schemas/taxes.py
index 8168bbc195..d5349499c0 100644
--- a/saleor/webhook/response_schemas/taxes.py
+++ b/saleor/webhook/response_schemas/taxes.py
@@ -7,13 +7,13 @@ from ...core.prices import MAXIMUM_PRICE
class LineCalculateTaxesSchema(BaseModel):
- tax_rate: Annotated[Decimal, Field(ge=0, le=100)]
+ tax_rate: Annotated[Decimal, Field(ge=0)]
total_gross_amount: Annotated[Decimal, Field(ge=0, le=MAXIMUM_PRICE)]
total_net_amount: Annotated[Decimal, Field(ge=0, le=MAXIMUM_PRICE)]
class CalculateTaxesSchema(BaseModel):
- shipping_tax_rate: Annotated[Decimal, Field(ge=0, le=100)]
+ shipping_tax_rate: Annotated[Decimal, Field(ge=0)]
shipping_price_gross_amount: Annotated[Decimal, Field(ge=0, le=MAXIMUM_PRICE)]
shipping_price_net_amount: Annotated[Decimal, Field(ge=0, le=MAXIMUM_PRICE)]
lines: list[LineCalculateTaxesSchema] = []
diff --git a/saleor/webhook/response_schemas/transaction.py b/saleor/webhook/response_schemas/transaction.py
index f6305afeab..7e1255c923 100644
--- a/saleor/webhook/response_schemas/transaction.py
+++ b/saleor/webhook/response_schemas/transaction.py
@@ -10,7 +10,6 @@ from pydantic import (
BaseModel,
Field,
HttpUrl,
- JsonValue,
field_validator,
)
@@ -20,7 +19,7 @@ from ...payment import (
TransactionAction,
TransactionEventType,
)
-from .utils.annotations import DatetimeUTC, DefaultIfNone, OnErrorSkipLiteral
+from .utils.annotations import DatetimeUTC, DefaultIfNone, JSONValue, OnErrorSkipLiteral
logger = logging.getLogger(__name__)
@@ -224,18 +223,18 @@ class TransactionChargeRequestedSyncFailureSchema(TransactionSyncFailureSchema):
]
-class TransactionCancelRequestedAsyncSchema(TransactionAsyncSchema):
+class TransactionCancelationRequestedAsyncSchema(TransactionAsyncSchema):
pass
-class TransactionCancelRequestedSyncSuccessSchema(TransactionSyncSuccessSchema):
+class TransactionCancelationRequestedSyncSuccessSchema(TransactionSyncSuccessSchema):
result: Annotated[ # type: ignore[name-defined]
Literal[TransactionEventTypeEnum.CANCEL_SUCCESS.name,],
Field(description="Result of the action"),
]
-class TransactionCancelRequestedSyncFailureSchema(TransactionSyncFailureSchema):
+class TransactionCancelationRequestedSyncFailureSchema(TransactionSyncFailureSchema):
result: Annotated[ # type: ignore[name-defined]
Literal[TransactionEventTypeEnum.CANCEL_FAILURE.name,],
Field(description="Result of the action"),
@@ -262,7 +261,7 @@ class TransactionRefundRequestedSyncFailureSchema(TransactionSyncFailureSchema):
class TransactionSessionBaseSchema(TransactionBaseSchema):
data: Annotated[
- DefaultIfNone[JsonValue],
+ DefaultIfNone[JSONValue],
Field(
description="The JSON data that will be returned to storefront",
default=None,
@@ -326,4 +325,4 @@ class TransactionSessionSuccessSchema(TransactionSessionBaseSchema):
class PaymentGatewayInitializeSessionSchema(BaseModel):
- data: JsonValue
+ data: JSONValue
diff --git a/saleor/webhook/response_schemas/utils/annotations.py b/saleor/webhook/response_schemas/utils/annotations.py
index c7eb05aa52..4b1c6c2eed 100644
--- a/saleor/webhook/response_schemas/utils/annotations.py
+++ b/saleor/webhook/response_schemas/utils/annotations.py
@@ -3,10 +3,13 @@ from datetime import UTC, datetime
from enum import Enum
from typing import Annotated, Any, TypeVar
+import pydantic
from pydantic import (
AfterValidator,
BeforeValidator,
+ Field,
GetCoreSchemaHandler,
+ TypeAdapter,
ValidationError,
ValidationInfo,
ValidatorFunctionWrapHandler,
@@ -15,6 +18,7 @@ from pydantic import (
from pydantic_core import PydanticOmit, PydanticUseDefault, core_schema
from ....core.utils.metadata_manager import metadata_is_valid
+from ....payment import interface
M = TypeVar("M")
logger = logging.getLogger(__name__)
@@ -146,3 +150,24 @@ class EnumName:
EnumByName = Annotated[T, EnumName()]
+
+
+class JSONValue:
+ """A wrapper to allow Pydantic to generate schema for JsonValue."""
+
+ @classmethod
+ def __get_pydantic_core_schema__(
+ cls, source_type, handler: GetCoreSchemaHandler
+ ) -> core_schema.CoreSchema:
+ # Use the original JsonValue schema (full validation)
+ json_schema = handler(pydantic.JsonValue)
+ return json_schema
+
+ @classmethod
+ def __get_pydantic_json_schema__(cls, core_schema, handler):
+ # Return a standard JSON-compatible schema (no recursion errors)
+ Json = Annotated[
+ interface.JSONValue,
+ Field(title="JsonValue"),
+ ]
+ return TypeAdapter(Json).json_schema()
diff --git a/saleor/webhook/tests/response_schemas/test_taxes.py b/saleor/webhook/tests/response_schemas/test_taxes.py
index 6045f903bc..0018b7e129 100644
--- a/saleor/webhook/tests/response_schemas/test_taxes.py
+++ b/saleor/webhook/tests/response_schemas/test_taxes.py
@@ -18,7 +18,7 @@ from ...response_schemas.taxes import CalculateTaxesSchema, LineCalculateTaxesSc
},
# String values with decimal points
{
- "tax_rate": "20.12",
+ "tax_rate": "120.12",
"total_gross_amount": "100.33",
"total_net_amount": "80.23",
},
@@ -73,9 +73,9 @@ def test_line_calculate_taxes_schema_valid(data):
"total_gross_amount": 100,
"total_net_amount": Decimal("-80.00"),
},
- # Invalid tax_rate (greater than 100)
+ # Negative tax_rate
{
- "tax_rate": Decimal("120.00"),
+ "tax_rate": Decimal("-120.00"),
"total_gross_amount": Decimal("100.00"),
"total_net_amount": Decimal("80.00"),
},
@@ -122,7 +122,7 @@ def test_line_calculate_taxes_schema_invalid(data):
],
},
{
- "shipping_tax_rate": 10,
+ "shipping_tax_rate": 110,
"shipping_price_gross_amount": 110,
"shipping_price_net_amount": 100,
"lines": [],
@@ -200,10 +200,10 @@ def test_calculate_taxes_schema_valid(data):
},
0,
),
- # Invalid case with shipping_tax_rate greater than 100
+ # Invalid case with negative shipping_tax_rate
(
{
- "shipping_tax_rate": Decimal("120.00"),
+ "shipping_tax_rate": -Decimal("120.00"),
"shipping_price_gross_amount": "110",
"shipping_price_net_amount": "100",
"lines": [
diff --git a/saleor/webhook/tests/response_schemas/test_transaction.py b/saleor/webhook/tests/response_schemas/test_transaction.py
index c3c9259702..1a99a0729f 100644
--- a/saleor/webhook/tests/response_schemas/test_transaction.py
+++ b/saleor/webhook/tests/response_schemas/test_transaction.py
@@ -11,9 +11,9 @@ from ....payment import TransactionAction, TransactionEventType
from ...response_schemas.transaction import (
PaymentGatewayInitializeSessionSchema,
TransactionBaseSchema,
- TransactionCancelRequestedAsyncSchema,
- TransactionCancelRequestedSyncFailureSchema,
- TransactionCancelRequestedSyncSuccessSchema,
+ TransactionCancelationRequestedAsyncSchema,
+ TransactionCancelationRequestedSyncFailureSchema,
+ TransactionCancelationRequestedSyncSuccessSchema,
TransactionChargeRequestedAsyncSchema,
TransactionChargeRequestedSyncFailureSchema,
TransactionChargeRequestedSyncSuccessSchema,
@@ -376,7 +376,7 @@ def test_transaction_cancel_requested_sync_success_schema_valid():
}
# when
- transaction = TransactionCancelRequestedSyncSuccessSchema.model_validate(data)
+ transaction = TransactionCancelationRequestedSyncSuccessSchema.model_validate(data)
# then
assert transaction.result == result
@@ -401,7 +401,7 @@ def test_transaction_cancel_requested_sync_success_schema_invalid(result):
# when
with pytest.raises(ValidationError) as exc_info:
- TransactionCancelRequestedSyncSuccessSchema.model_validate(data)
+ TransactionCancelationRequestedSyncSuccessSchema.model_validate(data)
# then
assert len(exc_info.value.errors()) == 1
@@ -422,7 +422,7 @@ def test_transaction_cancel_requested_sync_failure_schema_valid():
}
# when
- transaction = TransactionCancelRequestedSyncFailureSchema.model_validate(data)
+ transaction = TransactionCancelationRequestedSyncFailureSchema.model_validate(data)
# then
assert transaction.result == result
@@ -447,7 +447,7 @@ def test_transaction_cancel_requested_sync_failure_schema_invalid(result):
# when
with pytest.raises(ValidationError) as exc_info:
- TransactionCancelRequestedSyncFailureSchema.model_validate(data)
+ TransactionCancelationRequestedSyncFailureSchema.model_validate(data)
# then
assert len(exc_info.value.errors()) == 1
@@ -462,7 +462,7 @@ def test_transaction_cancel_requested_async_schema_valid():
}
# when
- transaction = TransactionCancelRequestedAsyncSchema.model_validate(data)
+ transaction = TransactionCancelationRequestedAsyncSchema.model_validate(data)
# then
assert transaction.psp_reference == "psp-async-123"
@@ -477,7 +477,7 @@ def test_transaction_cancel_requested_async_schema_invalid():
# when
with pytest.raises(ValidationError) as exc_info:
- TransactionCancelRequestedAsyncSchema.model_validate(data)
+ TransactionCancelationRequestedAsyncSchema.model_validate(data)
# then
assert len(exc_info.value.errors()) == 1
diff --git a/saleor/webhook/transport/list_stored_payment_methods.py b/saleor/webhook/transport/list_stored_payment_methods.py
index c82f35467f..d81229fd23 100644
--- a/saleor/webhook/transport/list_stored_payment_methods.py
+++ b/saleor/webhook/transport/list_stored_payment_methods.py
@@ -1,4 +1,5 @@
import logging
+from typing import cast
import graphene
from django.core.cache import cache
@@ -6,6 +7,7 @@ from pydantic import ValidationError
from ...app.models import App
from ...payment.interface import (
+ JSONValue,
PaymentGateway,
PaymentGatewayInitializeTokenizationResponseData,
PaymentGatewayInitializeTokenizationResult,
@@ -65,7 +67,7 @@ def get_list_stored_payment_methods_from_response(
if payment_method.credit_card_info
else None,
name=payment_method.name,
- data=payment_method.data,
+ data=payment_method.data, # type: ignore[arg-type]
gateway=PaymentGateway(
id=app_identifier, name=app.name, currencies=[currency], config=[]
),
@@ -140,6 +142,7 @@ def get_response_for_payment_gateway_initialize_tokenization(
result = PaymentGatewayInitializeTokenizationResult.FAILED_TO_INITIALIZE
error = parse_validation_error(e)
+ data = cast(JSONValue, data)
return PaymentGatewayInitializeTokenizationResponseData(
result=result, error=error, data=data
)