Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/order structs #36

Merged
merged 9 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/apis/cardtoken/create/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func main() {
ExpirationMonth: "11",
ExpirationYear: "2025",
SecurityCode: "123",
Cardholder: &cardtoken.Cardholder{
Identification: &cardtoken.Identification{
Cardholder: &cardtoken.CardholderRequest{
Identification: &cardtoken.IdentificationRequest{
Type: "CPF",
Number: "{{CPF_NUMBER}}",
},
Expand Down
5 changes: 3 additions & 2 deletions examples/apis/preapproval/search/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 All @@ -17,8 +18,8 @@ func main() {
client := preapproval.NewClient(cfg)

filters := preapproval.SearchRequest{
Limit: "10",
Offset: "10",
Limit: 10,
Offset: 10,
Filters: map[string]string{
"payer_id": "123123123",
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cardtoken/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func mockCardToken() *Response {
}
}

func parseDate(s string) *time.Time {
func parseDate(s string) time.Time {
d, _ := time.Parse(time.RFC3339, s)
return &d
return d
}
8 changes: 4 additions & 4 deletions pkg/cardtoken/request.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cardtoken

type Request struct {
Cardholder *Cardholder `json:"cardholder,omitempty"`
Cardholder *CardholderRequest `json:"cardholder,omitempty"`

SiteID string `json:"site_id,omitempty"`
CardNumber string `json:"card_number,omitempty"`
Expand All @@ -10,13 +10,13 @@ type Request struct {
SecurityCode string `json:"security_code,omitempty"`
}

type Cardholder struct {
Identification *Identification `json:"identification,omitempty"`
type CardholderRequest struct {
Identification *IdentificationRequest `json:"identification,omitempty"`

Name string `json:"name,omitempty"`
}

type Identification struct {
type IdentificationRequest struct {
Number string `json:"number,omitempty"`
Type string `json:"type,omitempty"`
}
12 changes: 6 additions & 6 deletions pkg/cardtoken/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package cardtoken
import "time"

type Response struct {
DateCreated *time.Time `json:"date_created"`
DateLastUpdated *time.Time `json:"date_last_updated"`
DateDue *time.Time `json:"date_due"`
Cardholder CardholderResponse `json:"cardholder"`
DateCreated time.Time `json:"date_created"`
DateLastUpdated time.Time `json:"date_last_updated"`
DateDue time.Time `json:"date_due"`

ID string `json:"id"`
FirstSixDigits string `json:"first_six_digits"`
LastFourDigits string `json:"last_four_digits"`
Status string `json:"status"`
LuhnValidation bool `json:"luhn_validation"`
LiveMode bool `json:"live_mode"`
RequireEsc bool `json:"require_esc"`
ExpirationMonth int `json:"expiration_month"`
ExpirationYear int `json:"expiration_year"`
CardNumberLength int `json:"card_number_length"`
SecurityCodeLength int `json:"security_code_length"`
LuhnValidation bool `json:"luhn_validation"`
LiveMode bool `json:"live_mode"`
RequireEsc bool `json:"require_esc"`
}

type CardholderResponse struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/customer/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import "time"

// Request represents a request for creating a customer.
type Request struct {
DateRegistered *time.Time `json:"date_registered,omitempty"`
Address *AddressResponse `json:"address,omitempty"`
Address *AddressRequest `json:"address,omitempty"`
Identification *IdentificationRequest `json:"identification,omitempty"`
Phone *PhoneRequest `json:"phone,omitempty"`
DateRegistered *time.Time `json:"date_registered,omitempty"`

DefaultAddress string `json:"default_address,omitempty"`
DefaultCard string `json:"default_card,omitempty"`
Expand Down
16 changes: 8 additions & 8 deletions pkg/customer/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import "time"

// Response represents a customer.
type Response struct {
DateRegistered *time.Time `json:"date_registered"`
DateCreated *time.Time `json:"date_created"`
DateLastUpdated *time.Time `json:"date_last_updated"`
Phone PhoneResponse `json:"phone"`
Identification IdentificationResponse `json:"identification"`
Address AddressResponse `json:"address"`
DateRegistered time.Time `json:"date_registered"`
DateCreated time.Time `json:"date_created"`
DateLastUpdated time.Time `json:"date_last_updated"`
Cards []CardResponse `json:"cards"`
Addresses []CompleteAddressResponse `json:"addresses"`

Expand Down Expand Up @@ -43,12 +43,12 @@ type AddressResponse struct {

// CardResponse represents a response for a card.
type CardResponse struct {
DateCreated *time.Time `json:"date_created"`
DateLastUpdated *time.Time `json:"date_last_updated"`
Cardholder CardholderResponse `json:"cardholder"`
Issuer IssuerResponse `json:"issuer"`
PaymentMethod PaymentMethodResponse `json:"payment_method"`
SecurityCode SecurityCodeResponse `json:"security_code"`
DateCreated time.Time `json:"date_created"`
DateLastUpdated time.Time `json:"date_last_updated"`

ID string `json:"id"`
CustomerID string `json:"customer_id"`
Expand All @@ -74,8 +74,8 @@ type IdentificationResponse struct {

// IssuerResponse represents a response for an issuer.
type IssuerResponse struct {
ID int `json:"id"`
Name string `json:"name"`
ID int `json:"id"`
}

// PaymentMethodResponse represents a response for a payment method.
Expand All @@ -89,17 +89,17 @@ type PaymentMethodResponse struct {

// SecurityCodeResponse represents a response for a security code.
type SecurityCodeResponse struct {
Length int `json:"length"`
CardLocation string `json:"card_location"`
Length int `json:"length"`
}

// CompleteAddressResponse represents a response for a complete address.
type CompleteAddressResponse struct {
DateCreated *time.Time `json:"date_created"`
City CityResponse `json:"city"`
State StateResponse `json:"state"`
Country CountryResponse `json:"country"`
Neighborhood NeighborhoodResponse `json:"neighborhood"`
DateCreated time.Time `json:"date_created"`

ID string `json:"id"`
StreetName string `json:"street_name"`
Expand Down
5 changes: 2 additions & 3 deletions pkg/customer/search_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import (
// Filters field can receive a lot of parameters. For details, see:
// https://www.mercadopago.com/developers/en/reference/customers/_customers_search/get.
type SearchRequest struct {
Limit int
Offset int
Filters map[string]string

Limit int
Offset int
}

// GetParams creates map to build query parameters. Keys will be changed to lower case.
Expand Down
2 changes: 1 addition & 1 deletion pkg/customer/search_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package customer

// SearchResponse represents the response from the search endpoint.
type SearchResponse struct {
Results []Response `json:"results"`
Paging PagingResponse `json:"paging"`
Results []Response `json:"results"`
}

// PagingResponse represents the paging information within SearchResponse.
Expand Down
14 changes: 7 additions & 7 deletions pkg/customercard/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestCreate(t *testing.T) {
Thumbnail: "https://http2.mlstatic.com/storage/logos-api-admin/[email protected]",
SecureThumbnail: "https://http2.mlstatic.com/storage/logos-api-admin/[email protected]",
},
SecurityCode: SecurityCode{
SecurityCode: SecurityCodeResponse{
Length: 3,
CardLocation: "back",
},
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestUpdate(t *testing.T) {
Thumbnail: "https://http2.mlstatic.com/storage/logos-api-admin/[email protected]",
SecureThumbnail: "https://http2.mlstatic.com/storage/logos-api-admin/[email protected]",
},
SecurityCode: SecurityCode{
SecurityCode: SecurityCodeResponse{
Length: 3,
CardLocation: "back",
},
Expand Down Expand Up @@ -345,7 +345,7 @@ func TestGet(t *testing.T) {
Thumbnail: "https://http2.mlstatic.com/storage/logos-api-admin/[email protected]",
SecureThumbnail: "https://http2.mlstatic.com/storage/logos-api-admin/[email protected]",
},
SecurityCode: SecurityCode{
SecurityCode: SecurityCodeResponse{
Length: 3,
CardLocation: "back",
},
Expand Down Expand Up @@ -460,7 +460,7 @@ func TestDelete(t *testing.T) {
Thumbnail: "https://http2.mlstatic.com/storage/logos-api-admin/[email protected]",
SecureThumbnail: "https://http2.mlstatic.com/storage/logos-api-admin/[email protected]",
},
SecurityCode: SecurityCode{
SecurityCode: SecurityCodeResponse{
Length: 3,
CardLocation: "back",
},
Expand Down Expand Up @@ -574,7 +574,7 @@ func TestList(t *testing.T) {
Thumbnail: "https://http2.mlstatic.com/storage/logos-api-admin/[email protected]",
SecureThumbnail: "https://http2.mlstatic.com/storage/logos-api-admin/[email protected]",
},
SecurityCode: SecurityCode{
SecurityCode: SecurityCodeResponse{
Length: 3,
CardLocation: "back",
},
Expand Down Expand Up @@ -602,7 +602,7 @@ func TestList(t *testing.T) {
}
}

func parseDate(s string) *time.Time {
func parseDate(s string) time.Time {
d, _ := time.Parse(time.RFC3339, s)
return &d
return d
}
12 changes: 6 additions & 6 deletions pkg/customercard/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import "time"

// Response represents a customer card.
type Response struct {
DateCreated *time.Time `json:"date_created"`
DateLastUpdated *time.Time `json:"date_last_updated"`
Issuer IssuerResponse `json:"issuer"`
Cardholder CardholderResponse `json:"cardholder"`
AdditionalInfo AdditionalInfoResponse `json:"additional_info"`
PaymentMethod PaymentMethodResponse `json:"payment_method"`
SecurityCode SecurityCode `json:"security_code"`
SecurityCode SecurityCodeResponse `json:"security_code"`
DateCreated time.Time `json:"date_created"`
DateLastUpdated time.Time `json:"date_last_updated"`

ID string `json:"id"`
CustomerID string `json:"customer_id"`
Expand Down Expand Up @@ -45,8 +45,8 @@ type IdentificationResponse struct {

// IssuerResponse represents the card issuer code.
type IssuerResponse struct {
ID int `json:"id"`
Name string `json:"name"`
ID int `json:"id"`
}

// PaymentMethodResponse represents the card's payment method.
Expand All @@ -59,7 +59,7 @@ type PaymentMethodResponse struct {
}

// SecurityCode represents the card's security code.
type SecurityCode struct {
Length int `json:"length"`
type SecurityCodeResponse struct {
CardLocation string `json:"card_location"`
Length int `json:"length"`
}
4 changes: 2 additions & 2 deletions pkg/invoice/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func TestSearch(t *testing.T) {
}
}

func parseDate(s string) *time.Time {
func parseDate(s string) time.Time {
d, _ := time.Parse(time.RFC3339, s)
return &d
return d
}
10 changes: 5 additions & 5 deletions pkg/invoice/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import "time"

// Response is the response from the Invoice API.
type Response struct {
DateCreated *time.Time `json:"date_created"`
DebitDate *time.Time `json:"debit_date"`
LastModified *time.Time `json:"last_modified"`
NextRetryDate *time.Time `json:"next_retry_date"`
Payment PaymentResponse `json:"payment"`
DateCreated time.Time `json:"date_created"`
DebitDate time.Time `json:"debit_date"`
LastModified time.Time `json:"last_modified"`
NextRetryDate time.Time `json:"next_retry_date"`

CurrencyID string `json:"currency_id"`
ExternalReference string `json:"external_reference"`
Expand All @@ -18,9 +18,9 @@ type Response struct {
Status string `json:"status"`
Summarized string `json:"summarized"`
Type string `json:"type"`
TransactionAmount float64 `json:"transaction_amount"`
ID int `json:"id"`
RetryAttempt int `json:"retry_attempt"`
TransactionAmount float64 `json:"transaction_amount"`
}

// PaymentResponse contains information about payment.
Expand Down
5 changes: 2 additions & 3 deletions pkg/invoice/search_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (

// SearchRequest is the helper structure to build search request.
type SearchRequest struct {
Limit int
Offset int
Filters map[string]string

Limit int
Offset int
}

// GetParams creates map to build query parameters. Keys will be changed to lower case.
Expand Down
4 changes: 2 additions & 2 deletions pkg/merchantorder/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ func buildResponseMock() *Response {
Nickname: "TEST_USER_658045679",
},
Marketplace: "NONE",
DateCreated: &dateCreated,
LastUpdated: &lastUpdate,
DateCreated: dateCreated,
LastUpdated: lastUpdate,
TotalAmount: 10,
SiteID: "MLB",
Items: []ItemResponse{
Expand Down
2 changes: 1 addition & 1 deletion pkg/merchantorder/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type ItemRequest struct {
PictureURL string `json:"picture_url,omitempty"`
CategoryID string `json:"category_id,omitempty"`
CurrencyID string `json:"currency_id,omitempty"`
Quantity int `json:"quantity,omitempty"`
UnitPrice float64 `json:"unit_price,omitempty"`
Quantity int `json:"quantity,omitempty"`
}

// CollectorRequest represents seller information.
Expand Down
Loading
Loading