Skip to content

Commit 2fa07e7

Browse files
Merge pull request #205 from RedisLabs/feat/marketplace-payment-essentials-sub
Splitting FixedSubscription into request and response
2 parents f69bb47 + 0d91d29 commit 2fa07e7

File tree

5 files changed

+54
-19
lines changed

5 files changed

+54
-19
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,34 @@
22
All notable changes to this project will be documented in this file.
33
See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/).
44

5+
## 0.27.0
6+
7+
### Updated
8+
9+
* Splitting Fixed Subscription structs into response and request structs, as JSON fields differ between the two uses.
10+
11+
## 0.26.0
12+
13+
### Fixed
14+
15+
* Fixes to the AA regions endpoint: removing the unfilled RegionId field and correcting the JSON for the DeploymentCidr field.
516

617
## 0.25.0
718

19+
### Added
20+
821
* Added payment method to the fixed subscription API. This should allow payments via the marketplace as well as credit cards.
922

1023
## 0.24.0
1124

25+
### Added
26+
*
1227
* Add endpoint for Active Active regions.
1328

1429
## 0.23.0
1530

31+
### Added
32+
1633
* Add Query Performance Factor property to subscription and database models
1734

1835
## 0.22.0

fixed_subscription_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestFixedSubscription_Create(t *testing.T) {
9090

9191
actual, err := subject.FixedSubscriptions.Create(
9292
context.TODO(),
93-
fixedSubscriptions.FixedSubscription{
93+
fixedSubscriptions.FixedSubscriptionRequest{
9494
Name: redis.String("My test fixed subscription"),
9595
PlanId: redis.Int(34858),
9696
PaymentMethodID: redis.Int(30949),
@@ -179,7 +179,7 @@ func TestFixedSubscription_Create_Marketplace(t *testing.T) {
179179

180180
actual, err := subject.FixedSubscriptions.Create(
181181
context.TODO(),
182-
fixedSubscriptions.FixedSubscription{
182+
fixedSubscriptions.FixedSubscriptionRequest{
183183
Name: redis.String("My test fixed subscription with marketplace payments"),
184184
PlanId: redis.Int(34811),
185185
PaymentMethod: redis.String("marketplace"),
@@ -274,13 +274,14 @@ func TestFixedSubscription_List(t *testing.T) {
274274
actual, err := subject.FixedSubscriptions.List(context.TODO())
275275
require.NoError(t, err)
276276

277-
assert.ElementsMatch(t, []*fixedSubscriptions.FixedSubscription{
277+
assert.ElementsMatch(t, []*fixedSubscriptions.FixedSubscriptionResponse{
278278
{
279279
ID: redis.Int(111614),
280280
Name: redis.String("My test fixed subscription"),
281281
Status: redis.String("active"),
282282
PlanId: redis.Int(34858),
283283
PaymentMethodID: redis.Int(30949),
284+
PaymentMethod: redis.String("credit-card"),
284285
CreationDate: redis.Time(time.Date(2024, 5, 9, 9, 36, 18, 0, time.UTC)),
285286
},
286287
{
@@ -289,6 +290,7 @@ func TestFixedSubscription_List(t *testing.T) {
289290
Status: redis.String("active"),
290291
PlanId: redis.Int(34858),
291292
PaymentMethodID: redis.Int(30949),
293+
PaymentMethod: redis.String("credit-card"),
292294
CreationDate: redis.Time(time.Date(2024, 5, 9, 10, 49, 52, 0, time.UTC)),
293295
},
294296
}, actual)
@@ -345,11 +347,12 @@ func TestFixedSubscription_Get(t *testing.T) {
345347
actual, err := subject.FixedSubscriptions.Get(context.TODO(), 111614)
346348
require.NoError(t, err)
347349

348-
assert.Equal(t, &fixedSubscriptions.FixedSubscription{
350+
assert.Equal(t, &fixedSubscriptions.FixedSubscriptionResponse{
349351
ID: redis.Int(111614),
350352
Name: redis.String("My test fixed subscription"),
351353
Status: redis.String("active"),
352354
PlanId: redis.Int(34858),
355+
PaymentMethod: redis.String("credit-card"),
353356
PaymentMethodID: redis.Int(30949),
354357
CreationDate: redis.Time(time.Date(2024, 5, 9, 9, 36, 18, 0, time.UTC)),
355358
}, actual)
@@ -439,7 +442,7 @@ func TestFixedSubscription_Update(t *testing.T) {
439442
err = subject.FixedSubscriptions.Update(
440443
context.TODO(),
441444
111614,
442-
fixedSubscriptions.FixedSubscription{
445+
fixedSubscriptions.FixedSubscriptionRequest{
443446
Name: redis.String("My renamed fixed subscription"),
444447
PlanId: redis.Int(34853),
445448
},

service/fixed/subscriptions/model.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,35 @@ import (
77
"github.com/RedisLabs/rediscloud-go-api/internal"
88
)
99

10-
type FixedSubscription struct {
11-
ID *int `json:"id,omitempty"` // Omit for Create and Update
10+
// Represents request information to create/update a fixed subscription
11+
type FixedSubscriptionRequest struct {
12+
Name *string `json:"name,omitempty"`
13+
PlanId *int `json:"planId,omitempty"`
14+
PaymentMethod *string `json:"paymentMethod,omitempty"`
15+
PaymentMethodID *int `json:"paymentMethodId,omitempty"`
16+
}
17+
18+
// Represents subscription info response from the get/list endpoints
19+
type FixedSubscriptionResponse struct {
20+
ID *int `json:"id,omitempty"`
1221
Name *string `json:"name,omitempty"`
13-
Status *string `json:"status,omitempty"` // Omit for Create and Update
22+
Status *string `json:"status,omitempty"`
1423
PlanId *int `json:"planId,omitempty"`
15-
PaymentMethod *string `json:"paymentMethod,omitempty"`
24+
PaymentMethod *string `json:"paymentMethodType,omitempty"`
1625
PaymentMethodID *int `json:"paymentMethodId,omitempty"`
17-
CreationDate *time.Time `json:"creationDate,omitempty"` // Omit for Create and Update
26+
CreationDate *time.Time `json:"creationDate,omitempty"`
27+
}
28+
29+
func (o FixedSubscriptionRequest) String() string {
30+
return internal.ToString(o)
1831
}
1932

20-
func (o FixedSubscription) String() string {
33+
func (o FixedSubscriptionResponse) String() string {
2134
return internal.ToString(o)
2235
}
2336

2437
type listFixedSubscriptionResponse struct {
25-
FixedSubscriptions []*FixedSubscription `json:"subscriptions"`
38+
FixedSubscriptions []*FixedSubscriptionResponse `json:"subscriptions"`
2639
}
2740

2841
type NotFound struct {

service/fixed/subscriptions/service.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewAPI(client HttpClient, taskWaiter TaskWaiter, logger Log) *API {
3535
}
3636

3737
// Create will create a new subscription.
38-
func (a *API) Create(ctx context.Context, subscription FixedSubscription) (int, error) {
38+
func (a *API) Create(ctx context.Context, subscription FixedSubscriptionRequest) (int, error) {
3939
var task internal.TaskResponse
4040
err := a.client.Post(ctx, "create fixed subscription", "/fixed/subscriptions", subscription, &task)
4141
if err != nil {
@@ -53,7 +53,7 @@ func (a *API) Create(ctx context.Context, subscription FixedSubscription) (int,
5353
}
5454

5555
// List will list all of the current account's fixed subscriptions.
56-
func (a *API) List(ctx context.Context) ([]*FixedSubscription, error) {
56+
func (a *API) List(ctx context.Context) ([]*FixedSubscriptionResponse, error) {
5757
var response listFixedSubscriptionResponse
5858
err := a.client.Get(ctx, "list fixed subscriptions", "/fixed/subscriptions", &response)
5959
if err != nil {
@@ -64,8 +64,8 @@ func (a *API) List(ctx context.Context) ([]*FixedSubscription, error) {
6464
}
6565

6666
// Get will retrieve an existing fixed subscription.
67-
func (a *API) Get(ctx context.Context, id int) (*FixedSubscription, error) {
68-
var response FixedSubscription
67+
func (a *API) Get(ctx context.Context, id int) (*FixedSubscriptionResponse, error) {
68+
var response FixedSubscriptionResponse
6969
err := a.client.Get(ctx, fmt.Sprintf("retrieve fixed subscription %d", id), fmt.Sprintf("/fixed/subscriptions/%d", id), &response)
7070
if err != nil {
7171
return nil, wrap404Error(id, err)
@@ -75,7 +75,7 @@ func (a *API) Get(ctx context.Context, id int) (*FixedSubscription, error) {
7575
}
7676

7777
// Update will make changes to an existing fixed subscription.
78-
func (a *API) Update(ctx context.Context, id int, subscription FixedSubscription) error {
78+
func (a *API) Update(ctx context.Context, id int, subscription FixedSubscriptionRequest) error {
7979
var task internal.TaskResponse
8080
err := a.client.Put(ctx, fmt.Sprintf("update fixed subscription %d", id), fmt.Sprintf("/fixed/subscriptions/%d", id), subscription, &task)
8181
if err != nil {

subscription_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ func TestSubscription_List(t *testing.T) {
152152
"id": 1,
153153
"name": "sdk",
154154
"status": "active",
155-
"paymentMethodType": "credit-card",
156155
"paymentMethodId": 2,
156+
"paymentMethodType": "credit-card",
157157
"memoryStorage": "ram",
158158
"storageEncryption": false,
159159
"numberOfDatabases": 1,
@@ -210,6 +210,7 @@ func TestSubscription_List(t *testing.T) {
210210
"name": "TF Example Subscription demo",
211211
"status": "pending",
212212
"paymentMethodId": 3,
213+
"paymentMethodType": "credit-card",
213214
"memoryStorage": "ram",
214215
"storageEncryption": false,
215216
"numberOfDatabases": 0,
@@ -260,8 +261,8 @@ func TestSubscription_List(t *testing.T) {
260261
ID: redis.Int(1),
261262
Name: redis.String("sdk"),
262263
Status: redis.String("active"),
263-
PaymentMethod: redis.String("credit-card"),
264264
PaymentMethodID: redis.Int(2),
265+
PaymentMethod: redis.String("credit-card"),
265266
MemoryStorage: redis.String("ram"),
266267
StorageEncryption: redis.Bool(false),
267268
NumberOfDatabases: redis.Int(1),
@@ -291,6 +292,7 @@ func TestSubscription_List(t *testing.T) {
291292
Name: redis.String("TF Example Subscription demo"),
292293
Status: redis.String("pending"),
293294
PaymentMethodID: redis.Int(3),
295+
PaymentMethod: redis.String("credit-card"),
294296
MemoryStorage: redis.String("ram"),
295297
StorageEncryption: redis.Bool(false),
296298
NumberOfDatabases: redis.Int(0),

0 commit comments

Comments
 (0)