Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkout: Add CartValidationResult to place order context if in failed state #319

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@

**checkout**
* Introducing Flamingo events on final states of the place order process
* API
* In case of an invalid cart during place order process we now expose the cart validation result, affected endpoints:
```
GET /api/v1/checkout/placeorder
POST /api/v1/checkout/placeorder/refresh
POST /api/v1/checkout/placeorder/refresh-blocking
```

**customer**
* Add mockery mocks for both `Customer` / `CustomerIdentityService` for easier testing
Expand Down
3 changes: 2 additions & 1 deletion cart/domain/validation/cartValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package validation

import (
"context"

"flamingo.me/flamingo-commerce/v3/cart/domain/decorator"

"flamingo.me/flamingo/v3/framework/web"
)

type (
//Result groups the validation result
// Result groups the validation result
Result struct {
HasCommonError bool
CommonErrorMessageKey string
Expand Down
33 changes: 21 additions & 12 deletions checkout/interfaces/controller/apicontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"flamingo.me/flamingo-commerce/v3/cart/domain/cart"
placeorderDomain "flamingo.me/flamingo-commerce/v3/cart/domain/placeorder"
"flamingo.me/flamingo-commerce/v3/cart/domain/validation"
"flamingo.me/flamingo-commerce/v3/checkout/application"
"flamingo.me/flamingo-commerce/v3/checkout/domain/placeorder/process"

Expand Down Expand Up @@ -35,12 +36,13 @@ type (

// placeOrderContext infos
placeOrderContext struct {
Cart *cart.Cart
OrderInfos *placedOrderInfos
State string
StateData process.StateData
UUID string
FailedReason string
Cart *cart.Cart
OrderInfos *placedOrderInfos
State string
StateData process.StateData
UUID string
FailedReason string
CartValidationResult *validation.Result
}

// placedOrderInfos infos
Expand Down Expand Up @@ -181,17 +183,24 @@ func (c *APIController) getPlaceOrderContext(ctx context.Context, pctx *process.
PlacedDecoratedCart: decoratedCart,
}
}

var validationResult *validation.Result
var failedReason string
if pctx.FailedReason != nil {
failedReason = pctx.FailedReason.Reason()
if reason, ok := pctx.FailedReason.(process.CartValidationErrorReason); ok {
validationResult = &reason.ValidationResult
}
}

return placeOrderContext{
Cart: &pctx.Cart,
OrderInfos: orderInfos,
State: pctx.CurrentStateName,
StateData: pctx.CurrentStateData,
FailedReason: failedReason,
UUID: pctx.UUID,
Cart: &pctx.Cart,
OrderInfos: orderInfos,
State: pctx.CurrentStateName,
StateData: pctx.CurrentStateData,
FailedReason: failedReason,
CartValidationResult: validationResult,
UUID: pctx.UUID,
}
}

Expand Down
3 changes: 3 additions & 0 deletions docs/openapi/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,9 @@ var doc = `{
"Cart": {
"$ref": "#/definitions/cart.Cart"
},
"CartValidationResult": {
"$ref": "#/definitions/validation.Result"
},
"FailedReason": {
"type": "string"
},
Expand Down
3 changes: 3 additions & 0 deletions docs/openapi/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,9 @@
"Cart": {
"$ref": "#/definitions/cart.Cart"
},
"CartValidationResult": {
"$ref": "#/definitions/validation.Result"
},
"FailedReason": {
"type": "string"
},
Expand Down
2 changes: 2 additions & 0 deletions docs/openapi/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ definitions:
properties:
Cart:
$ref: '#/definitions/cart.Cart'
CartValidationResult:
$ref: '#/definitions/validation.Result'
FailedReason:
type: string
OrderInfos:
Expand Down
2 changes: 1 addition & 1 deletion docs/swagger.go

Large diffs are not rendered by default.