epayments_client 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/epa/client.rb +11 -0
- data/lib/epa/json/client.rb +11 -11
- data/lib/epa/soap/client.rb +162 -0
- data/lib/epa/soap/exceptions.rb +6 -0
- data/lib/epayments_client.rb +4 -1
- metadata +23 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c35a5eef6cfafb897a4c36b12752e463ca0942c1
|
4
|
+
data.tar.gz: 7a40305a15a01f0b7277fc2fa9a8b92e407b1b98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba76617f38c931cbddf68f3ef86da9e7cbb2f7205ec323739d0e6a5825962a6afd9110db26ca3a02984a8c2d11ae38f4732de7d8e873aacff433fd8c0486dac5
|
7
|
+
data.tar.gz: 97bf29473eae9b27151619514c2a8f10956033d0d8975c15f37e3bae394e01a8be88862db0e19328323ae37472cdc9153d92da510cdf82a60195b250a868a8f6
|
data/lib/epa/client.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module Epa
|
2
|
+
class Client
|
3
|
+
def initialize(id, secret, api_type = :soap, options= {})
|
4
|
+
@client = "Epa::#{api_type.to_s.camelize}::Client".constantize.new(id, secret, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_missing(method, *arguments, &block)
|
8
|
+
@client.send method, *arguments
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/epa/json/client.rb
CHANGED
@@ -94,17 +94,6 @@ module Epa
|
|
94
94
|
response["transactions"]
|
95
95
|
end
|
96
96
|
|
97
|
-
private
|
98
|
-
|
99
|
-
def headers
|
100
|
-
@token ||= get_token
|
101
|
-
{
|
102
|
-
'Authorization' => "Bearer #{@token}",
|
103
|
-
'Accept' => 'application/json',
|
104
|
-
'Content-Type' => 'application/json'
|
105
|
-
}
|
106
|
-
end
|
107
|
-
|
108
97
|
def call_json_api(path, method = 'get', payload = "", headers = {})
|
109
98
|
uri = URI(API_URL)
|
110
99
|
uri.path = path
|
@@ -123,6 +112,17 @@ module Epa
|
|
123
112
|
json_response
|
124
113
|
end
|
125
114
|
|
115
|
+
private
|
116
|
+
|
117
|
+
def headers
|
118
|
+
@token ||= get_token
|
119
|
+
{
|
120
|
+
'Authorization' => "Bearer #{@token}",
|
121
|
+
'Accept' => 'application/json',
|
122
|
+
'Content-Type' => 'application/json'
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
126
|
def guess_code(code, message)
|
127
127
|
numbers = message.scan(/\d\,\d\,\d/).first
|
128
128
|
numbers.split(/\,/).map { |i| code[i.to_i - 1] }.join
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'savon'
|
2
|
+
require 'active_support/all'
|
3
|
+
|
4
|
+
module Epa
|
5
|
+
module Soap
|
6
|
+
class Client
|
7
|
+
|
8
|
+
attr_accessor :client_id, :secret_key, :config, :client
|
9
|
+
|
10
|
+
DEFAULTS = {
|
11
|
+
namespace_identifier: :tem,
|
12
|
+
env_namespace: :soapenv,
|
13
|
+
ssl_verify_mode: :none,
|
14
|
+
wsdl: 'https://www.epayments.com/api_v1.3/APIService.svc?wsdl',
|
15
|
+
log: false,
|
16
|
+
adapter: :net_http
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize(client_id, secret_key, options = {})
|
20
|
+
@client_id = client_id
|
21
|
+
@secret_key = secret_key
|
22
|
+
@config = DEFAULTS.merge options
|
23
|
+
end
|
24
|
+
|
25
|
+
def client
|
26
|
+
@client = Savon.client wsdl: config[:wsdl],
|
27
|
+
namespace_identifier: config[:namespace_identifier],
|
28
|
+
env_namespace: config[:env_namespace],
|
29
|
+
ssl_verify_mode: config[:ssl_verify_mode],
|
30
|
+
log: config[:log],
|
31
|
+
adapter: config[:adapter]
|
32
|
+
end
|
33
|
+
|
34
|
+
# available operations for Epayments API
|
35
|
+
def operations
|
36
|
+
client.operations
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_balances
|
40
|
+
payload = {
|
41
|
+
external_partner_id: client_id
|
42
|
+
}
|
43
|
+
|
44
|
+
call_soap_api __method__, payload, [:balances, :e_wallet_balance]
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_balance(currency, wallet)
|
48
|
+
payload = {
|
49
|
+
external_partner_id: client_id,
|
50
|
+
currency: currency,
|
51
|
+
e_wallet: wallet
|
52
|
+
}
|
53
|
+
|
54
|
+
call_soap_api __method__, payload, :balance
|
55
|
+
end
|
56
|
+
|
57
|
+
def balance(currency = 'USD', e_wallet = nil)
|
58
|
+
wallet = if e_wallet
|
59
|
+
get_balances.detect{|b| b[:currency] == currency && b[:e_wallet_number] == e_wallet}
|
60
|
+
else
|
61
|
+
get_balances.detect{|b| b[:currency] == currency}
|
62
|
+
end
|
63
|
+
wallet[:balance].to_f if wallet
|
64
|
+
end
|
65
|
+
|
66
|
+
def internal_payment(options)
|
67
|
+
payload = {
|
68
|
+
external_partner_id: client_id,
|
69
|
+
from_wallet_id: options[:from_wallet_id],
|
70
|
+
to_wallet_id: options[:to_wallet_id],
|
71
|
+
amount: options[:amount],
|
72
|
+
currency: options[:currency],
|
73
|
+
payment_id: options[:payment_id],
|
74
|
+
details: options[:details]
|
75
|
+
}
|
76
|
+
|
77
|
+
call_soap_api __method__, payload, :transaction_id
|
78
|
+
end
|
79
|
+
|
80
|
+
def transfer_funds(options)
|
81
|
+
internal_payment from_wallet_id: options[:from],
|
82
|
+
to_wallet_id: options[:to],
|
83
|
+
amount: options[:amount],
|
84
|
+
currency: options[:currency] || 'USD',
|
85
|
+
payment_id: options[:payment_id] || rand(2**32),
|
86
|
+
details: options[:details]
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_incoming_transactions options
|
90
|
+
payload = {
|
91
|
+
external_partner_id: client_id,
|
92
|
+
date_from: options[:date_from],
|
93
|
+
date_to: options[:date_to],
|
94
|
+
currency: options[:currency] || 'USD'
|
95
|
+
}
|
96
|
+
|
97
|
+
call_soap_api __method__, payload, [:transactions, :incoming_transaction]
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_transaction(options)
|
101
|
+
payload = {
|
102
|
+
external_partner_id: client_id,
|
103
|
+
e_wallet: options[:e_wallet],
|
104
|
+
transaction_id: options[:transaction_id]
|
105
|
+
}
|
106
|
+
call_soap_api __method__, payload, :transaction
|
107
|
+
end
|
108
|
+
|
109
|
+
def call_soap_api operation, params, return_key = nil
|
110
|
+
response = client.call operation, :message => prepare_body(params)
|
111
|
+
result = response.body[:"#{operation}_response"][:"#{operation}_result"]
|
112
|
+
if result[:response_code] == 'Ok'
|
113
|
+
return result if return_key.nil?
|
114
|
+
if return_key.is_a? Array
|
115
|
+
return_key.each { |value| result = result.[](value) }
|
116
|
+
result
|
117
|
+
else
|
118
|
+
result[return_key]
|
119
|
+
end
|
120
|
+
else
|
121
|
+
raise ApiError, result[:response_code]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
# generates signature
|
128
|
+
def sign params
|
129
|
+
signature = params.values.map { |v| format_before_sign(v) }.join('') + secret_key
|
130
|
+
Digest::MD5.hexdigest(signature).upcase
|
131
|
+
end
|
132
|
+
|
133
|
+
# formats values to meet signature formatting requirements
|
134
|
+
def format_before_sign value
|
135
|
+
case value
|
136
|
+
when Time
|
137
|
+
value.strftime("%Y.%m.%d")
|
138
|
+
when Float
|
139
|
+
'%.2f' % value
|
140
|
+
else
|
141
|
+
value.to_s
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# generates body of SOAP request
|
146
|
+
def prepare_body params
|
147
|
+
body_params = ActiveSupport::OrderedHash.new
|
148
|
+
params.each do |k, v|
|
149
|
+
value = if v.respond_to? :strftime
|
150
|
+
v.strftime("%Y-%m-%dT%T")
|
151
|
+
else
|
152
|
+
v.to_s
|
153
|
+
end
|
154
|
+
body_params[config[:namespace_identifier].to_s + ':' + k.to_s.camelize(:lower)] = value
|
155
|
+
end
|
156
|
+
body_params[config[:namespace_identifier].to_s + ":sign"] = sign(params)
|
157
|
+
body_params
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
data/lib/epayments_client.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epayments_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Harmaty
|
@@ -16,25 +16,43 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: savon
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.5.0
|
41
|
+
description: Ruby wrapper for epayments JSON and SOAP API
|
28
42
|
email: harmaty@gmail.com
|
29
43
|
executables: []
|
30
44
|
extensions: []
|
31
45
|
extra_rdoc_files: []
|
32
46
|
files:
|
47
|
+
- lib/epa/client.rb
|
33
48
|
- lib/epa/json/client.rb
|
34
49
|
- lib/epa/json/exceptions.rb
|
50
|
+
- lib/epa/soap/client.rb
|
51
|
+
- lib/epa/soap/exceptions.rb
|
35
52
|
- lib/epayments_client.rb
|
36
53
|
homepage: https://github.com/harmaty/epayments_client
|
37
|
-
licenses:
|
54
|
+
licenses:
|
55
|
+
- MIT
|
38
56
|
metadata: {}
|
39
57
|
post_install_message:
|
40
58
|
rdoc_options: []
|