webpay_rails 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -2
- data/.travis.yml +4 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +2 -0
- data/README.md +32 -7
- data/config.ru +7 -0
- data/lib/webpay_rails.rb +5 -0
- data/lib/webpay_rails/base.rb +107 -32
- data/lib/webpay_rails/errors.rb +46 -8
- data/lib/webpay_rails/soap.rb +28 -51
- data/lib/webpay_rails/soap_normal.rb +52 -0
- data/lib/webpay_rails/soap_nullify.rb +32 -0
- data/lib/webpay_rails/transaction.rb +4 -11
- data/lib/webpay_rails/transaction_base.rb +11 -0
- data/lib/webpay_rails/transaction_nullified.rb +18 -0
- data/lib/webpay_rails/transaction_result.rb +5 -13
- data/lib/webpay_rails/vault.rb +36 -0
- data/lib/webpay_rails/version.rb +1 -1
- data/spec/internal/app/controllers/orders_controller.rb +107 -0
- data/spec/internal/app/models/concerns/universally_unique_identifiable.rb +15 -0
- data/spec/internal/app/models/order.rb +17 -0
- data/spec/internal/app/models/order_blank.rb +4 -0
- data/spec/internal/app/models/order_invalid.rb +14 -0
- data/spec/internal/app/views/orders/failed.html.erb +1 -0
- data/spec/internal/app/views/orders/gateway.html.erb +8 -0
- data/spec/internal/app/views/orders/new.html.erb +6 -0
- data/spec/internal/app/views/orders/success.html.erb +18 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/routes.rb +10 -0
- data/spec/internal/db/schema.rb +22 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/internal/vendor/vault/597020000541.crt +22 -0
- data/spec/internal/vendor/vault/597020000541.key +27 -0
- data/spec/internal/vendor/vault/tbk.pem +17 -0
- data/spec/spec_helper.rb +31 -4
- data/spec/vault_helper.rb +67 -0
- data/spec/webpay_rails_spec.rb +296 -185
- data/webpay_rails.gemspec +18 -12
- metadata +162 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45f7d47cef070f34e7a49e4d82f56be925a24100
|
4
|
+
data.tar.gz: cd1194ac36020b9cad4a31c61335d7aac0552e14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aa2cc1b4cda7282b2c7a20e1fb2a6903eb7df616c60a43d3f86709fd7ad0e224619ce2104d78728b8f3c6dbd11e17ba997d1b1cd70f930f0e9f430cc7aa1d9d
|
7
|
+
data.tar.gz: b75e3b18b128b5ac3b4a7c38c5144068340f30661653ce1e96a13144a232a2a5ca9bdf472507424eaff2b8d75556f2e89863336320d4cb20f6880481b7d87341
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
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
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/limcross/webpay_rails)
|
4
4
|
[](https://codeclimate.com/github/limcross/webpay_rails)
|
5
|
+
[](https://coveralls.io/github/limcross/webpay_rails?branch=master)
|
6
|
+
[](https://gemnasium.com/github.com/limcross/webpay_rails)
|
5
7
|
[](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
|
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:
|
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
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
|
data/lib/webpay_rails/base.rb
CHANGED
@@ -3,50 +3,125 @@ module WebpayRails
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
-
|
7
|
-
|
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.
|
10
|
-
self.
|
11
|
-
self.
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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(
|
67
|
+
WebpayRails::Transaction.new(response)
|
26
68
|
end
|
27
69
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
85
|
+
acknowledge_transaction(args) if args[:ack] != false
|
36
86
|
|
37
|
-
|
87
|
+
WebpayRails::TransactionResult.new(response)
|
88
|
+
end
|
38
89
|
|
39
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
124
|
+
WebpayRails::TransactionNullified.new(response)
|
50
125
|
end
|
51
126
|
end
|
52
127
|
end
|
data/lib/webpay_rails/errors.rb
CHANGED
@@ -1,10 +1,48 @@
|
|
1
1
|
module WebpayRails
|
2
|
-
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
class
|
7
|
-
|
8
|
-
class InvalidEnvironment <
|
9
|
-
|
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
|
data/lib/webpay_rails/soap.rb
CHANGED
@@ -3,56 +3,32 @@ module WebpayRails
|
|
3
3
|
extend Savon::Model
|
4
4
|
|
5
5
|
def initialize(args)
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
6
|
+
@vault = args[:vault]
|
7
|
+
@environment = args[:environment] || :integration
|
8
|
+
@commerce_code = args[:commerce_code]
|
9
9
|
|
10
|
-
|
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
|
-
|
38
|
-
|
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
|
-
|
16
|
+
self.class.client(wsdl: wsdl_path, log: args[:log] || true,
|
17
|
+
logger: WebpayRails.logger)
|
46
18
|
end
|
47
19
|
|
48
|
-
|
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
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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::
|
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
|