This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFactory.go
129 lines (104 loc) · 4.51 KB
/
Factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package connectsdk
import (
"github.com/Ingenico-ePayments/connect-sdk-go/communicator"
"github.com/Ingenico-ePayments/connect-sdk-go/configuration"
"github.com/Ingenico-ePayments/connect-sdk-go/defaultimpl"
)
// CreateConfiguration creates a CommunicatorConfiguration with default settings and the given apiKeyID and secretAPIKey
func CreateConfiguration(apiKeyID, secretAPIKey, integrator string) (*configuration.CommunicatorConfiguration, error) {
newConf := configuration.DefaultConfiguration(apiKeyID, secretAPIKey, integrator)
return &newConf, nil
}
// CreateSessionBuilder creates a SessionBuilder with default settings and the given apiKeyID and secretAPIKey
func CreateSessionBuilder(apiKeyID, secretAPIKey, integrator string) (*communicator.SessionBuilder, error) {
configuration, err := CreateConfiguration(apiKeyID, secretAPIKey, integrator)
if err != nil {
return nil, err
}
return CreateSessionBuilderFromConfiguration(configuration)
}
// CreateSessionBuilderFromConfiguration creates a SessionBuilder with the given CommunicatorConfiguration
func CreateSessionBuilderFromConfiguration(configuration *configuration.CommunicatorConfiguration) (*communicator.SessionBuilder, error) {
builder, err := communicator.NewSessionBuilder()
if err != nil {
return nil, err
}
connection, err := defaultimpl.NewDefaultConnection(configuration.SocketTimeout,
configuration.ConnectTimeout,
configuration.KeepAliveTimeout,
configuration.IdleTimeout,
configuration.MaxConnections,
configuration.Proxy)
if err != nil {
return nil, err
}
metaDataProviderBuilder := communicator.NewMetaDataProviderBuilder(configuration.Integrator)
metaDataProviderBuilder.ShoppingCartExtension = configuration.ShoppingCartExtension
metaDataProvider, err := metaDataProviderBuilder.Build()
if err != nil {
return nil, err
}
authenticator, err := defaultimpl.NewDefaultAuthenticator(configuration.AuthorizationType,
configuration.APIKeyID,
configuration.SecretAPIKey)
if err != nil {
return nil, err
}
return builder.WithAPIEndpoint(&configuration.APIEndpoint).WithConnection(connection).WithMetaDataProvider(metaDataProvider).WithAuthenticator(authenticator), nil
}
// CreateCommunicator creates a Communicator with default settings and the given apiKeyID and secretAPIKey
func CreateCommunicator(apiKeyID, secretAPIKey, integrator string) (*communicator.Communicator, error) {
configuration, err := CreateConfiguration(apiKeyID, secretAPIKey, integrator)
if err != nil {
return nil, err
}
return CreateCommunicatorFromConfiguration(configuration)
}
// CreateCommunicatorFromConfiguration creates a Communicator with the given CommunicatorConfiguration
func CreateCommunicatorFromConfiguration(configuration *configuration.CommunicatorConfiguration) (*communicator.Communicator, error) {
builder, err := CreateSessionBuilderFromConfiguration(configuration)
if err != nil {
return nil, err
}
session, err := builder.Build()
if err != nil {
return nil, err
}
return CreateCommunicatorFromSession(session)
}
// CreateCommunicatorFromSession creates a Communicator with the given Session
func CreateCommunicatorFromSession(session *communicator.Session) (*communicator.Communicator, error) {
marshaller, err := defaultimpl.NewDefaultMarshaller()
if err != nil {
return nil, err
}
return communicator.NewCommunicator(session, marshaller)
}
// CreateClient creates a Client with default settings and the given apiKeyID and secretAPIKey
func CreateClient(apiKeyID, secretAPIKey, integrator string) (*Client, error) {
communicator, err := CreateCommunicator(apiKeyID, secretAPIKey, integrator)
if err != nil {
return nil, err
}
return CreateClientFromCommunicator(communicator)
}
// CreateClientFromConfiguration creates a Client with the given CommunicatorConfiguration
func CreateClientFromConfiguration(configuration *configuration.CommunicatorConfiguration) (*Client, error) {
communicator, err := CreateCommunicatorFromConfiguration(configuration)
if err != nil {
return nil, err
}
return CreateClientFromCommunicator(communicator)
}
// CreateClientFromSession creates a Client with the given Session
func CreateClientFromSession(session *communicator.Session) (*Client, error) {
communicator, err := CreateCommunicatorFromSession(session)
if err != nil {
return nil, err
}
return CreateClientFromCommunicator(communicator)
}
// CreateClientFromCommunicator creates a Client with the given Communicator
func CreateClientFromCommunicator(communicator *communicator.Communicator) (*Client, error) {
return NewClient(communicator)
}