Skip to content

Commit

Permalink
Adds support for Reconciliations API (CS1)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinseco committed Feb 2, 2023
1 parent e92159f commit 6bd3c41
Show file tree
Hide file tree
Showing 14 changed files with 1,030 additions and 19 deletions.
23 changes: 13 additions & 10 deletions abc/checkout_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ import (
payments "github.com/checkout/checkout-sdk-go/payments/abc"
"github.com/checkout/checkout-sdk-go/payments/hosted"
"github.com/checkout/checkout-sdk-go/payments/links"
"github.com/checkout/checkout-sdk-go/reconciliation"
"github.com/checkout/checkout-sdk-go/sources"
"github.com/checkout/checkout-sdk-go/tokens"
webhooks "github.com/checkout/checkout-sdk-go/webhooks/abc"
)

type Api struct {
Customers *customers.Client
Disputes *disputes.Client
Events *events.Client
Hosted *hosted.Client
Instruments *abc.Client
Links *links.Client
Payments *payments.Client
Sources *sources.Client
Tokens *tokens.Client
Webhooks *webhooks.Client
Customers *customers.Client
Disputes *disputes.Client
Events *events.Client
Hosted *hosted.Client
Instruments *abc.Client
Links *links.Client
Payments *payments.Client
Reconciliation *reconciliation.Client
Sources *sources.Client
Tokens *tokens.Client
Webhooks *webhooks.Client

Ideal *ideal.Client
Klarna *klarna.Client
Expand All @@ -46,6 +48,7 @@ func CheckoutApi(configuration *configuration.Configuration) *Api {
api.Instruments = abc.NewClient(configuration, apiClient)
api.Links = links.NewClient(configuration, apiClient)
api.Payments = payments.NewClient(configuration, apiClient)
api.Reconciliation = reconciliation.NewClient(configuration, apiClient)
api.Sources = sources.NewClient(configuration, apiClient)
api.Tokens = tokens.NewClient(configuration, apiClient)
api.Webhooks = webhooks.NewClient(configuration, apiClient)
Expand Down
8 changes: 8 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"net/http"
"time"
)

type AccountType string
Expand Down Expand Up @@ -234,3 +235,10 @@ type (
Percentage float32 `json:"percentage,omitempty"`
}
)

type (
DateRangeQuery struct {
From time.Time `url:"from,omitempty" layout:"2006-01-02T15:04:05Z"`
To time.Time `url:"to,omitempty" layout:"2006-01-02T15:04:05Z"`
}
)
2 changes: 1 addition & 1 deletion common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func BuildQueryPath(path string, queryValues interface{}) (string, error) {
return "", err
}

return fmt.Sprintf("/%s?%s", path, values.Encode()), nil
return fmt.Sprintf("%s?%s", path, values.Encode()), nil
}

func EscapeQuotes(s string) string {
Expand Down
2 changes: 1 addition & 1 deletion customers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *Client) Get(customerId string) (*GetCustomerResponse, error) {
}

var response GetCustomerResponse
err = c.apiClient.Get(common.BuildPath(common.BuildPath(Path), customerId), auth, &response)
err = c.apiClient.Get(common.BuildPath(Path, customerId), auth, &response)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion disputes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *Client) Query(queryFilter QueryFilter) (*QueryResponse, error) {
return nil, err
}

url, err := common.BuildQueryPath(disputes, queryFilter)
url, err := common.BuildQueryPath(common.BuildPath(disputes), queryFilter)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions events/abc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *Client) RetrieveAllEventTypesQuery(
return nil, err
}

url, err := common.BuildQueryPath(eventTypes, query)
url, err := common.BuildQueryPath(common.BuildPath(eventTypes), query)

