espago 0.0.9 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +15 -3
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +263 -47
  5. data/Guardfile +1 -0
  6. data/README.md +116 -6
  7. data/app/helpers/espago/masterpass_helper.rb +13 -0
  8. data/app/helpers/espago/secure_web_page_helper.rb +5 -0
  9. data/app/views/espago_masterpass/_masterpass_button.html.haml +20 -0
  10. data/app/views/espago_masterpass/_masterpass_pairing_button.html.haml +11 -0
  11. data/app/views/espago_masterpass/_masterpass_precheckout_button.html.haml +21 -0
  12. data/app/views/espago_secure_web_page/_form.html.haml +26 -0
  13. data/espago.gemspec +16 -9
  14. data/lib/espago/api_connection/{post_clients.rb → api.rb} +1 -5
  15. data/lib/espago/api_connection/api_delete.rb +9 -0
  16. data/lib/espago/api_connection/api_get.rb +13 -0
  17. data/lib/espago/api_connection/api_post.rb +9 -0
  18. data/lib/espago/api_connection/api_put.rb +9 -0
  19. data/lib/espago/api_connection/charges_complete_post.rb +9 -0
  20. data/lib/espago/api_connection/charges_delete.rb +9 -0
  21. data/lib/espago/api_connection/charges_get.rb +9 -0
  22. data/lib/espago/api_connection/charges_post.rb +9 -0
  23. data/lib/espago/api_connection/{post_charges_refund.rb → charges_refund_post.rb} +1 -5
  24. data/lib/espago/api_connection/clients_authorize_post.rb +9 -0
  25. data/lib/espago/api_connection/clients_delete.rb +9 -0
  26. data/lib/espago/api_connection/clients_get.rb +9 -0
  27. data/lib/espago/api_connection/clients_invoices_get.rb +9 -0
  28. data/lib/espago/api_connection/clients_post.rb +9 -0
  29. data/lib/espago/api_connection/clients_put.rb +9 -0
  30. data/lib/espago/api_connection/clients_subscriptions_get.rb +9 -0
  31. data/lib/espago/api_connection/complete_post.rb +14 -0
  32. data/lib/espago/api_connection/dcc_decision_post.rb +9 -0
  33. data/lib/espago/api_connection/invoice_items_delete.rb +9 -0
  34. data/lib/espago/api_connection/invoice_items_get.rb +9 -0
  35. data/lib/espago/api_connection/invoice_items_post.rb +9 -0
  36. data/lib/espago/api_connection/invoices_get.rb +9 -0
  37. data/lib/espago/api_connection/line_items_get.rb +9 -0
  38. data/lib/espago/api_connection/masterpass_post.rb +9 -0
  39. data/lib/espago/api_connection/plans_delete.rb +9 -0
  40. data/lib/espago/api_connection/plans_get.rb +9 -0
  41. data/lib/espago/api_connection/plans_post.rb +9 -0
  42. data/lib/espago/api_connection/plans_put.rb +9 -0
  43. data/lib/espago/api_connection/refunds_post.rb +9 -0
  44. data/lib/espago/api_connection/secure_web_page_register_post.rb +9 -0
  45. data/lib/espago/api_connection/subscriptions_delete.rb +9 -0
  46. data/lib/espago/api_connection/subscriptions_get.rb +9 -0
  47. data/lib/espago/api_connection/subscriptions_post.rb +9 -0
  48. data/lib/espago/api_connection/tokens_get.rb +9 -0
  49. data/lib/espago/api_connection/{delete_charges.rb → tokens_post.rb} +3 -2
  50. data/lib/espago/api_connection/visacheckout_post.rb +9 -0
  51. data/lib/espago/api_connection.rb +20 -9
  52. data/lib/espago/back_request.rb +33 -0
  53. data/lib/espago/client.rb +23 -9
  54. data/lib/espago/engine.rb +5 -0
  55. data/lib/espago/masterpass.rb +52 -0
  56. data/lib/espago/router.rb +1 -1
  57. data/lib/espago/secure_web_page.rb +31 -0
  58. data/lib/espago/version.rb +1 -1
  59. data/lib/espago.rb +11 -3
  60. data/lib/generators/espago/install_generator.rb +20 -0
  61. data/lib/generators/espago/templates/README +10 -0
  62. data/lib/generators/espago/templates/espago.rb +6 -0
  63. data/spec/espago/api_connection_spec.rb +5 -4
  64. data/spec/espago/back_request_spec.rb +33 -0
  65. data/spec/espago/client_spec.rb +21 -8
  66. data/spec/espago/error_spec.rb +4 -3
  67. data/spec/espago/response_spec.rb +10 -10
  68. data/spec/espago/router_spec.rb +6 -7
  69. data/spec/features/apis_spec.rb +21 -0
  70. data/spec/features/charges_spec.rb +79 -0
  71. data/spec/features/charges_spec_with_params_spec.rb +89 -0
  72. data/spec/features/clients_spec.rb +100 -0
  73. data/spec/features/dcc_decision_spec.rb +20 -0
  74. data/spec/features/error_spec.rb +28 -0
  75. data/spec/features/invoice_items_spec.rb +37 -0
  76. data/spec/features/invoices_spec.rb +24 -0
  77. data/spec/features/line_items_spec.rb +17 -0
  78. data/spec/features/plans_spec.rb +61 -0
  79. data/spec/features/secure_web_page_register_spec.rb +23 -0
  80. data/spec/features/subscriptions_spec.rb +43 -0
  81. data/spec/features/tokens_spec.rb +39 -0
  82. data/spec/fixtures/cassettes/api_2.yml +68 -0
  83. data/spec/fixtures/cassettes/api_3.yml +68 -0
  84. data/spec/fixtures/cassettes/charges_complete.yml +48 -0
  85. data/spec/fixtures/cassettes/charges_complete_deprecation.yml +48 -0
  86. data/spec/fixtures/cassettes/charges_destroy.yml +46 -0
  87. data/spec/fixtures/cassettes/charges_get.yml +67 -0
  88. data/spec/fixtures/cassettes/charges_get_pay_mTOngouLTJWZ0w.yml +48 -0
  89. data/spec/fixtures/cassettes/charges_post.yml +50 -0
  90. data/spec/fixtures/cassettes/charges_refund.yml +50 -0
  91. data/spec/fixtures/cassettes/clients_authorize.yml +50 -0
  92. data/spec/fixtures/cassettes/clients_delete.yml +44 -0
  93. data/spec/fixtures/cassettes/clients_get.yml +48 -0
  94. data/spec/fixtures/cassettes/clients_get_cli_w0Se2smYwyQ0Uw.yml +48 -0
  95. data/spec/fixtures/cassettes/clients_invoices.yml +48 -0
  96. data/spec/fixtures/cassettes/clients_post.yml +50 -0
  97. data/spec/fixtures/cassettes/clients_put.yml +50 -0
  98. data/spec/fixtures/cassettes/clients_subscriptions.yml +48 -0
  99. data/spec/fixtures/cassettes/dcc_decision_post.yml +50 -0
  100. data/spec/fixtures/cassettes/error_400.yml +48 -0
  101. data/spec/fixtures/cassettes/error_401.yml +48 -0
  102. data/spec/fixtures/cassettes/error_500.yml +48 -0
  103. data/spec/fixtures/cassettes/invoice_items_delete_ii_WDzszvhTshe78Xd.yml +44 -0
  104. data/spec/fixtures/cassettes/invoice_items_get_ii_5LS-YR7S1QaJBl3.yml +49 -0
  105. data/spec/fixtures/cassettes/invoice_items_post_ii_5LS-YR7S1QaJBl3.yml +51 -0
  106. data/spec/fixtures/cassettes/invoices_get.yml +48 -0
  107. data/spec/fixtures/cassettes/invoices_get_in_tUCMhwlg2nkvAaL.yml +48 -0
  108. data/spec/fixtures/cassettes/line_items_get.yml +47 -0
  109. data/spec/fixtures/cassettes/plans_delete.yml +42 -0
  110. data/spec/fixtures/cassettes/plans_get.yml +46 -0
  111. data/spec/fixtures/cassettes/plans_get_pl_12345.yml +46 -0
  112. data/spec/fixtures/cassettes/plans_post.yml +50 -0
  113. data/spec/fixtures/cassettes/plans_put.yml +46 -0
  114. data/spec/fixtures/cassettes/secure_web_page_register_post.yml +56 -0
  115. data/spec/fixtures/cassettes/subscriptions_delete_sub_8yYuCBKdywr7e2.yml +44 -0
  116. data/spec/fixtures/cassettes/subscriptions_get.yml +46 -0
  117. data/spec/fixtures/cassettes/subscriptions_get_sub_8yYuCBKdywr7e2.yml +46 -0
  118. data/spec/fixtures/cassettes/subscriptions_post.yml +50 -0
  119. data/spec/fixtures/cassettes/tokens_get.yml +48 -0
  120. data/spec/fixtures/cassettes/tokens_post.yml +56 -0
  121. data/spec/spec_helper.rb +29 -1
  122. metadata +271 -42
  123. data/lib/espago/api_connection/delete_clients.rb +0 -13
  124. data/lib/espago/api_connection/get_charges.rb +0 -17
  125. data/lib/espago/api_connection/get_clients.rb +0 -17
  126. data/lib/espago/api_connection/get_tokens.rb +0 -13
  127. data/lib/espago/api_connection/post_charges.rb +0 -13
  128. data/lib/espago/api_connection/post_clients_authorize.rb +0 -13
  129. data/lib/espago/api_connection/post_complete.rb +0 -13
  130. data/lib/espago/api_connection/post_tokens.rb +0 -14
  131. data/lib/espago/api_connection/put_clients.rb +0 -13
