webpay_rails 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c5dd0af35b42f251d1a42ac62f6782cc81e1c62
4
- data.tar.gz: e055ac2da4f8285ace56cfdc9e431fdcee59c5b8
3
+ metadata.gz: 23f8e8fe1419a4ac0dd8de9572fc19c2fbe3bc43
4
+ data.tar.gz: 9590cb7972cadb66a52ba53c00d30511f1bba908
5
5
  SHA512:
6
- metadata.gz: d1289617f1025538ab9aceac7872f373e2145c1c1cd83621688084b5f75c0f4392af0af6107abf70573e0e8ae2791f99b0cad36ca547c4727f4f587493ad4f59
7
- data.tar.gz: 3fdf4acc44422aedbb74d9eea988c2858bde353f0596233f82b8e55a5efc220568a4b92cceed919a4110270de85a64da612fef87e40490022e3839640262dce9
6
+ metadata.gz: ed9baa4e2f68e458865569d8361c22f3fd0a46a91619b7b54f82ea4338e189bdcee6aa8a4abd811388e44c7cdebcff38950f8bd87ecebaf43686747c261c0f48
7
+ data.tar.gz: be7d8ce811b8946bcd31da14f9975661b66a727f1aeb721602aa59608ac2fb560d2e185162cb4a64f276ba93ab6e58f50c67114c90c224bf3401ec56086dc857
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 1.0.2 - 2016-08-30
2
+
3
+ #### enhancements
4
+ * add rails logger support for savon
5
+ * add missing attributes on transanction result (`session_id`, `card_expiration_date`, `shares_number`)
6
+
1
7
  ### 1.0.1 - 2016-08-26
2
8
 
3
9
  #### bug fixes
data/README.md CHANGED
@@ -36,7 +36,8 @@ class Order < ActiveRecord::Base
36
36
  webpay_cert: '-----BEGIN CERTIFICATE-----
37
37
  ...
38
38
  -----END CERTIFICATE-----',
39
- environment: :integration
39
+ environment: :integration,
40
+ log: Rails.env.development?
40
41
  })
41
42
  end
42
43
  ```
@@ -61,8 +62,8 @@ This method return a `Transaction` object, that contain a redirection `url` and
61
62
  <% if @transaction.success? %>
62
63
  <%= form_tag(@transaction.url, method: "post") do %>
63
64
  <%= hidden_field_tag(:token_ws, @transaction.token) %>
64
- <%= submit_tag("Pagar con Webpay")
65
- <%= end %>
65
+ <%= submit_tag("Pagar con Webpay") %>
66
+ <% end %>
66
67
  <% end %>
67
68
  ```
68
69
 
@@ -76,11 +77,11 @@ When Webpay send a __POST__ to `return_url` with `token_ws`, we need to ask for
76
77
  @result = Order.transaction_result(params[:token_ws])
