cardflex-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +125 -0
  4. data/cardflex.gemspec +14 -0
  5. data/lib/cardflex.rb +32 -0
  6. data/lib/cardflex/base_module.rb +34 -0
  7. data/lib/cardflex/configuration.rb +96 -0
  8. data/lib/cardflex/customer_vault.rb +35 -0
  9. data/lib/cardflex/customer_vault_gateway.rb +26 -0
  10. data/lib/cardflex/error_response.rb +18 -0
  11. data/lib/cardflex/errors.rb +11 -0
  12. data/lib/cardflex/gateway.rb +35 -0
  13. data/lib/cardflex/http.rb +68 -0
  14. data/lib/cardflex/plan.rb +22 -0
  15. data/lib/cardflex/plan_gateway.rb +23 -0
  16. data/lib/cardflex/subscription.rb +24 -0
  17. data/lib/cardflex/subscription_gateway.rb +22 -0
  18. data/lib/cardflex/success_response.rb +15 -0
  19. data/lib/cardflex/test/test_values.rb +26 -0
  20. data/lib/cardflex/three_step.rb +42 -0
  21. data/lib/cardflex/three_step_gateway.rb +41 -0
  22. data/lib/cardflex/transaction.rb +52 -0
  23. data/lib/cardflex/transaction_gateway.rb +23 -0
  24. data/lib/cardflex/version.rb +9 -0
  25. data/lib/cardflex/xml.rb +11 -0
  26. data/lib/cardflex/xml/parser.rb +48 -0
  27. data/lib/cardflex/xml/serializer.rb +70 -0
  28. data/lib/ssl/ca-certificates.ca.crt +4190 -0
  29. data/spec/integration/cardflex/http_spec.rb +72 -0
  30. data/spec/integration/cardflex/plan_spec.rb +24 -0
  31. data/spec/integration/cardflex/three_step_gateway_spec.rb +47 -0
  32. data/spec/integration/cardflex/three_step_spec.rb +37 -0
  33. data/spec/integration/spec_helper.rb +24 -0
  34. data/spec/spec.opts +4 -0
  35. data/spec/spec_helper.rb +45 -0
  36. data/spec/ssl/certificate.crt +21 -0
  37. data/spec/ssl/geotrust_global.crt +20 -0
  38. data/spec/ssl/private_key.pem +30 -0
  39. data/spec/unit/cardflex/base_module_spec.rb +34 -0
  40. data/spec/unit/cardflex/configuration_spec.rb +61 -0
  41. data/spec/unit/cardflex/customer_vault_gateway_spec.rb +10 -0
  42. data/spec/unit/cardflex/errors_spec.rb +8 -0
  43. data/spec/unit/cardflex/gateway_spec.rb +11 -0
  44. data/spec/unit/cardflex/http_spec.rb +18 -0
  45. data/spec/unit/cardflex/three_step_gateway_spec.rb +29 -0
  46. data/spec/unit/cardflex/xml_spec.rb +90 -0
  47. data/spec/unit/spec_helper.rb +1 -0
  48. metadata +103 -0
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Cardflex::ConfigurationError do
4
+ it 'should add configuration error parameters' do
5
+ sut = Cardflex::ConfigurationError.new('test', 'test msg')
6
+ expect(sut.message).to eq 'Cardflex::Configuration.test test msg'
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Cardflex::Gateway do
4
+ it 'should accept a hash or a Configuration' do
5
+ config = Cardflex::Configuration.new({ :api_key => '123' })
6
+ config_hash = { :api_key => '123' }
7
+
8
+ expect(Cardflex::Gateway.new(config).config.api_key).to eq '123'
9
+ expect(Cardflex::Gateway.new(config_hash).config.api_key).to eq '123'
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Cardflex::Http do
4
+ describe '_verify_ssl_certificate' do
5
+ it 'should fail verification if preverify is false' do
6
+ context = OpenSSL::X509::StoreContext.new(OpenSSL::X509::Store.new)
7
+ sut = Cardflex::Configuration.instantiate.http._verify_ssl_certificate(false, context)
8
+ expect(sut).to eq false
9
+ end
10
+
11
+ it 'should fail verification if context has an error' do
12
+ context = OpenSSL::X509::StoreContext.new(OpenSSL::X509::Store.new)
13
+ context.error = 0
14
+ sut = Cardflex::Configuration.instantiate.http._verify_ssl_certificate(false, context)
15
+ expect(sut).to eq false
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Cardflex::ThreeStepGateway do
4
+ it 'should raise an ArgumentError if no redirect_url' do
5
+ expect do
6
+ Cardflex::Configuration.gateway.three_step.get_form_url(:sale => { :test => 'test' })
7
+ end.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should return a response with an error' do
11
+ allow_any_instance_of(Cardflex::Http).to receive(:_do_http).and_return(
12
+ SpecHelper::FakeResponse.new('<response><result>2</result></response>')
13
+ )
14
+
15
+ result = Cardflex::Configuration.gateway.three_step.get_form_url(:sale => { :test => 'test', :redirect_url => 'http://example.com' })
16
+ expect(result.result).to eq 2
17
+ expect(result.success?).to eq false
18
+ end
19
+
20
+ it 'should return a valid response' do
21
+ allow_any_instance_of(Cardflex::Http).to receive(:_do_http).and_return(
22
+ SpecHelper::FakeResponse.new("<response><result>1</result><form-url>http://test.com</form-url></response>")
23
+ )
24
+
25
+ result = Cardflex::Configuration.gateway.three_step.get_form_url(:sale => { :test => 'test', :redirect_url => 'http://example.com' })
26
+ expect(result.three_step.form_url).to eq 'http://test.com'
27
+ expect(result.success?).to eq true
28
+ end
29
+ end
@@ -0,0 +1,90 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe Cardflex::Xml::Serializer do
4
+ describe 'hash to xml' do
5
+ it 'should raise an argument error if no root' do
6
+ expect do
7
+ Cardflex::Xml::Serializer.hash_to_xml({})
8
+ end.to raise_error ArgumentError
9
+ end
10
+
11
+ it 'should turn a simple string hash into xml' do
12
+ hash = { :root => 'text' }
13
+ expect(Cardflex::Xml::Serializer.hash_to_xml(hash)).to match '<root>text</root>'
14
+ end
15
+
16
+ it 'should escape strings to xml' do
17
+ expect(Cardflex::Xml::Serializer._xml_escape('snake_case')).to eq 'snake-case'
18
+ expect(Cardflex::Xml::Serializer._xml_escape(:snake_case)).to eq 'snake-case'
19
+ expect(Cardflex::Xml::Serializer._xml_escape('&nbsp;')).to eq '&amp;nbsp;'
20
+ end
21
+
22
+ it 'should convert nested hashes to xml' do
23
+ simple_hash = { :root => { :nested => 'nested' }}
24
+ simple_xml = <<-END
25
+ <root>
26
+ <nested>nested</nested>
27
+ </root>
28
+ END
29
+ complex_hash = { :root => { :L1 => { :L2A => { :key => 'value' }, :L2B => { :key => 'value' }}}}
30
+ complex_xml = <<-END
31
+ <root>
32
+ <L1>
33
+ <L2A>
34
+ <key>value</key>
35
+ </L2A>
36
+ <L2B>
37
+ <key>value</key>
38
+ </L2B>
39
+ </L1>
40
+ </root>
41
+ END
42
+
43
+ expect(Cardflex::Xml::Serializer.hash_to_xml(simple_hash)).to match simple_xml
44
+ expect(Cardflex::Xml::Serializer.hash_to_xml(complex_hash)).to match complex_xml
45
+ end
46
+
47
+ it 'should convert symbols to strings' do
48
+ hash = { :root => { :nested => :value }}
49
+ xml = <<-END
50
+ <root>
51
+ <nested>value</nested>
52
+ </root>
53
+ END
54
+ expect(Cardflex::Xml::Serializer.hash_to_xml(hash)).to match xml
55
+ end
56
+
57
+ it 'should format numbers with decimals to 2 decimal places' do
58
+ num1_xml = <<-END
59
+ <root>
60
+ <num>1.00</num>
61
+ </root>
62
+ END
63
+ num2_xml = <<-END
64
+ <root>
65
+ <num>1</num>
66
+ </root>
67
+ END
68
+
69
+ expect(Cardflex::Xml::Serializer.hash_to_xml(:root => { :num => 1.0 })).to match num1_xml
70
+ expect(Cardflex::Xml::Serializer.hash_to_xml(:root => { :num => 1 })).to match num2_xml
71
+ end
72
+ end
73
+
74
+ describe 'xml to hash' do
75
+ it 'should return an empty has for a nil string' do
76
+ expect(Cardflex::Xml::Parser.xml_to_hash(nil)).to eq({})
77
+ end
78
+
79
+ it 'should parse simple xml' do
80
+ xml = '<root>nested</root>'
81
+ expect(Cardflex::Xml::Parser.xml_to_hash(xml)).to eq({ :root => 'nested' })
82
+ end
83
+
84
+ it 'should parse complex xml' do
85
+ xml = '<root><L1>value<L2><L3A>value</L3A><L3B>value</L3B></L2></L1></root>'
86
+ hash = { :root => { :L1 => { :L2 => { :L3A => 'value', :L3B => 'value' }}}}
87
+ expect(Cardflex::Xml::Parser.xml_to_hash(xml)).to eq(hash)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cardflex-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tom King
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - cardflex.gemspec
36
+ - lib/cardflex.rb
37
+ - lib/cardflex/base_module.rb
38
+ - lib/cardflex/configuration.rb
39
+ - lib/cardflex/customer_vault.rb
40
+ - lib/cardflex/customer_vault_gateway.rb
41
+ - lib/cardflex/error_response.rb
42
+ - lib/cardflex/errors.rb
43
+ - lib/cardflex/gateway.rb
44
+ - lib/cardflex/http.rb
45
+ - lib/cardflex/plan.rb
46
+ - lib/cardflex/plan_gateway.rb
47
+ - lib/cardflex/subscription.rb
48
+ - lib/cardflex/subscription_gateway.rb
49
+ - lib/cardflex/success_response.rb
50
+ - lib/cardflex/test/test_values.rb
51
+ - lib/cardflex/three_step.rb
52
+ - lib/cardflex/three_step_gateway.rb
53
+ - lib/cardflex/transaction.rb
54
+ - lib/cardflex/transaction_gateway.rb
55
+ - lib/cardflex/version.rb
56
+ - lib/cardflex/xml.rb
57
+ - lib/cardflex/xml/parser.rb
58
+ - lib/cardflex/xml/serializer.rb
59
+ - lib/ssl/ca-certificates.ca.crt
60
+ - spec/integration/cardflex/http_spec.rb
61
+ - spec/integration/cardflex/plan_spec.rb
62
+ - spec/integration/cardflex/three_step_gateway_spec.rb
63
+ - spec/integration/cardflex/three_step_spec.rb
64
+ - spec/integration/spec_helper.rb
65
+ - spec/spec.opts
66
+ - spec/spec_helper.rb
67
+ - spec/ssl/certificate.crt
68
+ - spec/ssl/geotrust_global.crt
69
+ - spec/ssl/private_key.pem
70
+ - spec/unit/cardflex/base_module_spec.rb
71
+ - spec/unit/cardflex/configuration_spec.rb
72
+ - spec/unit/cardflex/customer_vault_gateway_spec.rb
73
+ - spec/unit/cardflex/errors_spec.rb
74
+ - spec/unit/cardflex/gateway_spec.rb
75
+ - spec/unit/cardflex/http_spec.rb
76
+ - spec/unit/cardflex/three_step_gateway_spec.rb
77
+ - spec/unit/cardflex/xml_spec.rb
78
+ - spec/unit/spec_helper.rb
79
+ homepage: https://github.com/twking7/cardflex-ruby
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.2.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Cardflex gateway ruby client library
103
+ test_files: []