espago 0.0.9 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +15 -3
- data/Gemfile +2 -0
- data/Gemfile.lock +263 -47
- data/Guardfile +1 -0
- data/README.md +116 -6
- data/app/helpers/espago/masterpass_helper.rb +13 -0
- data/app/helpers/espago/secure_web_page_helper.rb +5 -0
- data/app/views/espago_masterpass/_masterpass_button.html.haml +20 -0
- data/app/views/espago_masterpass/_masterpass_pairing_button.html.haml +11 -0
- data/app/views/espago_masterpass/_masterpass_precheckout_button.html.haml +21 -0
- data/app/views/espago_secure_web_page/_form.html.haml +26 -0
- data/espago.gemspec +16 -9
- data/lib/espago/api_connection/{post_clients.rb → api.rb} +1 -5
- data/lib/espago/api_connection/api_delete.rb +9 -0
- data/lib/espago/api_connection/api_get.rb +13 -0
- data/lib/espago/api_connection/api_post.rb +9 -0
- data/lib/espago/api_connection/api_put.rb +9 -0
- data/lib/espago/api_connection/charges_complete_post.rb +9 -0
- data/lib/espago/api_connection/charges_delete.rb +9 -0
- data/lib/espago/api_connection/charges_get.rb +9 -0
- data/lib/espago/api_connection/charges_post.rb +9 -0
- data/lib/espago/api_connection/{post_charges_refund.rb → charges_refund_post.rb} +1 -5
- data/lib/espago/api_connection/clients_authorize_post.rb +9 -0
- data/lib/espago/api_connection/clients_delete.rb +9 -0
- data/lib/espago/api_connection/clients_get.rb +9 -0
- data/lib/espago/api_connection/clients_invoices_get.rb +9 -0
- data/lib/espago/api_connection/clients_post.rb +9 -0
- data/lib/espago/api_connection/clients_put.rb +9 -0
- data/lib/espago/api_connection/clients_subscriptions_get.rb +9 -0
- data/lib/espago/api_connection/complete_post.rb +14 -0
- data/lib/espago/api_connection/dcc_decision_post.rb +9 -0
- data/lib/espago/api_connection/invoice_items_delete.rb +9 -0
- data/lib/espago/api_connection/invoice_items_get.rb +9 -0
- data/lib/espago/api_connection/invoice_items_post.rb +9 -0
- data/lib/espago/api_connection/invoices_get.rb +9 -0
- data/lib/espago/api_connection/line_items_get.rb +9 -0
- data/lib/espago/api_connection/masterpass_post.rb +9 -0
- data/lib/espago/api_connection/plans_delete.rb +9 -0
- data/lib/espago/api_connection/plans_get.rb +9 -0
- data/lib/espago/api_connection/plans_post.rb +9 -0
- data/lib/espago/api_connection/plans_put.rb +9 -0
- data/lib/espago/api_connection/refunds_post.rb +9 -0
- data/lib/espago/api_connection/secure_web_page_register_post.rb +9 -0
- data/lib/espago/api_connection/subscriptions_delete.rb +9 -0
- data/lib/espago/api_connection/subscriptions_get.rb +9 -0
- data/lib/espago/api_connection/subscriptions_post.rb +9 -0
- data/lib/espago/api_connection/tokens_get.rb +9 -0
- data/lib/espago/api_connection/{delete_charges.rb → tokens_post.rb} +3 -2
- data/lib/espago/api_connection/visacheckout_post.rb +9 -0
- data/lib/espago/api_connection.rb +20 -9
- data/lib/espago/back_request.rb +33 -0
- data/lib/espago/client.rb +23 -9
- data/lib/espago/engine.rb +5 -0
- data/lib/espago/masterpass.rb +52 -0
- data/lib/espago/router.rb +1 -1
- data/lib/espago/secure_web_page.rb +31 -0
- data/lib/espago/version.rb +1 -1
- data/lib/espago.rb +11 -3
- data/lib/generators/espago/install_generator.rb +20 -0
- data/lib/generators/espago/templates/README +10 -0
- data/lib/generators/espago/templates/espago.rb +6 -0
- data/spec/espago/api_connection_spec.rb +5 -4
- data/spec/espago/back_request_spec.rb +33 -0
- data/spec/espago/client_spec.rb +21 -8
- data/spec/espago/error_spec.rb +4 -3
- data/spec/espago/response_spec.rb +10 -10
- data/spec/espago/router_spec.rb +6 -7
- data/spec/features/apis_spec.rb +21 -0
- data/spec/features/charges_spec.rb +79 -0
- data/spec/features/charges_spec_with_params_spec.rb +89 -0
- data/spec/features/clients_spec.rb +100 -0
- data/spec/features/dcc_decision_spec.rb +20 -0
- data/spec/features/error_spec.rb +28 -0
- data/spec/features/invoice_items_spec.rb +37 -0
- data/spec/features/invoices_spec.rb +24 -0
- data/spec/features/line_items_spec.rb +17 -0
- data/spec/features/plans_spec.rb +61 -0
- data/spec/features/secure_web_page_register_spec.rb +23 -0
- data/spec/features/subscriptions_spec.rb +43 -0
- data/spec/features/tokens_spec.rb +39 -0
- data/spec/fixtures/cassettes/api_2.yml +68 -0
- data/spec/fixtures/cassettes/api_3.yml +68 -0
- data/spec/fixtures/cassettes/charges_complete.yml +48 -0
- data/spec/fixtures/cassettes/charges_complete_deprecation.yml +48 -0
- data/spec/fixtures/cassettes/charges_destroy.yml +46 -0
- data/spec/fixtures/cassettes/charges_get.yml +67 -0
- data/spec/fixtures/cassettes/charges_get_pay_mTOngouLTJWZ0w.yml +48 -0
- data/spec/fixtures/cassettes/charges_post.yml +50 -0
- data/spec/fixtures/cassettes/charges_refund.yml +50 -0
- data/spec/fixtures/cassettes/clients_authorize.yml +50 -0
- data/spec/fixtures/cassettes/clients_delete.yml +44 -0
- data/spec/fixtures/cassettes/clients_get.yml +48 -0
- data/spec/fixtures/cassettes/clients_get_cli_w0Se2smYwyQ0Uw.yml +48 -0
- data/spec/fixtures/cassettes/clients_invoices.yml +48 -0
- data/spec/fixtures/cassettes/clients_post.yml +50 -0
- data/spec/fixtures/cassettes/clients_put.yml +50 -0
- data/spec/fixtures/cassettes/clients_subscriptions.yml +48 -0
- data/spec/fixtures/cassettes/dcc_decision_post.yml +50 -0
- data/spec/fixtures/cassettes/error_400.yml +48 -0
- data/spec/fixtures/cassettes/error_401.yml +48 -0
- data/spec/fixtures/cassettes/error_500.yml +48 -0
- data/spec/fixtures/cassettes/invoice_items_delete_ii_WDzszvhTshe78Xd.yml +44 -0
- data/spec/fixtures/cassettes/invoice_items_get_ii_5LS-YR7S1QaJBl3.yml +49 -0
- data/spec/fixtures/cassettes/invoice_items_post_ii_5LS-YR7S1QaJBl3.yml +51 -0
- data/spec/fixtures/cassettes/invoices_get.yml +48 -0
- data/spec/fixtures/cassettes/invoices_get_in_tUCMhwlg2nkvAaL.yml +48 -0
- data/spec/fixtures/cassettes/line_items_get.yml +47 -0
- data/spec/fixtures/cassettes/plans_delete.yml +42 -0
- data/spec/fixtures/cassettes/plans_get.yml +46 -0
- data/spec/fixtures/cassettes/plans_get_pl_12345.yml +46 -0
- data/spec/fixtures/cassettes/plans_post.yml +50 -0
- data/spec/fixtures/cassettes/plans_put.yml +46 -0
- data/spec/fixtures/cassettes/secure_web_page_register_post.yml +56 -0
- data/spec/fixtures/cassettes/subscriptions_delete_sub_8yYuCBKdywr7e2.yml +44 -0
- data/spec/fixtures/cassettes/subscriptions_get.yml +46 -0
- data/spec/fixtures/cassettes/subscriptions_get_sub_8yYuCBKdywr7e2.yml +46 -0
- data/spec/fixtures/cassettes/subscriptions_post.yml +50 -0
- data/spec/fixtures/cassettes/tokens_get.yml +48 -0
- data/spec/fixtures/cassettes/tokens_post.yml +56 -0
- data/spec/spec_helper.rb +29 -1
- metadata +271 -42
- data/lib/espago/api_connection/delete_clients.rb +0 -13
- data/lib/espago/api_connection/get_charges.rb +0 -17
- data/lib/espago/api_connection/get_clients.rb +0 -17
- data/lib/espago/api_connection/get_tokens.rb +0 -13
- data/lib/espago/api_connection/post_charges.rb +0 -13
- data/lib/espago/api_connection/post_clients_authorize.rb +0 -13
- data/lib/espago/api_connection/post_complete.rb +0 -13
- data/lib/espago/api_connection/post_tokens.rb +0 -14
- data/lib/espago/api_connection/put_clients.rb +0 -13
@@ -0,0 +1,14 @@
|
|
1
|
+
module Espago
|
2
|
+
class ApiConnection
|
3
|
+
class CompletePost < ApiPost
|
4
|
+
def initialize(connection)
|
5
|
+
warn "[DEPRECATION] `complete` is deprecated. Please use `charges_complete` instead."
|
6
|
+
super(connection)
|
7
|
+
end
|
8
|
+
|
9
|
+
def request(params = {})
|
10
|
+
super("charges/#{params[:charge_id]}/complete")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module Espago
|
2
2
|
class ApiConnection
|
3
|
-
class
|
3
|
+
class TokensPost < ApiPost
|
4
4
|
def initialize(connection)
|
5
5
|
@connection = connection
|
6
|
+
@connection.request(:authorization, :basic, Espago.public_key, '')
|
6
7
|
end
|
7
8
|
|
8
9
|
def request(params = {})
|
9
|
-
|
10
|
+
super("tokens", params)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -6,16 +6,26 @@ require "espago/error"
|
|
6
6
|
require "espago/response"
|
7
7
|
require "facets/kernel/require_all"
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
require "espago/api_connection/api"
|
10
|
+
require "espago/api_connection/api_delete"
|
11
|
+
require "espago/api_connection/api_get"
|
12
|
+
require "espago/api_connection/api_post"
|
13
|
+
require "espago/api_connection/api_put"
|
14
|
+
|
15
|
+
begin
|
16
|
+
require_all "error/*"
|
17
|
+
require_all "api_connection/*"
|
18
|
+
rescue LoadError #if "require_all" method isn't from kernel gem
|
19
|
+
require_rel "error/*"
|
20
|
+
require_rel "api_connection/*"
|
21
|
+
end
|
11
22
|
|
12
23
|
module Espago
|
13
24
|
class ApiConnection
|
14
|
-
extend Forwardable
|
15
|
-
def_delegator :@connection, :basic_auth, :authenticate
|
16
25
|
|
17
|
-
def initialize(enviroment)
|
26
|
+
def initialize(enviroment,headers)
|
18
27
|
@connection = Faraday.new(enviroment)
|
28
|
+
@connection.headers = headers
|
19
29
|
@router = Router
|
20
30
|
end
|
21
31
|
|
@@ -26,6 +36,10 @@ module Espago
|
|
26
36
|
handle_response response
|
27
37
|
end
|
28
38
|
|
39
|
+
def authenticate(username, password)
|
40
|
+
@connection.request(:authorization, :basic, username, password)
|
41
|
+
end
|
42
|
+
|
29
43
|
private
|
30
44
|
|
31
45
|
def handle_response(response)
|
@@ -37,7 +51,7 @@ module Espago
|
|
37
51
|
when 401
|
38
52
|
raise authentication_error(response)
|
39
53
|
else
|
40
|
-
raise api_error(response
|
54
|
+
raise api_error(response)
|
41
55
|
end
|
42
56
|
end
|
43
57
|
|
@@ -53,8 +67,5 @@ module Espago
|
|
53
67
|
ApiError.new(response)
|
54
68
|
end
|
55
69
|
|
56
|
-
def parse(body)
|
57
|
-
JSON.parse body
|
58
|
-
end
|
59
70
|
end
|
60
71
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "json"
|
2
|
+
require "time"
|
3
|
+
|
4
|
+
module Espago
|
5
|
+
class BackRequest
|
6
|
+
attr_reader :params
|
7
|
+
|
8
|
+
def initialize(params)
|
9
|
+
@params = parse(params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(attribute_name)
|
13
|
+
params[attribute_name.to_s]
|
14
|
+
end
|
15
|
+
|
16
|
+
def card
|
17
|
+
params["card"] || {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def created_at
|
21
|
+
Time.at(params["created_at"].to_i) rescue nil
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def parse(params)
|
27
|
+
JSON.parse params
|
28
|
+
rescue
|
29
|
+
params
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/lib/espago/client.rb
CHANGED
@@ -3,18 +3,24 @@ require "espago/response"
|
|
3
3
|
|
4
4
|
module Espago
|
5
5
|
class Client
|
6
|
-
attr_accessor :public_key, :app_id, :app_password, :production
|
6
|
+
attr_accessor :public_key, :app_id, :app_password, :api_version, :production, :checksum_key
|
7
7
|
NotAuthenticated = Class.new(StandardError)
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
|
-
@public_key, @app_id, @app_password = options.values_at( :public_key, :app_id, :app_password)
|
10
|
+
@public_key, @app_id, @app_password, @api_version, @checksum_key = options.values_at( :public_key, :app_id, :app_password, :api_version, :checksum_key)
|
11
11
|
@connection = options[:connection] || ApiConnection
|
12
12
|
end
|
13
13
|
|
14
14
|
def send_request(path, method, params = {})
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
|
16
|
+
app_id = params[:app_id].present? ? params.delete(:app_id) : @app_id
|
17
|
+
app_password = params[:app_password].present? ? params.delete(:app_password) : @app_password
|
18
|
+
production_param = !params[:production].nil? ? params.delete(:production) : production
|
19
|
+
|
20
|
+
raise NotAuthenticated unless valid?(app_id, app_password)
|
21
|
+
|
22
|
+
connection = @connection.new(enviroment(production_param),api_version_header)
|
23
|
+
connection.authenticate(app_id, app_password)
|
18
24
|
connection.create(path, method, params)
|
19
25
|
end
|
20
26
|
|
@@ -23,12 +29,20 @@ module Espago
|
|
23
29
|
end
|
24
30
|
|
25
31
|
private
|
26
|
-
def enviroment
|
27
|
-
|
32
|
+
def enviroment(production_param)
|
33
|
+
production_param ? "https://secure.espago.com/api" : "https://sandbox.espago.com/api"
|
34
|
+
end
|
35
|
+
|
36
|
+
def api_version_header
|
37
|
+
if @api_version.to_f.to_s == '3.0'
|
38
|
+
{'Accept' => "application/vnd.espago.v3+json"}
|
39
|
+
else
|
40
|
+
{'Accept' => "application/vnd.espago.v2+json"}
|
41
|
+
end
|
28
42
|
end
|
29
43
|
|
30
|
-
def valid?
|
31
|
-
|
44
|
+
def valid?(app_id, app_password)
|
45
|
+
app_id && app_password
|
32
46
|
end
|
33
47
|
end
|
34
48
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Espago
|
2
|
+
class Masterpass
|
3
|
+
def self.friendly_token
|
4
|
+
SecureRandom.base64(15).tr('+/=lIO0', 'aqrsxyz')
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.calculate(string)
|
8
|
+
Digest::MD5.hexdigest(string)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.calculate_checksum(app_id, session_id, amount, currency, checksum_key)
|
12
|
+
calculate [app_id.to_s, session_id.to_s, amount.to_s, currency.to_s, checksum_key.to_s].join('|')
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.calculate_checksum_pairing(app_id, session_id, user_id, checksum_key)
|
16
|
+
calculate [app_id.to_s, session_id.to_s, user_id.to_s, checksum_key.to_s].join('|')
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.masterpass_post(api_v=nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.make_currency(data_currency)
|
23
|
+
(data_currency || Espago.currency).upcase
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.prepare_form(data)
|
27
|
+
data[:masterpass_action] ||= 'checkout'
|
28
|
+
data[:app_id] ||= Espago.app_id
|
29
|
+
data[:api_version] ||= Espago.api_version
|
30
|
+
data[:amount] = format('%.2f', data[:amount])
|
31
|
+
data[:checksum] = calculate_checksum(data[:app_id],data[:session_id],data[:amount],data[:currency],data[:checksum_key]|| Espago.checksum_key)
|
32
|
+
data
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.prepare_pairing_form(data)
|
36
|
+
data[:masterpass_action] ||= 'pairing'
|
37
|
+
data[:app_id] ||= Espago.app_id
|
38
|
+
data[:api_version] ||= Espago.api_version
|
39
|
+
data[:checksum] = calculate_checksum_pairing(data[:app_id],data[:session_id],data[:user_id],data[:checksum_key]|| Espago.checksum_key)
|
40
|
+
data
|
41
|
+
end
|
42
|
+
def self.prepare_precheckout_form(data)
|
43
|
+
data[:masterpass_action] ||= 'precheckout'
|
44
|
+
data[:app_id] ||= Espago.app_id
|
45
|
+
data[:api_version] ||= Espago.api_version
|
46
|
+
data[:amount] = format('%.2f', data[:amount])
|
47
|
+
data[:checksum] = calculate_checksum(data[:app_id],data[:session_id],data[:amount],data[:currency],data[:checksum_key]|| Espago.checksum_key)
|
48
|
+
data
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|