Skip to content

Commit

Permalink
Fix exposed structures and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zhutik committed Jul 9, 2017
1 parent b579670 commit db2b700
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 76 deletions.
10 changes: 5 additions & 5 deletions adyen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
)

// New - creates Adyen instance
func New(env Environment, username, password, clientID, merchantAccount string) *Adyen {
func New(env environment, username, password, clientID, merchantAccount string) *Adyen {
return &Adyen{
Credentials: NewCredentials(env, username, password, merchantAccount, clientID),
Currency: DefaultCurrency,
Expand All @@ -27,7 +27,7 @@ func New(env Environment, username, password, clientID, merchantAccount string)
// NewWithHPP - create new Adyen instance with HPP credentials
//
// Use this constructor when you need to use Adyen HPP API
func NewWithHPP(env Environment, username, password, clientID, merchantAccount, hmac, skinCode, shopperLocale string) *Adyen {
func NewWithHPP(env environment, username, password, clientID, merchantAccount, hmac, skinCode, shopperLocale string) *Adyen {
return &Adyen{
Credentials: NewCredentialsWithHPPSettings(env, username, password, merchantAccount, clientID, hmac, skinCode, shopperLocale),
Currency: DefaultCurrency,
Expand All @@ -43,17 +43,17 @@ type Adyen struct {

// ClientURL - returns URl, that need to loaded in UI, to encrypt Credit Card information
func (a *Adyen) ClientURL() string {
return a.Credentials.env.ClientURL(a.Credentials.clientID)
return a.Credentials.Env.ClientURL(a.Credentials.ClientID)
}

// AdyenURL returns Adyen backend URL
func (a *Adyen) AdyenURL(requestType string) string {
return a.Credentials.env.BaseURL(APIVersion) + "/" + requestType
return a.Credentials.Env.BaseURL(APIVersion) + "/" + requestType
}

// CreateHPPUrl returns Adyen HPP url
func (a *Adyen) CreateHPPUrl(requestType string) string {
return a.Credentials.env.HppURL(requestType)
return a.Credentials.Env.HppURL(requestType)
}

// AttachLogger attach logger to API instance
Expand Down
50 changes: 25 additions & 25 deletions credetials.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,60 @@ package adyen
//
// Description:
//
// - env - Environment for next API calls
// - Env - Environment for next API calls
// - Username - API username for authentication
// - Password - API password for authentication
// - merchantID - Merchant Account settings for payment and modification requests
// - clientID - Used to load external JS files from Adyen, to encrypt client requests
// - MerchantID - Merchant Account settings for payment and modification requests
// - ClientID - Used to load external JS files from Adyen, to encrypt client requests
//
// You can create new API user there: https://ca-test.adyen.com/ca/ca/config/users.shtml
type APICredentials struct {
env Environment
Env environment
Username string
Password string
merchantID string
clientID string
hppSettings HPPCredentials
MerchantID string
ClientID string
HppSettings HPPCredentials
}

// HPPCredentials used to communicate with Adyen HPP API
//
// Description:
//
// - hmac - is generated when new Skin is created in Adyen Customer Area
// - skinCode - skin code from Adyen CA
// - shopperLocale - merchant local settings (in ISO format)
// - Hmac - is generated when new Skin is created in Adyen Customer Area
// - SkinCode - skin code from Adyen CA
// - ShopperLocale - merchant local settings (in ISO format)
//
// New skin can be created there https://ca-test.adyen.com/ca/ca/skin/skins.shtml
type HPPCredentials struct {
hmac string
skinCode string
shopperLocale string
Hmac string
SkinCode string
ShopperLocale string
}

// NewCredentials create new APICredentials
func NewCredentials(env Environment, username, password, merchantID, clientID string) APICredentials {
func NewCredentials(env environment, username, password, merchantID, clientID string) APICredentials {
return APICredentials{
env: env,
Env: env,
Username: username,
Password: password,
merchantID: merchantID,
clientID: clientID,
MerchantID: merchantID,
ClientID: clientID,
}
}

// NewCredentialsWithHPPSettings create new APICredentials and specify Adyen Hosted Payment Page settings
func NewCredentialsWithHPPSettings(env Environment, username, password, merchantID, clientID, hmac, skinCode, shopperLocale string) APICredentials {
func NewCredentialsWithHPPSettings(env environment, username, password, merchantID, clientID, hmac, skinCode, shopperLocale string) APICredentials {
return APICredentials{
env: env,
Env: env,
Username: username,
Password: password,
merchantID: merchantID,
clientID: clientID,
hppSettings: HPPCredentials{
hmac: hmac,
skinCode: skinCode,
shopperLocale: shopperLocale,
MerchantID: merchantID,
ClientID: clientID,
HppSettings: HPPCredentials{
Hmac: hmac,
SkinCode: skinCode,
ShopperLocale: shopperLocale,
},
}
}
12 changes: 6 additions & 6 deletions directory_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ type DirectoryLookupResponse struct {
type PaymentMethod struct {
BrandCode string `json:"brandCode"`
Name string `json:"name"`
Logos Logos `json:"logos"`
Issuers []Issuer `json:"issuers"`
Logos logos `json:"logos"`
Issuers []issuer `json:"issuers"`
}

// Logos - payment method logos
// logos - payment method logos
//
// Part of DirectoryLookupResponse
type Logos struct {
type logos struct {
Normal string `json:"normal"`
Small string `json:"small"`
Tiny string `json:"tiny"`
}

// Issuer - bank issuer type
// issuer - bank issuer type
//
// Part of DirectoryLookupResponse
type Issuer struct {
type issuer struct {
IssuerID string `json:"issuerId"`
Name string `json:"name"`
}
14 changes: 7 additions & 7 deletions environment.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package adyen

// Environment structure to support testing and production
type Environment struct {
// environment structure to support testing and production
type environment struct {
apiURL string
clientURL string
hppURL string
}

// NewEnvironment create environment based on api url
func NewEnvironment(apiURL, clientURL, hppURL string) Environment {
return Environment{apiURL: apiURL, clientURL: clientURL, hppURL: hppURL}
func NewEnvironment(apiURL, clientURL, hppURL string) environment {
return environment{apiURL: apiURL, clientURL: clientURL, hppURL: hppURL}
}

// BaseURL returns api base url
func (e Environment) BaseURL(version string) string {
func (e environment) BaseURL(version string) string {
return e.apiURL + "/" + version
}

// ClientURL returns Adyen Client URL to load external scripts
func (e Environment) ClientURL(clientID string) string {
func (e environment) ClientURL(clientID string) string {
return e.clientURL + clientID + ".shtml"
}

// HppURL returns Adyen HPP url to execute Hosted Payment Paged API requests
func (e Environment) HppURL(request string) string {
func (e environment) HppURL(request string) string {
return e.hppURL + request + ".shtml"
}

Expand Down
16 changes: 8 additions & 8 deletions modification_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package adyen
Adyen Modification actions
*/
const (
CaptureType = "capture"
CancelType = "cancel"
CancelOrRefundType = "cancelOrRefund"
RefundType = "refund"
captureType = "capture"
cancelType = "cancel"
cancelOrRefundType = "cancelOrRefund"
refundType = "refund"
)

// ModificationGateway - Adyen modification transaction logic, capture, cancel, refunds and e.t.c
Expand All @@ -17,7 +17,7 @@ type ModificationGateway struct {

// Capture - Perform capture payment in Adyen
func (a *ModificationGateway) Capture(req *Capture) (*CaptureResponse, error) {
resp, err := a.execute(CaptureType, req)
resp, err := a.execute(captureType, req)

if err != nil {
return nil, err
Expand All @@ -28,7 +28,7 @@ func (a *ModificationGateway) Capture(req *Capture) (*CaptureResponse, error) {

// Cancel - Perform cancellation of the authorised transaction
func (a *ModificationGateway) Cancel(req *Cancel) (*CancelResponse, error) {
resp, err := a.execute(CancelType, req)
resp, err := a.execute(cancelType, req)

if err != nil {
return nil, err
Expand All @@ -40,7 +40,7 @@ func (a *ModificationGateway) Cancel(req *Cancel) (*CancelResponse, error) {
// CancelOrRefund - Perform cancellation for not captured transaction
// otherwise perform refund action
func (a *ModificationGateway) CancelOrRefund(req *Cancel) (*CancelOrRefundResponse, error) {
resp, err := a.execute(CancelOrRefundType, req)
resp, err := a.execute(cancelOrRefundType, req)

if err != nil {
return nil, err
Expand All @@ -51,7 +51,7 @@ func (a *ModificationGateway) CancelOrRefund(req *Cancel) (*CancelOrRefundRespon

// Refund - perform refund for already captured request
func (a *ModificationGateway) Refund(req *Refund) (*RefundResponse, error) {
resp, err := a.execute(RefundType, req)
resp, err := a.execute(refundType, req)

if err != nil {
return nil, err
Expand Down
14 changes: 7 additions & 7 deletions payment_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ type PaymentGateway struct {
*Adyen
}

// AuthoriseType - authorise type request, @TODO: move to enums
const AuthoriseType = "authorise"
// authoriseType - authorise type request, @TODO: move to enums
const authoriseType = "authorise"

// DirectoryLookupURL - version 2 url for Directory Lookup request
const DirectoryLookupURL = "directory/v2"
// directoryLookupURL - version 2 url for Directory Lookup request
const directoryLookupURL = "directory/v2"

// AuthoriseEncrypted - Perform authorise payment in Adyen
func (a *PaymentGateway) AuthoriseEncrypted(req *AuthoriseEncrypted) (*AuthoriseResponse, error) {
resp, err := a.execute(AuthoriseType, req)
resp, err := a.execute(authoriseType, req)

if err != nil {
return nil, err
Expand All @@ -24,7 +24,7 @@ func (a *PaymentGateway) AuthoriseEncrypted(req *AuthoriseEncrypted) (*Authorise

// Authorise - Perform authorise payment in Adyen
func (a *PaymentGateway) Authorise(req *Authorise) (*AuthoriseResponse, error) {
resp, err := a.execute(AuthoriseType, req)
resp, err := a.execute(authoriseType, req)

if err != nil {
return nil, err
Expand All @@ -42,7 +42,7 @@ func (a *PaymentGateway) DirectoryLookup(req *DirectoryLookupRequest) (*Director
return nil, err
}

resp, err := a.executeHpp(DirectoryLookupURL, req)
resp, err := a.executeHpp(directoryLookupURL, req)

if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net/http"
)

// APIError - handle error (non 200 status) response from Adyen
type APIError struct {
// apiError - handle error (non 200 status) response from Adyen
type apiError struct {
ErrorType string `json:"errorType"`
ErrorCode string `json:"errorCode"`
Message string `json:"message"`
Expand All @@ -22,7 +22,7 @@ type Response struct {

// handleHTTPError - handle non 200 response from Adyen and create Error response instance
func (r *Response) handleHTTPError() error {
var a APIError
var a apiError

json.Unmarshal(r.Body, &a)
if a.Status > 299 {
Expand All @@ -33,7 +33,7 @@ func (r *Response) handleHTTPError() error {
}

// Error - error interface for ApiError
func (e APIError) Error() string {
func (e apiError) Error() string {
return fmt.Sprintf("[%s][%d]: (%s) %s", e.ErrorType, e.Status, e.ErrorCode, e.Message)
}

Expand Down
28 changes: 14 additions & 14 deletions signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"strings"
)

// ReplaceSpecialChars replace special characters according to Adyen documentation
// replaceSpecialChars replace special characters according to Adyen documentation
//
// Link: https://docs.adyen.com/developers/payments/accepting-payments/hmac-signature-calculation
func ReplaceSpecialChars(value string) string {
func replaceSpecialChars(value string) string {
temp := strings.Replace(value, "\\", "\\\\", -1)
temp = strings.Replace(temp, ":", "\\:", -1)

Expand All @@ -25,40 +25,40 @@ func ReplaceSpecialChars(value string) string {
// Link: https://docs.adyen.com/developers/payments/accepting-payments/hmac-signature-calculation
// @todo: refactor this method
func (r *DirectoryLookupRequest) CalculateSignature(adyen *Adyen) error {
if len(adyen.Credentials.merchantID) == 0 ||
len(adyen.Credentials.hppSettings.skinCode) == 0 ||
len(adyen.Credentials.hppSettings.hmac) == 0 {
if len(adyen.Credentials.MerchantID) == 0 ||
len(adyen.Credentials.HppSettings.SkinCode) == 0 ||
len(adyen.Credentials.HppSettings.Hmac) == 0 {
return errors.New("merchantID, skinCode and HMAC hash need to be specified")
}

// @todo write sorting for this map
keys := "countryCode"
values := ReplaceSpecialChars(r.CountryCode)
values := replaceSpecialChars(r.CountryCode)

keys += ":" + "currencyCode"
values += ":" + ReplaceSpecialChars(r.CurrencyCode)
values += ":" + replaceSpecialChars(r.CurrencyCode)

keys += ":" + "merchantAccount"
values += ":" + ReplaceSpecialChars(adyen.Credentials.merchantID)
values += ":" + replaceSpecialChars(adyen.Credentials.MerchantID)

keys += ":" + "merchantReference"
values += ":" + ReplaceSpecialChars(r.MerchantReference)
values += ":" + replaceSpecialChars(r.MerchantReference)

keys += ":" + "paymentAmount"
values += ":" + ReplaceSpecialChars(strconv.Itoa(r.PaymentAmount))
values += ":" + replaceSpecialChars(strconv.Itoa(r.PaymentAmount))

keys += ":" + "sessionValidity"
values += ":" + ReplaceSpecialChars(r.SessionsValidity)
values += ":" + replaceSpecialChars(r.SessionsValidity)

keys += ":" + "shipBeforeDate"
values += ":" + ReplaceSpecialChars(r.ShipBeforeDate)
values += ":" + replaceSpecialChars(r.ShipBeforeDate)

keys += ":" + "skinCode"
values += ":" + ReplaceSpecialChars(adyen.Credentials.hppSettings.skinCode)
values += ":" + replaceSpecialChars(adyen.Credentials.HppSettings.SkinCode)

fullString := keys + ":" + values

src, err := hex.DecodeString(adyen.Credentials.hppSettings.hmac)
src, err := hex.DecodeString(adyen.Credentials.HppSettings.Hmac)

if err != nil {
return err
Expand Down

0 comments on commit db2b700

Please sign in to comment.