@@ -1,13 +1,9 @@
1
1
  module Espago
2
2
  class ApiConnection
3
- class PostClients
3
+ class Api
4
4
  def initialize(connection)
5
5
  @connection = connection
6
6
  end
7
-
8
- def request(params = {})
9
- @connection.post 'clients', params
10
- end
11
7
  end
12
8
  end
13
9
  end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ApiDelete < Api
4
+ def request(path, param_id=nil)
5
+ @connection.delete "#{path}/#{param_id}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ApiGet < Api
4
+ def request(path, params = {}, param_id=nil)
5
+ if param_id
6
+ @connection.get "#{path}/#{param_id}"
7
+ else
8
+ @connection.get "#{path}", params
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ApiPost < Api
4
+ def request(path, params = {})
5
+ @connection.post path, params
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ApiPut < Api
4
+ def request(path, params={})
5
+ @connection.put path, params
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ChargesCompletePost < ApiPost
4
+ def request(params = {})
5
+ super("charges/#{params[:charge_id]}/complete", params.except(:charge_id))
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ChargesDelete < ApiDelete
4
+ def request(params = {})
5
+ super("charges",params[:charge_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ChargesGet < ApiGet
4
+ def request(params = {})
5
+ super('charges',params,params[:charge_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ChargesPost < ApiPost
4
+ def request(params = {})
5
+ super("charges", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,10 +1,6 @@
1
1
  module Espago
2
2
  class ApiConnection
3
- class PostChargesRefund
4
- def initialize(connection)
5
- @connection = connection
6
- end
7
-
3
+ class ChargesRefundPost < Api
8
4
  def request(params = {})
9
5
  @connection.post "charges/#{params[:charge_id]}/refund", params
10
6
  end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ClientsAuthorizePost < ApiPost
4
+ def request(params = {})
5
+ super("clients/#{params[:client_id]}/authorize")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ClientsDelete < ApiDelete
4
+ def request(params = {})
5
+ super("clients",params[:client_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ClientsGet < ApiGet
4
+ def request(params = {})
5
+ super('clients',params,params[:client_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ClientsInvoicesGet < ApiGet
4
+ def request(params = {})
5
+ super("clients/#{params[:client_id]}/invoices")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ClientsPost < ApiPost
4
+ def request(params = {})
5
+ super('clients', params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ClientsPut < ApiPut
4
+ def request(params = {})
5
+ super("clients/#{params[:client_id]}", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class ClientsSubscriptionsGet < ApiGet
4
+ def request(params = {})
5
+ super("clients/#{params[:client_id]}/subscriptions")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -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
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class DccDecisionPost < Api
4
+ def request(params = {})
5
+ @connection.post "charges/#{params[:charge_id]}/dcc_decision", params
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class InvoiceItemsDelete < ApiDelete
4
+ def request(params = {})
5
+ super("invoice_items",params[:invoice_item_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class InvoiceItemsGet < ApiGet
4
+ def request(params = {})
5
+ super("invoice_items",{},params[:invoice_item_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class InvoiceItemsPost < ApiPost
4
+ def request(params = {})
5
+ super("invoice_items", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class InvoicesGet < ApiGet
4
+ def request(params = {})
5
+ super('invoices',params,params[:invoice_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class LineItemsGet < ApiGet
4
+ def request(params = {})
5
+ super("invoices/#{params[:invoice_id]}/line_items")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class MasterpassPost < ApiPost
4
+ def request(params = {})
5
+ super("masterpass", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class PlansDelete < ApiDelete
4
+ def request(params = {})
5
+ super("plans",params[:plan_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class PlansGet < ApiGet
4
+ def request(params = {})
5
+ super('plans',params,params[:plan_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class PlansPost < ApiPost
4
+ def request(params = {})
5
+ super("plans", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class PlansPut < ApiPut
4
+ def request(params = {})
5
+ super("plans/#{params[:plan_id]}", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class RefundsPost < ApiPost
4
+ def request(params = {})
5
+ super("refunds", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class SecureWebPageRegisterPost < ApiPost
4
+ def request(params = {})
5
+ super("secure_web_page_register", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class SubscriptionsDelete < ApiDelete
4
+ def request(params = {})
5
+ super("subscriptions",params[:subscription_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class SubscriptionsGet < ApiGet
4
+ def request(params = {})
5
+ super('subscriptions',params,params[:subscription_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class SubscriptionsPost < ApiPost
4
+ def request(params = {})
5
+ super("subscriptions", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class TokensGet < ApiGet
4
+ def request(params = {})
5
+ super("tokens",{},params[:token_id])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,12 +1,13 @@
1
1
  module Espago
2
2
  class ApiConnection
3
- class DeleteCharges
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
- @connection.delete "charges/#{params[:charge_id]}"
10
+ super("tokens", params)
10
11
  end
11
12
  end
12
13
  end
@@ -0,0 +1,9 @@
1
+ module Espago
2
+ class ApiConnection
3
+ class VisacheckoutPost < ApiPost
4
+ def request(params = {})
5
+ super("visacheckout", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -6,16 +6,26 @@ require "espago/error"
6
6
  require "espago/response"
7
7
  require "facets/kernel/require_all"
8
8
 
9
- require_all "error/*"
10
- require_all "api_connection/*"
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.status, response.body)
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
- raise NotAuthenticated unless valid?
16
- connection = @connection.new(enviroment)
17
- connection.authenticate(@app_id, @app_password)
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
- production ? "https://secure.espago.com/api" : "https://sandbox.espago.com/api"
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
- @app_id && @app_password
44
+ def valid?(app_id, app_password)
45
+ app_id && app_password
32
46
  end
33
47
  end
34
48
  end
@@ -0,0 +1,5 @@
1
+ require 'rails'
2
+ module Espago
3
+ class Engine < Rails::Engine
4
+ end
5
+ 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
data/lib/espago/router.rb CHANGED
@@ -27,7 +27,7 @@ module Espago
27
27
  end
28
28
 
29
29
  def get_class_name
30
- method.to_s.capitalize + path.to_s.split("_").map(&:capitalize).join
30
+ path.to_s.split("_").map(&:capitalize).join + method.to_s.capitalize
31
31
  end
32
32
  end
33
33
  end