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
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ module Espago
5
+ class SecureWebPage
6
+ attr_accessor :production
7
+
8
+ def self.calculate_checksum(app_id, kind, session_id, amount, currency, ts, service_client_id, checksum_key)
9
+ return Digest::MD5.hexdigest(
10
+ [app_id.to_s, kind, session_id.to_s, amount.to_s, currency.to_s, ts.to_s, checksum_key.to_s].join('|')
11
+ ) if service_client_id.blank?
12
+ Digest::MD5.hexdigest(
13
+ [app_id.to_s, kind, session_id.to_s, amount.to_s, currency.to_s, ts.to_s, service_client_id.to_s, checksum_key.to_s].join('|')
14
+ )
15
+ end
16
+
17
+ def self.form_post(_api_v = nil)
18
+ Espago.production ? 'https://secure.espago.com/secure_web_page' : 'https://sandbox.espago.com/secure_web_page'
19
+ end
20
+
21
+ def self.prepare_form(data)
22
+ data[:kind] ||= 'sale'
23
+ data[:ts] ||= Time.now.to_i
24
+ data[:app_id] ||= Espago.app_id
25
+ data[:api_version] ||= Espago.api_version
26
+ data[:amount] = format('%.2f', data[:amount])
27
+ data[:checksum] = calculate_checksum(data[:app_id], data[:kind], data[:session_id], data[:amount], data[:currency], data[:ts], data[:service_client_id], data[:checksum_key] || Espago.checksum_key)
28
+ data
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Espago
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/espago.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require "espago/version"
2
2
  require "espago/client"
3
3
  require "espago/router"
4
+ require "espago/back_request"
5
+ require "espago/masterpass"
6
+ require "espago/secure_web_page"
7
+ require "espago/engine"
4
8
  require 'forwardable'
5
9
 
6
10
  module Espago
@@ -8,8 +12,8 @@ module Espago
8
12
  class << self
9
13
  extend Forwardable
10
14
 
11
- def_delegators :default_client, :public_key, :app_id, :app_password, :send_request, :production
12
- def_delegators :default_client, :public_key= , :app_id= , :app_password=, :production=
15
+ def_delegators :default_client, :public_key, :app_id, :app_password, :api_version, :send_request, :production, :checksum_key
16
+ def_delegators :default_client, :public_key= , :app_id= , :app_password=, :api_version=, :production=,:checksum_key=
13
17
 
14
18
  def method_missing(method, *args, &block)
15
19
  if Router.new(method, args[0]).path_exists?
@@ -19,9 +23,13 @@ module Espago
19
23
  end
20
24
  end
21
25
 
26
+ def self.setup
27
+ yield self
28
+ end
29
+
22
30
  private
23
31
  def default_client
24
32
  @default_client ||= Espago::Client.new
25
33
  end
26
34
  end
27
- end
35
+ end
@@ -0,0 +1,20 @@
1
+ require 'securerandom'
2
+
3
+ module Espago
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ desc "Creates a Espago initializer"
9
+
10
+ def copy_initializer
11
+ template "espago.rb", "config/initializers/espago.rb"
12
+ end
13
+
14
+ def show_readme
15
+ readme "README" if behavior == :invoke
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ ===============================================================================
2
+
3
+ You need to do some manual setup to get Espago working:
4
+
5
+ 1. Review settings in new config/initializers/espago.rb and update where
6
+ neccessary.
7
+
8
+ 2. Restart app
9
+
10
+ ===============================================================================
@@ -0,0 +1,6 @@
1
+ Espago.app_id = espago_app_id
2
+ Espago.app_password = espago_app_password
3
+ Espago.public_key = espago_public_key
4
+ Espago.production = espago_production
5
+ Espago.api_version = espago_api_version
6
+ Espago.checksum_key = espago_checksum_key
@@ -4,7 +4,7 @@ require "json"
4
4
 
5
5
  class StubbedResponse < Struct.new(:body, :status); end
6
6
 
7
- class Espago::ApiConnection::StubbedPath
7
+ class Espago::ApiConnection::PathStubbed
8
8
  def initialize(connection); end
9
9
 
10
10
  def request(params = {})
@@ -12,7 +12,7 @@ class Espago::ApiConnection::StubbedPath
12
12
  end
13
13
  end
14
14
 
15
- class Espago::ApiConnection::UnauthorizedPath
15
+ class Espago::ApiConnection::PathUnauthorized
16
16
  def initialize(connection)
