Skip to content

Commit

Permalink
Merge pull request #18 from jjideenschmiede/development
Browse files Browse the repository at this point in the history
Create a function to read all refunds
  • Loading branch information
gowizzard authored Oct 15, 2021
2 parents 286be97 + 8d33aa1 commit 29efdaf
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 8 deletions.
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ body := goidealo.FulfillmentInformationBody{
Carrier: "DHL",
TrackingCode: []string{"example-tracking-number-1234"},
}
// Set a merchant order number
// Set a fulfillment information
fulfillmentInformation, err := goidealo.FulfillmentInformation(325081, "00REAVQH3Y", body, r)
if err != nil {
fmt.Println(err)
Expand All @@ -328,15 +328,15 @@ r := goidealo.Request{
}

// Define body
body := RevokeOrderBody{
body := goidealo.RevokeOrderBody{
Sku: "21-Lloyd-27-600-12-Hagen-UK6.5-Gr.40",
RemainingQuantity: 0,
Reason: "MERCHANT_DECLINE",
Comment: "Sorry, buddy.",
}

// Set a merchant order number
revokeOrder, err := RevokeOrder(325081, "00ALP766AM", body, r)
// Revoke an order
revokeOrder, err := goidealo.RevokeOrder(325081, "00ALP766AM", body, r)
if err != nil {
fmt.Println(err)
} else {
Expand All @@ -356,13 +356,33 @@ r := goidealo.Request{
}

// Define body
body := RefundOrderBody{
body := goidealo.RefundOrderBody{
RefundAmount: 1.99,
Currency: "EUR",
}

// Set a merchant order number
refundOrder, err := RefundOrder(325081, "00ALP766AM", body, r)
// Set a refund for an order
refundOrder, err := goidealo.RefundOrder(325081, "00ALP766AM", body, r)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(refundOrder)
}
```

## Get refunds

If you want to read out the refunds, this is done as follows. [Here](https://cdn.idealo.com/folder/Direktkauf/documentation/merchant-order-api-v2.html#resources-refund-controller-it-get-refunds) you can find the description in the idealo documentation.

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

// Get refunds
refundOrder, err := goidealo.Refunds(325081, "00ALP766AM", r)
if err != nil {
fmt.Println(err)
} else {
Expand Down
57 changes: 56 additions & 1 deletion moa_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,25 @@ type RefundOrderBody struct {
Currency string `json:"currency"`
}

// RefundOrderReturn is to decode the data
// RefundOrderReturn is to decode the json return
type RefundOrderReturn struct {
Type string `json:"type"`
Title string `json:"title"`
Instance string `json:"instance"`
Reason string `json:"reason"`
}

// RefundsReturn is to decode the json return
type RefundsReturn struct {
RefundId string `json:"refundId"`
RefundTransactionId string `json:"refundTransactionId"`
Status string `json:"status"`
Currency string `json:"currency"`
RefundAmount float64 `json:"refundAmount"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}

// 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 @@ -505,3 +516,47 @@ func RefundOrder(shopId int, id string, body RefundOrderBody, r Request) (Refund
return decode, nil

}

// Refunds is to check the refunds for an order
func Refunds(shopId int, id string, r Request) ([]RefundsReturn, error) {

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

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

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

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

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

// Decode data
var decode []RefundsReturn

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

// Return data
return decode, nil

}

0 comments on commit 29efdaf

Please sign in to comment.