if err != nil {
return nil, err
Expand Down Expand Up @@ -77,7 +77,7 @@ func (c *Client) RetrieveEventsQuery(query QueryRetrieveEvents) (*EventsPageResp
return nil, err
}

url, err := common.BuildQueryPath(events, query)
url, err := common.BuildQueryPath(common.BuildPath(events), query)

if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion instruments/instruments.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/checkout/checkout-sdk-go/common"

const Path = "instruments"

const ValidationPath = "/validation/bank-accounts/"
const ValidationPath = "validation/bank-accounts"

type InstrumentType string

Expand Down
2 changes: 1 addition & 1 deletion payments/abc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *Client) RequestPaymentList(request payments.QueryRequest) (*GetPaymentL
return nil, err
}

url, err := common.BuildQueryPath(payments.PathPayments, request)
url, err := common.BuildQueryPath(common.BuildPath(payments.PathPayments), request)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion payments/nas/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *Client) RequestPaymentList(request payments.QueryRequest) (*GetPaymentL
return nil, err
}

url, err := common.BuildQueryPath(payments.PathPayments, request)
url, err := common.BuildQueryPath(common.BuildPath(payments.PathPayments), request)
if err != nil {
return nil, err
}
Expand Down
129 changes: 129 additions & 0 deletions reconciliation/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package reconciliation

import (
"github.com/checkout/checkout-sdk-go/client"
"github.com/checkout/checkout-sdk-go/common"
"github.com/checkout/checkout-sdk-go/configuration"
)

type Client struct {
configuration *configuration.Configuration
apiClient client.HttpClient
}

func NewClient(configuration *configuration.Configuration, apiClient client.HttpClient) *Client {
return &Client{
configuration: configuration,
apiClient: apiClient,
}
}

func (c *Client) QueryPaymentsReport(query PaymentReportsQuery) (*PaymentReportsResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey)
if err != nil {
return nil, err
}

url, err := common.BuildQueryPath(common.BuildPath(reporting, payments), query)
if err != nil {
return nil, err
}

var response PaymentReportsResponse
err = c.apiClient.Get(url, auth, &response)
if err != nil {
return nil, err
}

return &response, nil
}

func (c *Client) GetSinglePaymentReport(paymentId string) (*PaymentReportsResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey)
if err != nil {
return nil, err
}

var response PaymentReportsResponse
err = c.apiClient.Get(common.BuildPath(reporting, payments, paymentId), auth, &response)
if err != nil {
return nil, err
}

return &response, nil
}

func (c *Client) QueryStatementsReport(query common.DateRangeQuery) (*StatementReportsResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey)
if err != nil {
return nil, err
}

url, err := common.BuildQueryPath(common.BuildPath(reporting, statements), query)
if err != nil {
return nil, err
}

var response StatementReportsResponse
err = c.apiClient.Get(url, auth, &response)
if err != nil {
return nil, err
}

return &response, nil
}

func (c *Client) RetrieveCVSPaymentsReport(query common.DateRangeQuery) (*common.ContentResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey)
if err != nil {
return nil, err
}

url, err := common.BuildQueryPath(common.BuildPath(reporting, payments, download), query)
if err != nil {
return nil, err
}

var response common.ContentResponse
err = c.apiClient.Get(url, auth, &response)
if err != nil {
return nil, err
}

return &response, nil
}

func (c *Client) RetrieveCVSSingleStatementReport(statementId string) (*common.ContentResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey)
if err != nil {
return nil, err
}

var response common.ContentResponse
err = c.apiClient.Get(common.BuildPath(reporting, statements, statementId, payments, download), auth, &response)
if err != nil {
return nil, err
}

return &response, nil
}

func (c *Client) RetrieveCVSStatementsReport(query common.DateRangeQuery) (*common.ContentResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey)
if err != nil {
return nil, err
}

url, err := common.BuildQueryPath(common.BuildPath(reporting, statements, download), query)
if err != nil {
return nil, err
}

var response common.ContentResponse
err = c.apiClient.Get(url, auth, &response)
if err != nil {
return nil, err
}

return &response, nil
}
Loading

0 comments on commit 6bd3c41

Please sign in to comment.