17
17
  end
18
18
 
@@ -21,12 +21,13 @@ class Espago::ApiConnection::UnauthorizedPath
21
21
  end
22
22
  end
23
23
 
24
+
24
25
  describe Espago::ApiConnection do
25
- subject { Espago::ApiConnection.new("http://some.api.example.com") }
26
+ subject { Espago::ApiConnection.new("http://some.api.example.com",{'Accept' => "application/vnd.espago.v2+json"}) }
26
27
 
27
28
  context "#create" do
28
29
  it "returns response" do
29
- subject.create(:path, :stubbed).should be_a_kind_of Espago::Response
30
+ expect(subject.create(:path, :stubbed)).to be_a_kind_of Espago::Response
30
31
  end
31
32
  it "raises auth error" do
32
33
  expect { subject.create(:path, :unauthorized) }.to raise_error Espago::AuthenticationError
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+ require "espago/back_request"
3
+ require "json"
4
+
5
+
6
+ describe Espago::BackRequest do
7
+ subject { Espago::BackRequest.new(response)}
8
+ let(:response) {
9
+ {"id"=>"in_tUCMhwlg2nkvAaL",
10
+ "date"=>"1417030496",
11
+ "client"=>"cli_90Pi6Jf0ndl_PP",
12
+ "subscription"=>"sub_8yYuCBKdywr7e2",
13
+ "amount"=>"123.45",
14
+ "currency"=>"pln",
15
+ "paid"=>"true",
16
+ "issuer_response_code"=>"00",
17
+ "attempts"=>"1",
18
+ "next_payment_attempt"=>"",
19
+ "created_at"=>1417030497
20
+ }
21
+ }
22
+ it {
23
+ expect(subject.id).to eq("in_tUCMhwlg2nkvAaL")
24
+ expect(subject.subscription).to eq("sub_8yYuCBKdywr7e2")
25
+ expect(subject.amount).to eq("123.45")
26
+ expect(subject.currency).to eq("pln")
27
+ expect(subject.paid).to eq("true")
28
+ expect(subject.client).to eq("cli_90Pi6Jf0ndl_PP")
29
+ expect(subject.created_at).to eq(Time.at(1417030497))
30
+ expect(subject.card).to eq({})
31
+ expect(subject.imaginated_attribute).to be_nil
32
+ }
33
+ end
@@ -3,7 +3,7 @@ require 'espago/client'
3
3
  require "helpers/fake_response"
4
4
 
5
5
  class StubbedApiConnection
6
- def initialize(enviroment); end
6
+ def initialize(enviroment,headers); end
7
7
  def authenticate(app_id, app_password); end
8
8
  def create(path, method, params= {})
9
9
  'returned api data'
@@ -11,13 +11,14 @@ class StubbedApiConnection
11
11
  end
12
12
 
13
13
  describe Espago::Client do
14
- subject { Espago::Client.new( app_id: 'App12345', app_password: 'secret', connection: stubbed_api_connection) }
14
+ subject { Espago::Client.new( app_id: 'app_id_test', app_password: 'secret', connection: stubbed_api_connection, api_version: 2) }
15
15
  let(:stubbed_api_connection) { StubbedApiConnection }
16
16
  let(:response) { FakeResponse.new(200, {id: 1, status: "2012"}.to_json) }
17
17
 
18
- it { subject.should respond_to :app_id }
19
- it { subject.should respond_to :app_password }
20
- it { subject.should respond_to :public_key }
18
+ it { expect(subject).to respond_to :app_id }
19
+ it { expect(subject).to respond_to :app_password }
20
+ it { expect(subject).to respond_to :public_key }
21
+ it { expect(subject).to respond_to :api_version }
21
22
 
22
23
  context "#send_request" do
23
24
  let(:method) { :get }
@@ -25,7 +26,7 @@ describe Espago::Client do
25
26
  let(:params) { { name: "Jan Kowalski"} }
26
27
 
27
28
  it "should create an api request" do
28
- subject.send_request(path, method, params).should eq('returned api data')
29
+ expect(subject.send_request(path, method, params)).to eq('returned api data')
29
30
  end
30
31
 
31
32
  context "with no credentials" do
@@ -37,16 +38,28 @@ describe Espago::Client do
37
38
  end
38
39
  end
39
40
 
