forked from getconversio/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 256
/
fulfillment_request.go
73 lines (62 loc) · 3.39 KB
/
fulfillment_request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package goshopify
import (
"context"
"fmt"
)
const (
fulfillmentRequestBasePath = "fulfillment_orders"
)
// FulfillmentRequestService is an interface for interfacing with the fulfillment request endpoints of the Shopify API.
// https://shopify.dev/docs/api/admin-rest/2023-10/resources/fulfillmentrequest
type FulfillmentRequestService interface {
Send(context.Context, uint64, FulfillmentRequest) (*FulfillmentOrder, error)
Accept(context.Context, uint64, FulfillmentRequest) (*FulfillmentOrder, error)
Reject(context.Context, uint64, FulfillmentRequest) (*FulfillmentOrder, error)
}
type FulfillmentRequest struct {
Message string `json:"message,omitempty"`
FulfillmentOrderLineItems []FulfillmentOrderLineItem `json:"fulfillment_order_line_items,omitempty"`
Reason string `json:"reason,omitempty"`
LineItems []FulfillmentRequestLineItem `json:"line_items,omitempty"`
}
type FulfillmentRequestOrderLineItem struct {
Id uint64 `json:"id"`
Quantity uint64 `json:"quantity"`
}
type FulfillmentRequestLineItem struct {
FulfillmentOrderLineItemId uint64 `json:"fulfillment_order_line_item_id,omitempty"`
Message string `json:"message,omitempty"`
}
type FulfillmentRequestResource struct {
FulfillmentOrder *FulfillmentOrder `json:"fulfillment_order,omitempty"`
FulfillmentRequest FulfillmentRequest `json:"fulfillment_request,omitempty"`
OriginalFulfillmentOrder *FulfillmentOrder `json:"original_fulfillment_order,omitempty"`
}
// FulfillmentRequestServiceOp handles communication with the fulfillment request related methods of the Shopify API.
type FulfillmentRequestServiceOp struct {
client *Client
}
// Send sends a fulfillment request to the fulfillment service of a fulfillment order.
func (s *FulfillmentRequestServiceOp) Send(ctx context.Context, fulfillmentOrderId uint64, request FulfillmentRequest) (*FulfillmentOrder, error) {
path := fmt.Sprintf("%s/%d/fulfillment_request.json", fulfillmentRequestBasePath, fulfillmentOrderId)
wrappedData := FulfillmentRequestResource{FulfillmentRequest: request}
resource := new(FulfillmentRequestResource)
err := s.client.Post(ctx, path, wrappedData, resource)
return resource.OriginalFulfillmentOrder, err
}
// Accept accepts a fulfillment request sent to a fulfillment service for a fulfillment order.
func (s *FulfillmentRequestServiceOp) Accept(ctx context.Context, fulfillmentOrderId uint64, request FulfillmentRequest) (*FulfillmentOrder, error) {
path := fmt.Sprintf("%s/%d/fulfillment_request/accept.json", fulfillmentRequestBasePath, fulfillmentOrderId)
wrappedData := map[string]interface{}{"fulfillment_request": request}
resource := new(FulfillmentRequestResource)
err := s.client.Post(ctx, path, wrappedData, resource)
return resource.FulfillmentOrder, err
}
// Reject rejects a fulfillment request sent to a fulfillment service for a fulfillment order.
func (s *FulfillmentRequestServiceOp) Reject(ctx context.Context, fulfillmentOrderId uint64, request FulfillmentRequest) (*FulfillmentOrder, error) {
path := fmt.Sprintf("%s/%d/fulfillment_request/reject.json", fulfillmentRequestBasePath, fulfillmentOrderId)
wrappedData := map[string]interface{}{"fulfillment_request": request}
resource := new(FulfillmentRequestResource)
err := s.client.Post(ctx, path, wrappedData, resource)
return resource.FulfillmentOrder, err
}