Przeliczanie koszyka¶
Możliwe, że użytkownik chce zmodyfikować koszyk zmieniając ilość produktu lub dodając kod rabatowy. W przypadku zmiany ilości, OpenApp musi zweryfikować tę zmianę, aby mieć pewność dostępności produktu w nowej ilości i wpływu tej zmiany na koszty dostawy. Podobnie w przypadku dodania kodu rabatowego bezpośrednio w aplikacji OpenApp.
sequenceDiagram
autonumber
actor User
participant OpenApp
participant Merchant
Merchant->>User: show OpenApp widget
User->>User: scan widget
User->>+OpenApp: load basket
OpenApp->>+Merchant: retrieve basket
Merchant->>-OpenApp: send basket
OpenApp->>-User: send basket
User->>+OpenApp: add discount coupon
OpenApp->>+Merchant: recalculate basket
Merchant->>-OpenApp: send basket
OpenApp->>-User: send basket
User->>+OpenApp: confirm
OpenApp->>OpenApp: validate payment
OpenApp->>+Merchant: place order
Merchant->>-OpenApp: confirm
OpenApp->>-User: confirm
Request¶
W takim przypadku OpenApp wykona POST HTTP do endpointu skonfigurowanego w panelu sprzedawcy, ze zaktualizowanym koszykiem w treści żądania:
Więc jeśli skonfigurowałeś URL przeliczania koszyka na https://shop.example.com/api/openapp/basket
, OpenApp wyśle następujące żądanie do serwera:
Treść zapytania zawiera szczegóły koszyka zmienione przez użytkownika. Na przykład:
{
"description": "Basket recalculate request",
"additionalProperties": false,
"type": "object",
"properties": {
"requestId": {
"description": "The ID of the request as generated by OpenApp.",
"maxLength": 36,
"type": "string",
"title": "requestId"
},
"id": {
"description": "A null value for the basket id indicates that this is a request to create a new basket for a repurchase.",
"maxLength": 36,
"type": "string",
"title": "id"
},
"price": {
"$ref": "#/definitions/RecalculatePrice",
"title": "price"
},
"products": {
"type": "array",
"items": {
"$ref": "#/definitions/RecalculateProduct"
},
"title": "products"
},
"loggedUser": {
"type": "string",
"title": "loggedUser"
}
},
"required": [
"price",
"products",
"requestId"
],
"definitions": {
"RecalculatePrice": {
"title": "RecalculatePrice",
"type": "object",
"properties": {
"currency": {
"description": "The currency",
"type": "string",
"title": "currency"
},
"discounts": {
"description": "Discounts to apply in price calculation.",
"type": "array",
"items": {
"$ref": "#/definitions/RecalculateDiscount"
},
"title": "discounts"
}
},
"required": [
"currency",
"discounts"
]
},
"RecalculateDiscount": {
"title": "RecalculateDiscount",
"type": "object",
"properties": {
"code": {
"description": "The discount code.",
"maxLength": 36,
"type": "string",
"title": "code"
}
},
"required": [
"code"
]
},
"RecalculateProduct": {
"title": "RecalculateProduct",
"type": "object",
"properties": {
"ean": {
"description": "The ean (or other barcode on the product). Specifying this allows the user to search in his order history by scanning the barcode to do a re-purchase.",
"maxLength": 36,
"type": "string",
"title": "ean"
},
"id": {
"description": "The unique ID of the product.",
"maxLength": 36,
"type": "string",
"title": "id"
},
"quantity": {
"description": "The requested quantity",
"type": "number",
"title": "quantity"
}
},
"required": [
"id",
"quantity"
]
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
}
Response¶
W odpowiedzi sklep powinien przesłać zawartość koszyka i dostępne opcje dostawy w takim samym formacie, jak w przypadku odpowiedzi na pobranie koszyka. Oczywiście może się zdarzyć, że sklep nie będzie w stanie sprostać żądanej zmianie koszyka, na przykład z powodu niedostępności większej liczby produktu. W tym scenariuszu sklep powininien odpowiedzieć z dostępną częścią koszyka oraz kodem błędu, aby OpenApp mógł wyświetlic te informacje użytkownikowi. Pokazuje to poniższy przykład:
Powyższy przykład reprezentuje bardzo prosty koszyk. Po pełny opis modelu koszyka sprawdź JSON schema koszyka