77
78
  ```
78
79
 
79
- This method return a `TransactionResult` object, that contain an `accounting_date`, `buy_order`, `card_number`, `amount`, `commerce_code`, `authorization_code`, `payment_type_code`, `response_code`, `transaction_date`, `url_redirection` and `vci`.
80
+ This method return a `TransactionResult` object, that contain an `buy_order`, `session_id`, `accounting_date`, `transaction_date`, `vci`, `url_redirection`, `card_number`, `card_expiration_date`, `authorization_code`, `payment_type_code`, `response_code`, `amount`, `shares_number` and `commerce_code`.
80
81
 
81
82
  At this point we have confirmed the transaction with Transbank, performing the operation `acknowledge_transaction` by means of `transaction_result`.
82
83
 
83
- Now we need to send back the customer to `url_redirection` with `token_ws` in the same way we did earlier in the initialization of the transaction.
84
+ Now we need to send back the customer to `url_redirection` with `token_ws` through __GET__ method.
84
85
 
85
86
  #### Ending a transaction
86
87
 
@@ -22,11 +22,7 @@ module WebpayRails
22
22
 
23
23
  raise WebpayRails::InvalidCertificate unless WebpayRails::Verifier.verify(response, webpay_cert)
24
24
 
25
- document = Nokogiri::HTML(response.to_s)
26
- WebpayRails::Transaction.new({
27
- token: document.at_xpath('//token').text.to_s,
28
- url: document.at_xpath('//url').text.to_s
29
- })
25
+ WebpayRails::Transaction.new(Nokogiri::HTML(response.to_s))
30
26
  end
31
27
 
32
28
  def transaction_result(token)
@@ -36,24 +32,11 @@ module WebpayRails
36
32
  raise WebpayRails::FailedGetResult
37
33
  end
38
34
 
39
- raise WebpayRails::InvalidResultResponse unless response
35
+ raise WebpayRails::InvalidResultResponse if response.blank?
40
36
 
41
37
  acknowledge_transaction(token)
42
38
 
43
- document = Nokogiri::HTML(response.to_s)
44
- WebpayRails::TransactionResult.new({
45
- accounting_date: document.at_xpath('//accountingdate').text.to_s,
46
- buy_order: document.at_xpath('//buyorder').text.to_s,
47
- card_number: document.at_xpath('//cardnumber').text.to_s,
48
- amount: document.at_xpath('//amount').text.to_s,
49
- commerce_code: document.at_xpath('//commercecode').text.to_s,
50
- authorization_code: document.at_xpath('//authorizationcode').text.to_s,
51
- payment_type_code: document.at_xpath('//paymenttypecode').text.to_s,
52
- response_code: document.at_xpath('//responsecode').text.to_s,
53
- transaction_date: document.at_xpath('//transactiondate').text.to_s,
54
- url_redirection: document.at_xpath('//urlredirection').text.to_s,
55
- vci: document.at_xpath('//vci').text.to_s
56
- })
39
+ WebpayRails::TransactionResult.new(Nokogiri::HTML(response.to_s))
57
40
  end
58
41
 
59
42
  def acknowledge_transaction(token)
@@ -63,7 +46,7 @@ module WebpayRails
63
46
  raise WebpayRails::FailedAcknowledgeTransaction
64
47
  end
65
48
 
66
- raise WebpayRails::InvalidAcknowledgeResponse unless response
49
+ raise WebpayRails::InvalidAcknowledgeResponse if response.blank?
67
50
  end
68
51
  end
69
52
  end
@@ -0,0 +1,7 @@
1
+ module WebpayRails
2
+ class Railties < ::Rails::Railtie
3
+ initializer 'Rails logger' do
4
+ WebpayRails.logger = Rails.logger
5
+ end
6
+ end
7
+ end
@@ -7,7 +7,7 @@ module WebpayRails
7
7
  @public_cert = OpenSSL::X509::Certificate.new(args[:public_cert])
8
8
  @environment = args[:environment]
9
9
 
10
- self.class.client(wsdl: wsdl_path)
10
+ self.class.client(wsdl: wsdl_path, log: args[:log], logger: WebpayRails.logger)
11
11
  end
12
12
 
13
13
  def init_transaction(commerce_code, amount, buy_order, session_id, return_url, final_url)
@@ -1,14 +1,24 @@
1
1
  module WebpayRails
2
2
  class Transaction
3
- attr_reader :token, :url
3
+ def self.attr_list
4
+ [:token, :url]
5
+ end
4
6
 
5
- def initialize(args)
6
- @token = args[:token]
7
- @url = args[:url]
7
+ def initialize(document)
8
+ self.class.attr_list.each do |k|
9
+ v = document.at_xpath("//#{k.to_s.tr('_', '')}")
10
+ send("#{k}=", v.text.to_s) unless v.nil?
11
+ end
8
12
  end
9
13
 
10
14
  def success?
11
- !@token.blank?
15
+ !token.blank?
12
16
  end
17
+
18
+ attr_reader *attr_list
19
+
20
+ private
21
+
22
+ attr_writer *attr_list
13
23
  end
14
24
  end
@@ -1,25 +1,35 @@
1
1
  module WebpayRails
2
2
  class TransactionResult
3
- attr_reader :accounting_date, :buy_order, :card_number, :amount, :commerce_code,
4
- :authorization_code, :payment_type_code, :response_code, :transaction_date,
5
- :url_redirection, :vci
6
-
7
- def initialize(args)
8
- @accounting_date = args[:accounting_date]
9
- @buy_order = args[:buy_order]
10
- @card_number = args[:card_number]
11
- @amount = args[:amount]
12
- @commerce_code = args[:commerce_code]
13
- @authorization_code = args[:authorization_code]
14
- @payment_type_code = args[:payment_type_code]
15
- @response_code = args[:response_code]
16
- @transaction_date = args[:transaction_date]
17
- @url_redirection = args[:url_redirection]
18
- @vci = args[:vci]
3
+
4
+ def self.attr_list
5
+ [
6
+ :buy_order, :session_id, :accounting_date, :transaction_date, :vci,
7
+ :url_redirection,
8
+
9
+ # card details
10
+ :card_number, :card_expiration_date,
11
+
12
+ # transaction details
13
+ :authorization_code, :payment_type_code, :response_code,
14
+ :amount, :shares_number, :commerce_code
15
+ ]
16
+ end
17
+
18
+ def initialize(document)
19
+ self.class.attr_list.each do |k|
20
+ v = document.at_xpath("//#{k.to_s.tr('_', '')}")
21
+ send("#{k}=", v.text.to_s) unless v.nil?
22
+ end
19
23
  end
20
24
 
21
25
  def approved?
22
- @response_code.to_i == 0
26
+ response_code.to_i == 0
23
27
  end
28
+
29
+ attr_reader *attr_list
30
+
31
+ private
32
+
33
+ attr_writer *attr_list
24
34
  end
25
35
  end
@@ -1,3 +1,3 @@
1
1
  module WebpayRails
2
- VERSION = "1.0.1".freeze
2
+ VERSION = "1.0.2".freeze
3
3
  end
data/lib/webpay_rails.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rails'
1
2
  require 'active_support/concern'
2
3
 
3
4
  require 'signer'
@@ -13,10 +14,15 @@ require 'webpay_rails/soap'
13
14
  require 'webpay_rails/verifier'
14
15
  require 'webpay_rails/transaction'
15
16
  require 'webpay_rails/transaction_result'
17
+ require 'webpay_rails/railites'
16
18
 
17
19
  module WebpayRails
18
20
  autoload :Base, 'webpay_rails/base'
19
21
 
22
+ class << self
23
+ attr_accessor :logger
24
+ end
25
+
20
26
  def self.extended(base)
21
27
  base.include WebpayRails::Base
22
28
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
+ require 'active_record'
4
5
  require 'webpay_rails'
5
6
 
6
7
  RSpec.configure do |config|
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_record'
3
2
 
4
3
  silence_warnings do
5
4
  ActiveRecord::Migration.verbose = false
@@ -82,7 +81,8 @@ CpEvgcRIv/OeIi6Jbuu3NrPdGPwzYkzlOQnmgio5RGb6GSs+OQ0mUWZ9J1+YtdZc+xTga0x7nsCT
82
81
  2QR2bX/W2H6ktRcLsgBK9mq7lE36p3q6c9DtZJE+xfA4NGCYWM9hd8pbusnoNO7AFxJZOuuvLZI7
83
82
  JvD7YLhPvCYKry7N6x3l
84
83
  -----END CERTIFICATE-----',
85
- environment: :integration
84
+ environment: :integration,
85
+ log: false
86
86
  })
87
87
  end
88
88
 
@@ -90,12 +90,12 @@ describe WebpayRails do
90
90
  let(:amount) { 1000 }
91
91
  let(:buy_order) { rand(1111111..9999999) }
92
92
  let(:session_id) { 'aj2h4kj2' }
93
- let(:result_url) { 'http://localhost:3000/tbknormal?option=result' }
93
+ let(:return_url) { 'http://localhost:3000/tbknormal?option=return' }
94
94
  let(:final_url) { 'http://localhost:3000/tbknormal?option=final' }
95
95
 
96
96
  describe WebpayRails::Transaction do
97
97
  describe "when all is ok" do
98
- let(:transaction) { Order.init_transaction(amount, buy_order, session_id, result_url, final_url) }
98
+ let(:transaction) { Order.init_transaction(amount, buy_order, session_id, return_url, final_url) }
99
99
 
100
100
  it { expect(transaction).to be_kind_of(WebpayRails::Transaction) }
101
101
 
@@ -114,6 +114,7 @@ describe WebpayRails do
114
114
 
115
115
  describe "when not" do
116
116
  it { expect{Order.init_transaction(amount, buy_order, session_id, '', '')}.to raise_error(WebpayRails::FailedInitTransaction) }
117
+ it { expect{Order.init_transaction(0, buy_order, session_id, return_url, final_url)}.to raise_error(WebpayRails::FailedInitTransaction) }
117
118
  end
118
119
  end
119
120
 
data/webpay_rails.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency 'savon', '~> 2'
24
24
  s.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.7.2'
25
25
  s.add_dependency 'activesupport', '>= 3.2'
26
+ s.add_dependency 'railties', '>= 4.1.0', '< 5.1'
26
27
 
27
28
  s.add_development_dependency 'rspec', '~> 3.4'
28
29
  s.add_development_dependency 'activerecord', '>= 3.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpay_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastián Orellana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-26 00:00:00.000000000 Z
11
+ date: 2016-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: signer
@@ -72,6 +72,26 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '3.2'
75
+ - !ruby/object:Gem::Dependency
76
+ name: railties
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 4.1.0
82
+ - - "<"
83
+ - !ruby/object:Gem::Version
84
+ version: '5.1'
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 4.1.0
92
+ - - "<"
93
+ - !ruby/object:Gem::Version
94
+ version: '5.1'
75
95
  - !ruby/object:Gem::Dependency
76
96
  name: rspec
77
97
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +167,7 @@ files:
147
167
  - lib/webpay_rails.rb
148
168
  - lib/webpay_rails/base.rb
149
169
  - lib/webpay_rails/errors.rb
170
+ - lib/webpay_rails/railites.rb
150
171
  - lib/webpay_rails/soap.rb
151
172
  - lib/webpay_rails/transaction.rb
152
173
  - lib/webpay_rails/transaction_result.rb