pag_seguro 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pag_seguro/checkout.xml.haml +1 -1
- data/lib/pag_seguro/day_of_year.rb +4 -3
- data/lib/pag_seguro/errors/unauthorized.rb +1 -1
- data/lib/pag_seguro/errors/unknown_error.rb +1 -1
- data/lib/pag_seguro/item.rb +5 -5
- data/lib/pag_seguro/notification.rb +5 -4
- data/lib/pag_seguro/payment.rb +39 -23
- data/lib/pag_seguro/payment_method.rb +12 -12
- data/lib/pag_seguro/pre_approval.rb +7 -4
- data/lib/pag_seguro/query.rb +12 -8
- data/lib/pag_seguro/sender.rb +10 -10
- data/lib/pag_seguro/shipping.rb +12 -11
- data/lib/pag_seguro/transaction.rb +31 -27
- data/lib/pag_seguro/version.rb +1 -1
- data/lib/pagseguro_decimal_validator.rb +4 -2
- data/spec/factories.rb +1 -1
- data/spec/pag_seguro/checkout_xml_spec.rb +9 -9
- data/spec/pag_seguro/convert_field_to_digit_spec.rb +2 -2
- data/spec/pag_seguro/day_of_year_spec.rb +1 -1
- data/spec/pag_seguro/errors/unknown_error_spec.rb +2 -2
- data/spec/pag_seguro/integration/checkout_spec.rb +4 -4
- data/spec/pag_seguro/integration/notification_spec.rb +3 -3
- data/spec/pag_seguro/integration/query_spec.rb +2 -2
- data/spec/pag_seguro/item_spec.rb +6 -4
- data/spec/pag_seguro/payment_method_spec.rb +10 -10
- data/spec/pag_seguro/payment_spec.rb +11 -10
- data/spec/pag_seguro/pre_approval_spec.rb +3 -2
- data/spec/pag_seguro/query_spec.rb +2 -2
- data/spec/pag_seguro/sender_spec.rb +5 -5
- data/spec/pag_seguro/shipping_spec.rb +3 -3
- data/spec/pag_seguro/transaction_spec.rb +2 -2
- data/spec/pag_seguro/version_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bbfb84a631ab24786de12bc5e7a16a107d09790
|
4
|
+
data.tar.gz: a9c38a18d3194f2962e58d9813597c162aac5cc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf1a7901bec996be24ca3b9f85adde8508a7cea7a5e0c05ba143c086a628be9cc110aa7976861a5251dab76107ad5eba3bf8ad6f890307ecc894615fe0b31e50
|
7
|
+
data.tar.gz: 0438005dd35769dc354816e7be964d892e68b4e2c60d444ca2bfeea5a8c2c8b9f3088b7344cbfebbc16ecfed5dd707f696052edc9fbaaaa6b12b823d3bc27d8c
|
@@ -21,15 +21,16 @@ module PagSeguro
|
|
21
21
|
"#{"%02d" % @month}-#{"%02d" % @day}"
|
22
22
|
end
|
23
23
|
|
24
|
+
# very simple date validation, just to smoke test possible
|
25
|
+
# errors of switching day with month
|
24
26
|
def valid?
|
25
|
-
# very simple date validation, just to smoke test possible errors of switching day with month
|
26
27
|
@day < 31 && @month < 12
|
27
28
|
end
|
28
29
|
|
29
30
|
def <=>(other_day_of_the_year)
|
30
|
-
return
|
31
|
+
return 1 if @month > other_day_of_the_year.month
|
31
32
|
return -1 if @month < other_day_of_the_year.month
|
32
33
|
@day <=> other_day_of_the_year.day
|
33
34
|
end
|
34
35
|
end
|
35
|
-
end
|
36
|
+
end
|
data/lib/pag_seguro/item.rb
CHANGED
@@ -2,17 +2,17 @@ module PagSeguro
|
|
2
2
|
class Item
|
3
3
|
include ActiveModel::Validations
|
4
4
|
extend PagSeguro::ConvertFieldToDigit
|
5
|
-
|
5
|
+
|
6
6
|
attr_accessor :id, :description, :amount, :quantity, :shipping_cost, :weight
|
7
7
|
attr_reader_as_digit :amount, :shipping_cost
|
8
|
-
|
8
|
+
|
9
9
|
validates :id, presence: true
|
10
10
|
validates :description, presence: true
|
11
11
|
validates :amount, pagseguro_decimal: true, presence: true
|
12
12
|
validates :shipping_cost, pagseguro_decimal: true
|
13
13
|
validates :weight, numericality: { only_integer: true, greater_than: 0, allow_blank: true }
|
14
14
|
validates :quantity, presence: true, numericality: { only_integer: true, greater_than: 0, less_than: 1000 }
|
15
|
-
|
15
|
+
|
16
16
|
def initialize(attributes = {})
|
17
17
|
@id = attributes[:id]
|
18
18
|
@description = attributes[:description]
|
@@ -21,9 +21,9 @@ module PagSeguro
|
|
21
21
|
@shipping_cost = attributes[:shipping_cost]
|
22
22
|
@weight = attributes[:weight]
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def description
|
26
26
|
@description.present? && @description.size > 100 ? @description[0..99] : @description
|
27
27
|
end
|
28
28
|
end
|
29
|
-
end
|
29
|
+
end
|
@@ -1,16 +1,17 @@
|
|
1
1
|
module PagSeguro
|
2
2
|
class Notification < Transaction
|
3
|
-
|
4
|
-
def initialize(email
|
3
|
+
|
4
|
+
def initialize(email, token, notification_code)
|
5
5
|
raise "Needs a notification code" if notification_code.blank?
|
6
6
|
raise "Needs an email" if email.blank?
|
7
7
|
raise "Needs a token" if token.blank?
|
8
8
|
@data = transaction_data(email, token, notification_code)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
private
|
12
12
|
def transaction_data(email, token, notification_code)
|
13
|
-
|
13
|
+
notification_url = "#{PAGSEGURO_TRANSACTIONS_URL}/notifications/#{notification_code}"
|
14
|
+
super RestClient.get notification_url, params: {email: email, token: token}
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/lib/pag_seguro/payment.rb
CHANGED
@@ -3,15 +3,17 @@ module PagSeguro
|
|
3
3
|
include ActiveModel::Validations
|
4
4
|
extend PagSeguro::ConvertFieldToDigit
|
5
5
|
|
6
|
-
attr_accessor :id, :email, :token, :items, :sender, :shipping,
|
7
|
-
|
6
|
+
attr_accessor :id, :email, :token, :items, :sender, :shipping,
|
7
|
+
:extra_amount, :redirect_url, :max_uses, :max_age,
|
8
|
+
:response, :pre_approval
|
9
|
+
|
8
10
|
attr_reader_as_digit :extra_amount
|
9
|
-
|
11
|
+
|
10
12
|
validates_presence_of :email, :token
|
11
13
|
validates :extra_amount, pagseguro_decimal: true
|
12
14
|
validates_format_of :redirect_url, with: URI::regexp(%w(http https)), message: " must give a correct url for redirection", allow_blank: true
|
13
15
|
validate :max_uses_number, :max_age_number, :valid_pre_approval, :valid_items
|
14
|
-
|
16
|
+
|
15
17
|
def initialize(email = nil, token = nil, options = {})
|
16
18
|
@email = email unless email.nil?
|
17
19
|
@token = token unless token.nil?
|
@@ -25,60 +27,74 @@ module PagSeguro
|
|
25
27
|
@max_age = options[:max_age]
|
26
28
|
@pre_approval = options[:pre_approval]
|
27
29
|
end
|
28
|
-
|
30
|
+
|
29
31
|
def self.checkout_payment_url(code)
|
30
32
|
"https://pagseguro.uol.com.br/v2/checkout/payment.html?code=#{code}"
|
31
33
|
end
|
32
|
-
|
34
|
+
|
33
35
|
def checkout_xml
|
34
36
|
xml_content = File.open( File.dirname(__FILE__) + "/checkout.xml.haml" ).read
|
35
37
|
haml_engine = Haml::Engine.new(xml_content)
|
36
|
-
|
38
|
+
|
39
|
+
haml_engine.render Object.new,
|
40
|
+
items: @items,
|
41
|
+
payment: self,
|
42
|
+
sender: @sender,
|
43
|
+
shipping: @shipping,
|
44
|
+
pre_approval: @pre_approval
|
37
45
|
end
|
38
|
-
|
46
|
+
|
39
47
|
def checkout_url_with_params
|
40
48
|
"https://ws.pagseguro.uol.com.br/v2/checkout?email=#{@email}&token=#{@token}"
|
41
49
|
end
|
42
|
-
|
50
|
+
|
43
51
|
def checkout_payment_url
|
44
52
|
self.class.checkout_payment_url(code)
|
45
53
|
end
|
46
|
-
|
54
|
+
|
47
55
|
def code
|
48
56
|
response || parse_checkout_response
|
49
57
|
parse_code
|
50
58
|
end
|
51
|
-
|
59
|
+
|
52
60
|
def date
|
53
61
|
response || parse_checkout_response
|
54
62
|
parse_date
|
55
63
|
end
|
56
|
-
|
64
|
+
|
57
65
|
def reset!
|
58
66
|
@response = nil
|
59
67
|
end
|
60
|
-
|
68
|
+
|
61
69
|
protected
|
62
70
|
def max_uses_number
|
63
|
-
|
71
|
+
if @max_uses.present? && @max_uses.to_i <= 0
|
72
|
+
errors.add(:max_uses, " must be an integer greater than 0")
|
73
|
+
end
|
64
74
|
end
|
65
|
-
|
75
|
+
|
66
76
|
def max_age_number
|
67
|
-
|
77
|
+
if @max_age.present? && @max_age.to_i < 30
|
78
|
+
errors.add(:max_age, " must be an integer grater or equal to 30")
|
79
|
+
end
|
68
80
|
end
|
69
81
|
|
70
82
|
def valid_pre_approval
|
71
|
-
|
83
|
+
if pre_approval && !pre_approval.valid?
|
84
|
+
errors.add(:pre_approval, " must be valid")
|
85
|
+
end
|
72
86
|
end
|
73
87
|
|
74
88
|
def valid_items
|
75
|
-
|
89
|
+
if items.blank? || !items.all?(&:valid?)
|
90
|
+
errors.add(:items, " must be all valid")
|
91
|
+
end
|
76
92
|
end
|
77
|
-
|
93
|
+
|
78
94
|
def send_checkout
|
79
95
|
RestClient.post(checkout_url_with_params, checkout_xml, content_type: "application/xml"){|resp, request, result| resp }
|
80
96
|
end
|
81
|
-
|
97
|
+
|
82
98
|
def parse_checkout_response
|
83
99
|
res = send_checkout
|
84
100
|
raise Errors::Unauthorized if res.code == 401
|
@@ -86,11 +102,11 @@ module PagSeguro
|
|
86
102
|
raise Errors::UnknownError.new(res) if res.code != 200
|
87
103
|
@response = res.body
|
88
104
|
end
|
89
|
-
|
105
|
+
|
90
106
|
def parse_date
|
91
|
-
DateTime.iso8601(
|
107
|
+
DateTime.iso8601(Nokogiri::XML(response.body).css("checkout date").first.content)
|
92
108
|
end
|
93
|
-
|
109
|
+
|
94
110
|
def parse_code
|
95
111
|
Nokogiri::XML(response.body).css("checkout code").first.content
|
96
112
|
end
|
@@ -2,47 +2,47 @@
|
|
2
2
|
module PagSeguro
|
3
3
|
class PaymentMethod
|
4
4
|
attr_accessor :code, :type
|
5
|
-
|
5
|
+
|
6
6
|
# Payment Method types
|
7
7
|
CREDIT_CARD = 1
|
8
8
|
BANK_BILL = 2
|
9
9
|
ONLINE_DEBIT = 3
|
10
10
|
PAG_SEGURO_BALANCE = 4
|
11
11
|
OI_PAGGO = 5
|
12
|
-
|
12
|
+
|
13
13
|
def initialize(options = {})
|
14
14
|
@code = options[:code]
|
15
15
|
@type = options[:type]
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def code
|
19
19
|
@code.to_i
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def type
|
23
23
|
@type.to_i
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def credit_card?
|
27
27
|
CREDIT_CARD == type
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def bank_bill?
|
31
31
|
BANK_BILL == type
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def online_debit?
|
35
35
|
ONLINE_DEBIT == type
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def pag_seguro_balance?
|
39
39
|
PAG_SEGURO_BALANCE == type
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def oi_paggo?
|
43
43
|
OI_PAGGO == type
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def name
|
47
47
|
case code
|
48
48
|
when 101 then "Cartão de crédito Visa"
|
@@ -61,7 +61,7 @@ module PagSeguro
|
|
61
61
|
when 303 then "Débito online Unibanco"
|
62
62
|
when 304 then "Débito online Banco do Brasil"
|
63
63
|
when 305 then "Débito online Banco Real"
|
64
|
-
when 306 then "Débito online Banrisul"
|
64
|
+
when 306 then "Débito online Banrisul"
|
65
65
|
when 307 then "Débito online HSBC"
|
66
66
|
when 401 then "Saldo PagSeguro"
|
67
67
|
when 501 then "Oi Paggo"
|
@@ -69,4 +69,4 @@ module PagSeguro
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
-
end
|
72
|
+
end
|
@@ -7,8 +7,11 @@ module PagSeguro
|
|
7
7
|
DAYS_OF_WEEK = %w(monday tuesday wednesday thursday friday saturday sunday)
|
8
8
|
DATE_RANGE = 17856.hours
|
9
9
|
|
10
|
-
attr_accessor :name, :details, :amount_per_payment, :period,
|
11
|
-
|
10
|
+
attr_accessor :name, :details, :amount_per_payment, :period,
|
11
|
+
:day_of_week, :day_of_month, :day_of_year, :initial_date,
|
12
|
+
:final_date, :max_amount_per_period, :max_total_amount,
|
13
|
+
:review_URL
|
14
|
+
|
12
15
|
attr_reader_as_digit :amount_per_payment, :max_amount_per_period, :max_total_amount
|
13
16
|
|
14
17
|
validates_presence_of :name, :period, :final_date, :max_total_amount, :max_amount_per_period
|
@@ -16,7 +19,7 @@ module PagSeguro
|
|
16
19
|
validates_inclusion_of :day_of_week, in: DAYS_OF_WEEK, if: :weekly?
|
17
20
|
validates_inclusion_of :day_of_month, in: (1..28), if: :monthly?
|
18
21
|
validates_presence_of :day_of_year, if: :yearly?
|
19
|
-
validates_format_of :day_of_year, with:
|
22
|
+
validates_format_of :day_of_year, with: /\A\d{2}-\d{2}\z/, if: :yearly?
|
20
23
|
validate :initial_date_range, :final_date_range
|
21
24
|
validates :max_amount_per_period, pagseguro_decimal: true
|
22
25
|
validates :max_total_amount, pagseguro_decimal: true
|
@@ -81,4 +84,4 @@ module PagSeguro
|
|
81
84
|
errors.add(:final_date) if final_date > (initial_date || Time.now) + DATE_RANGE
|
82
85
|
end
|
83
86
|
end
|
84
|
-
end
|
87
|
+
end
|
data/lib/pag_seguro/query.rb
CHANGED
@@ -1,25 +1,28 @@
|
|
1
1
|
module PagSeguro
|
2
2
|
class Query < Transaction
|
3
|
-
|
4
|
-
def initialize(email
|
3
|
+
|
4
|
+
def initialize(email, token, transaction_code)
|
5
5
|
raise "Needs a transaction code" if transaction_code.blank?
|
6
6
|
raise "Needs an email" if email.blank?
|
7
7
|
raise "Needs a token" if token.blank?
|
8
8
|
@data = transaction_data(email, token, transaction_code)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def self.find(email, token, options={})
|
12
12
|
url = Transaction::PAGSEGURO_TRANSACTIONS_URL
|
13
13
|
url += "/abandoned" if options[:abandoned]
|
14
|
+
|
14
15
|
transactions_data = Nokogiri::XML(RestClient.get url, params: search_params(email, token, options))
|
15
|
-
transactions_data.css("transaction").map
|
16
|
+
transactions_data.css("transaction").map do |transaction_xml|
|
17
|
+
Transaction.new(transaction_xml)
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
21
|
def self.search_params(email, token, options={})
|
19
22
|
params = {email: email, token: token}
|
20
23
|
params[:initialDate], params[:finalDate] = parse_dates(options)
|
21
|
-
params[:page]
|
22
|
-
params[:maxPageResults]
|
24
|
+
params[:page] = options[:page] if options[:page]
|
25
|
+
params[:maxPageResults] = options[:max_page_results] if options[:max_page_results]
|
23
26
|
params
|
24
27
|
end
|
25
28
|
|
@@ -34,10 +37,11 @@ module PagSeguro
|
|
34
37
|
|
35
38
|
return initial_date.to_time.iso8601, final_date.to_time.iso8601
|
36
39
|
end
|
37
|
-
|
40
|
+
|
38
41
|
private
|
39
42
|
def transaction_data(email, token, transaction_code)
|
40
|
-
|
43
|
+
transaction_url = "#{PAGSEGURO_TRANSACTIONS_URL}/#{transaction_code}"
|
44
|
+
super RestClient.get transaction_url, params: {email: email, token: token}
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
data/lib/pag_seguro/sender.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
module PagSeguro
|
2
2
|
class Sender
|
3
3
|
attr_accessor :name, :email, :phone_ddd, :phone_number
|
4
|
-
|
4
|
+
|
5
5
|
def initialize(options = {})
|
6
6
|
@name = options[:name]
|
7
7
|
@email = options[:email]
|
8
8
|
@phone_ddd = options[:phone_ddd]
|
9
9
|
@phone_number = options[:phone_number]
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def email
|
13
13
|
valid_email? ? @email : nil
|
14
14
|
end
|
15
15
|
|
16
16
|
def valid_email?
|
17
|
-
@email =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\
|
17
|
+
@email =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i && @email.size <= 60
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def name
|
21
21
|
return nil unless valid_name?
|
22
22
|
@name.gsub(/ +/, " ")[0..49]
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def valid_name?
|
26
26
|
@name =~ /\S+ +\S+/
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def phone_ddd
|
30
|
-
@phone_ddd if @phone_ddd.to_s =~
|
30
|
+
@phone_ddd if @phone_ddd.to_s =~ /\A\d{2}\z/
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def phone_number
|
34
|
-
@phone_number if @phone_number.to_s
|
34
|
+
@phone_number if @phone_number.to_s =~/\A\d{8,9}\z/
|
35
35
|
end
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
data/lib/pag_seguro/shipping.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
module PagSeguro
|
2
2
|
class Shipping
|
3
3
|
include ActiveModel::Validations
|
4
|
-
|
4
|
+
|
5
5
|
PAC = 1
|
6
6
|
SEDEX = 2
|
7
7
|
UNIDENTIFIED = 3
|
8
|
-
|
8
|
+
|
9
9
|
validates :postal_code, numericality: true, length: {is: 8}
|
10
|
-
|
11
|
-
attr_accessor :type, :state, :city, :postal_code, :district,
|
12
|
-
|
10
|
+
|
11
|
+
attr_accessor :type, :state, :city, :postal_code, :district,
|
12
|
+
:street, :number, :complement, :cost
|
13
|
+
|
13
14
|
def initialize(attributes = {})
|
14
15
|
@type = attributes[:type] || UNIDENTIFIED
|
15
16
|
@state = attributes[:state]
|
@@ -21,25 +22,25 @@ module PagSeguro
|
|
21
22
|
@complement = attributes[:complement]
|
22
23
|
@cost = attributes[:cost]
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
def postal_code
|
26
27
|
@postal_code if @postal_code.present? && @postal_code.to_s.size == 8
|
27
28
|
end
|
28
|
-
|
29
|
+
|
29
30
|
def type
|
30
31
|
@type.to_i
|
31
32
|
end
|
32
|
-
|
33
|
+
|
33
34
|
def pac?
|
34
35
|
PAC == type
|
35
36
|
end
|
36
|
-
|
37
|
+
|
37
38
|
def sedex?
|
38
39
|
SEDEX == type
|
39
40
|
end
|
40
|
-
|
41
|
+
|
41
42
|
def unidentified?
|
42
43
|
UNIDENTIFIED == type
|
43
44
|
end
|
44
45
|
end
|
45
|
-
end
|
46
|
+
end
|
@@ -6,7 +6,7 @@ module PagSeguro
|
|
6
6
|
attr_accessor :data
|
7
7
|
|
8
8
|
PAGSEGURO_TRANSACTIONS_URL = "https://ws.pagseguro.uol.com.br/v2/transactions"
|
9
|
-
|
9
|
+
|
10
10
|
# possible status values
|
11
11
|
PAGSEGURO_PROCESSING = 1
|
12
12
|
PAGSEGURO_IN_ANALYSIS = 2
|
@@ -15,14 +15,14 @@ module PagSeguro
|
|
15
15
|
PAGSEGURO_DISPUTED = 5
|
16
16
|
PAGSEGURO_RETURNED = 6
|
17
17
|
PAGSEGURO_CANCELLED = 7
|
18
|
-
|
18
|
+
|
19
19
|
# possible type values
|
20
20
|
PAGSEGURO_PAYMENT = 1
|
21
21
|
PAGSEGURO_TRANSFER = 2
|
22
22
|
PAGSEGURO_ADDITION_OF_FUNDS = 3
|
23
23
|
PAGSEGURO_CHARGE = 4
|
24
24
|
PAGSEGURO_BONUS = 5
|
25
|
-
|
25
|
+
|
26
26
|
def self.status_for(status_code)
|
27
27
|
case status_code
|
28
28
|
when PAGSEGURO_PROCESSING then :processing
|
@@ -42,7 +42,7 @@ module PagSeguro
|
|
42
42
|
def id
|
43
43
|
@data.css("reference").first.content
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def gross_amount
|
47
47
|
@data.css("grossAmount").first.content
|
48
48
|
end
|
@@ -66,29 +66,33 @@ module PagSeguro
|
|
66
66
|
def installment_count
|
67
67
|
@data.css("installmentCount").first.content.to_i
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def item_count
|
71
71
|
@data.css("itemCount").first.content.to_i
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def transaction_id
|
75
75
|
@data.css("code").first.content
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def date
|
79
79
|
DateTime.iso8601( @data.css("date").first.content )
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def items
|
83
83
|
@data.css("items item").map do |i|
|
84
|
-
Item.new
|
84
|
+
Item.new id: parse_item(i, "id"),
|
85
|
+
description: parse_item(i, "description"),
|
86
|
+
quantity: parse_item(i, "quantity"),
|
87
|
+
amount: parse_item(i, "amount")
|
85
88
|
end
|
86
89
|
end
|
87
|
-
|
90
|
+
|
88
91
|
def payment_method
|
89
|
-
PaymentMethod.new code: parse_css("paymentMethod code"),
|
92
|
+
PaymentMethod.new code: parse_css("paymentMethod code"),
|
93
|
+
type: parse_css("paymentMethod type")
|
90
94
|
end
|
91
|
-
|
95
|
+
|
92
96
|
def sender
|
93
97
|
sn = Sender.new
|
94
98
|
sn.name = parse_css("sender name")
|
@@ -97,7 +101,7 @@ module PagSeguro
|
|
97
101
|
sn.phone_number = parse_css("sender phone number")
|
98
102
|
sn
|
99
103
|
end
|
100
|
-
|
104
|
+
|
101
105
|
def shipping
|
102
106
|
sh = Shipping.new
|
103
107
|
sh.type = parse_css("shipping type")
|
@@ -111,7 +115,7 @@ module PagSeguro
|
|
111
115
|
sh.complement = parse_css("shipping address complement")
|
112
116
|
sh
|
113
117
|
end
|
114
|
-
|
118
|
+
|
115
119
|
def status
|
116
120
|
@data.css("status").first.content.to_i
|
117
121
|
end
|
@@ -123,7 +127,7 @@ module PagSeguro
|
|
123
127
|
def processing?
|
124
128
|
PAGSEGURO_PROCESSING == status
|
125
129
|
end
|
126
|
-
|
130
|
+
|
127
131
|
def in_analysis?
|
128
132
|
PAGSEGURO_IN_ANALYSIS == status
|
129
133
|
end
|
@@ -131,43 +135,43 @@ module PagSeguro
|
|
131
135
|
def approved?
|
132
136
|
PAGSEGURO_APPROVED == status
|
133
137
|
end
|
134
|
-
|
138
|
+
|
135
139
|
def available?
|
136
140
|
PAGSEGURO_AVAILABLE == status
|
137
141
|
end
|
138
|
-
|
142
|
+
|
139
143
|
def disputed?
|
140
144
|
PAGSEGURO_DISPUTED == status
|
141
145
|
end
|
142
|
-
|
146
|
+
|
143
147
|
def returned?
|
144
148
|
PAGSEGURO_RETURNED == status
|
145
149
|
end
|
146
|
-
|
150
|
+
|
147
151
|
def cancelled?
|
148
152
|
PAGSEGURO_CANCELLED == status
|
149
153
|
end
|
150
|
-
|
154
|
+
|
151
155
|
def payment?
|
152
156
|
PAGSEGURO_PAYMENT == type
|
153
157
|
end
|
154
|
-
|
158
|
+
|
155
159
|
def transfer?
|
156
160
|
PAGSEGURO_TRANSFER == type
|
157
161
|
end
|
158
|
-
|
162
|
+
|
159
163
|
def addition_of_funds?
|
160
164
|
PAGSEGURO_ADDITION_OF_FUNDS == type
|
161
165
|
end
|
162
|
-
|
166
|
+
|
163
167
|
def charge?
|
164
168
|
PAGSEGURO_CHARGE == type
|
165
169
|
end
|
166
|
-
|
170
|
+
|
167
171
|
def bonus?
|
168
172
|
PAGSEGURO_BONUS == type
|
169
173
|
end
|
170
|
-
|
174
|
+
|
171
175
|
protected
|
172
176
|
def transaction_data(transaction_xml)
|
173
177
|
transaction_xml.instance_of?(Nokogiri::XML::Element) ? transaction_xml : Nokogiri::XML(transaction_xml)
|
@@ -176,10 +180,10 @@ module PagSeguro
|
|
176
180
|
def parse_item(data, attribute)
|
177
181
|
data.css(attribute).first.content
|
178
182
|
end
|
179
|
-
|
183
|
+
|
180
184
|
def parse_css(selector)
|
181
185
|
value = @data.css(selector).first
|
182
186
|
value.nil? ? nil : value.content
|
183
|
-
end
|
187
|
+
end
|
184
188
|
end
|
185
189
|
end
|
data/lib/pag_seguro/version.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
class PagseguroDecimalValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
|
3
|
+
unless value.nil? || value =~ /\A\d+\.\d{2}\z/
|
4
|
+
object.errors.add(attribute, error_message)
|
5
|
+
end
|
4
6
|
end
|
5
7
|
|
6
8
|
def error_message
|
7
9
|
" must be a decimal and have 2 digits after the dot"
|
8
10
|
end
|
9
|
-
end
|
11
|
+
end
|
data/spec/factories.rb
CHANGED
@@ -18,9 +18,9 @@ describe PagSeguro::Payment do
|
|
18
18
|
it 'should be a valid xml' do
|
19
19
|
expect { Nokogiri::XML(payment.checkout_xml) { |config| config.options = Nokogiri::XML::ParseOptions::STRICT } }.to_not raise_error
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
its(:checkout_xml){ should match(/^<\?xml.+encoding="UTF-8".+\?>$/) }
|
23
|
-
|
23
|
+
|
24
24
|
describe 'settings' do
|
25
25
|
it { xml_content('checkout reference').should be_empty }
|
26
26
|
it { xml_content('checkout extraAmount').should be_empty }
|
@@ -33,22 +33,22 @@ describe PagSeguro::Payment do
|
|
33
33
|
before{ payment.id = 305 }
|
34
34
|
it { xml_content('checkout reference').should == '305' }
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
context 'with extra amount' do
|
38
38
|
before{ payment.extra_amount = '10.50' }
|
39
39
|
it { xml_content('checkout extraAmount').should == '10.50' }
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
context 'with redirect url' do
|
43
43
|
before{ payment.redirect_url = 'http://heavenstudio.com.br' }
|
44
44
|
it { xml_content('checkout redirectURL').should == 'http://heavenstudio.com.br' }
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
context 'with max uses' do
|
48
48
|
before{ payment.max_uses = '10' }
|
49
49
|
it { xml_content('checkout maxUses').should == '10' }
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
context 'with max age' do
|
53
53
|
before{ payment.max_age = '5000' }
|
54
54
|
it { xml_content('checkout maxAge').should == '5000' }
|
@@ -65,12 +65,12 @@ describe PagSeguro::Payment do
|
|
65
65
|
it { xml_collection('checkout items item quantity').should == ['4', '1', '2', '89'] }
|
66
66
|
it { xml_collection('checkout items item shippingCost').should == ['1.00', '12.00'] }
|
67
67
|
it { xml_collection('checkout items item weight').should == ['10', '300', '400'] }
|
68
|
-
|
68
|
+
|
69
69
|
it 'should escape html in item description' do
|
70
70
|
payment.checkout_xml.should include('A Book & Cover')
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
describe 'sender info' do
|
75
75
|
context 'without sender' do
|
76
76
|
it { xml_content('checkout sender name').should be_empty }
|
@@ -88,7 +88,7 @@ describe PagSeguro::Payment do
|
|
88
88
|
it { xml_content('checkout sender phone number').should == '993430994' }
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
describe 'shipping info' do
|
93
93
|
context 'without shipping' do
|
94
94
|
it { xml_content('checkout shipping').should be_empty }
|
@@ -7,7 +7,7 @@ end
|
|
7
7
|
describe PagSeguro::ConvertFieldToDigit do
|
8
8
|
subject{ MyObject.new }
|
9
9
|
|
10
|
-
context "normal object" do
|
10
|
+
context "normal object" do
|
11
11
|
context "with numeric price" do
|
12
12
|
before{ subject.price = 10.02 }
|
13
13
|
its(:price){ should == 10.02 }
|
@@ -65,4 +65,4 @@ describe PagSeguro::ConvertFieldToDigit do
|
|
65
65
|
its(:amount){ should == nil }
|
66
66
|
end
|
67
67
|
end
|
68
|
-
end
|
68
|
+
end
|
@@ -4,7 +4,7 @@ class MockResponse
|
|
4
4
|
def code
|
5
5
|
10000
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def body
|
9
9
|
" error description"
|
10
10
|
end
|
@@ -14,4 +14,4 @@ describe PagSeguro::Errors::UnknownError do
|
|
14
14
|
it "should be able to raise an unknown error" do
|
15
15
|
lambda { raise PagSeguro::Errors::UnknownError.new(MockResponse.new) }.should raise_error(PagSeguro::Errors::UnknownError, "Unknown response code (10000):\n error description")
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
@@ -9,7 +9,7 @@ describe PagSeguro::Payment do
|
|
9
9
|
pending "You need to set your token for your PagSeguro account in spec/pag_seguro/integration/config.yml in order to run this spec"
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
context "with all fields" do
|
14
14
|
let(:payment){ build :payment_with_all_fields, email: EMAIL, token: TOKEN }
|
15
15
|
subject { payment }
|
@@ -37,7 +37,7 @@ describe PagSeguro::Payment do
|
|
37
37
|
context "with items" do
|
38
38
|
let(:payment){ build :payment_with_items, email: EMAIL, token: TOKEN }
|
39
39
|
subject { payment }
|
40
|
-
|
40
|
+
|
41
41
|
its('code.size'){ should == 32 }
|
42
42
|
its(:date){ should be_an_instance_of(DateTime) }
|
43
43
|
|
@@ -52,9 +52,9 @@ describe PagSeguro::Payment do
|
|
52
52
|
expect { payment.code }.to raise_error(PagSeguro::Errors::InvalidData)
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should raise unauthorized error if email and token do not match" do
|
57
57
|
payment = build :payment, email: "not_a_user@not_an_email.com", token: "NOTATOKEN7F048A09A8AEFDD1E5A7B91"
|
58
58
|
expect { payment.code }.to raise_error(PagSeguro::Errors::Unauthorized)
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
@@ -13,7 +13,7 @@ describe PagSeguro::Notification do
|
|
13
13
|
@notification = PagSeguro::Notification.new(EMAIL, TOKEN, NOTIFICATION_CODE)
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it { @notification.transaction_id.should be_present }
|
18
18
|
it { @notification.date.should be_present }
|
19
19
|
it { @notification.id.should be_present }
|
@@ -38,7 +38,7 @@ describe PagSeguro::Notification do
|
|
38
38
|
item.quantity.should be_present
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it { @notification.sender.email.should be_present }
|
43
43
|
it { @notification.shipping.type.should be_present }
|
44
|
-
end
|
44
|
+
end
|
@@ -14,7 +14,7 @@ describe PagSeguro::Query do
|
|
14
14
|
@query = PagSeguro::Query.new(EMAIL, TOKEN, TRANSACTION_ID)
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it { @query.transaction_id.should be_present }
|
19
19
|
it { @query.date.should be_present }
|
20
20
|
it { @query.id.should be_present }
|
@@ -39,7 +39,7 @@ describe PagSeguro::Query do
|
|
39
39
|
item.quantity.should be_present
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it { @query.sender.email.should be_present }
|
44
44
|
it { @query.shipping.type.should be_present }
|
45
45
|
end
|
@@ -15,7 +15,7 @@ describe PagSeguro::Item do
|
|
15
15
|
it { should validate_presence_of :id }
|
16
16
|
it { should validate_presence_of :description }
|
17
17
|
it { should validate_presence_of :amount }
|
18
|
-
|
18
|
+
|
19
19
|
it { should_not allow_value(nil).for(:quantity) }
|
20
20
|
it { should_not allow_value(0).for(:quantity) }
|
21
21
|
it { should_not allow_value(1000).for(:quantity) }
|
@@ -25,13 +25,15 @@ describe PagSeguro::Item do
|
|
25
25
|
it { should_not allow_value("10,50").for(:amount) }
|
26
26
|
it { should_not allow_value("R$ 10.50").for(:amount) }
|
27
27
|
it { should_not allow_value("-10.50").for(:amount) }
|
28
|
+
it { should_not allow_value("10.50\nanything").for(:amount) }
|
28
29
|
it { should allow_value("10.50").for(:amount) }
|
29
30
|
it { should allow_value(10).for(:amount) }
|
30
31
|
it { should allow_value(BigDecimal.new("10.5")).for(:amount) }
|
31
|
-
|
32
|
+
|
32
33
|
it { should_not allow_value("10,50").for(:shipping_cost) }
|
33
34
|
it { should_not allow_value("R$ 10.50").for(:shipping_cost) }
|
34
35
|
it { should_not allow_value("-10.50").for(:shipping_cost) }
|
36
|
+
it { should_not allow_value("10.50\nanything").for(:shipping_cost) }
|
35
37
|
it { should allow_value("10.50").for(:shipping_cost) }
|
36
38
|
it { should allow_value(10).for(:shipping_cost) }
|
37
39
|
it { should allow_value(BigDecimal.new("10.5")).for(:shipping_cost) }
|
@@ -41,7 +43,7 @@ describe PagSeguro::Item do
|
|
41
43
|
it { should_not allow_value("0").for(:quantity) }
|
42
44
|
it { should_not allow_value("-1").for(:quantity) }
|
43
45
|
it { should allow_value("1").for(:quantity) }
|
44
|
-
|
46
|
+
|
45
47
|
it { should_not allow_value("-10").for(:weight) }
|
46
48
|
it { should_not allow_value("10.5").for(:weight) }
|
47
49
|
it { should_not allow_value("10,5").for(:weight) }
|
@@ -50,4 +52,4 @@ describe PagSeguro::Item do
|
|
50
52
|
it "should trim description to 100 characters if it has more than 100 characters" do
|
51
53
|
PagSeguro::Item.new(description: "-" * 101).description.size.should == 100
|
52
54
|
end
|
53
|
-
end
|
55
|
+
end
|
@@ -3,28 +3,28 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe PagSeguro::PaymentMethod do
|
5
5
|
it { should have_attribute_accessor(:code) }
|
6
|
-
it { should have_attribute_accessor(:type) }
|
7
|
-
|
6
|
+
it { should have_attribute_accessor(:type) }
|
7
|
+
|
8
8
|
context "initalized with code and type" do
|
9
9
|
subject { build :payment_method, code: "101", type: "1" }
|
10
10
|
|
11
11
|
its(:code){ should == 101 }
|
12
12
|
its(:type){ should == 1 }
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
describe "types" do
|
16
16
|
let(:payment_method){ PagSeguro::PaymentMethod.new }
|
17
|
-
|
17
|
+
|
18
18
|
context "with type 1" do
|
19
19
|
subject { build :payment_method, type: 1 }
|
20
20
|
it { should be_credit_card }
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
context "with if type 2" do
|
24
24
|
subject { build :payment_method, type: 2 }
|
25
25
|
it { should be_bank_bill }
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
context "with if type 3" do
|
29
29
|
subject { build :payment_method, type: 3 }
|
30
30
|
it { should be_online_debit }
|
@@ -34,18 +34,18 @@ describe PagSeguro::PaymentMethod do
|
|
34
34
|
subject { build :payment_method, type: 4 }
|
35
35
|
it { should be_pag_seguro_balance }
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
context "with type 5" do
|
39
39
|
subject { build :payment_method, type: 5 }
|
40
40
|
it { should be_oi_paggo }
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
describe "codes" do
|
45
45
|
def should_have_meaning_for_code(meaning, code)
|
46
46
|
PagSeguro::PaymentMethod.new(code: code).name.should be == meaning
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
it { should_have_meaning_for_code("Cartão de crédito Visa", 101) }
|
50
50
|
it { should_have_meaning_for_code("Cartão de crédito MasterCard", 102) }
|
51
51
|
it { should_have_meaning_for_code("Cartão de crédito American Express", 103) }
|
@@ -68,4 +68,4 @@ describe PagSeguro::PaymentMethod do
|
|
68
68
|
it { should_have_meaning_for_code("Oi Paggo", 501) }
|
69
69
|
it { should_have_meaning_for_code("Desconhecido", 0) }
|
70
70
|
end
|
71
|
-
end
|
71
|
+
end
|
@@ -48,14 +48,15 @@ describe PagSeguro::Payment do
|
|
48
48
|
|
49
49
|
it { validate_presence_of :email }
|
50
50
|
it { validate_presence_of :token }
|
51
|
-
|
51
|
+
|
52
52
|
it { should_not allow_value('10,50').for(:extra_amount) }
|
53
53
|
it { should_not allow_value('R$ 10.50').for(:extra_amount) }
|
54
54
|
it { should_not allow_value('-10.50').for(:extra_amount) }
|
55
|
+
it { should_not allow_value('10.50\nanything').for(:extra_amount) }
|
55
56
|
it { should allow_value('10.50').for(:extra_amount) }
|
56
57
|
it { should allow_value(10).for(:extra_amount) }
|
57
58
|
it { should allow_value(BigDecimal.new('10.5')).for(:extra_amount) }
|
58
|
-
|
59
|
+
|
59
60
|
it { should_not allow_value('something.com.br').for(:redirect_url)}
|
60
61
|
it { should allow_value('http://something.com.br').for(:redirect_url)}
|
61
62
|
|
@@ -85,17 +86,17 @@ describe PagSeguro::Payment do
|
|
85
86
|
subject { build :payment_with_item }
|
86
87
|
it { should be_valid }
|
87
88
|
end
|
88
|
-
|
89
|
+
|
89
90
|
context 'checking out' do
|
90
91
|
let(:payment){ build(:payment) }
|
91
92
|
it 'should generate a checkout url with an external code' do
|
92
93
|
PagSeguro::Payment.checkout_payment_url('aabbcc').should == 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code=aabbcc'
|
93
94
|
end
|
94
|
-
|
95
|
+
|
95
96
|
it 'should have a checkout_url_with_params' do
|
96
97
|
payment.checkout_url_with_params.should == 'https://ws.pagseguro.uol.com.br/v2/checkout?email=myemail&token=mytoken'
|
97
98
|
end
|
98
|
-
|
99
|
+
|
99
100
|
it 'should generate a checkout url based on the received response' do
|
100
101
|
payment.stub code: 'aabbcc'
|
101
102
|
payment.checkout_payment_url.should == 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code=aabbcc'
|
@@ -109,18 +110,18 @@ describe PagSeguro::Payment do
|
|
109
110
|
PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :body){ 'some body info' }
|
110
111
|
expect { payment.send(:parse_checkout_response) }.to_not raise_error
|
111
112
|
end
|
112
|
-
|
113
|
+
|
113
114
|
it 'should raise PagSeguro::Errors::InvalidData if response code is 400' do
|
114
115
|
PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :code){ 400 }
|
115
116
|
PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :body){ 'some error description' }
|
116
117
|
expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::InvalidData)
|
117
118
|
end
|
118
|
-
|
119
|
+
|
119
120
|
it 'should raise PagSeguro::Errors::Unauthorized if response code is 400' do
|
120
121
|
PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :code){ 401 }
|
121
122
|
expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::Unauthorized)
|
122
123
|
end
|
123
|
-
|
124
|
+
|
124
125
|
it 'should raise PagSeguro::Errors::UnknownError if response code is not 200, 400 or 401' do
|
125
126
|
PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :code){ 300 }
|
126
127
|
PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :body){ 'some response body' }
|
@@ -132,7 +133,7 @@ describe PagSeguro::Payment do
|
|
132
133
|
PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :body){ 'some response body' }
|
133
134
|
expect { payment.send(:parse_checkout_response) }.to change { payment.response }.from(nil).to('some response body')
|
134
135
|
end
|
135
|
-
|
136
|
+
|
136
137
|
it 'should be able to reset response' do
|
137
138
|
payment.response = 'something'
|
138
139
|
expect { payment.reset! }.to change{ payment.response }.from('something').to(nil)
|
@@ -179,4 +180,4 @@ describe PagSeguro::Payment do
|
|
179
180
|
payment.date
|
180
181
|
end
|
181
182
|
end
|
182
|
-
end
|
183
|
+
end
|
@@ -47,7 +47,7 @@ describe PagSeguro::PreApproval do
|
|
47
47
|
it { should_not allow_value( Time.now - 10.minutes + 5.days ).for(:final_date) }
|
48
48
|
it { should allow_value( Time.now + 5.days ).for(:final_date) }
|
49
49
|
it { should allow_value( (PagSeguro::PreApproval::DATE_RANGE - 5.minutes + 5.days).from_now ).for(:final_date) }
|
50
|
-
it { should_not allow_value( PagSeguro::PreApproval::DATE_RANGE.from_now + 5.minutes + 5.days ).for(:final_date) }
|
50
|
+
it { should_not allow_value( PagSeguro::PreApproval::DATE_RANGE.from_now + 5.minutes + 5.days ).for(:final_date) }
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "initialized with minimum attributes" do
|
@@ -101,6 +101,7 @@ describe PagSeguro::PreApproval do
|
|
101
101
|
it { should allow_value('01-01').for(:day_of_year) }
|
102
102
|
it { should allow_value(PagSeguro::DayOfYear.new(month: 1, day: 1)).for(:day_of_year) }
|
103
103
|
it { should_not allow_value('1-1').for(:day_of_year) }
|
104
|
+
it { should_not allow_value("10-22\nanything").for(:day_of_year) }
|
104
105
|
|
105
106
|
its(:period){ should == 'yearly' }
|
106
107
|
its(:day_of_year){ should == '03-01' }
|
@@ -109,4 +110,4 @@ describe PagSeguro::PreApproval do
|
|
109
110
|
it { should be_yearly }
|
110
111
|
end
|
111
112
|
end
|
112
|
-
end
|
113
|
+
end
|
@@ -33,7 +33,7 @@ describe PagSeguro::Query do
|
|
33
33
|
PagSeguro::Query.stub(search_params: params)
|
34
34
|
RestClient.should_receive(:get).with("https://ws.pagseguro.uol.com.br/v2/transactions/abandoned", params: params)
|
35
35
|
PagSeguro::Query.find "email", "token", abandoned: true
|
36
|
-
end
|
36
|
+
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context "with a stubbed response" do
|
@@ -60,7 +60,7 @@ describe PagSeguro::Query do
|
|
60
60
|
it { search_params.keys.should_not include :page }
|
61
61
|
it { search_params[:finalDate].should include Date.today.iso8601 }
|
62
62
|
it { search_params[:initialDate].should include Date.yesterday.iso8601 }
|
63
|
-
|
63
|
+
|
64
64
|
it "should call parse_dates" do
|
65
65
|
PagSeguro::Query.should_receive(:parse_dates)
|
66
66
|
search_params
|
@@ -2,12 +2,12 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe PagSeguro::Sender do
|
5
|
-
context "instance" do
|
5
|
+
context "instance" do
|
6
6
|
it { should have_attribute_accessor(:email) }
|
7
7
|
it { should have_attribute_accessor(:name) }
|
8
8
|
it { should have_attribute_accessor(:phone_ddd) }
|
9
9
|
it { should have_attribute_accessor(:phone_number) }
|
10
|
-
|
10
|
+
|
11
11
|
context "initialized with all attributes" do
|
12
12
|
subject { PagSeguro::Sender.new attributes_for(:sender) }
|
13
13
|
its(:name){ should == "Stefano Diem Benatti" }
|
@@ -15,7 +15,7 @@ describe PagSeguro::Sender do
|
|
15
15
|
its(:phone_ddd){ should == 11 }
|
16
16
|
its(:phone_number){ should == 993430994 }
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
context "with invalid e-mail" do
|
20
20
|
subject { build :sender, email: "nothing" }
|
21
21
|
its(:email){ should be_nil }
|
@@ -50,7 +50,7 @@ describe PagSeguro::Sender do
|
|
50
50
|
it { should be_a_valid_name }
|
51
51
|
its(:name){ should == "a" * 50 }
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
context "with double spaces in name" do
|
55
55
|
subject { build :sender, name: "Stefano Benatti" }
|
56
56
|
it { should be_a_valid_name }
|
@@ -67,4 +67,4 @@ describe PagSeguro::Sender do
|
|
67
67
|
its(:phone_number){ should be_nil }
|
68
68
|
end
|
69
69
|
end
|
70
|
-
end
|
70
|
+
end
|
@@ -18,14 +18,14 @@ describe PagSeguro::Shipping do
|
|
18
18
|
|
19
19
|
describe "instance" do
|
20
20
|
subject{ build(:shipping) }
|
21
|
-
|
21
|
+
|
22
22
|
it { should be_valid }
|
23
23
|
its(:cost){ should == "12.13" }
|
24
24
|
its(:postal_code){ should == "05363000" }
|
25
25
|
|
26
26
|
context "with invalid postal_code" do
|
27
27
|
subject{ build(:shipping, postal_code: 1234567) }
|
28
|
-
its(:postal_code){ should be_blank }
|
28
|
+
its(:postal_code){ should be_blank }
|
29
29
|
end
|
30
30
|
|
31
31
|
context "with type 1" do
|
@@ -43,4 +43,4 @@ describe PagSeguro::Shipping do
|
|
43
43
|
it { should be_unidentified }
|
44
44
|
end
|
45
45
|
end
|
46
|
-
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pag_seguro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Diem Benatti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|