zipMoney 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +287 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/zipMoney.rb +54 -0
- data/lib/zipMoney/api.rb +192 -0
- data/lib/zipMoney/api/cancel.rb +44 -0
- data/lib/zipMoney/api/capture.rb +44 -0
- data/lib/zipMoney/api/checkout.rb +52 -0
- data/lib/zipMoney/api/configure.rb +34 -0
- data/lib/zipMoney/api/query.rb +43 -0
- data/lib/zipMoney/api/quote.rb +54 -0
- data/lib/zipMoney/api/refund.rb +46 -0
- data/lib/zipMoney/api/settings.rb +16 -0
- data/lib/zipMoney/configuration.rb +49 -0
- data/lib/zipMoney/errors.rb +11 -0
- data/lib/zipMoney/express.rb +65 -0
- data/lib/zipMoney/request.rb +22 -0
- data/lib/zipMoney/resources.rb +71 -0
- data/lib/zipMoney/response.rb +68 -0
- data/lib/zipMoney/util.rb +53 -0
- data/lib/zipMoney/version.rb +3 -0
- data/lib/zipMoney/webhook.rb +67 -0
- data/zipMoney.gemspec +37 -0
- metadata +145 -0
data/lib/zipMoney/api.rb
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
module ZipMoney
|
2
|
+
class Api
|
3
|
+
|
4
|
+
attr_accessor :options, :config, :payload, :response
|
5
|
+
|
6
|
+
HTTP_METHOD_POST = :post
|
7
|
+
HTTP_METHOD_GET = :get
|
8
|
+
|
9
|
+
# Initializes a new api object
|
10
|
+
#
|
11
|
+
# @param [conf] ZipMoney::Configuration
|
12
|
+
# @param [options] api options
|
13
|
+
#
|
14
|
+
# @return ZipMoney::Api instance
|
15
|
+
def initialize(conf,options={})
|
16
|
+
if conf.new.class == ZipMoney::Configuration
|
17
|
+
@config = conf
|
18
|
+
else
|
19
|
+
raise ArgumentError, "Config is not valid"
|
20
|
+
end
|
21
|
+
@options = options
|
22
|
+
end
|
23
|
+
|
24
|
+
# Appends api credentials to the request object
|
25
|
+
#
|
26
|
+
# @param [data] Request data
|
27
|
+
#
|
28
|
+
# @return data
|
29
|
+
def append_api_credentials(params)
|
30
|
+
is_param_defined(params) do
|
31
|
+
params = Struct::ApiCredentials.new
|
32
|
+
params.version = Struct::Version.new
|
33
|
+
end
|
34
|
+
if params.merchant_id == nil
|
35
|
+
params.merchant_id = self.config.merchant_id
|
36
|
+
end
|
37
|
+
if params.merchant_key == nil
|
38
|
+
params.merchant_key = self.config.merchant_key
|
39
|
+
end
|
40
|
+
if params.version.client == nil
|
41
|
+
params.version.client = ZipMoney::Configuration::API_NAME + " Version:" + ZipMoney::Configuration::API_VERSION
|
42
|
+
end
|
43
|
+
if params.version.platform == nil
|
44
|
+
params.version.platform = ZipMoney::Configuration::API_PLATFORM
|
45
|
+
end
|
46
|
+
params
|
47
|
+
end
|
48
|
+
|
49
|
+
# Checks if data is a Struct and calls the block passed as parameter if true
|
50
|
+
#
|
51
|
+
# @param [data] Request data
|
52
|
+
#
|
53
|
+
# @return true|false
|
54
|
+
def is_param_defined(params)
|
55
|
+
yield if !params.is_a?(Struct)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Makes request to the zipMoney endpoint
|
59
|
+
#
|
60
|
+
# @param [resource] endpoint resource
|
61
|
+
# @param [method] method get|post
|
62
|
+
# @param [params] request parameters
|
63
|
+
#
|
64
|
+
# @return ZipMoney::Response object
|
65
|
+
def request(resource, method, params = nil)
|
66
|
+
resource = Resources.get(resource, method, params)
|
67
|
+
params = append_api_credentials(params)
|
68
|
+
|
69
|
+
if method == :post
|
70
|
+
payload = prepare_params(params)
|
71
|
+
else
|
72
|
+
payload = {}
|
73
|
+
end
|
74
|
+
|
75
|
+
headers = @options[:headers] || {}
|
76
|
+
if method == :get
|
77
|
+
resource.send(method, headers) do |response, request, result, &block|
|
78
|
+
ZipMoney::Response.new(response)
|
79
|
+
end
|
80
|
+
else
|
81
|
+
resource.send(method, payload, headers) do |response, request, result, &block|
|
82
|
+
ZipMoney::Response.new(response)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Converts the parameters(Hash) to json
|
88
|
+
#
|
89
|
+
# @param [params] request parameters
|
90
|
+
#
|
91
|
+
# @return data as json
|
92
|
+
def prepare_params(params)
|
93
|
+
begin
|
94
|
+
params = Util.struct_to_hash(params).to_json
|
95
|
+
rescue TypeError => e
|
96
|
+
if params.is_a?(Hash)
|
97
|
+
params = params.to_json
|
98
|
+
else
|
99
|
+
raise ArgumentError, "Invalid params provided"
|
100
|
+
end
|
101
|
+
rescue JSON::ParserError => e
|
102
|
+
if params.is_a?(Hash)
|
103
|
+
params = params.to_json
|
104
|
+
else
|
105
|
+
raise ArgumentError, "Invalid params provided"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
params
|
109
|
+
end
|
110
|
+
|
111
|
+
# Makes checkout call on the zipMoney endpoint
|
112
|
+
#
|
113
|
+
# @param [params] request parameters
|
114
|
+
#
|
115
|
+
# @return ZipMoney::Response object
|
116
|
+
def checkout(params)
|
117
|
+
request(Resources::RESOURCE_CHECKOUT, HTTP_METHOD_POST, params)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Makes quote call on the zipMoney endpoint
|
121
|
+
#
|
122
|
+
# @param [params] request parameters
|
123
|
+
#
|
124
|
+
# @return ZipMoney::Response object
|
125
|
+
def quote(params)
|
126
|
+
request(Resources::RESOURCE_QUOTE, HTTP_METHOD_POST, params)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Makes capture call on the zipMoney endpoint
|
130
|
+
#
|
131
|
+
# @param [params] request parameters
|
132
|
+
#
|
133
|
+
# @return ZipMoney::Response object
|
134
|
+
def capture(params)
|
135
|
+
request(Resources::RESOURCE_CAPTURE, HTTP_METHOD_POST, params)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Makes refund call on the zipMoney endpoint
|
139
|
+
#
|
140
|
+
# @param [params] request parameters
|
141
|
+
#
|
142
|
+
# @return ZipMoney::Response object
|
143
|
+
def refund(params)
|
144
|
+
request(Resources::RESOURCE_REFUND, HTTP_METHOD_POST, params)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Makes cancel call on the zipMoney endpoint
|
148
|
+
#
|
149
|
+
# @param [params] request parameters
|
150
|
+
#
|
151
|
+
# @return ZipMoney::Response object
|
152
|
+
def cancel(params)
|
153
|
+
request(Resources::RESOURCE_CANCEL, HTTP_METHOD_POST, params)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Makes query call on the zipMoney endpoint
|
157
|
+
#
|
158
|
+
# @param [params] request parameters
|
159
|
+
#
|
160
|
+
# @return ZipMoney::Response object
|
161
|
+
def query(params)
|
162
|
+
request(Resources::RESOURCE_QUERY, HTTP_METHOD_POST, params)
|
163
|
+
end
|
164
|
+
|
165
|
+
# Makes configure call on the zipMoney endpoint
|
166
|
+
#
|
167
|
+
# @param [params] request parameters
|
168
|
+
#
|
169
|
+
# @return ZipMoney::Response object
|
170
|
+
def configure(params)
|
171
|
+
request(Resources::RESOURCE_CONFIGURE, HTTP_METHOD_POST, params)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Makes settings call on the zipMoney endpoint
|
175
|
+
#
|
176
|
+
# @param [params] request parameters
|
177
|
+
#
|
178
|
+
# @return ZipMoney::Response object
|
179
|
+
def settings
|
180
|
+
request(Resources::RESOURCE_SETTINGS, HTTP_METHOD_POST)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Makes heartbeat call on the zipMoney endpoint
|
184
|
+
#
|
185
|
+
# @param [params] request parameters
|
186
|
+
#
|
187
|
+
# @return ZipMoney::Response object
|
188
|
+
def heartbeat
|
189
|
+
request(Resources::RESOURCE_HEARTBEAT, HTTP_METHOD_POST)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ZipMoney
|
2
|
+
class Cancel
|
3
|
+
include Request
|
4
|
+
|
5
|
+
attr_accessor :params
|
6
|
+
Struct.new("CancelParams", :txn_id, :merchant_id, :merchant_key, :order, :order_id, :quote_id, :reference, :version, :metadata)
|
7
|
+
|
8
|
+
# Initializes a ZipMoney::Cancel object
|
9
|
+
#
|
10
|
+
# Returns ZipMoney::Cancel object
|
11
|
+
def initialize
|
12
|
+
@params = Struct::CancelParams.new
|
13
|
+
@params.order = Struct::Order.new
|
14
|
+
@params.order.detail = Array.new
|
15
|
+
@params.metadata = Struct::Metadata.new
|
16
|
+
@params.version = Struct::Version.new
|
17
|
+
end
|
18
|
+
|
19
|
+
# Performs the Cancel api call on zipMoney endpoint
|
20
|
+
#
|
21
|
+
# Returns ZipMoney::Cancel object
|
22
|
+
def do
|
23
|
+
validate
|
24
|
+
ZipMoney.api.cancel(@params)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Performs the parameters validation
|
28
|
+
def validate
|
29
|
+
raise ArgumentError, "Params emtpy" if @params.nil?
|
30
|
+
@errors = []
|
31
|
+
@errors << 'txn_id must be provided' if @params.txn_id.nil?
|
32
|
+
@errors << 'order must be provided' if @params.order.nil?
|
33
|
+
@errors << 'order.id must be provided' if @params.order.id.nil?
|
34
|
+
@errors << 'order.total must be provided' if@params.order.total.nil?
|
35
|
+
@errors << 'order.shipping_value must be provided' if @params.order.shipping_value.nil?
|
36
|
+
@errors << 'order.tax must be provided' if @params.order.tax.nil?
|
37
|
+
@errors << 'order detail must be provided' if @params.order.detail.nil?
|
38
|
+
|
39
|
+
validate_item_details @params.order.detail
|
40
|
+
|
41
|
+
raise ZipMoney::RequestError.new("Following error(s) occurred while making request, please resolve them to make the request: #{@errors}") if @errors.any?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ZipMoney
|
2
|
+
class Capture
|
3
|
+
include Request
|
4
|
+
|
5
|
+
attr_accessor :params
|
6
|
+
|
7
|
+
Struct.new("CaptureParams", :txn_id, :order_id, :quote_id, :order, :reference, :version, :metadata, :merchant_id, :merchant_key)
|
8
|
+
|
9
|
+
# Initializes a ZipMoney::Capture object
|
10
|
+
#
|
11
|
+
# Returns ZipMoney::Capture object
|
12
|
+
def initialize
|
13
|
+
@params = Struct::CaptureParams.new
|
14
|
+
@params.order = Struct::Order.new
|
15
|
+
@params.metadata = Struct::Metadata.new
|
16
|
+
@params.version = Struct::Version.new
|
17
|
+
@params.order.detail = Array.new
|
18
|
+
end
|
19
|
+
|
20
|
+
# Performs the Capture api call on zipMoney endpoint
|
21
|
+
#
|
22
|
+
# Returns ZipMoney::Cancel object
|
23
|
+
def do
|
24
|
+
validate
|
25
|
+
ZipMoney.api.capture(@params)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Performs the parameters validation
|
29
|
+
def validate
|
30
|
+
raise ArgumentError, "Params emtpy" if @params.nil?
|
31
|
+
@errors = []
|
32
|
+
@errors << 'txn_id must be provided' if @params.txn_id.nil?
|
33
|
+
@errors << 'order.id must be provided' if @params.order.id.nil?
|
34
|
+
@errors << 'order.total must be provided' if @params.order.total.nil?
|
35
|
+
@errors << 'order.shipping_value must be provided' if @params.order.shipping_value.nil?
|
36
|
+
@errors << 'order.tax must be provided' if @params.order.tax.nil?
|
37
|
+
@errors << 'order detail must be provided' if @params.order.detail.nil?
|
38
|
+
|
39
|
+
validate_item_details @params.order.detail
|
40
|
+
|
41
|
+
raise ZipMoney::RequestError.new("Following error(s) occurred while making request, please resolve them to make the request: #{@errors}") if @errors.any?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ZipMoney
|
2
|
+
class Checkout
|
3
|
+
include Request
|
4
|
+
|
5
|
+
attr_accessor :params
|
6
|
+
|
7
|
+
Struct.new("CheckoutParams", :charge, :currency_code, :return_url, :cancel_url, :notify_url, :error_url, :in_store, :txn_id, :token, :merchant_id, :merchant_key,
|
8
|
+
:order_id, :order, :consumer, :billing_address, :shipping_address, :version, :metadata)
|
9
|
+
|
10
|
+
# Initializes a ZipMoney::Checkout object
|
11
|
+
#
|
12
|
+
# Returns ZipMoney::Checkout object
|
13
|
+
def initialize
|
14
|
+
@params = Struct::CheckoutParams.new
|
15
|
+
@params.order = Struct::Order.new
|
16
|
+
@params.billing_address = Struct::Address.new
|
17
|
+
@params.shipping_address = Struct::Address.new
|
18
|
+
@params.consumer = Struct::Consumer.new
|
19
|
+
@params.metadata = Struct::Metadata.new
|
20
|
+
@params.version = Struct::Version.new
|
21
|
+
@params.order.detail = Array.new
|
22
|
+
end
|
23
|
+
|
24
|
+
# Performs the Checkout api call on zipMoney endpoint
|
25
|
+
#
|
26
|
+
# Returns ZipMoney::Checkout object
|
27
|
+
def do
|
28
|
+
validate
|
29
|
+
|
30
|
+
ZipMoney.api.checkout(self.params)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Performs the parameters validation
|
34
|
+
def validate
|
35
|
+
raise ArgumentError, "Params emtpy" if @params.nil?
|
36
|
+
@errors = []
|
37
|
+
@errors << 'charge must be provided' if @params.charge.nil?
|
38
|
+
@errors << 'currency_code must be provided' if @params.currency_code.nil?
|
39
|
+
@errors << 'order_id must be provided' if @params.order_id.nil?
|
40
|
+
@errors << 'order must be provided' if @params.order.nil?
|
41
|
+
@errors << 'order.id must be provided' if @params.order.id.nil?
|
42
|
+
@errors << 'order.total must be provided' if @params.order.total.nil?
|
43
|
+
@errors << 'order.shipping_value must be provided' if @params.order.shipping_value.nil?
|
44
|
+
@errors << 'order.tax must be provided' if @params.order.tax.nil?
|
45
|
+
@errors << 'order detail must be provided' if @params.order.detail.nil?
|
46
|
+
|
47
|
+
validate_item_details @params.order.detail
|
48
|
+
|
49
|
+
raise ZipMoney::RequestError.new("Following error(s) occurred while making request, please resolve them to make the request: #{@errors}") if @errors.any?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ZipMoney
|
2
|
+
class Configure
|
3
|
+
include Request
|
4
|
+
|
5
|
+
attr_accessor :params
|
6
|
+
|
7
|
+
Struct.new("ConfigureParams", :base_url, :merchant_id, :merchant_key, :version, :metadata)
|
8
|
+
|
9
|
+
# Initializes a ZipMoney::Configure object
|
10
|
+
#
|
11
|
+
# Returns ZipMoney::Configure object
|
12
|
+
def initialize
|
13
|
+
@params = Struct::ConfigureParams.new
|
14
|
+
@params.metadata = Struct::Metadata.new
|
15
|
+
@params.version = Struct::Version.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# Performs the Configure api call on zipMoney endpoint
|
19
|
+
#
|
20
|
+
# Returns ZipMoney::Configure object
|
21
|
+
def do
|
22
|
+
validate
|
23
|
+
ZipMoney.api.configure(self.params)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Performs the parameters validation
|
27
|
+
def validate
|
28
|
+
raise ArgumentError, "Params emtpy" if params.nil?
|
29
|
+
@errors = []
|
30
|
+
@errors << 'base_url must be provided' if self.params.txn_id.nil?
|
31
|
+
raise ZipMoney::RequestError.new("Following error(s) occurred while making request, please resolve them to make the request: #{@errors}") if @errors.any?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ZipMoney
|
2
|
+
class Query
|
3
|
+
include Request
|
4
|
+
|
5
|
+
attr_accessor :params
|
6
|
+
|
7
|
+
Struct.new("QueryParams", :orders, :merchant_id, :merchant_key, :version, :metadata)
|
8
|
+
Struct.new("QueryOrder", :id, :status, :error_message, :txn_id)
|
9
|
+
|
10
|
+
# Initializes a ZipMoney::Query object
|
11
|
+
#
|
12
|
+
# Returns ZipMoney::Query object
|
13
|
+
def initialize
|
14
|
+
@params = Struct::QueryParams.new
|
15
|
+
@params.orders = Array.new
|
16
|
+
@params.metadata = Struct::Metadata.new
|
17
|
+
@params.version = Struct::Version.new
|
18
|
+
end
|
19
|
+
|
20
|
+
# Performs the Query api call on zipMoney endpoint
|
21
|
+
#
|
22
|
+
# Returns ZipMoney::Query object
|
23
|
+
def do
|
24
|
+
validate
|
25
|
+
ZipMoney.api.query(@params)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Performs the parameters validation
|
29
|
+
def validate
|
30
|
+
raise ArgumentError, "Params emtpy" if @params.nil?
|
31
|
+
@errors = []
|
32
|
+
@errors << 'at least one order must be provided' if @params.orders.nil?
|
33
|
+
|
34
|
+
@params.orders.each_with_index do |item,index|
|
35
|
+
@errors << "order.detail[#{index}].id must be provided" if item.id.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
raise ZipMoney::RequestError.new("Following error(s) occurred while making request, please resolve them to make the request: #{@errors}") if @errors.any?
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module ZipMoney
|
2
|
+
class Quote
|
3
|
+
include Request
|
4
|
+
|
5
|
+
attr_accessor :params
|
6
|
+
|
7
|
+
Struct.new("QuoteParams", :currency_code, :cart_url, :success_url, :cancel_url, :refer_url, :error_url, :decline_url, :in_store, :checkout_source, :txn_id, :merchant_id, :merchant_key,
|
8
|
+
:quote_id, :order, :consumer, :billing_address, :shipping_address, :version, :metadata, :token)
|
9
|
+
|
10
|
+
# Initializes a ZipMoney::Quote object
|
11
|
+
#
|
12
|
+
# Returns ZipMoney::Quote object
|
13
|
+
def initialize
|
14
|
+
@params = Struct::QuoteParams.new
|
15
|
+
@params.order = Struct::Order.new
|
16
|
+
@params.billing_address = Struct::Address.new
|
17
|
+
@params.shipping_address = Struct::Address.new
|
18
|
+
@params.consumer = Struct::Consumer.new
|
19
|
+
@params.metadata = Struct::Metadata.new
|
20
|
+
@params.version = Struct::Version.new
|
21
|
+
@params.order.detail = Array.new
|
22
|
+
end
|
23
|
+
|
24
|
+
# Performs the Quote api call on zipMoney endpoint
|
25
|
+
#
|
26
|
+
# Returns ZipMoney::Quote object
|
27
|
+
def do
|
28
|
+
validate
|
29
|
+
ZipMoney.api.quote(@params)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Performs the parameters validation
|
33
|
+
def validate
|
34
|
+
raise ArgumentError, "Params emtpy" if @params.nil?
|
35
|
+
@errors = []
|
36
|
+
@errors << 'quote_id must be provided' if @params.quote_id.nil?
|
37
|
+
@errors << 'success_url must be provided' if @params.success_url.nil?
|
38
|
+
@errors << 'cancel_url must be provided' if @params.cancel_url.nil?
|
39
|
+
@errors << 'error_url must be provided' if @params.error_url.nil?
|
40
|
+
@errors << 'decline_url must be provided' if @params.decline_url.nil?
|
41
|
+
@errors << 'quote_id must be provided' if @params.quote_id.nil?
|
42
|
+
@errors << 'order must be provided' if @params.order.nil?
|
43
|
+
@errors << 'order.id must be provided' if @params.order.id.nil?
|
44
|
+
@errors << 'order.total must be provided' if @params.order.total.nil?
|
45
|
+
@errors << 'order.shipping_value must be provided' if @params.order.shipping_value.nil?
|
46
|
+
@errors << 'order.tax must be provided' if @params.order.tax.nil?
|
47
|
+
@errors << 'order detail must be provided' if @params.order.detail.nil?
|
48
|
+
|
49
|
+
validate_item_details @params.order.detail
|
50
|
+
|
51
|
+
raise ZipMoney::RequestError.new("Following error(s) occurred while making request, please resolve them to make the request: #{@errors}") if @errors.any?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|