-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder_status.go
70 lines (60 loc) · 1.68 KB
/
order_status.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
package smartbonus
import (
"fmt"
)
// List of order statuses
type OrderStatusType int
const (
NEW OrderStatusType = iota
PAYMENT_PENDING
PAYMENT_CANCELED
PROCESSING
AWAITING_SHIPMENT
AWAITING_PICKUP
COMPLETED
CANCELED
REFUNDED
AWAITING_WEB_PAYMENT
WEB_PAYMENT_SUCCESSFUL
_
AWAITING_FOR_COLLECT
COLLECTING
TRANSFERRED_FOR_DELIVERY
DELIVERING
CANCEL_REQUEST
AWAITING_POST_PAYMENT
)
func (OrderStatusType) getTitles() []string {
return []string{"new", "payment_pending", "payment_canceled", "processing", "awaiting_shipment", "awaiting_pickup", "completed", "canceled",
"refunded", "awaiting_web_payment", "web_payment_successful", "", "awaiting_for_collect", "collecting", "transferred_for_delivery",
"delivering", "cancel_request", "awaiting_post_payment"}
}
func (s OrderStatusType) Get(status string) (OrderStatusType, error) {
for i, st := range s.getTitles() {
if st == status {
return OrderStatusType(i), nil
}
}
return 0, fmt.Errorf("status is not found '%s'", status)
}
func (a OrderStatusType) String() string {
return a.getTitles()[a]
}
// Body of status:
type StatusBody struct {
Store
OrderId string `json:"order_id"` // identifier of order in smartbonus
Status OrderStatusType `json:"status"` // one of OrderStatuses
}
// Change status of order that created in smartbonus app
// If status changed client receive push notification about it
func changeOrderStatus(storeId string, statusBody StatusBody) error {
var result interface{}
statusBody.StoreId = storeId
if err := sendPostRequest(rootPath+"v2/order/status", statusBody, &result); err != nil {
return err
} else if result != nil {
return fmt.Errorf("%v", result)
}
return nil
}