Skip to content

Commit

Permalink
Switch params order
Browse files Browse the repository at this point in the history
  • Loading branch information
gdeandradero committed Mar 13, 2024
1 parent d723d2d commit 084245e
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/apis/merchantorder/update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func main() {
},
}

order, err = client.Update(context.Background(), req, order.ID)
order, err = client.Update(context.Background(), order.ID, req)
if err != nil {
fmt.Println(err)
return
Expand Down
3 changes: 2 additions & 1 deletion examples/apis/preapproval/update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"

"github.com/mercadopago/sdk-go/pkg/config"
"github.com/mercadopago/sdk-go/pkg/preapproval"
)
Expand Down Expand Up @@ -46,7 +47,7 @@ func main() {
Reason: "Yoga Class",
}

result, err = client.Update(context.Background(), update, result.ID)
result, err = client.Update(context.Background(), result.ID, update)
if err != nil {
fmt.Println(err)
return
Expand Down
3 changes: 2 additions & 1 deletion examples/apis/preapprovalplan/update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"

"github.com/mercadopago/sdk-go/pkg/preapprovalplan"

"github.com/mercadopago/sdk-go/pkg/config"
Expand Down Expand Up @@ -57,7 +58,7 @@ func main() {
},
}

result, err = client.Update(context.Background(), req, result.ID)
result, err = client.Update(context.Background(), result.ID, req)
if err != nil {
fmt.Println(err)
return
Expand Down
2 changes: 1 addition & 1 deletion examples/apis/preference/update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
},
}

