Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2090 from OpenBazaar/brian.checkoutBreakdown
Browse files Browse the repository at this point in the history
Add /ob/checkoutbreakdown Endpoint
  • Loading branch information
cpacia committed Jun 30, 2020
2 parents e981100 + c74057a commit e02ac53
Show file tree
Hide file tree
Showing 4 changed files with 385 additions and 56 deletions.
2 changes: 2 additions & 0 deletions api/endpoints.go
Expand Up @@ -91,6 +91,8 @@ func post(i *jsonAPIHandler, path string, w http.ResponseWriter, r *http.Request
i.POSTShutdown(w, r)
case strings.HasPrefix(path, "/ob/estimatetotal"):
i.POSTEstimateTotal(w, r)
case strings.HasPrefix(path, "/ob/checkoutbreakdown"):
i.POSTCheckoutBreakdown(w, r)
case strings.HasPrefix(path, "/ob/fetchratings"):
i.POSTFetchRatings(w, r)
case strings.HasPrefix(path, "/ob/sales"):
Expand Down
23 changes: 23 additions & 0 deletions api/jsonapi.go
Expand Up @@ -3578,6 +3578,29 @@ func (i *jsonAPIHandler) GETFees(w http.ResponseWriter, r *http.Request) {
SanitizedResponse(w, string(out))
}

func (i *jsonAPIHandler) POSTCheckoutBreakdown(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
var data repo.PurchaseData
err := decoder.Decode(&data)
if err != nil {
ErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
cb, err := i.node.CheckoutBreakdown(&data)
if err != nil {
ErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

out, err := json.MarshalIndent(cb, "", " ")
if err != nil {
ErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

SanitizedResponse(w, string(out))
}

func (i *jsonAPIHandler) POSTEstimateTotal(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
var data repo.PurchaseData
Expand Down

0 comments on commit e02ac53

Please sign in to comment.