41
+ context "#send_request_with_app_id_and_password" do
42
+ subject { Espago::Client.new(connection: stubbed_api_connection, api_version: 2) }
43
+ let(:method) { :get }
44
+ let(:path) { :new_client }
45
+ let(:params) { { name: "Jan Kowalski", app_id: 'app_id_test', app_password: 'secret'} }
46
+
47
+ it "should create an api request" do
48
+ expect(subject.send_request(path, method, params)).to eq('returned api data')
49
+ end
50
+
51
+ end
52
+
40
53
  context "#parse_response" do
41
54
  subject { Espago::Client.new }
42
55
 
43
56
  it "should delegate work to parser" do
44
- Espago::Response.should_receive(:new).with(response)
57
+ expect(Espago::Response).to receive(:new).with(response)
45
58
  subject.parse_response(response)
46
59
  end
47
60
 
48
61
  it "should parse response into object" do
49
- subject.parse_response(response).class.should eq(Espago::Response)
62
+ expect(subject.parse_response(response).class).to eq(Espago::Response)
50
63
  end
51
64
  end
52
65
 
@@ -10,7 +10,8 @@ describe Espago::Error do
10
10
  let(:response) {
11
11
  FakeResponse.new(422, response_body)
12
12
  }
13
-
14
- its(:body) { should eq('body') }
15
- its(:status) { should eq(422) }
13
+ it {
14
+ expect(subject.body).to eq('body')
15
+ expect(subject.status).to eq(422)
16
+ }
16
17
  end
@@ -25,14 +25,14 @@ describe Espago::Response do
25
25
  }
26
26
  }.to_json)
27
27
  }
28
-
29
- its(:id) { should eq("pay_hViT20SOWaUL_w") }
30
- its(:description) { should eq("Zakupy z example.com") }
31
- its(:amount) { should eq("49.99") }
32
- its(:currency) { should eq("pln") }
33
- its(:state) { should eq("executed") }
34
- its(:client) { should eq("cli_wm7dGQltAqIfH8") }
35
- its(:created_at) { should eq(Time.parse("2013-06-28 10:31:14 +0200")) }
36
- its(:imaginated_attribute) { should be_nil }
37
-
28
+ it {
29
+ expect(subject.id).to eq("pay_hViT20SOWaUL_w")
30
+ expect(subject.description).to eq("Zakupy z example.com")
31
+ expect(subject.amount).to eq("49.99")
32
+ expect(subject.currency).to eq("pln")
33
+ expect(subject.state).to eq("executed")
34
+ expect(subject.client).to eq("cli_wm7dGQltAqIfH8")
35
+ expect(subject.created_at).to eq(Time.parse("2013-06-28 10:31:14 +0200"))
36
+ expect(subject.imaginated_attribute).to be_nil
37
+ }
38
38
  end
@@ -1,17 +1,17 @@
1
1
  require "spec_helper"
2
2
  require "espago/router"
3
3
 
4
- class Espago::ApiConnection::GetStubbedRequest; end
4
+ class Espago::ApiConnection::StubbedRequestGet; end
5
5
 
6
6
  describe Espago::Router do
7
7
  subject { Espago::Router.new(:stubbed_request, :get) }
8
8
 
9
- it { subject.should respond_to :path}
10
- it { subject.should respond_to :method}
9
+ it { expect(subject).to respond_to :path}
10
+ it { expect(subject).to respond_to :method}
11
11
 
12
12
  context "#route" do
13
13
  it "should get a class name depending on path and method" do
14
- subject.route.should eq( Espago::ApiConnection::GetStubbedRequest )
14
+ expect(subject.route).to eq( Espago::ApiConnection::StubbedRequestGet )
15
15
  end
16
16
 
17
17
  it "should raise error if class not found" do
@@ -22,14 +22,13 @@ describe Espago::Router do
22
22
 
23
23
  context "#path_exists?" do
24
24
  it "should return if path exists" do
25
- subject.path_exists?.should be_true
25
+ expect(subject.path_exists?).to be_truthy
26
26
  end
27
27
 
28
28
  context "with invalid path name" do
29
29
  subject { Espago::Router.new(:not, :existing) }
30
-
31
30
  it "should return false" do
32
- subject.path_exists?.should_not be_true
31
+ expect(subject.path_exists?).not_to be_truthy
33
32
  end
34
33
  end
35
34
  end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe 'Two api headers test' do
