webpay_rails 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -2
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.md +14 -0
  5. data/Gemfile +2 -0
  6. data/README.md +32 -7
  7. data/config.ru +7 -0
  8. data/lib/webpay_rails.rb +5 -0
  9. data/lib/webpay_rails/base.rb +107 -32
  10. data/lib/webpay_rails/errors.rb +46 -8
  11. data/lib/webpay_rails/soap.rb +28 -51
  12. data/lib/webpay_rails/soap_normal.rb +52 -0
  13. data/lib/webpay_rails/soap_nullify.rb +32 -0
  14. data/lib/webpay_rails/transaction.rb +4 -11
  15. data/lib/webpay_rails/transaction_base.rb +11 -0
  16. data/lib/webpay_rails/transaction_nullified.rb +18 -0
  17. data/lib/webpay_rails/transaction_result.rb +5 -13
  18. data/lib/webpay_rails/vault.rb +36 -0
  19. data/lib/webpay_rails/version.rb +1 -1
  20. data/spec/internal/app/controllers/orders_controller.rb +107 -0
  21. data/spec/internal/app/models/concerns/universally_unique_identifiable.rb +15 -0
  22. data/spec/internal/app/models/order.rb +17 -0
  23. data/spec/internal/app/models/order_blank.rb +4 -0
  24. data/spec/internal/app/models/order_invalid.rb +14 -0
  25. data/spec/internal/app/views/orders/failed.html.erb +1 -0
  26. data/spec/internal/app/views/orders/gateway.html.erb +8 -0
  27. data/spec/internal/app/views/orders/new.html.erb +6 -0
  28. data/spec/internal/app/views/orders/success.html.erb +18 -0
  29. data/spec/internal/config/database.yml +3 -0
  30. data/spec/internal/config/routes.rb +10 -0
  31. data/spec/internal/db/schema.rb +22 -0
  32. data/spec/internal/public/favicon.ico +0 -0
  33. data/spec/internal/vendor/vault/597020000541.crt +22 -0
  34. data/spec/internal/vendor/vault/597020000541.key +27 -0
  35. data/spec/internal/vendor/vault/tbk.pem +17 -0
  36. data/spec/spec_helper.rb +31 -4
  37. data/spec/vault_helper.rb +67 -0
  38. data/spec/webpay_rails_spec.rb +296 -185
  39. data/webpay_rails.gemspec +18 -12
  40. metadata +162 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66d74da610bd48aff215127601149dfb400f2c04
4
- data.tar.gz: dbb3e7a94ebdc13ad70a44e10347813c69a934d7
3
+ metadata.gz: 45f7d47cef070f34e7a49e4d82f56be925a24100
4
+ data.tar.gz: cd1194ac36020b9cad4a31c61335d7aac0552e14
5
5
  SHA512:
