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

Implements card #10

Merged
merged 57 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
198b679
Add client card
eltinMeli Feb 5, 2024
20d3568
Merge branch 'feature/implements-client-generic' into feature/impleme…
eltinMeli Feb 7, 2024
1b49a3c
add options http
eltinMeli Feb 9, 2024
159ca45
adjusts tests
eltinMeli Feb 9, 2024
034c26d
add user client api
edmarSoaress Jan 31, 2024
9b51325
adjust pointer in object
edmarSoaress Jan 31, 2024
89a3d9f
adjusts merge
eltinMeli Feb 9, 2024
958cb52
Improve structs
gdeandradero Jan 25, 2024
144158d
Add more fields to response struct
gdeandradero Jan 25, 2024
fa60eb8
Adjust search
gdeandradero Jan 26, 2024
5bce1d7
Add some tests
gdeandradero Jan 26, 2024
16c25a2
Refactor tests
gdeandradero Jan 26, 2024
70554e3
Add payment examples
gdeandradero Jan 26, 2024
aba10c3
Search test
gdeandradero Jan 27, 2024
139ec82
Add get tests
gdeandradero Jan 27, 2024
e1e6e03
Add cancel test
gdeandradero Jan 27, 2024
889b1dc
Add capture test
gdeandradero Jan 27, 2024
20967cf
Add capture amount test
gdeandradero Jan 27, 2024
2f4c115
Add integration tests
gdeandradero Jan 27, 2024
f55b892
merge main into feature payment implementation
edmarSoaress Jan 31, 2024
eb243d6
adjust integration test
edmarSoaress Jan 31, 2024
3852389
adjust examples
edmarSoaress Jan 31, 2024
cca8c95
adjust capture payment integration tests
edmarSoaress Feb 1, 2024
e79aee9
adjust examples and integration test
edmarSoaress Feb 1, 2024
d65833a
adjust examples
edmarSoaress Feb 1, 2024
42299e0
rename variable names
edmarSoaress Feb 1, 2024
480e5de
remover pointer from response
edmarSoaress Feb 2, 2024
200783f
Add CI workflow
lucmantovani Feb 2, 2024
dd061c4
merge with develop and adjust test
edmarSoaress Feb 7, 2024
5c0cbdb
add lint suggestion
edmarSoaress Feb 7, 2024
473cebb
add lint suggestion
edmarSoaress Feb 7, 2024
1646ac0
merge with feature payment
edmarSoaress Feb 7, 2024
742c2d0
change client name
edmarSoaress Feb 8, 2024
28e7fb1
change name of client test
edmarSoaress Feb 8, 2024
6bf8ac5
Card token - Initial version
Feb 7, 2024
8302328
Card token - refacting client
Feb 7, 2024
e36ea55
Card token - add unit tests
Feb 8, 2024
fa4c4de
Card token - add integrated test
Feb 8, 2024
e4b7561
Card token - add integrated test
Feb 8, 2024
768fd8e
Card token - code quality
Feb 8, 2024
666fb04
Card token - code quality
Feb 8, 2024
ebed749
Card token - code quality
Feb 8, 2024
341ba01
Card token - code quality
Feb 8, 2024
3c567b5
Card token - code quality
Feb 8, 2024
8ad5cd3
Card token - code quality
Feb 8, 2024
abe2ff3
Card token - code quality
Feb 9, 2024
a3610a6
Card token - code quality
Feb 9, 2024
362a42f
Card token - code quality
Feb 9, 2024
022a15d
Add client card
eltinMeli Feb 5, 2024
3e6edf1
adjusts merge conflicts
eltinMeli Feb 9, 2024
b58cc5d
Clean code
eltinMeli Feb 9, 2024
90b09f2
adjust conflict payment method
eltinMeli Feb 9, 2024
bb36d83
adjust name client pm
eltinMeli Feb 9, 2024
5e06100
adjust ci lint
eltinMeli Feb 9, 2024
ce0ed5b
adjust order tests
eltinMeli Feb 9, 2024
69c6931
remove const param
eltinMeli Feb 9, 2024
f0b2b41
Adjusted test text and url values
eltinMeli Feb 14, 2024
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
30 changes: 30 additions & 0 deletions examples/apis/customercard/create/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"context"
"fmt"

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

func main() {
accessToken := "{{ACCESS_TOKEN}}"

cfg, err := config.New(accessToken)
if err != nil {
fmt.Println(err)
return
}

req := customercard.Request{Token: "{{CARD_TOKEN}}"}

client := customercard.NewClient(cfg)
card, err := client.Create(context.Background(), "{{CUSTOMER_ID}}", req)
if err != nil {
fmt.Println(err)
return
}

fmt.Println(card)
}
28 changes: 28 additions & 0 deletions examples/apis/customercard/delete/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"context"
"fmt"

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

func main() {
accessToken := "{{ACCESS_TOKEN}}"

cfg, err := config.New(accessToken)
if err != nil {
fmt.Println(err)
return
}

client := customercard.NewClient(cfg)
card, err := client.Delete(context.Background(), "{{CUSTOMER_ID}}", "{{CARD_ID}}")
if err != nil {
fmt.Println(err)
return
}

fmt.Println(card)
}
28 changes: 28 additions & 0 deletions examples/apis/customercard/get/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"context"
"fmt"

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

