Skip to content

Commit

Permalink
Merge pull request #15 from jjideenschmiede/development
Browse files Browse the repository at this point in the history
Create function to set fulfillment information
  • Loading branch information
gowizzard authored Oct 14, 2021
2 parents 13bf9dd + 0ac0cbf commit fce942a
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 20 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,29 @@ if err != nil {
} else {
fmt.Println(merchantOrderNumber)
}
```

## Set Fulfillment Information

If you want to assign the fulfillment to an order, you can do this with the following function. [Here](https://cdn.idealo.com/folder/Direktkauf/documentation/merchant-order-api-v2.html#resources-fulfillment-controller-it-set-fulfillment-information) you can find the description in the idealo documentation.

```go
// Define request
r := goidealo.Request{
AccessToken: "",
Sandbox: false,
}

// Define body
body := goidealo.FulfillmentInformationBody{
Carrier: "DHL",
TrackingCode: []string{"example-tracking-number-1234"},
}
// Set a merchant order number
fulfillmentInformation, err := goidealo.FulfillmentInformation(325081, "00REAVQH3Y", body, r)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(fulfillmentInformation)
}
```
111 changes: 91 additions & 20 deletions moa_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@ import (
"time"
)

// MerchantOrderNumberBody is to structure the data
type MerchantOrderNumberBody struct {
MerchantOrderNumber string `json:"merchantOrderNumber"`
}

// MerchantOrderNumberReturn is to decode the json return
type MerchantOrderNumberReturn struct {
Type string `json:"type"`
Title string `json:"title"`
Instance string `json:"instance"`
FieldErrors []struct {
Field string `json:"field"`
Message string `json:"message"`
} `json:"fieldErrors"`
}

// OrdersReturn is to decode the json return
type OrdersReturn struct {
Content []struct {
Expand Down Expand Up @@ -65,10 +49,10 @@ type OrdersReturn struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
AddressLine1 string `json:"addressLine1"`
AddressLine2 string `json:"addressLine2"`
PostalCode string `json:"postalCode"`
City string `json:"city"`
CountryCode string `json:"countryCode"`
AddressLine2 string `json:"addressLine2,omitempty"`
} `json:"billingAddress"`
ShippingAddress struct {
Salutation string `json:"salutation"`
Expand All @@ -80,9 +64,12 @@ type OrdersReturn struct {
CountryCode string `json:"countryCode"`
} `json:"shippingAddress"`
Fulfillment struct {
Method string `json:"method"`
Tracking []interface{} `json:"tracking"`
Options []interface{} `json:"options"`
Method string `json:"method"`
Tracking []struct {
Code string `json:"code"`
Carrier string `json:"carrier"`
} `json:"tracking"`
Options []interface{} `json:"options"`
} `json:"fulfillment"`
Refunds []interface{} `json:"refunds"`
} `json:"content"`
Expand Down Expand Up @@ -142,6 +129,39 @@ type OrderReturn struct {
Refunds []interface{} `json:"refunds"`
}

// MerchantOrderNumberBody is to structure the data
type MerchantOrderNumberBody struct {
MerchantOrderNumber string `json:"merchantOrderNumber"`
}

// MerchantOrderNumberReturn is to decode the json return
type MerchantOrderNumberReturn struct {
Type string `json:"type"`
Title string `json:"title"`
Instance string `json:"instance"`
FieldErrors []struct {
Field string `json:"field"`
Message string `json:"message"`
} `json:"fieldErrors"`
}

// FulfillmentInformationBody is to structure the data
type FulfillmentInformationBody struct {
Carrier string `json:"carrier"`
TrackingCode []string `json:"trackingCode"`
}

// FulfillmentInformationReturn is to decode the json return
type FulfillmentInformationReturn struct {
Type string `json:"type"`
Title string `json:"title"`
Instance string `json:"instance"`
FieldErrors []struct {
Field string `json:"field"`
Message string `json:"message"`
} `json:"fieldErrors"`
}

// Orders is to get a list of orders from the moa api
func Orders(shopId int, parameter map[string]string, r Request) (OrdersReturn, error) {

Expand Down Expand Up @@ -299,3 +319,54 @@ func MerchantOrderNumber(shopId int, id string, body MerchantOrderNumberBody, r
return decode, nil

}

// FulfillmentInformation is to set the fulfillment information
func FulfillmentInformation(shopId int, id string, body FulfillmentInformationBody, r Request) (FulfillmentInformationReturn, error) {

// Convert body data
convert, err := json.Marshal(body)
if err != nil {
return FulfillmentInformationReturn{}, err
}

// Config new request
c := Config{
Moa: true,
Path: fmt.Sprintf("/api/v2/shops/%d/orders/%s/fulfillment", shopId, id),
Method: "POST",
Body: convert,
}

// Check sandbox
if r.Sandbox {
c.Moa = false
c.MoaSandbox = true
}

// Send new request
response, err := c.Send(r)
if err != nil {
return FulfillmentInformationReturn{}, err
}

// Close request body
defer response.Body.Close()

// Check response status
err = pwsStatusCodes(response.Status)
if err != nil {
return FulfillmentInformationReturn{}, err
}

// Decode data
var decode FulfillmentInformationReturn

err = json.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return FulfillmentInformationReturn{}, err
}

// Return data
return decode, nil

}

0 comments on commit fce942a

Please sign in to comment.