6
- metadata.gz: bbb1a70435388af9aaf3c25e51b7fc5c4b76be65138ca9da7cd4dfb2f48d4cbfd01795b988f12bb507113ed682aeaae3f81add4f617085a27156927322ba798f
7
- data.tar.gz: e636f89ac6cd8e7deb37c654cd39c8d7e3012a5f5d3ed5b6b1df9e7585203474ac37b655f3c1aa52314b0ebf4d9cef28e7debc90171c6054b115fbea53cc9efe
6
+ metadata.gz: 3aa2cc1b4cda7282b2c7a20e1fb2a6903eb7df616c60a43d3f86709fd7ad0e224619ce2104d78728b8f3c6dbd11e17ba997d1b1cd70f930f0e9f430cc7aa1d9d
7
+ data.tar.gz: b75e3b18b128b5ac3b4a7c38c5144068340f30661653ce1e96a13144a232a2a5ca9bdf472507424eaff2b8d75556f2e89863336320d4cb20f6880481b7d87341
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
- test/dummy/log/*
2
- test/dummy/tmp/*
1
+ spec/internal/log/*
2
+ spec/internal/tmp/*
3
+ spec/internal/db/*.sqlite3
4
+ spec/internal/db/log/*.log
3
5
  *~
4
6
  coverage/*
5
7
  *.sqlite3
data/.travis.yml CHANGED
@@ -4,5 +4,9 @@ cache: bundler
4
4
  rvm:
5
5
  - 2.2.2
6
6
  - 2.3.0
7
+ env:
8
+ - CAPYBARA_DRIVER=poltergeist
9
+ after_success:
10
+ - coveralls
7
11
  notifications:
8
12
  email: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  ### Unreleased
2
2
 
3
+ ### 1.1.0 - 2016-11-03
4
+
5
+ #### bug fixes
6
+ * fix response verification
7
+
8
+ #### enhancements
9
+ * add support for nullify method
10
+ * raise detailed execptions when rescued from Savon::SOAPFault
11
+ * group certificates and private keys on Vault
12
+ * improve execptions when missing certificates, private_keys or commerce_code, and when set an invalid environment
13
+ * add support for certificates and private key as a files
14
+ * replace specific exceptions by generic exceptions with more detailed explanations
15
+ * add an option for disable the auto acknowledgement on transaction_result method
16
+
3
17
  ### 1.0.3 - 2016-09-15
4
18
 
5
19
  #### bug fixes
data/Gemfile CHANGED
@@ -12,3 +12,5 @@ gemspec
12
12
 
13
13
  # To use a debugger
14
14
  # gem 'byebug', group: [:development, :test]
15
+
16
+ gem 'phantomjs', group: :development, require: 'phantomjs/poltergeist'
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/limcross/webpay_rails.svg?branch=master)](https://travis-ci.org/limcross/webpay_rails)
4
4
  [![Code Climate](https://codeclimate.com/github/limcross/webpay_rails/badges/gpa.svg)](https://codeclimate.com/github/limcross/webpay_rails)
5
+ [![Coverage Status](https://coveralls.io/repos/github/limcross/webpay_rails/badge.svg?branch=master)](https://coveralls.io/github/limcross/webpay_rails?branch=master)
6
+ [![Dependency Status](https://gemnasium.com/badges/github.com/limcross/webpay_rails.svg)](https://gemnasium.com/github.com/limcross/webpay_rails)
5
7
  [![Gem Version](https://badge.fury.io/rb/webpay_rails.svg)](https://badge.fury.io/rb/webpay_rails)
6
8
 
7
9
  WebpayRails is an easy solution for integrate Transbank Webpay in Rails applications.
@@ -9,6 +11,9 @@ WebpayRails is an easy solution for integrate Transbank Webpay in Rails applicat
9
11
  _This gem (including certificates used in tests) was originally based on the SDK for Ruby (distributed under the **open source license**) available in www.transbankdevelopers.cl_
10
12
 
11
13
  ## Getting started
14
+
15
+ __This README is only valid for the *master* branch, click [here](https://github.com/limcross/webpay_rails/blob/v1.1.0/README.md) for see the latest released version.__
16
+
12
17
  You can add it to your `Gemfile`:
13
18
 
14
19
  ```ruby
@@ -20,12 +25,11 @@ Run the bundle command to install it.
20
25
  ### Configuring models
21
26
  After that, extend the model to `WebpayRails` and add `webpay_rails` to this, like below.
22
27
 
23
-
24
28
  ```ruby
25
29
  class Order < ActiveRecord::Base
26
30
  extend WebpayRails
27
31
 
28
- webpay_rails({
32
+ webpay_rails(
29
33
  commerce_code: 123456789,
30
34
  private_key: '-----BEGIN RSA PRIVATE KEY-----
31
35
  ...
@@ -38,10 +42,16 @@ class Order < ActiveRecord::Base
38
42
  -----END CERTIFICATE-----',
39
43
  environment: :integration,
40
44
  log: Rails.env.development?
41
- })
45
+ )
42
46
  end
43
47
  ```
44
48
 
49
+ As you can see for `private_key`, `public_cert`, and `webpay_cert`, the content of the files is entered, without prejudice to the above you can also indicate the absolute path to these files.
50
+
51
+ The default `environment` is `:integration`, and the valid environments are `:integration`, `:certification` and `:production`. Depending on the environment is assigned the wsdl path.
52
+
53
+ The `log` is very useful when generating the evidence of integration, and is enabled by default.
54
+
45
55
  Obviously all these values should not be defined directly in the model. It is strongly recommended to use environment variables for this ([dotenv](https://github.com/bkeepers/dotenv)).
46
56
 
47
57
  ### Using WebpayRails
@@ -51,16 +61,16 @@ Obviously all these values should not be defined directly in the model. It is st
51
61
  First we need to initialize an transaction, like below:
52
62
 
53
63
  ```ruby
54
- @transaction = Order.init_transaction(amount, buy_order, session_id, return_url, final_url)
64
+ @transaction = Order.init_transaction(amount: amount, buy_order: buy_order, session_id: session_id, return_url: return_url, final_url: final_url)
55
65
  ```
56
66
 
57
- Where `amount` is an __integer__ that define the amount of the transaction (_obviously_), `buy_order` is an __intenger__ that define the order number of the buy, `session_id` is an __string__ that define a local variable that will be returned as part of the result of the transaction, `return_url` and `final_url` are a __string__ for the redirections.
67
+ Where `amount` is an __integer__ that define the amount of the transaction (_obviously_), `buy_order` is an __string__ that define the order number of the buy, `session_id` is an __string__ that define a local variable that will be returned as part of the result of the transaction, `return_url` and `final_url` are a __string__ for the redirections.
58
68
 
59
69
  This method return a `Transaction` object, that contain a redirection `url` and `token` for redirect the customer through POST method, like below.
60
70
 
61
71
  ```erb
62
72
  <% if @transaction.success? %>
63
- <%= form_tag(@transaction.url, method: "post") do %>
73
+ <%= form_tag(@transaction.url, method: :post) do %>
64
74
  <%= hidden_field_tag(:token_ws, @transaction.token) %>
65
75
  <%= submit_tag("Pagar con Webpay") %>
66
76
  <% end %>
@@ -74,7 +84,7 @@ Once Webpay displays the form of payment and authorization of the bank, the cust
74
84
  When Webpay send a __POST__ to `return_url` with `token_ws`, we need to ask for the transaction result, like below.
75
85
 
76
86
  ```ruby
77
- @result = Order.transaction_result(params[:token_ws])
87
+ @result = Order.transaction_result(token: params[:token_ws])
78
88
  ```
79
89
 
80
90
  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`.
@@ -87,6 +97,21 @@ Now we need to send back the customer to `url_redirection` with `token_ws` throu
87
97
 
88
98
  When Webpay send customer to `final_url`, we are done. Finally the transaction has ended. :clap:
89
99
 
100
+ #### Nullify a transaction
101
+
102
+ To cancel a transaction we must use the method described below.
103
+
104
+ ```ruby
105
+ @transaction = Order.nullify(authorization_code: authorization_code, authorized_amount: authorized_amount, buy_order: buy_order, nullify_amount: nullify_amount)
106
+ ```
107
+
108
+ Where `authorization_code`, `authorized_amount`, `buy_order`, are known and corresponds to the transaction to be canceled, and `nullify_amount` it corresponds to the amount to be canceled.
109
+
110
+ This method return a `TransactionNullified` object, that contain an `token`, `authorization_code`, `authorization_date`, `balance` and
111
+ `nullified_amount`.
112
+
113
+ Note that you can only make a single cancellation, whether total or partial.
114
+
90
115
  ## Contributing
91
116
  Any contribution is welcome. Personally I prefer to use English to do documentation and describe commits, however there is no problem if you make your comments and issues in Spanish.
92
117
 
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize! :active_record, :action_controller, :action_view
7
+ run Combustion::Application
data/lib/webpay_rails.rb CHANGED
@@ -10,10 +10,15 @@ require 'openssl'
10
10
 
11
11
  require 'webpay_rails/version'
12
12
  require 'webpay_rails/errors'
13
+ require 'webpay_rails/vault'
13
14
  require 'webpay_rails/soap'
15
+ require 'webpay_rails/soap_normal'
16
+ require 'webpay_rails/soap_nullify'
14
17
  require 'webpay_rails/verifier'
18
+ require 'webpay_rails/transaction_base'
15
19
  require 'webpay_rails/transaction'
16
20
  require 'webpay_rails/transaction_result'
21
+ require 'webpay_rails/transaction_nullified'
17
22
  require 'webpay_rails/railites'
18
23
 
19
24
  module WebpayRails
@@ -3,50 +3,125 @@ module WebpayRails
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- def webpay_rails(options)
7
- class_attribute :commerce_code, :webpay_cert, :environment, :soap, instance_accessor: false
6
+ # Setup a model for use Webpay Rails.
7
+ #
8
+ # ==== Variations of #webpay_rails
9
+ #
10
+ # # setup with certificates and private_key content
11
+ # webpay_rails(
12
+ # commerce_code: 123456789,
13
+ # private_key: '-----BEGIN RSA PRIVATE KEY-----
14
+ # ...
15
+ # -----END RSA PRIVATE KEY-----',
16
+ # public_cert: '-----BEGIN CERTIFICATE-----
17
+ # ...
18
+ # -----END CERTIFICATE-----',
19
+ # webpay_cert: '-----BEGIN CERTIFICATE-----
20
+ # ...
21
+ # -----END CERTIFICATE-----',
22
+ # environment: :integration,
23
+ # log: Rails.env.development?
24
+ # )
25
+ #
26
+ # # setup with certificates and private_key files
27
+ # webpay_rails(
28
+ # commerce_code: 123456789,
29
+ # private_key: 'absolute/path/to/private_key.key',
30
+ # public_cert: 'absolute/path/to/public_cert.crt',
31
+ # webpay_cert: 'absolute/path/to/webpay_cert.crt',
32
+ # environment: :integration,
33
+ # log: Rails.env.development?
34
+ # )
35
+ def webpay_rails(args)
36
+ class_attribute :vault, :soap_normal, :soap_nullify,
37
+ instance_accessor: false
8
38
 
9
- self.commerce_code = options[:commerce_code]
10
- self.webpay_cert = OpenSSL::X509::Certificate.new(options[:webpay_cert])
11
- self.environment = options[:environment]
12
-
13
- self.soap = WebpayRails::Soap.new(options)
39
+ self.vault = args[:vault] = WebpayRails::Vault.new(args)
40
+ self.soap_normal = WebpayRails::SoapNormal.new(args)
41
+ self.soap_nullify = WebpayRails::SoapNullify.new(args)
14
42
  end
15
43
 
16
- def init_transaction(amount, buy_order, session_id, return_url, final_url)
17
- begin
18
- response = soap.init_transaction(commerce_code, amount, buy_order, session_id, return_url, final_url)
19
- rescue StandardError
20
- raise WebpayRails::FailedInitTransaction
21
- end
22
-
23
- raise WebpayRails::InvalidCertificate unless WebpayRails::Verifier.verify(response, webpay_cert)
44
+ # Initializes a transaction
45
+ # Returns a WebpayRails::Transaction if successfully initialised.
46
+ # If fault a WebpayRails::RequestFailed exception is raised.
47
+ # If the SOAP response cant be verified a WebpayRails::InvalidCertificate
48
+ # exception is raised.
49
+ #
50
+ # === Arguments
51
+ # [:amount]
52
+ # An integer that define the amount of the transaction.
53
+ # [:buy_order]
54
+ # An string that define the order number of the buy.
55
+ # [:session_id]
56
+ # An string that define a local variable that will be returned as
57
+ # part of the result of the transaction.
58
+ # [:return_url]
59
+ # An string that define the url that Webpay redirect after client is
60
+ # authorized (or not) by the bank for get the result of the transaction.
61
+ # [:final_url]
62
+ # An string that define the url that Webpay redirect after they show
63
+ # the webpay invoice, or cancel the transaction from Webpay.
64
+ def init_transaction(args)
65
+ response = soap_normal.init_transaction(args)
24
66
 
25
- WebpayRails::Transaction.new(Nokogiri::HTML(response.to_s))
67
+ WebpayRails::Transaction.new(response)
26
68
  end
27
69
 
28
- def transaction_result(token)
29
- begin
30
- response = soap.get_transaction_result(token)
31
- rescue StandardError
32
- raise WebpayRails::FailedGetResult
33
- end
70
+ # Retrieves the result of a transaction
71
+ # Returns a WebpayRails::TransactionResult if successfully get a response.
72
+ # If fault a WebpayRails::RequestFailed exception is raised.
73
+ # If the SOAP response cant be verified a WebpayRails::InvalidCertificate
74
+ # exception is raised.
75
+ #
76
+ # === Arguments
77
+ # [:token]
78
+ # An string that responds Webpay when redirect to +return_url+.
79
+ # [:ack]
80
+ # An optional boolean with which you can disable the auto
81
+ # acknowledgement (I guess if you do this, you will know what you do).
82
+ def transaction_result(args)
83
+ response = soap_normal.get_transaction_result(args)
34
84
 
35
- raise WebpayRails::InvalidResultResponse if response.blank?
85
+ acknowledge_transaction(args) if args[:ack] != false
36
86
 
37
- acknowledge_transaction(token)
87
+ WebpayRails::TransactionResult.new(response)
88
+ end
38
89
 
39
- WebpayRails::TransactionResult.new(Nokogiri::HTML(response.to_s))
90
+ # Reports the correct reception of the result of the transaction
91
+ # If fault a WebpayRails::RequestFailed exception is raised.
92
+ # If the SOAP response cant be verified a WebpayRails::InvalidCertificate
93
+ # exception is raised.
94
+ #
95
+ # === Arguments
96
+ # [:token]
97
+ # An string that responds Webpay when redirect to +return_url+.
98
+ #
99
+ # NOTE: It is not necessary to use this method because it is consumed by
100
+ # +transaction_result+.
101
+ def acknowledge_transaction(args)
102
+ soap_normal.acknowledge_transaction(args)
40
103
  end
41
104
 
42
- def acknowledge_transaction(token)
43
- begin
44
- response = soap.acknowledge_transaction(token)
45
- rescue StandardError
46
- raise WebpayRails::FailedAcknowledgeTransaction
47
- end
105
+ # Nullify a transaction
106
+ # Returns a WebpayRails::TransactionNullified if successfully initialised.
107
+ # If fault a WebpayRails::RequestFailed exception is raised.
108
+ # If the SOAP response cant be verified a WebpayRails::InvalidCertificate
109
+ # exception is raised.
110
+ #
111
+ # === Arguments
112
+ # [:authorization_code]
113
+ # An string that original belongs to the transaction.
114
+ # [:authorize_amount]
115
+ # An integer that define the original amount of the transaction.
116
+ # [:buy_order]
117
+ # An string that define the order number of the transaction to be
118
+ # nullified.
119
+ # [:nullify_amount]
120
+ # An intenger that define the amount to be nullified on the transaction.
121
+ def nullify(args)
122
+ response = soap_nullify.nullify(args)
48
123
 
49
- raise WebpayRails::InvalidAcknowledgeResponse if response.blank?
124
+ WebpayRails::TransactionNullified.new(response)
50
125
  end
51
126
  end
52
127
  end
@@ -1,10 +1,48 @@
1
1
  module WebpayRails
2
- class Error < StandardError; end
3
- class FailedInitTransaction < Error; end
4
- class FailedGetResult < Error; end
5
- class InvalidResultResponse < Error; end
6
- class FailedAcknowledgeTransaction < Error; end
7
- class InvalidAcknowledgeResponse < Error; end
8
- class InvalidEnvironment < Error; end
9
- class InvalidCertificate < Error; end
2
+ # Generic WebpayRails exception class.
3
+ class WebpayRailsError < StandardError; end
4
+
5
+ # Raise when the commerce code has not been defined.
6
+ class MissingCommerceCode < WebpayRailsError; end
7
+ # Raise when the environment is not valid.
8
+ class InvalidEnvironment < WebpayRailsError; end
9
+
10
+ # Generic Soap exception class.
11
+ class SoapError < WebpayRailsError
12
+ def initialize(action, error)
13
+ super("Attempted to #{action} but #{error}")
14
+ end
15
+ end
16
+
17
+ # Raise when the SOAP request has failed.
18
+ class RequestFailed < SoapError
19
+ def initialize(action, error)
20
+ super(action, "SOAP responds with a #{error.http.code} " \
21
+ "status code: #{error}")
22
+ end
23
+ end
24
+ # Raise when the SOAP response of a request is blank.
25
+ class InvalidResponse < SoapError
26
+ def initialize(action)
27
+ super(action, 'SOAP response is blank')
28
+ end
29
+ end
30
+ # Raise when the SOAP response cannot be verify with the webpay cert.
31
+ class InvalidCertificate < SoapError
32
+ def initialize(action)
33
+ super(action, 'the response was not signed with the correct certificate')
34
+ end
35
+ end
36
+
37
+ # Generic Vault exception class.
38
+ class VaultError < WebpayRailsError; end
39
+
40
+ # Raise when vault cant load the file.
41
+ class FileNotFound < VaultError; end
42
+ # Raise when private key has not been defined.
43
+ class MissingPrivateKey < VaultError; end
44
+ # Raise when public certificate has not been defined.
45
+ class MissingPublicCertificate < VaultError; end
46
+ # Raise when webpay certificate has not been defined.
47
+ class MissingWebpayCertificate < VaultError; end
10
48
  end
@@ -3,56 +3,32 @@ module WebpayRails
3
3
  extend Savon::Model
4
4
 
5
5
  def initialize(args)
6
- @private_key = OpenSSL::PKey::RSA.new(args[:private_key])
7
- @public_cert = OpenSSL::X509::Certificate.new(args[:public_cert])
8
- @environment = args[:environment]
6
+ @vault = args[:vault]
7
+ @environment = args[:environment] || :integration
8
+ @commerce_code = args[:commerce_code]
9
9
 
10
- self.class.client(wsdl: wsdl_path, log: args[:log], logger: WebpayRails.logger)
11
- end
12
-
13
- def init_transaction(commerce_code, amount, buy_order, session_id, return_url, final_url)
14
- request = client.build_request(:init_transaction, message: {
15
- wsInitTransactionInput: {
16
- wSTransactionType: 'TR_NORMAL_WS',
17
- buyOrder: buy_order,
18
- sessionId: session_id,
19
- returnURL: return_url,
20
- finalURL: final_url,
21
- transactionDetails: {
22
- amount: amount,
23
- commerceCode: commerce_code,
24
- buyOrder: buy_order
25
- }
26
- }
27
- })
28
-
29
- call(request, :init_transaction)
30
- end
31
-
32
- def get_transaction_result(token)
33
- request = client.build_request(:get_transaction_result, message: {
34
- tokenInput: token
35
- })
10
+ raise WebpayRails::MissingCommerceCode unless @commerce_code
36
11
 
37
- call(request, :get_transaction_result)
38
- end
39
-
40
- def acknowledge_transaction(token)
41
- request = client.build_request(:acknowledge_transaction, message: {
42
- tokenInput: token
43
- })
12
+ unless valid_environments.include? @environment
13
+ raise WebpayRails::InvalidEnvironment
14
+ end
44
15
 
45
- call(request, :acknowledge_transaction)
16
+ self.class.client(wsdl: wsdl_path, log: args[:log] || true,
17
+ logger: WebpayRails.logger)
46
18
  end
47
19
 
48
- private
20
+ private
49
21
 
50
22
  def call(request, operation)
51
23
  signed_document = sign_xml(request)
52
24
 
53
- client.call(operation) do
25
+ response = client.call(operation) do
54
26
  xml signed_document.to_xml(save_with: 0)
55
27
  end
28
+
29
+ verify_response(response, operation)
30
+ rescue Savon::SOAPFault => error
31
+ raise WebpayRails::RequestFailed.new(operation, error)
56
32
  end
57
33
 
58
34
  def sign_xml(input_xml)
@@ -63,8 +39,8 @@ module WebpayRails
63
39
 
64
40
  signer = Signer.new(xml)
65
41
 
66
- signer.cert = @public_cert
67
- signer.private_key = @private_key
42
+ signer.cert = @vault.public_cert
43
+ signer.private_key = @vault.private_key
68
44
 
69
45
  signer.document.xpath('//soapenv:Body', { soapenv: 'http://schemas.xmlsoap.org/soap/envelope/' }).each do |node|
70
46
  signer.digest!(node)
@@ -75,7 +51,7 @@ module WebpayRails
75
51
 
76
52
  document = Nokogiri::XML(signed_xml)
77
53
  x509data = document.at_xpath('//*[local-name()=\'X509Data\']')
78
- new_data = x509data.clone()
54
+ new_data = x509data.clone
79
55
  new_data.set_attribute('xmlns:ds', 'http://www.w3.org/2000/09/xmldsig#')
80
56
 
81
57
  n = Nokogiri::XML::Node.new('wsse:SecurityTokenReference', document)
@@ -85,17 +61,18 @@ module WebpayRails
85
61
  document
86
62
  end
87
63
 
88
- def wsdl_path
89
- case @environment
90
- when :production
91
- 'https://webpay3g.transbank.cl/WSWebpayTransaction/cxf/WSWebpayService?wsdl'
92
- when :certification
93
- 'https://webpay3gint.transbank.cl/WSWebpayTransaction/cxf/WSWebpayService?wsdl'
94
- when :integration
95
- 'https://webpay3gint.transbank.cl/WSWebpayTransaction/cxf/WSWebpayService?wsdl'
64
+ def verify_response(response, operation)
65
+ raise(WebpayRails::InvalidResponse, operation) if response.blank?
66
+
67
+ if WebpayRails::Verifier.verify(response, @vault.webpay_cert)
68
+ response
96
69
  else
97
- raise WebpayRails::InvalidEnvironment
70
+ raise WebpayRails::InvalidCertificate, operation
98
71
  end
99
72
  end
73
+
74
+ def valid_environments
75
+ [:production, :certification, :integration]
76
+ end
100
77
  end
101
78
  end