Skip to content

Commit

Permalink
Point - Code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
meliguilhermefernandes committed Feb 22, 2024
1 parent de1bcca commit bbfc9a9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/apis/point/search/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
}

client := point.NewClient(cfg)
ppi, err := client.Search(context.Background(), "{{PAYMENT_INTENT_ID}}")
ppi, err := client.Get(context.Background(), "{{PAYMENT_INTENT_ID}}")
if err != nil {
fmt.Println(err)
return
Expand Down
38 changes: 19 additions & 19 deletions pkg/point/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
)

const (
urlBase = "https://api.mercadopago.com"
paymentIntentUrl = urlBase + "/point/integration-api/devices/:device_id/payment-intents"
paymentIntentSearchUrl = urlBase + "/point/integration-api/payment-intents/:payment_intent_id"
paymentIntentCancelUrl = urlBase + "/point/integration-api/devices/:device_id/payment-intents/:payment_intent_id"
devicesUrl = urlBase + "/point/integration-api/devices"
deviceWithIDUrl = urlBase + "/point/integration-api/devices/:device_id"
urlBase = "https://api.mercadopago.com/point"
urlDevices = urlBase + "/integration-api/devices/"
urlPaymentIntent = urlDevices + ":device_id/payment-intents"
urlPaymentIntentSearch = urlBase + "/integration-api/payment-intents/:payment_intent_id"
urlPaymentIntentCancel = urlDevices + ":device_id/payment-intents/:payment_intent_id"
urlDevicesWithID = urlDevices + ":device_id"
)

// client is the implementation of Client.
Expand All @@ -26,27 +26,27 @@ 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.br/developers/pt/reference/integrations_api_paymentintent_mlb/_point_integration-api_devices_deviceid_payment-intents/post
// Reference: https://www.mercadopago.com/developers/en/reference/integrations_api_paymentintent_mlb/_point_integration-api_devices_deviceid_payment-intents/post
Create(ctx context.Context, deviceID string, request Request) (*CreateResponse, error)

// Search a point payment intent.
// Get a point payment intent.
// It is a search request to the endpoint: https://api.mercadopago.com/point/integration-api/payment-intents/{payment_intent_id}
// Reference: https://www.mercadopago.com.br/developers/pt/reference/integrations_api/_point_integration-api_payment-intents_paymentintentid/get
Search(ctx context.Context, paymentIntentID string) (*SearchResponse, error)
// Reference: https://www.mercadopago.com/developers/en/reference/integrations_api/_point_integration-api_payment-intents_paymentintentid/get
Get(ctx context.Context, paymentIntentID string) (*SearchResponse, error)

// 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.br/developers/pt/reference/integrations_api/_point_integration-api_devices_deviceid_payment-intents_paymentintentid/delete
// 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)

// GetDevices search devices.
// It is a search request to the endpoint: https://api.mercadopago.com/point/integration-api/devices
// Reference: https://www.mercadopago.com.br/developers/pt/reference/integrations_api/_point_integration-api_devices/get
// Reference: https://www.mercadopago.com/developers/en/reference/integrations_api/_point_integration-api_devices/get
GetDevices(ctx context.Context) (*DevicesResponse, error)

// UpdateDeviceOperationMode getintentstatus device.
// It is a patch request to the endpoint: https://api.mercadopago.com/point/integration-api/devices/{device-id}
// Reference: https://www.mercadopago.com.br/developers/pt/reference/integrations_api/_point_integration-api_devices_device-id/patch
// Reference: https://www.mercadopago.com/developers/en/reference/integrations_api/_point_integration-api_devices_device-id/patch
UpdateDeviceOperationMode(ctx context.Context, deviceID string, request UpdateDeviceOperatingModeRequest) (*OperationModeResponse, error)
}

Expand All @@ -60,20 +60,20 @@ func (c *client) Create(ctx context.Context, deviceID string, request Request) (
"device_id": deviceID,
}

res, err := baseclient.Post[*CreateResponse](ctx, c.cfg, paymentIntentUrl, request, baseclient.WithPathParams(params))
res, err := baseclient.Post[*CreateResponse](ctx, c.cfg, urlPaymentIntent, request, baseclient.WithPathParams(params))
if err != nil {
return nil, err
}

return res, nil
}

