dineromail 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  /nbproject/
6
+ .redcar/
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ LICENSE
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2011 Simplex. http://soluciones-simplex.com.ar
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
@@ -46,4 +46,11 @@ You need to create a config file (config/initializers/dineromail.rb) with:
46
46
 
47
47
  == Example dineromail forward page
48
48
 
49
- <%= dineromail_button('Item name',price,:transaction_id => @transaction_id) %>
49
+ <%= dineromail_button('Item name',price,:transaction_id => @transaction_id) %>
50
+
51
+ == Contributing to Dineromail
52
+
53
+ * Fork the project.
54
+ * Make your feature addition or bug fix
55
+ * Send me a pull request.
56
+
@@ -16,8 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency "httparty"
17
17
  s.add_dependency "rails", ["~> 3.0"]
18
18
  s.add_development_dependency "bundler"
19
- s.add_development_dependency "rspec"
20
-
19
+ s.add_development_dependency "rspec-rails"
20
+ s.add_development_dependency "rspec2-rails-views-matchers"
21
+
21
22
  s.files = `git ls-files`.split("\n")
22
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -7,9 +7,13 @@ module Dineromail
7
7
  element :transaction_id, Integer, :tag => 'ID'
8
8
  element :type, String, :tag => 'TIPO'
9
9
 
10
+ def initialize(options = {})
11
+ @options = options.symbolize_keys
12
+ end
13
+
10
14
  def status_report
11
15
  unless @status_report
12
- @status_report = StatusReport.get_report_for(transaction_id)
16
+ @status_report = StatusReport.get_report_for(transaction_id,@options)
13
17
  end
14
18
  @status_report
15
19
  end
@@ -21,16 +21,25 @@ module Dineromail
21
21
  INVALID_PASSWORD_OR_ACCOUNT_NUMBER_REQUEST_STATUS = 7
22
22
  TRANSACTION_NOT_FOUND_REQUEST_STATUS = 8
23
23
 
24
+
24
25
  def valid_report?
25
26
  report_status == VALID_REPORT_STATUS
26
27
  end
27
28
 
28
29
 
29
- def self.get_report_for(transaction_id)
30
- account_number = Dineromail.configuration.account_number
31
- password = Dineromail.configuration.password
32
- ipn_url = Dineromail.configuration.ipn_webservice_url
33
- request_data = "<REPORTE>
30
+ def self.get_report_for(transaction_id,options = {})
31
+ options = options.symbolize_keys
32
+ ipn_url = options[:ipn_webservice_url] || Dineromail.configuration.ipn_webservice_url
33
+ request_data = xml_request_for(transaction_id,options)
34
+ response = HTTParty.get ipn_url , :query => {:data => request_data}
35
+ self.parse response.body
36
+ end
37
+
38
+ def self.xml_request_for(transaction_id,options = {})
39
+ options = options.symbolize_keys
40
+ account_number = options[:account_number] || Dineromail.configuration.account_number
41
+ password = options[:password] || Dineromail.configuration.password
42
+ "<REPORTE>
34
43
  <NROCTA>#{account_number}</NROCTA>
35
44
  <DETALLE>
36
45
  <CONSULTA>
@@ -42,8 +51,6 @@ module Dineromail
42
51
  </CONSULTA>
43
52
  </DETALLE>
44
53
  </REPORTE>"
45
- response = HTTParty.get ipn_url , :query => {:data => request_data}
46
- self.parse response.body
47
54
  end
48
55
 
49
56
  end
@@ -1,3 +1,3 @@
1
1
  module Dineromail
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -11,9 +11,7 @@ describe Dineromail::Notification do
11
11
 
12
12
  it 'should get automaticaly the status data associated with the notification' do
13
13
  HTTParty.stub!(:get).and_return {
14
- response = Object.new
15
- response.stub!(:body).and_return(File.read( 'spec/fixtures/status_report.xml'))
16
- response
14
+ stub :body => File.read( 'spec/fixtures/status_report.xml')
17
15
  }
18
16
  notification_xml = File.read( 'spec/fixtures/notification.xml')
19
17
  notifications = Dineromail::Notification.parse(notification_xml)
@@ -1,4 +1,6 @@
1
1
  require 'spec_helper'
2
+ require 'rspec/rails'
3
+ require 'rspec/rails/views/matchers'
2
4
 
3
5
  describe Dineromail::StatusReport do
4
6
  it 'should load the status report from xml' do
@@ -30,4 +32,29 @@ describe Dineromail::StatusReport do
30
32
  item.count.should == 2
31
33
  item.unit_price.should == 6.9
32
34
  end