4
+
5
+ it "API v.2" do
6
+ Espago.api_version = '2'
7
+ VCR.use_cassette('api 2') do
8
+ response = Espago.charges :get
9
+ expect(response.count).to eq(596)
10
+ end
11
+ end
12
+
13
+ it "API v.3" do
14
+ Espago.api_version = '3'
15
+ VCR.use_cassette('api 3') do
16
+ response = Espago.charges :get
17
+ expect(response.count).to eq(596)
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,79 @@
1
+
2
+
3
+ require "spec_helper"
4
+
5
+ describe 'Espago.charges' do
6
+
7
+ it "should get list of charges" do
8
+ VCR.use_cassette('charges get') do
9
+ response = Espago.charges :get
10
+ expect(response.count).to eq(589)
11
+ end
12
+ end
13
+
14
+ it "should get info abount charges" do
15
+ VCR.use_cassette('charges get pay_mTOngouLTJWZ0w') do
16
+ response = Espago.charges :get,{charge_id:'pay_mTOngouLTJWZ0w'}
17
+ expect(response.status).to eq(200)
18
+ expect(response.channel).to eq('elavon')
19
+ expect(response.state).to eq('executed')
20
+ expect(response.currency).to eq('PLN')
21
+ expect(response.description).to eq('Test12345')
22
+ expect(response.client).to eq('cli_YM5tKz6-IfhN7T')
23
+ expect(response.created_at).to eq Time.at(1416917311)
24
+ end
25
+ end
26
+
27
+ it "should get params from new charge" do
28
+ VCR.use_cassette('charges post') do
29
+ response = Espago.charges :post, { amount:'49.99',
30
+ currency:'PLN',
31
+ description:'Test12345',
32
+ card: {
33
+ first_name: 'Jan',
34
+ last_name: 'Kowalski',
35
+ number: '4242424242424242',
36
+ verification_value: '123',
37
+ year:'2015',
38
+ month:'2'
39
+ },
40
+ }
41
+ expect(response.status).to eq(201)
42
+ expect(response.channel).to eq('elavon')
43
+ expect(response.state).to eq('executed')
44
+ expect(response.currency).to eq('PLN')
45
+ expect(response.description).to eq('Test12345')
46
+ expect(response.client).to eq('cli_YM5tKz6-IfhN7T')
47
+ expect(response.created_at).to eq Time.at(1416917311)
48
+ end
49
+ end
50
+
51
+ it "should get 204 status after destroy charge" do
52
+ VCR.use_cassette('charges destroy') do
53
+ response = Espago.charges :delete,{charge_id:'pay_kQmS_3RTfm4eix'}
54
+ expect(response.state).to eq('reversed')
55
+ end
56
+ end
57
+
58
+ it "should get refunded status after refund charge" do
59
+ VCR.use_cassette('charges refund') do
60
+ response = Espago.charges_refund :post,{charge_id:'pay_lQGyIon5qG59O5'}
61
+ expect(response.state).to eq('refunded')
62
+ end
63
+ end
64
+
65
+ it "should get params from complete charge" do
66
+ VCR.use_cassette('charges complete') do
67
+ response = Espago.charges_complete :post,{charge_id:'pay_kQmS_3RTfm4eix'}
68
+ expect(response.state).to eq('executed')
69
+ end
70
+ end
71
+
72
+ it "should get params from complete charge (deprecated)" do
73
+ VCR.use_cassette('charges complete deprecation') do
74
+ response = Espago.complete :post,{charge_id:'pay_Wmu3hmXJIG4jsg'}
75
+ expect(response.state).to eq('executed')
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,89 @@
1
+
2
+ require "spec_helper"
3
+
4
+ describe 'Espago.charges_with_params' do
5
+
6
+ before :each do
7
+ Espago.app_id = ''
8
+ Espago.app_password = ''
9
+ Espago.public_key = ''
10
+ Espago.production = true
11
+ end
12
+
13
+ it "should get list of charges" do
14
+ VCR.use_cassette('charges get') do
15
+ response = Espago.charges :get,{app_id: 'app_id_test', app_password: 'app_password_test', production: false}
16
+ expect(response.count).to eq(589)
17
+ end
18
+ end
19
+
20
+ it "should get info abount charges" do
21
+ VCR.use_cassette('charges get pay_mTOngouLTJWZ0w') do
22
+ response = Espago.charges :get,{charge_id:'pay_mTOngouLTJWZ0w', app_id: 'app_id_test', app_password: 'app_password_test', production: false}
23
+ expect(response.status).to eq(200)
24
+ expect(response.channel).to eq('elavon')
25
+ expect(response.state).to eq('executed')
26
+ expect(response.currency).to eq('PLN')
27
+ expect(response.description).to eq('Test12345')
28
+ expect(response.client).to eq('cli_YM5tKz6-IfhN7T')
29
+ expect(response.created_at).to eq Time.at(1416917311)
30
+ end
31
+ end
32
+
33
+ it "should get params from new charge" do
34
+ VCR.use_cassette('charges post') do
35
+ response = Espago.charges :post, {
36
+ app_id: 'app_id_test',
37
+ app_password: 'app_password_test',
38
+ production: false,
39
+ amount:'49.99',
40
+ currency:'PLN',
41
+ description:'Test12345',
42
+ card: {
43
+ first_name: 'Jan',
44
+ last_name: 'Kowalski',
45
+ number: '4242424242424242',
46
+ verification_value: '123',
47
+ year:'2015',
48
+ month:'2'
49
+ },
50
+ }
51
+ expect(response.status).to eq(201)
52
+ expect(response.channel).to eq('elavon')
53
+ expect(response.state).to eq('executed')
54
+ expect(response.currency).to eq('PLN')
55
+ expect(response.description).to eq('Test12345')
56
+ expect(response.client).to eq('cli_YM5tKz6-IfhN7T')
57
+ expect(response.created_at).to eq Time.at(1416917311)
58
+ end
59
+ end
60
+
61
+ it "should get 204 status after destroy charge" do
62
+ VCR.use_cassette('charges destroy') do
63
+ response = Espago.charges :delete,{charge_id:'pay_kQmS_3RTfm4eix', app_id: 'app_id_test', app_password: 'app_password_test', production: false}
64
+ expect(response.state).to eq('reversed')
65
+ end
66
+ end
67
+
68
+ it "should get refunded status after refund charge" do
69
+ VCR.use_cassette('charges refund') do
70
+ response = Espago.charges_refund :post,{charge_id:'pay_lQGyIon5qG59O5', app_id: 'app_id_test', app_password: 'app_password_test', production: false}
71
+ expect(response.state).to eq('refunded')
72
+ end
73
+ end
74
+
75
+ it "should get params from complete charge" do
76
+ VCR.use_cassette('charges complete') do
77
+ response = Espago.charges_complete :post,{charge_id:'pay_kQmS_3RTfm4eix', app_id: 'app_id_test', app_password: 'app_password_test', production: false}
78
+ expect(response.state).to eq('executed')
79
+ end
80
+ end
81
+
82
+ it "should get params from complete charge (deprecated)" do
83
+ VCR.use_cassette('charges complete deprecation') do
84
+ response = Espago.complete :post,{charge_id:'pay_Wmu3hmXJIG4jsg', app_id: 'app_id_test', app_password: 'app_password_test', production: false}
85
+ expect(response.state).to eq('executed')
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,100 @@
1
+ require "spec_helper"
2
+
3
+ describe 'Espago.clients' do
4
+
5
+ it "should get list of clients" do
6
+ VCR.use_cassette('clients get') do
7
+ response = Espago.clients :get
8
+ expect(response.count).to eq(597)
9
+ end
10
+ end
11
+
12
+ it "should get info abount clients" do
13
+ VCR.use_cassette('clients get cli_w0Se2smYwyQ0Uw') do
14
+ response = Espago.clients :get,{client_id:'cli_w0Se2smYwyQ0Uw'}
15
+ expect(response.email).to eq(nil)
16
+ expect(response.card['company']).to eq('VI')
17
+ expect(response.description).to eq(nil)
18
+ expect(response.created_at).to eq Time.at(1417004837)
19
+ end
20
+ end
21
+
22
+ it "should get params from new client" do
23
+ VCR.use_cassette('clients post') do
24
+ response = Espago.clients :post, { card: {
25
+ first_name: 'Jan',
26
+ last_name: 'Kowalski',
27
+ number: '424242424242',
28
+ verification_value: '123',
29
+ year:'2015',
30
+ month:'2'
31
+ },
32
+ }
33
+ expect(response.status).to eq(201)
34
+ expect(response.card['company']).to eq('VI')
35
+ expect(response.card['last4']).to eq('4242')
36
+ expect(response.card['authorized']).to eq(nil)
37
+ expect(response.deleted).to eq(false)
38
+ expect(response.created_at).to eq Time.at(1417007099)
39
+ end
40
+ end
41
+
42
+ it "should get status after authorize client card" do
43
+ VCR.use_cassette('clients authorize') do
44
+ response = Espago.clients_authorize :post,{client_id:'cli_w0Se2smYwyQ0Uw'}
45
+ expect(response.status).to eq(201)
46
+ expect(response.card['company']).to eq('VI')
47
+ expect(response.card['last4']).to eq('1112')
48
+ expect(response.card['authorized']).to eq(true)
49
+ end
50
+ end
51
+
52
+
53
+ it "should get params from updated client" do
54
+ VCR.use_cassette('clients put') do
55
+ response = Espago.clients :put, { client_id:'cli_w0Se2smYwyQ0Uw',
56
+ card: {
57
+ first_name: 'Jan',
58
+ last_name: 'Kowalski',
59
+ number: '4242424242424242',
60
+ verification_value: '123',
61
+ year:'2015',
62
+ month:'2'
63
+ },
64
+ }
65
+ expect(response.status).to eq(200)
66
+ expect(response.card['company']).to eq('VI')
67
+ expect(response.card['last4']).to eq('4242')
68
+ expect(response.card['authorized']).to eq(nil)
69
+ expect(response.deleted).to eq(false)
70
+ expect(response.created_at).to eq Time.at(1417004837)
71
+ end
72
+ end
73
+
74
+ it "should get client invoices" do
75
+ VCR.use_cassette('clients invoices') do
76
+ response = Espago.clients_invoices :get, { client_id:'cli_w0Se2smYwyQ0Uw'}
77
+ expect(response.status).to eq(200)
78
+ expect(response.count).to eq(0)
79
+ expect(response.invoices).to eq([])
80
+ end
81
+ end
82
+
83
+
84
+ it "should get client subscriptions" do
85
+ VCR.use_cassette('clients subscriptions') do
86
+ response = Espago.clients_subscriptions :get, { client_id:'cli_w0Se2smYwyQ0Uw'}
87
+ expect(response.status).to eq(200)
88
+ expect(response.count).to eq(0)
89
+ expect(response.subscriptions).to eq([])
90
+ end
91
+ end
92
+
93
+ it "should get status 204 after delete client" do
94
+ VCR.use_cassette('clients delete') do
95
+ response = Espago.clients :delete, { client_id:'cli_5rDoJyvKDM4RbM'}
96
+ expect(response.status).to eq(204)
97
+ end
98
+ end
99
+
100
+ end
@@ -0,0 +1,20 @@
1
+
2
+ require "spec_helper"
3
+
4
+ describe 'Espago.dcc_decision' do
5
+
6
+ it "should get params from new charge" do
7
+ VCR.use_cassette('dcc_decision post') do
8
+ response = Espago.dcc_decision :post, {charge_id:'pay_mTOngouLTJWZ0w', decision:'Y'}
9
+ expect(response.status).to eq(201)
10
+ expect(response.channel).to eq('elavon')
11
+ expect(response.state).to eq('executed')
12
+ expect(response.currency).to eq('PLN')
13
+ expect(response.description).to eq('Test12345')
14
+ expect(response.client).to eq('cli_YM5tKz6-IfhN7T')
15
+ expect(response.created_at).to eq Time.at(1416917311)
16
+ end
17
+ end
18
+
19
+
20
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe 'Fake errors!' do
4
+
5
+ it "should get 500 error" do
6
+ VCR.use_cassette('error 500') do
7
+ expect {response = Espago.plans :get }.to raise_error(Espago::ApiError)
8
+ end
9
+ end
10
+
11
+ it "should get 400 error" do
12
+ VCR.use_cassette('error 400') do
13
+ expect {response = Espago.plans :get }.to raise_error(Espago::InvalidRequestError)
14
+ end
15
+ end
16
+
17
+ it "should get 401 error" do
18
+ VCR.use_cassette('error 401') do
19
+ expect {response = Espago.plans :get }.to raise_error(Espago::AuthenticationError)
20
+ end
21
+ end
22
+
23
+ it "method missing" do
24
+ VCR.use_cassette('method missing') do
25
+ expect {Espago.method_missing :get}.to raise_error(NoMethodError)
26
+ end
27
+ end
28
+ end