netaxept 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in netaxept.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ # If you want to make this the default task
8
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ module Netaxept
2
+ class ErrorMessage
3
+ attr_accessor :message, :code, :source, :text
4
+ def initialize(node)
5
+ super
6
+ if(node)
7
+ @message = node["Message"]
8
+ @code = node["Code"]
9
+ @source = node["ResponseSource"]
10
+ @text = node["ResponseText"]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module Netaxept
2
+ module Responses
3
+
4
+ class RegisterResponse < Response
5
+
6
+ attr_reader :transaction_id
7
+
8
+ def initialize(node)
9
+ super(node)
10
+ if(success?)
11
+ @transaction_id = node["RegisterResponse"]["TransactionId"]
12
+ end
13
+ end
14
+
15
+ end # RegisterResponse
16
+
17
+ end # Responses
18
+ end # Netaxept
@@ -0,0 +1,25 @@
1
+ module Netaxept
2
+ module Responses
3
+
4
+ class Response
5
+
6
+ attr_reader :errors
7
+
8
+ def initialize(node)
9
+ super()
10
+ @errors = []
11
+ if(node["Exception"])
12
+ errors << Netaxept::ErrorMessage.new(node["Exception"]["Error"])
13
+ elsif(node["BBSException"])
14
+ errors << Netaxept::ErrorMessage.new(node)
15
+ end
16
+ end
17
+
18
+ def success?
19
+ self.errors.empty?
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ module Netaxept
2
+ module Responses
3
+ class SaleResponse < Response
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,69 @@
1
+ require "httparty"
2
+
3
+ module Netaxept
4
+ class Service
5
+ include HTTParty
6
+
7
+ default_params :CurrencyCode => "NOK"
8
+
9
+ module Configuration
10
+
11
+ ##
12
+ # Stores the merchant id and the token for later requests
13
+
14
+ def authenticate(merchant_id, token)
15
+ default_params({
16
+ :MerchantId => merchant_id,
17
+ :token => token
18
+ })
19
+ end
20
+
21
+ ##
22
+ # Switches between sandbox and production environment
23
+
24
+ def environment=(new_environment)
25
+ if(new_environment == :production)
26
+ base_uri "https://epayment.bbs.no/"
27
+ end
28
+ if(new_environment == :test)
29
+ base_uri "https://epayment-test.bbs.no/"
30
+ end
31
+ end
32
+
33
+ end
34
+ extend Configuration
35
+
36
+ environment = :production
37
+
38
+ ##
39
+ # Registers the order parameters with netaxept. Returns a Responses::RegisterResponse
40
+
41
+ def register(amount, order_id, options = {})
42
+
43
+ params = {}
44
+ params[:query] = {
45
+ :amount => amount,
46
+ :orderNumber => order_id
47
+ }.merge(options)
48
+
49
+ Responses::RegisterResponse.new(self.class.get("/Netaxept/Register.aspx", params).parsed_response)
50
+
51
+ end
52
+
53
+ ##
54
+ # Captures the whole amount instantly
55
+
56
+ def sale(transaction_id, amount)
57
+ params = {
58
+ :query => {
59
+ :amount => amount,
60
+ :transactionId => transaction_id,
61
+ :operation => "SALE"
62
+ }
63
+ }
64
+
65
+ Responses::SaleResponse.new(self.class.get("/Netaxept/Process.aspx", params).parsed_response)
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module Netaxept
2
+ VERSION = "0.0.2"
3
+ end
data/lib/netaxept.rb ADDED
@@ -0,0 +1,20 @@
1
+ # This gem wraps the current Netaxept REST api in a nice fashion
2
+ #
3
+ # Author:: Håkon Lerring (mailto:hakon@powow.no)
4
+ # Copyright:: Copyright © 2011 Powow AS
5
+ # License:: TODO!
6
+
7
+ module Netaxept
8
+ autoload :Version, "netaxept/version"
9
+ autoload :Service, "netaxept/service"
10
+ autoload :Configuration, "netaxept/configuration"
11
+ autoload :ErrorMessage, "netaxept/error_message"
12
+
13
+ module Responses
14
+
15
+ autoload :Response, "netaxept/responses/response"
16
+ autoload :RegisterResponse, "netaxept/responses/register_response"
17
+ autoload :SaleResponse, "netaxept/responses/sale_response"
18
+
19
+ end
20
+ end
data/netaxept.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "netaxept/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "netaxept"
7
+ s.version = Netaxept::VERSION
8
+ s.authors = ["Håkon Lerring"]
9
+ s.email = ["hakon@powow.no"]
10
+ s.homepage = ""
11
+ s.summary = %q{A gem for speaking to Nets Netaxept credit card payment service}
12
+ s.description = %q{This gem simplifies the comunication with the netaxept service significantly. Right now it only supports register and sale, more is to come.}
13
+ s.has_rdoc = true
14
+
15
+ s.rubyforge_project = "netaxept"
16
+
17
+ s.add_dependency "httparty", "~>0.7"
18
+
19
+ s.add_development_dependency "rspec"
20
+ s.add_development_dependency "rdoc"
21
+ s.add_development_dependency "vcr"
22
+ s.add_development_dependency "fakeweb"
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ s.require_paths = ["lib"]
28
+ end
@@ -0,0 +1,58 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://epayment-test.bbs.no:443/Netaxept/Register.aspx?CurrencyCode=NOK&MerchantId=123123&token=123test&amount=20100&orderNumber=12&redirectUrl=http%3A%2F%2Flocalhost%3A3000%2Forder%2F1%2Freturn
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ cache-control:
14
+ - private
15
+ content-type:
16
+ - text/xml
17
+ server:
18
+ - Microsoft-IIS/7.5
19
+ x-aspnet-version:
20
+ - 2.0.50727
21
+ x-powered-by:
22
+ - ASP.NET
23
+ date:
24
+ - Wed, 03 Aug 2011 12:59:50 GMT
25
+ content-length:
26
+ - '228'
27
+ body: ! "<?xml version=\"1.0\"?>\r\n<RegisterResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
28
+ xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <TransactionId>ab4a60dcecd04eddac3ae9bde6718718</TransactionId>\r\n</RegisterResponse>"
29
+ http_version: '1.1'
30
+ - !ruby/struct:VCR::HTTPInteraction
31
+ request: !ruby/struct:VCR::Request
32
+ method: :get
33
+ uri: https://epayment-test.bbs.no:443/Netaxept/Register.aspx?CurrencyCode=NOK&MerchantId=123123&token=123test&amount=0&orderNumber=12&redirectUrl=http%3A%2F%2Flocalhost%3A3000%2Forder%2F1%2Freturn
34
+ body: !!null
35
+ headers: !!null
36
+ response: !ruby/struct:VCR::Response
37
+ status: !ruby/struct:VCR::ResponseStatus
38
+ code: 200
39
+ message: OK
40
+ headers:
41
+ cache-control:
42
+ - private
43
+ content-type:
44
+ - text/xml
45
+ server:
46
+ - Microsoft-IIS/7.5
47
+ x-aspnet-version:
48
+ - 2.0.50727
49
+ x-powered-by:
50
+ - ASP.NET
51
+ date:
52
+ - Wed, 03 Aug 2011 12:59:50 GMT
53
+ content-length:
54
+ - '271'
55
+ body: ! "<?xml version=\"1.0\"?>\r\n<Exception xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
56
+ xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <Error xsi:type=\"ValidationException\">\r\n
57
+ \ <Message>Transaction amount must be greater than zero.</Message>\r\n </Error>\r\n</Exception>"
58
+ http_version: '1.1'
@@ -0,0 +1,60 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://epayment-test.bbs.no:443/Netaxept/Register.aspx?CurrencyCode=NOK&MerchantId=123123&token=123test&amount=20100&orderNumber=12&redirectUrl=http%3A%2F%2Flocalhost%3A3000%2Forder%2F1%2Freturn
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ cache-control:
14
+ - private
15
+ content-type:
16
+ - text/xml
17
+ server:
18
+ - Microsoft-IIS/7.5
19
+ x-aspnet-version:
20
+ - 2.0.50727
21
+ x-powered-by:
22
+ - ASP.NET
23
+ date:
24
+ - Wed, 03 Aug 2011 13:25:01 GMT
25
+ content-length:
26
+ - '228'
27
+ body: ! "<?xml version=\"1.0\"?>\r\n<RegisterResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
28
+ xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <TransactionId>899995942e1e4d43b0c8e0957b4716db</TransactionId>\r\n</RegisterResponse>"
29
+ http_version: '1.1'
30
+ - !ruby/struct:VCR::HTTPInteraction
31
+ request: !ruby/struct:VCR::Request
32
+ method: :get
33
+ uri: https://epayment-test.bbs.no:443/Netaxept/Process.aspx?CurrencyCode=NOK&MerchantId=123123&token=123test&amount=20100&transactionId=899995942e1e4d43b0c8e0957b4716db&operation=SALE
34
+ body: !!null
35
+ headers: !!null
36
+ response: !ruby/struct:VCR::Response
37
+ status: !ruby/struct:VCR::ResponseStatus
38
+ code: 200
39
+ message: OK
40
+ headers:
41
+ cache-control:
42
+ - private
43
+ content-type:
44
+ - text/xml
45
+ server:
46
+ - Microsoft-IIS/7.5
47
+ x-aspnet-version:
48
+ - 2.0.50727
49
+ x-powered-by:
50
+ - ASP.NET
51
+ date:
52
+ - Wed, 03 Aug 2011 13:26:52 GMT
53
+ content-length:
54
+ - '440'
55
+ body: ! "<?xml version=\"1.0\"?>\r\n<ProcessResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
56
+ xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <Operation>SALE</Operation>\r\n
57
+ \ <ResponseCode>OK</ResponseCode>\r\n <AuthorizationId>093083</AuthorizationId>\r\n
58
+ \ <TransactionId>899995942e1e4d43b0c8e0957b4716db</TransactionId>\r\n <ExecutionTime>2011-08-03T15:26:53.5194685+02:00</ExecutionTime>\r\n
59
+ \ <MerchantId>123123</MerchantId>\r\n</ProcessResponse>"
60
+ http_version: '1.1'
@@ -0,0 +1,86 @@
1
+ require "spec_helper"
2
+
3
+ describe Netaxept::Service do
4
+
5
+ let(:service) { Netaxept::Service.new }
6
+
7
+ describe ".authenticate" do
8
+ it "sets merchant id and token as default params" do
9
+ Netaxept::Service.should_receive(:default_params).with({
10
+ :MerchantId => "12341234",
11
+ :token => "abc123"
12
+ })
13
+
14
+ Netaxept::Service.authenticate("12341234", "abc123")
15
+ end
16
+ end
17
+
18
+ describe ".environment" do
19
+ it "sets the base_uri to https://epayment-test.bbs.no/ when set to test" do
20
+ Netaxept::Service.should_receive(:base_uri).with "https://epayment-test.bbs.no/"
21
+
22
+ Netaxept::Service.environment = :test
23
+ end
24
+
25
+ it "sets the base_uri to https://epayment.bbs.no/ when set to production" do
26
+ Netaxept::Service.should_receive(:base_uri).with "https://epayment.bbs.no/"
27
+
28
+ Netaxept::Service.environment = :production
29
+ end
30
+ end
31
+
32
+ describe ".register" do
33
+ use_vcr_cassette
34
+
35
+ describe "a valid request" do
36
+
37
+ let(:response) { service.register(20100, 12, :redirectUrl => "http://localhost:3000/order/1/return") }
38
+
39
+ it "is successful" do
40
+ response.success?.should == true
41
+ end
42
+
43
+ it "has a transaction_id" do
44
+ response.transaction_id.should_not be_nil
45
+ end
46
+
47
+ end
48
+
49
+ describe "a request without error (no money)" do
50
+
51
+ let(:response) { service.register(0, 12, :redirectUrl => "http://localhost:3000/order/1/return") }
52
+
53
+ it "is not a success" do
54
+ response.success?.should == false
55
+ end
56
+
57
+ it "does not have a transaction id" do
58
+ response.transaction_id.should be_nil
59
+ end
60
+
61
+ it "has an error message" do
62
+ response.errors.first.message.should == "Transaction amount must be greater than zero."
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ describe ".sale" do
70
+ use_vcr_cassette
71
+
72
+ let(:transaction_id) { service.register(20100, 12, :redirectUrl => "http://localhost:3000/order/1/return").transaction_id }
73
+
74
+ describe "a valid request" do
75
+
76
+ let(:response) { service.sale(transaction_id, 20100) }
77
+
78
+ it "is a success" do
79
+ response.success?.should == true
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,2 @@
1
+ NETAXEPT_TEST_MERCHANT_ID = "123123"
2
+ NETAXEPT_TEST_TOKEN = "123test"
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'vcr'
5
+ require "fakeweb"
6
+
7
+ require 'netaxept' # and any other gems you need
8
+ require "netaxept_credentials"
9
+
10
+ VCR.config do |c|
11
+ c.cassette_library_dir = 'spec/cassettes'
12
+ c.stub_with :fakeweb
13
+ c.default_cassette_options = { :record => :new_episodes }
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+
18
+ config.extend VCR::RSpec::Macros
19
+
20
+ end
21
+
22
+ Netaxept::Service.authenticate(NETAXEPT_TEST_MERCHANT_ID, NETAXEPT_TEST_TOKEN)
23
+ Netaxept::Service.environment = :test
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" ?>
2
+ <RegisterResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <TransactionId>b127f98b77f741fca6bb49981ee6e846</TransactionId>
4
+ </RegisterResponse>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0"?>
2
+ <Exception xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <Error xsi:type="ValidationException">
4
+ <Message>Missing parameter: 'Order Number'</Message>
5
+ </Error>
6
+ </Exception>
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netaxept
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Håkon Lerring
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-03 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ requirement: &2158181140 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '0.7'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2158181140
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &2158180720 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2158180720
37
+ - !ruby/object:Gem::Dependency
38
+ name: rdoc
39
+ requirement: &2158180260 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2158180260
48
+ - !ruby/object:Gem::Dependency
49
+ name: vcr
50
+ requirement: &2158179840 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2158179840
59
+ - !ruby/object:Gem::Dependency
60
+ name: fakeweb
61
+ requirement: &2158179420 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2158179420
70
+ description: This gem simplifies the comunication with the netaxept service significantly.
71
+ Right now it only supports register and sale, more is to come.
72
+ email:
73
+ - hakon@powow.no
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .rspec
80
+ - Gemfile
81
+ - Rakefile
82
+ - lib/netaxept.rb
83
+ - lib/netaxept/error_message.rb
84
+ - lib/netaxept/responses/register_response.rb
85
+ - lib/netaxept/responses/response.rb
86
+ - lib/netaxept/responses/sale_response.rb
87
+ - lib/netaxept/service.rb
88
+ - lib/netaxept/version.rb
89
+ - netaxept.gemspec
90
+ - spec/cassettes/Netaxept_Service/_register.yml
91
+ - spec/cassettes/Netaxept_Service/_sale.yml
92
+ - spec/netaxept/service_spec.rb
93
+ - spec/netaxept_credentials.rb
94
+ - spec/spec_helper.rb
95
+ - spec/support/responses/register_response.xml
96
+ - spec/support/responses/register_without_order_id_response.xml
97
+ has_rdoc: true
98
+ homepage: ''
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project: netaxept
118
+ rubygems_version: 1.6.2
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: A gem for speaking to Nets Netaxept credit card payment service
122
+ test_files:
123
+ - spec/cassettes/Netaxept_Service/_register.yml
124
+ - spec/cassettes/Netaxept_Service/_sale.yml
125
+ - spec/netaxept/service_spec.rb
126
+ - spec/netaxept_credentials.rb
127
+ - spec/spec_helper.rb
128
+ - spec/support/responses/register_response.xml
129
+ - spec/support/responses/register_without_order_id_response.xml