func main() {
accessToken := "{{ACCESS_TOKEN}}"

cfg, err := config.New(accessToken)
if err != nil {
fmt.Println(err)
return
}

client := customercard.NewClient(cfg)
card, err := client.Get(context.Background(), "{{CUSTOMER_ID}}", "{{CARD_ID}}")
if err != nil {
fmt.Println(err)
return
}

fmt.Println(card)
}
30 changes: 30 additions & 0 deletions examples/apis/customercard/list/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"context"
"fmt"

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

func main() {
accessToken := "{{ACCESS_TOKEN}}"

cfg, err := config.New(accessToken)
if err != nil {
fmt.Println(err)
return
}

client := customercard.NewClient(cfg)
cards, err := client.List(context.Background(), "{{CUSTOMER_ID}}")
if err != nil {
fmt.Println(err)
return
}

for _, c := range cards {
fmt.Println(c)
}
}
30 changes: 30 additions & 0 deletions examples/apis/customercard/update/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"context"
"fmt"

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

func main() {
accessToken := "{{ACCESS_TOKEN}}"

cfg, err := config.New(accessToken)
if err != nil {
fmt.Println(err)
return
}

req := customercard.Request{Token: "{{CARD_TOKEN}}"}

client := customercard.NewClient(cfg)
card, err := client.Update(context.Background(), "{{CUSTOMER_ID}}", "{{CARD_ID}}", req)
if err != nil {
fmt.Println(err)
return
}

fmt.Println(card)
}
121 changes: 121 additions & 0 deletions pkg/customercard/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package customercard

import (
"context"

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

const (
urlBase = "https://api.mercadopago.com/v1/customers/{customer_id}/cards"
urlWithID = urlBase + "/{card_id}"
)

// Client contains the methods to interact with the Customer Cards API.
type Client interface {
// Create a new customer card.
// It is a post request to the endpoint: https://api.mercadopago.com/v1/customer/{customer_id}/cards
// Reference: https://www.mercadopago.com/developers/en/reference/cards/_customers_customer_id_cards/post
Create(ctx context.Context, customerID string, request Request) (*Response, error)

// Get a customer card by id.
// It is a get request to the endpoint: https://api.mercadopago.com/v1/customer/{customer_id}/cards/{card_id}
// Reference: https://www.mercadopago.com/developers/en/reference/cards/_customers_customer_id_cards_id/get
Get(ctx context.Context, customerID, cardID string) (*Response, error)

// Update a customer card by id.
// It is a put request to the endpoint: https://api.mercadopago.com/v1/customer/{customer_id}/cards/{card_id}
// Reference: https://www.mercadopago.com/developers/en/reference/cards/_customers_customer_id_cards_id/put
Update(ctx context.Context, customerID, cardID string, request Request) (*Response, error)

// Delete deletes a customer card by id.
// It is a delete request to the endpoint: https://api.mercadopago.com/v1/customer/{customer_id}/cards/{card_id}
// Reference: https://www.mercadopago.com/developers/en/reference/cards/_customers_customer_id_cards_id/delete
Delete(ctx context.Context, customerID, cardID string) (*Response, error)

// List all customer cards.
// It is a get request to the endpoint: https://api.mercadopago.com/v1/customer/{customer_id}/cards
// Reference: https://www.mercadopago.com/developers/en/reference/cards/_customers_customer_id_cards/get
List(ctx context.Context, customerID string) ([]Response, error)
}

// client is the implementation of Client.
type client struct {
config *config.Config
}

// NewClient returns a new Customer Card Client.
func NewClient(c *config.Config) Client {
return &client{
config: c,
}
}

func (c *client) Create(ctx context.Context, customerID string, request Request) (*Response, error) {
params := map[string]string{
"customer_id": customerID,
}

res, err := httpclient.Post[Response](ctx, c.config, urlBase, request, httpclient.WithPathParams(params))
if err != nil {
return nil, err
}

return res, nil
}

func (c *client) Get(ctx context.Context, customerID, cardID string) (*Response, error) {
params := map[string]string{
"customer_id": customerID,
"card_id": cardID,
}

res, err := httpclient.Get[Response](ctx, c.config, urlWithID, httpclient.WithPathParams(params))
if err != nil {
return nil, err
}

return res, nil
}

func (c *client) Update(ctx context.Context, customerID, cardID string, request Request) (*Response, error) {
params := map[string]string{
"customer_id": customerID,
"card_id": cardID,
}

res, err := httpclient.Put[Response](ctx, c.config, urlWithID, request, httpclient.WithPathParams(params))
if err != nil {
return nil, err
}

return res, nil
}

func (c *client) Delete(ctx context.Context, customerID, cardID string) (*Response, error) {
params := map[string]string{
"customer_id": customerID,
"card_id": cardID,
}

res, err := httpclient.Delete[Response](ctx, c.config, urlWithID, nil, httpclient.WithPathParams(params))
if err != nil {
return nil, err
}

return res, nil
}

func (c *client) List(ctx context.Context, customerID string) ([]Response, error) {
params := map[string]string{
"customer_id": customerID,
}

res, err := httpclient.Get[[]Response](ctx, c.config, urlBase, httpclient.WithPathParams(params))
if err != nil {
return nil, err
}

return *res, nil
}
Loading
Loading