35
+
36
+ it 'should use the configuration to get the parameters for the request if no options are given' do
37
+ transaction_id = 42
38
+ Dineromail.configure do |c|
39
+ c.account_number = '10000'
40
+ c.password = 'password-123'
41
+ end
42
+ xml_request = Dineromail::StatusReport.xml_request_for(transaction_id)
43
+ xml_request.should have_tag('nrocta', :text => '10000')
44
+ xml_request.should have_tag('clave', :text => 'password-123')
45
+ xml_request.should have_tag('id', :text => '42')
46
+ end
47
+
48
+ it 'should use the option parameters for the request if options are given' do
49
+ transaction_id = 42
50
+ Dineromail.configure do |c|
51
+ c.account_number = '10000'
52
+ c.password = 'password-123'
53
+ end
54
+ xml_request = Dineromail::StatusReport.xml_request_for(transaction_id,{:account_number => '2000',:password => 'password-456'})
55
+ xml_request.should have_tag('nrocta', :text => '2000')
56
+ xml_request.should have_tag('clave', :text => 'password-456')
57
+ xml_request.should have_tag('id', :text => '42')
58
+ end
59
+
33
60
  end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+ require 'rspec/rails'
3
+ require 'rspec/rails/views/matchers'
4
+
5
+ describe DineromailHelper do
6
+ describe "#dineromail_button" do
7
+ it 'should create a form with hidden fields' do
8
+ generated_html = helper.dineromail_button('item name',9.56)
9
+ generated_html.should have_tag('form') do
10
+ with_tag "input", :with => { :name => 'NombreItem', :type => 'hidden', :value => 'item name' }
11
+ with_tag "input", :with => { :name => 'PrecioItem', :type => 'hidden', :value => '9.56' }
12
+ end
13
+ end
14
+ end
15
+
16
+ describe "#dineromail_inputs" do
17
+ it 'should create hidden fields without a form' do
18
+ generated_html = helper.dineromail_inputs('item name',9.56)
19
+ generated_html.should_not have_tag('form')
20
+ generated_html.should have_tag('input', :with => {:type => 'hidden'})
21
+ end
22
+
23
+ it 'should accept a transaction_id option' do
24
+ generated_html = helper.dineromail_inputs('item name',9.56, :transaction_id => '1234567')
25
+ generated_html.should have_tag('input', :with => {:name => 'TRX_ID', :type => 'hidden', :value => '1234567'})
26
+ end
27
+
28
+ it 'should accept a logo_url option' do
29
+ generated_html = helper.dineromail_inputs('item name',9.56, :logo_url => 'http://test.com')
30
+ generated_html.should have_tag('input', :with => {:name => 'image_url', :type => 'hidden', :value => 'http://test.com'})
31
+ end
32
+
33
+ it 'should accept a return_url option' do
34
+ generated_html = helper.dineromail_inputs('item name',9.56, :return_url => 'http://test.com')
35
+ generated_html.should have_tag('input', :with => {:name => 'DireccionExito', :type => 'hidden', :value => 'http://test.com'})
36
+ end
37
+
38
+ it 'should accept an error_url option' do
39
+ generated_html = helper.dineromail_inputs('item name',9.56, :error_url => 'http://test.com')
40
+ generated_html.should have_tag('input', :with => {:name => 'DireccionFracaso', :type => 'hidden', :value => 'http://test.com'})
41
+ end
42
+
43
+ it 'should accept a message option' do
44
+ generated_html = helper.dineromail_inputs('item name',9.56, :message => true)
45
+ generated_html.should have_tag('input', :with => {:name => 'Mensaje', :type => 'hidden', :value => '1'})
46
+ generated_html = helper.dineromail_inputs('item name',9.56, :message => false)
47
+ generated_html.should have_tag('input', :with => {:name => 'Mensaje', :type => 'hidden', :value => '0'})
48
+ end
49
+
50
+ it 'should accept an account_number option' do
51
+ generated_html = helper.dineromail_inputs('item name',9.56, :account_number => '1234567')
52
+ generated_html.should have_tag('input', :with => {:name => 'E_Comercio', :type => 'hidden', :value => '1234567'})
53
+ end
54
+
55
+ it 'should accept a pay_methods option' do
56
+ generated_html = helper.dineromail_inputs('item name',9.56, :pay_methods => '1')
57
+ generated_html.should have_tag('input', :with => {:name => 'MediosPago', :type => 'hidden', :value => '1'})
58
+ end
59
+
60
+ it 'should accept a currency option' do
61
+ currency = Dineromail::Configuration::PESO
62
+ generated_html = helper.dineromail_inputs('item name',9.56, :currency => currency)
63
+ generated_html.should have_tag('input', :with => {:name => 'TipoMoneda', :type => 'hidden', :value => currency.to_s})
64
+ end
65
+
66
+ it 'should accept an item_number option' do
67
+ generated_html = helper.dineromail_inputs('item name',9.56, :item_number => '1')
68
+ generated_html.should have_tag('input', :with => {:name => 'NroItem', :type => 'hidden', :value => '1'})
69
+ end
70
+
71
+ it 'should read logo_url from configuration if no value is given' do
72
+ Dineromail.configure do |c|
73
+ c.logo_url = 'http://test.com'
74
+ end
75
+
76
+ generated_html = helper.dineromail_inputs('item name',9.56)
77
+ generated_html.should have_tag('input', :with => {:name => 'image_url', :type => 'hidden', :value => 'http://test.com'})
78
+ end
79
+
80
+ it 'should read return_url from configuration if no value is given' do
81
+ Dineromail.configure do |c|
82
+ c.return_url = 'http://test.com'
83
+ end
84
+
85
+ generated_html = helper.dineromail_inputs('item name',9.56)
86
+ generated_html.should have_tag('input', :with => {:name => 'DireccionExito', :type => 'hidden', :value => 'http://test.com'})
87
+ end
88
+
89
+ it 'should read error_url from configuration if no value is given' do
90
+ Dineromail.configure do |c|
91
+ c.error_url = 'http://test.com'
92
+ end
93
+
94
+ generated_html = helper.dineromail_inputs('item name',9.56)
95
+ generated_html.should have_tag('input', :with => {:name => 'DireccionFracaso', :type => 'hidden', :value => 'http://test.com'})
96
+ end
97
+
98
+ it 'should read account_number from configuration if no value is given' do
99
+ Dineromail.configure do |c|
100
+ c.account_number = '1234567'
101
+ end
102
+
103
+ generated_html = helper.dineromail_inputs('item name',9.56)
104
+ generated_html.should have_tag('input', :with => {:name => 'E_Comercio', :type => 'hidden', :value => '1234567'})
105
+ end
106
+
107
+ it 'should read pay_methods from configuration if no value is given' do
108
+ Dineromail.configure do |c|
109
+ c.pay_methods = '1'
110
+ end
111
+
112
+ generated_html = helper.dineromail_inputs('item name',9.56)
113
+ generated_html.should have_tag('input', :with => {:name => 'MediosPago', :type => 'hidden', :value => '1'})
114
+ end
115
+
116
+ it 'should read currency from configuration if no value is given' do
117
+ currency = Dineromail::Configuration::PESO
118
+ Dineromail.configure do |c|
119
+ c.currency = currency
120
+ end
121
+
122
+ generated_html = helper.dineromail_inputs('item name',9.56)
123
+ generated_html.should have_tag('input', :with => {:name => 'TipoMoneda', :type => 'hidden', :value => currency.to_s})
124
+ end
125
+
126
+ end
127
+ end
128
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dineromail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nicolas Mosconi
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-06-23 00:00:00 -03:00
20
+ date: 2011-09-05 00:00:00 -03:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -78,7 +78,7 @@ dependencies:
78
78
  type: :development