func (c *client) Search(ctx context.Context, paymentIntentID string) (*SearchResponse, error) {
func (c *client) Get(ctx context.Context, paymentIntentID string) (*SearchResponse, error) {
params := map[string]string{
"payment_intent_id": paymentIntentID,
}

res, err := baseclient.Get[*SearchResponse](ctx, c.cfg, paymentIntentSearchUrl, baseclient.WithPathParams(params))
res, err := baseclient.Get[*SearchResponse](ctx, c.cfg, urlPaymentIntentSearch, baseclient.WithPathParams(params))
if err != nil {
return nil, err
}
Expand All @@ -87,7 +87,7 @@ func (c *client) Cancel(ctx context.Context, deviceID string, paymentIntentID st
"payment_intent_id": paymentIntentID,
}

res, err := baseclient.Delete[*CancelResponse](ctx, c.cfg, paymentIntentCancelUrl, nil, baseclient.WithPathParams(params))
res, err := baseclient.Delete[*CancelResponse](ctx, c.cfg, urlPaymentIntentCancel, nil, baseclient.WithPathParams(params))
if err != nil {
return nil, err
}
Expand All @@ -96,7 +96,7 @@ func (c *client) Cancel(ctx context.Context, deviceID string, paymentIntentID st
}

func (c *client) GetDevices(ctx context.Context) (*DevicesResponse, error) {
res, err := baseclient.Get[*DevicesResponse](ctx, c.cfg, devicesUrl)
res, err := baseclient.Get[*DevicesResponse](ctx, c.cfg, urlDevices)
if err != nil {
return nil, err
}
Expand All @@ -109,7 +109,7 @@ func (c *client) UpdateDeviceOperationMode(ctx context.Context, deviceID string,
"device_id": deviceID,
}

res, err := baseclient.Patch[*OperationModeResponse](ctx, c.cfg, deviceWithIDUrl, request, baseclient.WithPathParams(params))
res, err := baseclient.Patch[*OperationModeResponse](ctx, c.cfg, urlDevicesWithID, request, baseclient.WithPathParams(params))
if err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/point/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestCreate(t *testing.T) {
wantErr string
}{
{
name: "should_return_error_when_create",
name: "should_return_error_when_create_point_transaction_intent",
fields: fields{
cfg: &config.Config{
Requester: &httpclient.Mock{
Expand All @@ -67,7 +67,7 @@ func TestCreate(t *testing.T) {
wantErr: "transport level error: some error",
},
{
name: "should_create_success",
name: "should_create_point_transaction_intent_success",
fields: fields{
cfg: &config.Config{
Requester: &httpclient.Mock{
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestCreate(t *testing.T) {
}
}

func TestSearch(t *testing.T) {
func TestGet(t *testing.T) {
type fields struct {
cfg *config.Config
}
Expand All @@ -153,7 +153,7 @@ func TestSearch(t *testing.T) {
wantErr string
}{
{
name: "should_return_error_when_search",
name: "should_return_error_when_get_point_transaction_intent",
fields: fields{
cfg: &config.Config{
Requester: &httpclient.Mock{
Expand All @@ -171,7 +171,7 @@ func TestSearch(t *testing.T) {
wantErr: "transport level error: some error",
},
{
name: "should_search_success",
name: "should_get_point_transaction_intent_success",
fields: fields{
cfg: &config.Config{
Requester: &httpclient.Mock{
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestSearch(t *testing.T) {
c := &client{
cfg: tt.fields.cfg,
}
got, err := c.Search(tt.args.ctx, tt.args.paymentIntentID)
got, err := c.Get(tt.args.ctx, tt.args.paymentIntentID)
gotErr := ""
if err != nil {
gotErr = err.Error()
Expand Down Expand Up @@ -244,7 +244,7 @@ func TestCancel(t *testing.T) {
wantErr string
}{
{
name: "should_return_error_when_cancel",
name: "should_return_error_when_cancel_point_transaction_intent",
fields: fields{
cfg: &config.Config{
Requester: &httpclient.Mock{
Expand All @@ -263,7 +263,7 @@ func TestCancel(t *testing.T) {
wantErr: "transport level error: some error",
},
{
name: "should_cancel_success",
name: "should_cancel_point_transaction_intent_success",
fields: fields{
cfg: &config.Config{
Requester: &httpclient.Mock{
Expand Down

0 comments on commit bbfc9a9

Please sign in to comment.