github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/bss/v2/orders/requests.go (about) 1 package orders 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 ) 6 7 type UnsubscribeOpts struct { 8 ResourceIds []string `json:"resource_ids" required:"true"` 9 UnsubscribeType int `json:"unsubscribe_type" required:"true"` 10 } 11 12 type UnsubscribeOptsBuilder interface { 13 ToOrderUnsubscribeMap() (map[string]interface{}, error) 14 } 15 16 func (opts UnsubscribeOpts) ToOrderUnsubscribeMap() (map[string]interface{}, error) { 17 return golangsdk.BuildRequestBody(opts, "") 18 } 19 20 func Unsubscribe(client *golangsdk.ServiceClient, opts UnsubscribeOptsBuilder) (r UnsubscribeResult) { 21 reqBody, err := opts.ToOrderUnsubscribeMap() 22 if err != nil { 23 r.Err = err 24 return 25 } 26 _, r.Err = client.Post(unsubscribeURL(client), reqBody, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}}) 27 return 28 } 29 30 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 31 _, r.Err = client.Get(getURL(client, id), &r.Body, nil) 32 return 33 } 34 35 type PayOrderOpts struct { 36 OrderId string `json:"order_id" required:"true"` 37 // Whether coupons are used for order payment. If this parameter is set to YES, the coupon_infos 38 // field is mandatory. If this parameter is set to NO, the value of coupon_infos is ignored. 39 UseCoupon string `json:"use_coupon" required:"true"` 40 // Whether a discount is used for order payment. If this parameter is set to YES, the discount_infos 41 // field is mandatory. If this parameter is set to NO, the value of discount_infos is ignored. 42 UseDiscount string `json:"use_discount" required:"true"` 43 // The coupons info, if UseCoupon is set to YES, this parameter is mandatory 44 CouponInfos []CouponSimpleInfo `json:"coupon_infos,omitempty"` 45 // The discounts info, if UseDiscount is set to YES, this parameter is mandatory 46 DiscountInfos []DiscountSimpleInfo `json:"discount_infos,omitempty"` 47 } 48 49 type CouponSimpleInfo struct { 50 // Coupon ID 51 Id string `json:"id" required:"true"` 52 // Coupon type 53 // 300: Discount coupon (reserved) 54 // 301: Promotion coupon 55 // 302: Promotion flexi-purchase coupon (reserved) 56 // 303: Promotion stored-value card (reserved) 57 Type int `json:"type" required:"true"` 58 } 59 60 type DiscountSimpleInfo struct { 61 // Discount ID 62 Id string `json:"id" required:"true"` 63 // Discount type 64 // 0: promotion discount 65 // 2: commercial discount 66 // 3: discount granted by a partner 67 Type int `json:"type" required:"true"` 68 } 69 70 type PayOrderOptsBuilder interface { 71 ToPayOrderMap() (map[string]interface{}, error) 72 } 73 74 func (opts PayOrderOpts) ToPayOrderMap() (map[string]interface{}, error) { 75 return golangsdk.BuildRequestBody(opts, "") 76 } 77 78 func PayOrder(client *golangsdk.ServiceClient, opts PayOrderOptsBuilder) (r PayOrderResult) { 79 reqBody, err := opts.ToPayOrderMap() 80 if err != nil { 81 r.Err = err 82 return 83 } 84 _, r.Err = client.Post(payOrderURL(client), reqBody, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{204}}) 85 return 86 }