netaxept 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
- pkg/*
4
+ pkg/*
5
+ .DS_Store
data/README.md CHANGED
@@ -1,14 +1,63 @@
1
- [![Build Status](https://secure.travis-ci.org/Hakon/netaxept.png)](http://travis-ci.org/Hakon/netaxept)
2
-
3
1
  Installation
4
2
  -----------
3
+ run
5
4
 
6
5
  gem install netaxept
7
6
 
7
+ or include in your _Gemfile_:
8
+
9
+ gem 'netaxept'
10
+
11
+ Usage
12
+ -----
13
+
14
+ First step is to tell Netaxept your credentials and the desired mode:
15
+
16
+ Netaxept::Service.authenticate <merchant id>, <token>
17
+ Netaxept::Service.environment = :test|:production
18
+
19
+ To interact with Netaxept you need to create an instance of `Netaxept::Service`:
20
+
21
+ service = Netaxept::Service.new
22
+
23
+ ### General
24
+
25
+ Every request returns a `Netaxept::Response` object, which has a `success?` method.
26
+ In case of an error you can call `errors`, which gives you a list of `Netaxept::ErrorMessage`s
27
+ (each with a `message`, `code`, `source` and `text`).
28
+
29
+ ### Off-site payment workflow
30
+
31
+ The following applies for the _Nets hosted_ service type where the user is redirect to the
32
+ Netaxept site to enter her payment details (see the
33
+ [Netaxept docs](http://www.betalingsterminal.no/Netthandel-forside/Teknisk-veiledning/Overview/)
34
+ for details).
35
+
36
+ #### Registering a payment
37
+
38
+ service.register <amount in cents>, <order number>, <options>
39
+
40
+ Required options are `CurrencyCode` (3 letter ISO code) and `redirectUrl`.
41
+
42
+ On success the response object gives you a `transaction_id`.
43
+ You pass that to `Netaxept::Service.terminal_url(<transaction id>)` to get the URL for redirecting the user.
44
+
45
+ For details on the options see http://www.betalingsterminal.no/Netthandel-forside/Teknisk-veiledning/API/Register/
46
+
47
+ #### Completing a payment
48
+
49
+ After the user has authorized the payment on the Netaxept site he is redirected to the `redirectUrl` you provided. Netaxept adds a `resonseCode` and `transactionId` parameter to the URL. To finalize the payment you call `sale` on the service.
50
+
51
+ service.sale <transaction id>, <amount in cents>
52
+
53
+ The response is a `Responses::SaleResponse` which only has the `success?` and `errors` methods mentioned under _General_.
54
+
55
+ Congratulations, you have processed a payment.
56
+
8
57
  Testing
9
58
  -------
10
59
 
11
60
  To run the tests:
12
61
 
13
62
  $ bundle
14
- $ rake
63
+ $ rake MERCHANT_ID=<your merchant id> NETAXEPT_TOKEN=<your token>
@@ -19,5 +19,6 @@ module Netaxept
19
19
  autoload :CaptureResponse, "netaxept/responses/capture_response"
20
20
 
21
21
  autoload :CreditResponse, "netaxept/responses/credit_response"
22
+ autoload :AnnulResponse, "netaxept/responses/annul_response"
22
23
  end
23
24
  end
@@ -0,0 +1,7 @@
1
+ module Netaxept
2
+ module Responses
3
+ class AnnulResponse < Response
4
+
5
+ end
6
+ end
7
+ end
@@ -113,6 +113,17 @@ module Netaxept
113
113
  Responses::CreditResponse.new(self.class.get("/Netaxept/Process.aspx", params).parsed_response)
114
114
  end
115
115
 
116
+ def annul(transaction_id)
117
+ params = {
118
+ :query => {
119
+ :transactionId => transaction_id,
120
+ :operation => "ANNUL"
121
+ }
122
+ }
123
+
124
+ Responses::AnnulResponse.new(self.class.get("/Netaxept/Process.aspx", params).parsed_response)
125
+ end
126
+
116
127
  ##
117
128
  # The terminal url for a given transaction id
118
129
 
@@ -1,3 +1,3 @@
1
1
  module Netaxept
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Netaxept::VERSION
8
8
  s.authors = ["Håkon Lerring", "Theodor Tonum"]
9
9
  s.email = ["hakon@powow.no", "theodor@tonum.no"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/Hakon/netaxept"
11
11
  s.summary = %q{A gem for speaking to Nets Netaxept credit card payment service}
12
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
13
  s.has_rdoc = true
@@ -19,8 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency "rake"
20
20
  s.add_development_dependency "rspec"
21
21
  s.add_development_dependency "rdoc"
22
- s.add_development_dependency "vcr"
23
- s.add_development_dependency "fakeweb"
22
+ s.add_development_dependency "mechanize"
24
23
 
25
24
  s.files = `git ls-files`.split("\n")
26
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -7,26 +7,26 @@ describe Netaxept::Service do
7
7
  describe ".authenticate" do
8
8
  it "sets merchant id and token as default params" do
9
9
  Netaxept::Service.should_receive(:default_params).with({
10
- :MerchantId => "12341234",
11
- :token => "abc123"
10
+ :MerchantId => NETAXEPT_TEST_MERCHANT_ID,
11
+ :token => NETAXEPT_TEST_TOKEN
12
12
  })
13
13
 
14
- Netaxept::Service.authenticate("12341234", "abc123")
14
+ Netaxept::Service.authenticate(NETAXEPT_TEST_MERCHANT_ID, NETAXEPT_TEST_TOKEN)
15
15
  end
16
16
  end
17
17
 
18
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
19
  it "sets the base_uri to https://epayment.bbs.no/ when set to production" do
26
20
  Netaxept::Service.should_receive(:base_uri).with "https://epayment.bbs.no/"
27
21
 
28
22
  Netaxept::Service.environment = :production
29
23
  end
24
+
25
+ it "sets the base_uri to https://epayment-test.bbs.no/ when set to test" do
26
+ Netaxept::Service.should_receive(:base_uri).with "https://epayment-test.bbs.no/"
27
+
28
+ Netaxept::Service.environment = :test
29
+ end
30
30
  end
31
31
 
32
32
  describe ".terminal_url" do
@@ -46,14 +46,13 @@ describe Netaxept::Service do
46
46
  end
47
47
 
48
48
  describe ".register" do
49
- use_vcr_cassette
50
49
 
51
50
  describe "a valid request" do
52
51
 
53
52
  let(:response) { service.register(20100, 12, :redirectUrl => "http://localhost:3000/order/1/return") }
54
53
 
55
54
  it "is successful" do
56
- response.success?.should == true
55
+ response.should be_successful
57
56
  end
58
57
 
59
58
  it "has a transaction_id" do
@@ -67,87 +66,88 @@ describe Netaxept::Service do
67
66
  let(:response) { service.register(0, 12, :redirectUrl => "http://localhost:3000/order/1/return") }
68
67
 
69
68
  it "is not a success" do
70
- response.success?.should == false
69
+ response.should fail.with_message("Transaction amount must be greater than zero.")
71
70
  end
72
71
 
73
72
  it "does not have a transaction id" do
74
73
  response.transaction_id.should be_nil
75
74
  end
76
75
 
77
- it "has an error message" do
78
- response.errors.first.message.should == "Transaction amount must be greater than zero."
79
- end
80
-
81
76
  end
82
77
 
83
78
  end
84
79
 
85
- describe ".sale" do
86
- use_vcr_cassette
80
+ context "with a transaction id" do
87
81
 
88
82
  let(:transaction_id) { service.register(20100, 12, :redirectUrl => "http://localhost:3000/order/1/return").transaction_id }
83
+
84
+ before do
85
+
86
+ # Register some card data with the transaction.
87
+ url = Netaxept::Service.terminal_url(transaction_id)
88
+ mechanic = Mechanize.new
89
+ mechanic.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
90
+ mechanic.get(url) do |page|
91
+ form = page.form_with(:name => "form1")
92
+ cc_form = form.click_button(form.button_with(:value => /^Neste/)).form_with(:name => "form1") do |form|
93
+
94
+ form["ctl10$cardNo"] = "4925000000000004"
95
+ form.field_with(:id => "month").options.last.tick
96
+ form.field_with(:id => "year").options.last.tick
97
+ form["ctl10$securityCode"] = "111"
98
+
99
+ end
100
+ mechanic.redirect_ok = false
101
+ cc_form.click_button(cc_form.button_with(:id => "okButton"))
102
+ end
103
+
104
+ end
89
105
 
90
- describe "a valid request" do
91
-
92
- let(:response) { service.sale(transaction_id, 20100) }
93
-
106
+ describe "a valid sale request" do
107
+
94
108
  it "is a success" do
95
- response.success?.should == true
109
+ response = service.sale(transaction_id, 20100)
110
+ response.should be_successful
96
111
  end
97
112
 
98
113
  end
99
-
100
- end
101
-
102
- describe ".auth" do
103
- use_vcr_cassette
104
-
105
- let(:transaction_id) { service.register(20100, 12, :redirectUrl => "http://localhost:3000/order/1/return").transaction_id }
106
-
107
- describe "a valid request" do
108
-
109
- let(:response) { service.auth(transaction_id, 20100) }
114
+
115
+ describe "a valid auth request" do
110
116
 
111
117
  it "is a success" do
112
- response.success?.should == true
118
+ response = service.auth(transaction_id, 20100)
119
+ response.should be_successful
113
120
  end
114
121
 
115
122
  end
116
- end
117
123
 
118
- describe ".capture" do
119
- use_vcr_cassette
120
-
121
- let(:transaction_id) { service.register(20100, 12, :redirectUrl => "http://localhost:3000/order/1/return").transaction_id }
122
-
123
- describe "a valid request" do
124
-
125
- let(:response) { service.capture(transaction_id, 20100) }
124
+ describe "a valid capture request" do
126
125
 
127
126
  it "is a success" do
128
- response.success?.should == true
127
+ service.auth(transaction_id, 20100)
128
+ response = service.capture(transaction_id, 20100)
129
+ response.should be_successful
129
130
  end
130
131
 
131
132
  end
132
- end
133
133
 
134
- describe ".credit" do
135
- use_vcr_cassette
136
-
137
- let(:transaction_id) { service.register(20100, 12, :redirectUrl => "http://localhost:3000/order/1/return").transaction_id }
134
+ describe "a valid credit request" do
138
135
 
139
- describe "a valid request" do
136
+ it "is a success" do
137
+ service.sale(transaction_id, 20100)
140
138
 
141
- before(:each) do
142
- service.auth(transaction_id, 20100)
143
- service.capture(transaction_id, 20100)
139
+ service.credit(transaction_id, 20100).should be_successful
144
140
  end
141
+ end
142
+
143
+ describe "a valid annul request" do
145
144
 
146
145
  it "is a success" do
147
- service.credit(transaction_id, 20100).success?.should == true
146
+ service.auth(transaction_id, 20100)
147
+ service.annul(transaction_id).should be_successful
148
148
  end
149
149
  end
150
150
 
151
+
151
152
  end
152
-
153
153
  end
@@ -1,2 +1,2 @@
1
- NETAXEPT_TEST_MERCHANT_ID = "123123"
2
- NETAXEPT_TEST_TOKEN = "123test"
1
+ NETAXEPT_TEST_MERCHANT_ID = ENV["MERCHANT_ID"]
2
+ NETAXEPT_TEST_TOKEN = ENV["NETAXEPT_TOKEN"]
@@ -1,22 +1,13 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
- require 'vcr'
5
- require "fakeweb"
6
-
7
4
  require 'netaxept' # and any other gems you need
8
5
  require "netaxept_credentials"
9
6
 
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
7
+ require "mechanize"
15
8
 
16
- RSpec.configure do |config|
17
-
18
- config.extend VCR::RSpec::Macros
19
-
9
+ Dir.glob(File.join(File.dirname(__FILE__),"support/matchers/*_matcher.rb")) do |file|
10
+ require file
20
11
  end
21
12
 
22
13
  Netaxept::Service.authenticate(NETAXEPT_TEST_MERCHANT_ID, NETAXEPT_TEST_TOKEN)
@@ -0,0 +1,47 @@
1
+ RSpec::Matchers.define :be_successful do
2
+
3
+ match do |response|
4
+ response.success?
5
+ end
6
+
7
+ failure_message_for_should do |response|
8
+ errors = response.errors.map(&:message).join(", ")
9
+ "#{response} should be successful, got error(s): #{errors}"
10
+ end
11
+
12
+ failure_message_for_should_not do |response|
13
+ "#{response} should not be successful"
14
+ end
15
+
16
+ end
17
+
18
+ RSpec::Matchers.define :fail do
19
+ chain :with_message do |message|
20
+ @message = message
21
+ end
22
+
23
+ match do |response|
24
+ @failure = !response.success?
25
+
26
+ if(@message)
27
+ @failure && response.errors.map(&:message).include?(@message)
28
+ else
29
+ @failure
30
+ end
31
+
32
+ end
33
+
34
+ failure_message_for_should do |response|
35
+ errors = response.errors.map(&:message).join(", ")
36
+ if(@message)
37
+ "#{response} should have error message: #{@message}"
38
+ else
39
+ "#{response} should not be successful"
40
+ end
41
+ end
42
+
43
+ failure_message_for_should_not do |response|
44
+ "#{response} should be successful"
45
+ end
46
+
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netaxept
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-01-16 00:00:00.000000000 Z
13
+ date: 2012-12-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
17
- requirement: &70230869242240 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '0.7'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70230869242240
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '0.7'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: rake
28
- requirement: &70230869240580 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '0'
34
39
  type: :development
35
40
  prerelease: false
36
- version_requirements: *70230869240580
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: rspec
39
- requirement: &70230869238440 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '0'
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70230869238440
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: rdoc
50
- requirement: &70230869236020 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,21 +70,15 @@ dependencies:
55
70
  version: '0'
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *70230869236020
59
- - !ruby/object:Gem::Dependency
60
- name: vcr
61
- requirement: &70230869080020 !ruby/object:Gem::Requirement
73
+ version_requirements: !ruby/object:Gem::Requirement
62
74
  none: false
63
75
  requirements:
64
76
  - - ! '>='
65
77
  - !ruby/object:Gem::Version
66
78
  version: '0'
67
- type: :development
68
- prerelease: false
69
- version_requirements: *70230869080020
70
79
  - !ruby/object:Gem::Dependency
71
- name: fakeweb
72
- requirement: &70230869078320 !ruby/object:Gem::Requirement
80
+ name: mechanize
81
+ requirement: !ruby/object:Gem::Requirement
73
82
  none: false
74
83
  requirements:
75
84
  - - ! '>='
@@ -77,7 +86,12 @@ dependencies:
77
86
  version: '0'
78
87
  type: :development
79
88
  prerelease: false
80
- version_requirements: *70230869078320
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
81
95
  description: This gem simplifies the comunication with the netaxept service significantly.
82
96
  Right now it only supports register and sale, more is to come.
83
97
  email:
@@ -95,6 +109,7 @@ files:
95
109
  - Rakefile
96
110
  - lib/netaxept.rb
97
111
  - lib/netaxept/error_message.rb
112
+ - lib/netaxept/responses/annul_response.rb
98
113
  - lib/netaxept/responses/auth_response.rb
99
114
  - lib/netaxept/responses/capture_response.rb
100
115
  - lib/netaxept/responses/credit_response.rb
@@ -104,17 +119,11 @@ files:
104
119
  - lib/netaxept/service.rb
105
120
  - lib/netaxept/version.rb
106
121
  - netaxept.gemspec
107
- - spec/cassettes/Netaxept_Service/_auth.yml
108
- - spec/cassettes/Netaxept_Service/_capture.yml
109
- - spec/cassettes/Netaxept_Service/_credit.yml
110
- - spec/cassettes/Netaxept_Service/_register.yml
111
- - spec/cassettes/Netaxept_Service/_sale.yml
112
122
  - spec/netaxept/service_spec.rb
113
123
  - spec/netaxept_credentials.rb
114
124
  - spec/spec_helper.rb
115
- - spec/support/responses/register_response.xml
116
- - spec/support/responses/register_without_order_id_response.xml
117
- homepage: ''
125
+ - spec/support/matchers/response_success_matcher.rb
126
+ homepage: https://github.com/Hakon/netaxept
118
127
  licenses: []
119
128
  post_install_message:
120
129
  rdoc_options: []
@@ -134,18 +143,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
143
  version: '0'
135
144
  requirements: []
136
145
  rubyforge_project: netaxept
137
- rubygems_version: 1.8.10
146
+ rubygems_version: 1.8.23
138
147
  signing_key:
139
148
  specification_version: 3
140
149
  summary: A gem for speaking to Nets Netaxept credit card payment service
141
150
  test_files:
142
- - spec/cassettes/Netaxept_Service/_auth.yml
143
- - spec/cassettes/Netaxept_Service/_capture.yml
144
- - spec/cassettes/Netaxept_Service/_credit.yml
145
- - spec/cassettes/Netaxept_Service/_register.yml
146
- - spec/cassettes/Netaxept_Service/_sale.yml
147
151
  - spec/netaxept/service_spec.rb
148
152
  - spec/netaxept_credentials.rb
149
153
  - spec/spec_helper.rb
150
- - spec/support/responses/register_response.xml
151
- - spec/support/responses/register_without_order_id_response.xml
154
+ - spec/support/matchers/response_success_matcher.rb
155
+ has_rdoc: true