<commit_before>package adyen

import (
	"bytes"
	"encoding/json"
	"net/http"
)

// DefaultCurrency default currency for transactions
const DefaultCurrency = "EUR"

// New - creates Adyen instance
func New(username, password, clientID, merchantAccount string) *Adyen {
	return &Adyen{
		Username:        username,
		Password:        password,
		ClientID:        clientID,
		MerchantAccount: merchantAccount,
		Currency:        DefaultCurrency,
	}
}

// Adyen - base structure with configuration options
type Adyen struct {
	Username        string
	Password        string
	ClientID        string
	MerchantAccount string
	Currency        string
}

// Version of a current Adyen API
const (
	APIVersion         = "v25"
	AdyenTestURL       = "https://pal-test.adyen.com/pal/servlet/Payment"
	AdyenClientTestURL = "https://test.adyen.com/hpp/cse/js/"
)

// ClientURL - returns URl, that need to loaded in UI, to encrypt Credit Card information
func (a *Adyen) ClientURL() string {
	return AdyenClientTestURL + a.ClientID + ".shtml"
}

// AdyenURL returns Adyen backend URL
func (a *Adyen) AdyenURL(requestType string) string {
	return AdyenTestURL + "/" + APIVersion + "/" + requestType
}

// SetCurrency set default currency for transactions
func (a *Adyen) SetCurrency(currency string) {
	a.Currency = currency
}

// execute request on Adyen side, transforms "requestEntity" into JSON representation
func (a *Adyen) execute(method string, requestEntity interface{}) (*Response, error) {
	body, err := json.Marshal(requestEntity)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("POST", a.AdyenURL(method), bytes.NewBuffer(body))
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	req.SetBasicAuth(a.Username, a.Password)

	client := &http.Client{}
	resp, err := client.Do(req)

	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	buf := new(bytes.Buffer)
	buf.ReadFrom(resp.Body)

	//fmt.Println(buf.String())

	providerResponse := &Response{
		Response: resp,
		Body:     buf.Bytes(),
	}

	err = providerResponse.handleHTTPError()

	if err != nil {
		return nil, err
	}

	return providerResponse, nil
}

// Payment - returns PaymentGateway
func (a *Adyen) Payment() *PaymentGateway {
	return &PaymentGateway{a}
}

// Modification - returns ModificationGateway
func (a *Adyen) Modification() *ModificationGateway {<commit_msg>Add logger for API calls<commit_after>package adyen

import (
	"bytes"
	"encoding/json"
	"log"
	"net/http"
)

// DefaultCurrency default currency for transactions
const DefaultCurrency = "EUR"

// New - creates Adyen instance
func New(username, password, clientID, merchantAccount string) *Adyen {
	return &Adyen{
		Username:        username,
		Password:        password,
		ClientID:        clientID,
		MerchantAccount: merchantAccount,
		Currency:        DefaultCurrency,
	}
}

// Adyen - base structure with configuration options
type Adyen struct {
	Username        string
	Password        string
	ClientID        string
	MerchantAccount string
	Currency        string
	Logger          *log.Logger
}

// Version of a current Adyen API
const (
	APIVersion         = "v25"
	AdyenTestURL       = "https://pal-test.adyen.com/pal/servlet/Payment"
	AdyenClientTestURL = "https://test.adyen.com/hpp/cse/js/"
)

// ClientURL - returns URl, that need to loaded in UI, to encrypt Credit Card information
func (a *Adyen) ClientURL() string {
	return AdyenClientTestURL + a.ClientID + ".shtml"
}

// AdyenURL returns Adyen backend URL
func (a *Adyen) AdyenURL(requestType string) string {
	return AdyenTestURL + "/" + APIVersion + "/" + requestType
}

// AttachLogger attach logger to API instance
func (a *Adyen) AttachLogger(Logger *log.Logger) {
	a.Logger = Logger
}

// SetCurrency set default currency for transactions
func (a *Adyen) SetCurrency(currency string) {
	a.Currency = currency
}

// execute request on Adyen side, transforms "requestEntity" into JSON representation
func (a *Adyen) execute(method string, requestEntity interface{}) (*Response, error) {
	body, err := json.Marshal(requestEntity)
	if err != nil {
		return nil, err
	}

	url := a.AdyenURL(method)
	req, err := http.NewRequest("POST", url, bytes.NewBuffer(body))
	if err != nil {
		return nil, err
	}

	if a.Logger != nil {
		a.Logger.Printf("[Request]: %s %s\n%s", method, url, body)
	}

	req.Header.Set("Content-Type", "application/json")
	req.SetBasicAuth(a.Username, a.Password)

	client := &http.Client{}
	resp, err := client.Do(req)

	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	buf := new(bytes.Buffer)
	buf.ReadFrom(resp.Body)

	if a.Logger != nil {
		a.Logger.Printf("[Response]: %s %s\n%s", method, url, buf.String())
	}

	providerResponse := &Response{
		Response: resp,
		Body:     buf.Bytes(),
	}

	err = providerResponse.handleHTTPError()

	if err != nil {
		return nil, err
	}

	return providerResponse, nil
}

// Payment - returns PaymentGateway
func (a *Adyen) Payment() *PaymentGateway {
	return &PaymentGateway{a}
}

// Modification - returns ModificationGateway
func (a *Adyen) Modification() *ModificationGateway {
{'fraction_non_alphanumeric': 0.11946125317196955, 'fraction_numerical': 0.0007807925043919579, 'mean_word_length': 3.63710407239819, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1927589', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1693, 'n_words': 469}