79
79
  version_requirements: *id004
80
80
  - !ruby/object:Gem::Dependency
81
- name: rspec
81
+ name: rspec-rails
82
82
  prerelease: false
83
83
  requirement: &id005 !ruby/object:Gem::Requirement
84
84
  none: false
@@ -91,6 +91,20 @@ dependencies:
91
91
  version: "0"
92
92
  type: :development
93
93
  version_requirements: *id005
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec2-rails-views-matchers
96
+ prerelease: false
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ type: :development
107
+ version_requirements: *id006
94
108
  description: Integration with dineromail plataform for rails projects
95
109
  email:
96
110
  - nicolas@soluciones-simplex.com.ar
@@ -105,6 +119,7 @@ extra_rdoc_files: []
105
119
  files:
106
120
  - .gitignore
107
121
  - Gemfile
122
+ - LICENSE
108
123
  - README.rdoc
109
124
  - Rakefile
110
125
  - dineromail.gemspec
@@ -121,6 +136,7 @@ files:
121
136
  - spec/dineromail/status_report_spec.rb
122
137
  - spec/fixtures/notification.xml
123
138
  - spec/fixtures/status_report.xml
139
+ - spec/helpers/dineromail_helper_spec.rb
124
140
  - spec/spec_helper.rb
125
141
  has_rdoc: true
126
142
  homepage: ""