diff --git a/examples/apis/cardtoken/create/main.go b/examples/apis/cardtoken/create/main.go index 7a5eed0b..f7c756ac 100644 --- a/examples/apis/cardtoken/create/main.go +++ b/examples/apis/cardtoken/create/main.go @@ -19,7 +19,22 @@ func main() { client := cardtoken.NewClient(cfg) - result, err := client.Create(context.Background(), cardtoken.Request{}) + var req = cardtoken.Request{ + SiteID: "{{SiteID}}", + CardNumber: "{{CardNumber}}", + ExpirationMonth: "11", + ExpirationYear: "2025", + SecurityCode: "123", + Cardholder: &cardtoken.Cardholder{ + Identification: &cardtoken.Identification{ + Type: "CPF", + Number: "{{CPFNumber}}", + }, + Name: "{{PaymentMethod}}", + }, + } + + result, err := client.Create(context.Background(), req) if err != nil { return } diff --git a/pkg/cardtoken/client.go b/pkg/cardtoken/client.go index 60064460..7b212d4e 100644 --- a/pkg/cardtoken/client.go +++ b/pkg/cardtoken/client.go @@ -2,7 +2,6 @@ package cardtoken import ( "context" - "fmt" "github.com/mercadopago/sdk-go/pkg/config" "github.com/mercadopago/sdk-go/pkg/internal/httpclient" @@ -27,7 +26,7 @@ func NewClient(c *config.Config) Client { func (c *client) Create(ctx context.Context, request Request) (*Response, error) { res, err := httpclient.Post[Response](ctx, c.cfg, url, request) if err != nil { - return nil, fmt.Errorf("error create card token: %w", err) + return nil, err } return res, nil } diff --git a/pkg/cardtoken/client_test.go b/pkg/cardtoken/client_test.go index 0d59be0f..f226352b 100644 --- a/pkg/cardtoken/client_test.go +++ b/pkg/cardtoken/client_test.go @@ -70,7 +70,7 @@ func TestCreate(t *testing.T) { ctx: context.Background(), }, want: nil, - wantErr: "error create card token: transport level error: some error", + wantErr: "transport level error: some error", }, } for _, tt := range tests { diff --git a/pkg/cardtoken/mock.go b/pkg/cardtoken/mock.go index 8a17b43e..77bcb907 100644 --- a/pkg/cardtoken/mock.go +++ b/pkg/cardtoken/mock.go @@ -11,8 +11,8 @@ func mockCardToken() *Response { ExpirationMonth: 11, ExpirationYear: 2025, LastFourDigits: "6351", - Cardholder: Cardholder{ - Identification: Identification{ + Cardholder: &Cardholder{ + Identification: &Identification{ Number: "70383868084", Type: "CPF", }, @@ -36,8 +36,8 @@ func MockCardTokenRequest() Request { ExpirationMonth: "11", ExpirationYear: "2025", SecurityCode: "123", - Cardholder: Cardholder{ - Identification: Identification{ + Cardholder: &Cardholder{ + Identification: &Identification{ Type: "CPF", Number: "70383868084", }, diff --git a/pkg/cardtoken/request.go b/pkg/cardtoken/request.go index f549a08e..68941ac4 100644 --- a/pkg/cardtoken/request.go +++ b/pkg/cardtoken/request.go @@ -1,17 +1,17 @@ package cardtoken type Request struct { - SiteID string `json:"site_id"` - CardNumber string `json:"card_number"` - ExpirationYear string `json:"expiration_year"` - ExpirationMonth string `json:"expiration_month"` - SecurityCode string `json:"security_code"` - Cardholder Cardholder `json:"cardholder"` + SiteID string `json:"site_id"` + CardNumber string `json:"card_number"` + ExpirationYear string `json:"expiration_year"` + ExpirationMonth string `json:"expiration_month"` + SecurityCode string `json:"security_code"` + Cardholder *Cardholder `json:"cardholder,omitempty"` } type Cardholder struct { - Identification Identification `json:"identification"` - Name string `json:"name"` + Identification *Identification `json:"identification,omitempty"` + Name string `json:"name"` } type Identification struct { diff --git a/pkg/cardtoken/response.go b/pkg/cardtoken/response.go index 2c2ae3a0..359f7b65 100644 --- a/pkg/cardtoken/response.go +++ b/pkg/cardtoken/response.go @@ -3,19 +3,19 @@ package cardtoken import "time" type Response struct { - 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"` - DateCreated *time.Time `json:"date_created"` - DateLastUpdated *time.Time `json:"date_last_updated"` - DateDue *time.Time `json:"date_due"` - Cardholder Cardholder `json:"cardholder"` + 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"` + DateCreated *time.Time `json:"date_created"` + DateLastUpdated *time.Time `json:"date_last_updated"` + DateDue *time.Time `json:"date_due"` + Cardholder *Cardholder `json:"cardholder"` }