pref, err = client.Update(context.Background(), req, pref.ID)
pref, err = client.Update(context.Background(), pref.ID, req)
if err != nil {
fmt.Println(err)
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/merchantorder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Client interface {
// Update a merchant order.
// It is a put request to the endpoint: https://api.mercadopago.com/merchant_orders/{id}
// Reference: https://www.mercadopago.com/developers/en/reference/merchant_orders/_merchant_orders_id/put
Update(ctx context.Context, request UpdateRequest, id int) (*Response, error)
Update(ctx context.Context, id int, request UpdateRequest) (*Response, error)

// Create a merchant order.
// It is a post request to the endpoint: https://api.mercadopago.com/merchant_orders
Expand Down Expand Up @@ -84,7 +84,7 @@ func (c *client) Search(ctx context.Context, request SearchRequest) (*SearchResp
return result, nil
}

func (c *client) Update(ctx context.Context, request UpdateRequest, id int) (*Response, error) {
func (c *client) Update(ctx context.Context, id int, request UpdateRequest) (*Response, error) {
pathParams := map[string]string{
"id": strconv.Itoa(int(id)),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/merchantorder/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestUpdate(t *testing.T) {
c := &client{
cfg: tt.fields.config,
}
got, err := c.Update(tt.args.ctx, UpdateRequest{}, 1622029222)
got, err := c.Update(tt.args.ctx, 1622029222, UpdateRequest{})
gotErr := ""
if err != nil {
gotErr = err.Error()
Expand Down
3 changes: 1 addition & 2 deletions pkg/point/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type client struct {

// Client contains the methods to interact with the Point API.
type Client interface {

// Create a point payment intent.
// It is a post request to the endpoint: https://api.mercadopago.com/point/integration-api/devices/{device_id}/payment-intents
// Reference: https://www.mercadopago.com/developers/en/reference/integrations_api_paymentintent_mlb/_point_integration-api_devices_deviceid_payment-intents/post
Expand All @@ -38,7 +37,7 @@ type Client interface {
// Cancel a point payment intent.
// It is a cancel request to the endpoint: https://api.mercadopago.com/point/integration-api/devices/{device_id}/payment-intents/{payment_intent_id}
// Reference: https://www.mercadopago.com/developers/en/reference/integrations_api/_point_integration-api_devices_deviceid_payment-intents_paymentintentid/delete
Cancel(ctx context.Context, deviceID string, paymentIntentID string) (*CancelResponse, error)
Cancel(ctx context.Context, deviceID, paymentIntentID string) (*CancelResponse, error)

// ListDevices retrieve devices.
// It is a get request to the endpoint: https://api.mercadopago.com/point/integration-api/devices
Expand Down
7 changes: 4 additions & 3 deletions pkg/preapproval/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package preapproval

import (
"context"
"net/http"

"github.com/mercadopago/sdk-go/pkg/config"
"github.com/mercadopago/sdk-go/pkg/internal/httpclient"
"net/http"
)

const (
Expand All @@ -28,7 +29,7 @@ type Client interface {
// Update updates details a pre-approval by ID.
// It is a put request to the endpoint: https://api.mercadopago.com/preapproval/{id}
// Reference: https://www.mercadopago.com/developers/en/reference/subscriptions/_preapproval_id/put
Update(ctx context.Context, request UpdateRequest, id string) (*Response, error)
Update(ctx context.Context, id string, request UpdateRequest) (*Response, error)

// Search finds all pre-approval information generated through specific filters.
// It is a get request to the endpoint: https://api.mercadopago.com/preapproval/search
Expand Down Expand Up @@ -80,7 +81,7 @@ func (c *client) Get(ctx context.Context, id string) (*Response, error) {
return result, nil
}

func (c *client) Update(ctx context.Context, request UpdateRequest, id string) (*Response, error) {
func (c *client) Update(ctx context.Context, id string, request UpdateRequest) (*Response, error) {
pathParams := map[string]string{
"id": id,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/preapproval/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func TestUpdate(t *testing.T) {
c := &client{
cfg: tt.fields.config,
}
got, err := c.Update(tt.args.ctx, tt.args.request, tt.args.id)
got, err := c.Update(tt.args.ctx, tt.args.id, tt.args.request)
gotErr := ""
if err != nil {
gotErr = err.Error()
Expand Down
4 changes: 2 additions & 2 deletions pkg/preapprovalplan/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Client interface {
// Update updates details a pre-approval plan by ID.
// It is a put request to the endpoint: https://api.mercadopago.com/preapproval_plan/{id}
// Reference: https://www.mercadopago.com/developers/en/reference/subscriptions/_preapproval_plan_id/put
Update(ctx context.Context, request Request, id string) (*Response, error)
Update(ctx context.Context, id string, request Request) (*Response, error)

// Search finds all pre-approval plan information generated through specific filters.
// It is a get request to the endpoint: https://api.mercadopago.com/preapproval_plan/search
Expand Down Expand Up @@ -81,7 +81,7 @@ func (c *client) Get(ctx context.Context, id string) (*Response, error) {
return result, nil
}

func (c *client) Update(ctx context.Context, request Request, id string) (*Response, error) {
func (c *client) Update(ctx context.Context, id string, request Request) (*Response, error) {
pathParams := map[string]string{
"id": id,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/preapprovalplan/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func TestUpdate(t *testing.T) {
cfg: tt.fields.config,
}

got, err := c.Update(tt.args.ctx, tt.args.request, tt.args.id)
got, err := c.Update(tt.args.ctx, tt.args.id, tt.args.request)
gotErr := ""
if err != nil {
gotErr = err.Error()
Expand Down
4 changes: 2 additions & 2 deletions pkg/preference/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Client interface {
// Update updates details for a payment preference.
// It is a put request to the endpoint: https://api.mercadopago.com/checkout/preferences/{id}
// Reference: https://www.mercadopago.com/developers/en/reference/preferences/_checkout_preferences_id/put
Update(ctx context.Context, request Request, id string) (*Response, error)
Update(ctx context.Context, id string, request Request) (*Response, error)

// Search finds all preference information generated through specific filters
// It is a get request to the endpoint: https://api.mercadopago.com/checkout/preferences/search
Expand Down Expand Up @@ -81,7 +81,7 @@ func (c *client) Get(ctx context.Context, id string) (*Response, error) {
return result, nil
}

func (c *client) Update(ctx context.Context, request Request, id string) (*Response, error) {
func (c *client) Update(ctx context.Context, id string, request Request) (*Response, error) {
pathParams := map[string]string{
"id": id,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/preference/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func TestUpdate(t *testing.T) {
},
},
}
got, err := c.Update(tt.args.ctx, dto, "1273205088-6a2d2fa5-edb8-4d06-90c7-74b756a75f38")
got, err := c.Update(tt.args.ctx, "1273205088-6a2d2fa5-edb8-4d06-90c7-74b756a75f38", dto)
gotErr := ""
if err != nil {
gotErr = err.Error()
Expand Down
2 changes: 1 addition & 1 deletion test/integration/merchantorder/merchant_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestMerchantOrder(t *testing.T) {
},
}

order, err = client.Update(context.Background(), req, order.ID)
order, err = client.Update(context.Background(), order.ID, req)
if order == nil {
fmt.Println(err)
t.Error("merchant order can't be nil")
Expand Down
7 changes: 4 additions & 3 deletions test/integration/preapproval/preapproval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package integration

import (
"context"
"github.com/mercadopago/sdk-go/pkg/config"
"github.com/mercadopago/sdk-go/pkg/preapproval"
"os"
"testing"

"github.com/mercadopago/sdk-go/pkg/config"
"github.com/mercadopago/sdk-go/pkg/preapproval"
)

func TestPreApproval(t *testing.T) {
Expand Down Expand Up @@ -117,7 +118,7 @@ func TestPreApproval(t *testing.T) {
},
}

result, err = client.Update(context.Background(), update, result.ID)
result, err = client.Update(context.Background(), result.ID, update)
if result == nil {
t.Error("preapproval can't be nil")
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/preapproval_plan/preapproval_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestPreApprovalPlan(t *testing.T) {
},
}

result, err = client.Update(context.Background(), req, result.ID)
result, err = client.Update(context.Background(), result.ID, req)
if result == nil {
t.Error("preapproval_plan can't be nil")
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/preference/preference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestPreference(t *testing.T) {
},
}

pref, err = client.Update(context.Background(), req, pref.ID)
pref, err = client.Update(context.Background(), pref.ID, req)
if pref == nil {
t.Error("preference can't be nil")
}
Expand Down

0 comments on commit 084245e

Please sign in to comment.