Skip to content

Commit 8a6aadb

Browse files
authored
feat(billing): add support for RedeemCoupon (scaleway#2590)
1 parent f52d194 commit 8a6aadb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

api/billing/v2beta1/billing_sdk.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,15 @@ func (r *ListTaxesResponse) UnsafeAppend(res interface{}) (uint64, error) {
918918
return uint64(len(results.Taxes)), nil
919919
}
920920

921+
// RedeemCouponRequest: redeem coupon request.
922+
type RedeemCouponRequest struct {
923+
// OrganizationID: the Organization ID of the discount.
924+
OrganizationID string `json:"-"`
925+
926+
// Code: the code of the coupon to redeem.
927+
Code string `json:"-"`
928+
}
929+
921930
// This API allows you to manage and query your Scaleway billing and consumption.
922931
type API struct {
923932
client *scw.Client
@@ -1156,3 +1165,31 @@ func (s *API) ListDiscounts(req *ListDiscountsRequest, opts ...scw.RequestOption
11561165
}
11571166
return &resp, nil
11581167
}
1168+
1169+
// RedeemCoupon: Redeem a coupon given the related code.
1170+
func (s *API) RedeemCoupon(req *RedeemCouponRequest, opts ...scw.RequestOption) (*Discount, error) {
1171+
var err error
1172+
1173+
if req.OrganizationID == "" {
1174+
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
1175+
req.OrganizationID = defaultOrganizationID
1176+
}
1177+
1178+
query := url.Values{}
1179+
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
1180+
parameter.AddToQuery(query, "code", req.Code)
1181+
1182+
scwReq := &scw.ScalewayRequest{
1183+
Method: "POST",
1184+
Path: "/billing/v2beta1/redeem-coupon",
1185+
Query: query,
1186+
}
1187+
1188+
var resp Discount
1189+
1190+
err = s.client.Do(scwReq, &resp, opts...)
1191+
if err != nil {
1192+
return nil, err
1193+
}
1194+
return &resp, nil
1195+
}

0 commit comments

Comments
 (0)