pagseguro-transparente 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +34 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +89 -0
- data/README.md +79 -0
- data/Rakefile +5 -0
- data/coverage/.last_run.json +5 -0
- data/coverage/.resultset.json +1665 -0
- data/coverage/assets/0.8.0/application.css +799 -0
- data/coverage/assets/0.8.0/application.js +1559 -0
- data/coverage/assets/0.8.0/colorbox/border.png +0 -0
- data/coverage/assets/0.8.0/colorbox/controls.png +0 -0
- data/coverage/assets/0.8.0/colorbox/loading.gif +0 -0
- data/coverage/assets/0.8.0/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.8.0/favicon_green.png +0 -0
- data/coverage/assets/0.8.0/favicon_red.png +0 -0
- data/coverage/assets/0.8.0/favicon_yellow.png +0 -0
- data/coverage/assets/0.8.0/loading.gif +0 -0
- data/coverage/assets/0.8.0/magnify.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.8.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +10198 -0
- data/lib/pagseguro/address.rb +46 -0
- data/lib/pagseguro/bank.rb +15 -0
- data/lib/pagseguro/credit_card.rb +23 -0
- data/lib/pagseguro/document.rb +20 -0
- data/lib/pagseguro/exceptions.rb +22 -0
- data/lib/pagseguro/holder.rb +24 -0
- data/lib/pagseguro/installment.rb +17 -0
- data/lib/pagseguro/item.rb +29 -0
- data/lib/pagseguro/items.rb +16 -0
- data/lib/pagseguro/notification/address.rb +43 -0
- data/lib/pagseguro/notification/item.rb +14 -0
- data/lib/pagseguro/notification/items.rb +18 -0
- data/lib/pagseguro/notification/payment_method.rb +19 -0
- data/lib/pagseguro/notification/phone.rb +19 -0
- data/lib/pagseguro/notification/sender.rb +23 -0
- data/lib/pagseguro/notification/shipping.rb +23 -0
- data/lib/pagseguro/notification.rb +82 -0
- data/lib/pagseguro/phone.rb +21 -0
- data/lib/pagseguro/request.rb +21 -0
- data/lib/pagseguro/sender.rb +28 -0
- data/lib/pagseguro/session/response.rb +15 -0
- data/lib/pagseguro/session.rb +7 -0
- data/lib/pagseguro/shipping.rb +23 -0
- data/lib/pagseguro/transaction/serializer.rb +158 -0
- data/lib/pagseguro/transaction.rb +91 -0
- data/lib/pagseguro/version.rb +3 -0
- data/lib/pagseguro-transparente.rb +1 -0
- data/lib/pagseguro.rb +54 -0
- data/pagseguro-transparente.gemspec +34 -0
- data/spec/pagseguro/address_spec.rb +35 -0
- data/spec/pagseguro/bank_spec.rb +17 -0
- data/spec/pagseguro/credit_card_spec.rb +18 -0
- data/spec/pagseguro/document_spec.rb +18 -0
- data/spec/pagseguro/holder_spec.rb +18 -0
- data/spec/pagseguro/installment_spec.rb +14 -0
- data/spec/pagseguro/item_spec.rb +28 -0
- data/spec/pagseguro/items_spec.rb +13 -0
- data/spec/pagseguro/notification/address_spec.rb +33 -0
- data/spec/pagseguro/notification/item_spec.rb +15 -0
- data/spec/pagseguro/notification/items_spec.rb +31 -0
- data/spec/pagseguro/notification/payment_method_spec.rb +21 -0
- data/spec/pagseguro/notification/phone_spec.rb +21 -0
- data/spec/pagseguro/notification/sender_spec.rb +26 -0
- data/spec/pagseguro/notification/shipping_spec.rb +22 -0
- data/spec/pagseguro/notification_spec.rb +45 -0
- data/spec/pagseguro/pagseguro_spec.rb +23 -0
- data/spec/pagseguro/phone_spec.rb +19 -0
- data/spec/pagseguro/sender_spec.rb +20 -0
- data/spec/pagseguro/session/response_spec.rb +17 -0
- data/spec/pagseguro/session_spec.rb +23 -0
- data/spec/pagseguro/shipping_spec.rb +22 -0
- data/spec/pagseguro/transaction/serializer_spec.rb +131 -0
- data/spec/pagseguro/transaction_spec.rb +91 -0
- data/spec/spec_helper.rb +16 -0
- metadata +311 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Transaction
|
3
|
+
class Serializer
|
4
|
+
# The payment request that will be serialized.
|
5
|
+
attr_reader :transaction
|
6
|
+
|
7
|
+
def initialize(transaction)
|
8
|
+
@transaction = transaction
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_params
|
12
|
+
raise InvalidTransaction, transaction.errors.messages unless transaction.valid?
|
13
|
+
|
14
|
+
params[:email] = PagSeguro.email
|
15
|
+
params[:token] = PagSeguro.token
|
16
|
+
|
17
|
+
|
18
|
+
params[:notificationURL] = transaction.notification_url
|
19
|
+
params[:currency] = transaction.currency
|
20
|
+
params[:paymentMethod] = transaction.payment_method
|
21
|
+
params[:paymentMode] = transaction.payment_mode
|
22
|
+
params[:reference] = transaction.reference
|
23
|
+
params[:extraAmount] = transaction.extra_amount
|
24
|
+
|
25
|
+
transaction.items.each.with_index(1) do |item, index|
|
26
|
+
serialize_item(item, index)
|
27
|
+
end
|
28
|
+
|
29
|
+
serialize_sender(transaction.sender)
|
30
|
+
serialize_bank(transaction.bank)
|
31
|
+
serialize_credit_card(transaction.credit_card)
|
32
|
+
serialize_shipping(transaction.shipping)
|
33
|
+
|
34
|
+
|
35
|
+
params[:receiverEmail] = transaction.receiver_email if transaction.receiver_email
|
36
|
+
|
37
|
+
params.delete_if {|key, value| value.nil? }
|
38
|
+
|
39
|
+
params
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def params
|
44
|
+
@params ||= {}
|
45
|
+
end
|
46
|
+
|
47
|
+
def serialize_shipping(shipping)
|
48
|
+
return unless shipping
|
49
|
+
raise InvalidShipping, shipping.errors.messages unless shipping.valid?
|
50
|
+
|
51
|
+
params[:shippingType] = shipping.type_id
|
52
|
+
params[:shippingCost] = to_amount(shipping.cost)
|
53
|
+
|
54
|
+
serialize_address_shipping(shipping.address)
|
55
|
+
end
|
56
|
+
|
57
|
+
def serialize_item(item, index)
|
58
|
+
return unless item
|
59
|
+
raise InvalidItem, item.errors.messages unless item.valid?
|
60
|
+
|
61
|
+
params["itemId#{index}".to_sym] = item.id
|
62
|
+
params["itemDescription#{index}".to_sym] = item.description
|
63
|
+
params["itemAmount#{index}".to_sym] = to_amount(item.amount)
|
64
|
+
params["itemQuantity#{index}".to_sym] = item.quantity
|
65
|
+
end
|
66
|
+
|
67
|
+
def serialize_sender(sender)
|
68
|
+
return unless sender
|
69
|
+
raise InvalidSender, sender.errors.messages unless sender.valid?
|
70
|
+
|
71
|
+
params[:senderName] = sender.name
|
72
|
+
params[:senderCPF] = sender.document.value
|
73
|
+
params[:senderEmail] = sender.email
|
74
|
+
params[:senderHash] = sender.hash_id
|
75
|
+
|
76
|
+
serialize_phone(sender.phone)
|
77
|
+
end
|
78
|
+
|
79
|
+
def serialize_phone(phone)
|
80
|
+
return unless phone
|
81
|
+
raise InvalidPhone, phone.errors.messages unless phone.valid?
|
82
|
+
|
83
|
+
params[:senderAreaCode] = phone.area_code
|
84
|
+
params[:senderPhone] = phone.number
|
85
|
+
end
|
86
|
+
|
87
|
+
def serialize_bank(bank)
|
88
|
+
return unless bank
|
89
|
+
raise InvalidBank, bank.errors.messages unless bank.valid?
|
90
|
+
|
91
|
+
params[:bankName] = bank.name
|
92
|
+
end
|
93
|
+
|
94
|
+
def serialize_credit_card(credit_card)
|
95
|
+
return unless credit_card
|
96
|
+
raise InvalidCreditCard, credit_card.errors.messages unless credit_card.valid?
|
97
|
+
|
98
|
+
params[:creditCardToken] = credit_card.token
|
99
|
+
|
100
|
+
serialize_installment(credit_card.installment)
|
101
|
+
serialize_holder(credit_card.holder)
|
102
|
+
serialize_address(credit_card.billing_address)
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def serialize_installment(installment)
|
107
|
+
return unless installment
|
108
|
+
raise InvalidInstallment, installment.errors.messages unless installment.valid?
|
109
|
+
|
110
|
+
params[:installmentQuantity] = installment.quantity
|
111
|
+
params[:installmentValue] = installment.value
|
112
|
+
end
|
113
|
+
|
114
|
+
def serialize_holder(holder)
|
115
|
+
return unless holder
|
116
|
+
raise InvalidHolder, holder.errors.messages unless holder.valid?
|
117
|
+
|
118
|
+
params[:creditCardHolderName] = holder.name
|
119
|
+
params[:creditCardHolderCPF] = holder.document.value
|
120
|
+
params[:creditCardHolderBirthDate] = holder.birthdate
|
121
|
+
params[:creditCardHolderAreaCode] = holder.phone.area_code
|
122
|
+
params[:creditCardHolderPhone] = holder.phone.number
|
123
|
+
end
|
124
|
+
|
125
|
+
def serialize_address_shipping(address)
|
126
|
+
return unless address
|
127
|
+
raise InvalidAddress, address.errors.messages unless address.valid?
|
128
|
+
|
129
|
+
params[:shippingAddressCountry] = address.country
|
130
|
+
params[:shippingAddressState] = address.state
|
131
|
+
params[:shippingAddressCity] = address.city
|
132
|
+
params[:shippingAddressPostalCode] = address.postal_code
|
133
|
+
params[:shippingAddressDistrict] = address.district
|
134
|
+
params[:shippingAddressStreet] = address.street
|
135
|
+
params[:shippingAddressNumber] = address.number
|
136
|
+
params[:shippingAddressComplement] = address.complement
|
137
|
+
end
|
138
|
+
|
139
|
+
def serialize_address(address)
|
140
|
+
return unless address
|
141
|
+
raise InvalidAddress, address.errors.messages unless address.valid?
|
142
|
+
|
143
|
+
params[:billingAddressCountry] = address.country
|
144
|
+
params[:billingAddressState] = address.state
|
145
|
+
params[:billingAddressCity] = address.city
|
146
|
+
params[:billingAddressPostalCode] = address.postal_code
|
147
|
+
params[:billingAddressDistrict] = address.district
|
148
|
+
params[:billingAddressStreet] = address.street
|
149
|
+
params[:billingAddressNumber] = address.number
|
150
|
+
params[:billingAddressComplement] = address.complement
|
151
|
+
end
|
152
|
+
|
153
|
+
def to_amount(amount)
|
154
|
+
"%.2f" % BigDecimal(amount.to_s).round(2).to_s("F") if amount
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Transaction < Request
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
validates_presence_of :currency, :payment_method, :items, :sender, :shipping
|
6
|
+
validates_presence_of :bank, if: :paid_with_eft?
|
7
|
+
validates_presence_of :credit_card, if: :paid_with_card?
|
8
|
+
validates_inclusion_of :payment_method, in: %w(creditCard boleto eft)
|
9
|
+
# Determines for which url PagSeguro will send the order related
|
10
|
+
# notifications codes.
|
11
|
+
# Optional. Any change happens in the transaction status, a new notification
|
12
|
+
# request will be send to this url. You can use that for update the related
|
13
|
+
# order.
|
14
|
+
attr_accessor :notification_url
|
15
|
+
|
16
|
+
# Set the payment currency.
|
17
|
+
# Defaults to BRL.
|
18
|
+
attr_accessor :currency
|
19
|
+
|
20
|
+
# Set the payment method.
|
21
|
+
# Payment method should be creditCard, boleto or eft.
|
22
|
+
attr_accessor :payment_method
|
23
|
+
|
24
|
+
# Set the payment mode
|
25
|
+
attr_accessor :payment_mode
|
26
|
+
|
27
|
+
# Set the reference code.
|
28
|
+
# Optional. You can use the reference code to store an identifier so you can
|
29
|
+
# associate the PagSeguro transaction to a transaction in your system.
|
30
|
+
# Tipically this is the order id.
|
31
|
+
attr_accessor :reference
|
32
|
+
|
33
|
+
# Get the payment sender.
|
34
|
+
attr_accessor :sender
|
35
|
+
|
36
|
+
|
37
|
+
# Get the payment sender.
|
38
|
+
attr_accessor :credit_card
|
39
|
+
|
40
|
+
attr_accessor :receiver_email
|
41
|
+
|
42
|
+
# Set the bank name.
|
43
|
+
# Optional. Bank name should be used for eft payment method
|
44
|
+
# to specify which the buyer should be redirect.
|
45
|
+
attr_accessor :bank
|
46
|
+
|
47
|
+
attr_accessor :shipping
|
48
|
+
|
49
|
+
attr_accessor :extra_amount
|
50
|
+
|
51
|
+
# Products/items in this payment request.
|
52
|
+
def items
|
53
|
+
@items ||= Items.new
|
54
|
+
end
|
55
|
+
|
56
|
+
# Normalize the items list.
|
57
|
+
def items=(_items)
|
58
|
+
_items.each {|item| items << item }
|
59
|
+
end
|
60
|
+
|
61
|
+
# Calls the PagSeguro web service and register this request for payment.
|
62
|
+
def register
|
63
|
+
# raise 'An error' unless self.valid?
|
64
|
+
params = Serializer.new(self).to_params
|
65
|
+
Response.new post('/transactions', params)
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize(options = {})
|
69
|
+
@currency = "BRL"
|
70
|
+
@payment_mode = 'default'
|
71
|
+
@notification_url = options[:notification_url]
|
72
|
+
@payment_method = options[:payment_method]
|
73
|
+
@reference = options[:reference] if options[:reference]
|
74
|
+
@extra_amount = options[:extra_amount] if options[:extra_amount]
|
75
|
+
@receiver_email = options[:receiver_email] if options[:receiver_email]
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def endpoint
|
80
|
+
PagSeguro.api_url("checkout")
|
81
|
+
end
|
82
|
+
|
83
|
+
def paid_with_card?
|
84
|
+
payment_method == "creditCard"
|
85
|
+
end
|
86
|
+
|
87
|
+
def paid_with_eft?
|
88
|
+
payment_method == "eft"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "pagseguro"
|
data/lib/pagseguro.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "active_model"
|
2
|
+
require "pagseguro/version"
|
3
|
+
require "pagseguro/request"
|
4
|
+
require "pagseguro/session"
|
5
|
+
require "pagseguro/session/response"
|
6
|
+
require "pagseguro/item"
|
7
|
+
require "pagseguro/items"
|
8
|
+
require "pagseguro/transaction"
|
9
|
+
require "pagseguro/transaction/serializer"
|
10
|
+
require "pagseguro/notification"
|
11
|
+
require "pagseguro/notification/address"
|
12
|
+
require "pagseguro/notification/item"
|
13
|
+
require "pagseguro/notification/items"
|
14
|
+
require "pagseguro/notification/payment_method"
|
15
|
+
require "pagseguro/notification/phone"
|
16
|
+
require "pagseguro/notification/sender"
|
17
|
+
require "pagseguro/notification/shipping"
|
18
|
+
require "pagseguro/sender"
|
19
|
+
require "pagseguro/phone"
|
20
|
+
require "pagseguro/document"
|
21
|
+
require "pagseguro/bank"
|
22
|
+
require "pagseguro/credit_card"
|
23
|
+
require "pagseguro/holder"
|
24
|
+
require "pagseguro/address"
|
25
|
+
require "pagseguro/shipping"
|
26
|
+
require "pagseguro/installment"
|
27
|
+
require "pagseguro/exceptions"
|
28
|
+
|
29
|
+
module PagSeguro
|
30
|
+
class << self
|
31
|
+
# Primary e-mail associated with this account.
|
32
|
+
attr_accessor :email
|
33
|
+
|
34
|
+
# The API token associated with this account.
|
35
|
+
attr_accessor :token
|
36
|
+
|
37
|
+
# The PagSeguro environment.
|
38
|
+
# Only +production+ for now.
|
39
|
+
attr_accessor :environment
|
40
|
+
end
|
41
|
+
|
42
|
+
self.environment = :production
|
43
|
+
|
44
|
+
# Set the global configuration.
|
45
|
+
#
|
46
|
+
# PagSeguro.configure do |config|
|
47
|
+
# config.email = "john@example.com"
|
48
|
+
# config.token = "abc"
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
def self.configure(&block)
|
52
|
+
yield self
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "./lib/pagseguro/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.required_ruby_version = ">= 1.9.3"
|
6
|
+
spec.name = "pagseguro-transparente"
|
7
|
+
spec.version = PagSeguro::VERSION
|
8
|
+
spec.authors = ["Cirdes Henrique"]
|
9
|
+
spec.email = ["cirdes@gmail.com"]
|
10
|
+
spec.description = "Integração com o novo checkout transparente do Pagseguro."
|
11
|
+
spec.summary = spec.description
|
12
|
+
spec.homepage = "http://www.eventick.com.br"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "httparty"
|
21
|
+
spec.add_dependency "nokogiri"
|
22
|
+
spec.add_dependency "json"
|
23
|
+
spec.add_dependency "activemodel"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "shoulda-matchers", '2.5.0'
|
29
|
+
spec.add_development_dependency "coveralls"
|
30
|
+
spec.add_development_dependency "webmock"
|
31
|
+
spec.add_development_dependency 'thread_safe', '0.2.0'
|
32
|
+
#spec.add_development_dependency "pry-meta"
|
33
|
+
#spec.add_development_dependency "autotest-standalone"
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Address do
|
4
|
+
let(:address) { PagSeguro::Address.new }
|
5
|
+
subject { address }
|
6
|
+
|
7
|
+
it { should respond_to(:postal_code) }
|
8
|
+
it { should respond_to(:street) }
|
9
|
+
it { should respond_to(:number) }
|
10
|
+
it { should respond_to(:complement) }
|
11
|
+
it { should respond_to(:district) }
|
12
|
+
it { should respond_to(:city) }
|
13
|
+
it { should respond_to(:state) }
|
14
|
+
it { should respond_to(:country) }
|
15
|
+
|
16
|
+
describe 'presence validations' do
|
17
|
+
it { should validate_presence_of(:postal_code) }
|
18
|
+
it { should validate_presence_of(:street) }
|
19
|
+
it { should validate_presence_of(:number) }
|
20
|
+
it { should validate_presence_of(:district) }
|
21
|
+
it { should validate_presence_of(:city) }
|
22
|
+
it { should validate_presence_of(:state) }
|
23
|
+
it { should validate_presence_of(:country) }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'length validations' do
|
27
|
+
it { should ensure_length_of(:country).is_equal_to(3) }
|
28
|
+
it { should ensure_length_of(:state).is_equal_to(2) }
|
29
|
+
it { should ensure_length_of(:postal_code).is_equal_to(8) }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'set default country' do
|
33
|
+
its(:country) { should eq('BRA') }
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Bank do
|
4
|
+
let(:bank) { PagSeguro::Bank.new(:itau) }
|
5
|
+
subject { bank }
|
6
|
+
|
7
|
+
it { should respond_to(:name) }
|
8
|
+
|
9
|
+
describe 'presence validations' do
|
10
|
+
it { should validate_presence_of(:name) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'inclusion validations' do
|
14
|
+
let(:banks) { %w(bradesco itau bancodobrasil banrisul hsbc) }
|
15
|
+
it { should ensure_inclusion_of(:name).in_array(banks) }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::CreditCard do
|
4
|
+
let(:card) { PagSeguro::CreditCard.new('card_token') }
|
5
|
+
subject { card }
|
6
|
+
|
7
|
+
it { should respond_to(:token) }
|
8
|
+
it { should respond_to(:installment) }
|
9
|
+
it { should respond_to(:holder) }
|
10
|
+
it { should respond_to(:billing_address) }
|
11
|
+
|
12
|
+
describe 'presence validations' do
|
13
|
+
it { should validate_presence_of(:token) }
|
14
|
+
it { should validate_presence_of(:installment) }
|
15
|
+
it { should validate_presence_of(:holder) }
|
16
|
+
it { should validate_presence_of(:billing_address) }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Document do
|
4
|
+
let(:document) { PagSeguro::Document.new('017.345.345-00') }
|
5
|
+
subject { document }
|
6
|
+
|
7
|
+
it { should respond_to(:type) }
|
8
|
+
it { should respond_to(:value) }
|
9
|
+
|
10
|
+
describe 'presence validations' do
|
11
|
+
it { should validate_presence_of(:type) }
|
12
|
+
it { should validate_presence_of(:value) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'set default country' do
|
16
|
+
its(:type) { should eq('CPF') }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Holder do
|
4
|
+
let(:holder) { PagSeguro::Holder.new('Cleonice Maria', '31/12/2013') }
|
5
|
+
subject { holder }
|
6
|
+
|
7
|
+
it { should respond_to(:name) }
|
8
|
+
it { should respond_to(:birthdate) }
|
9
|
+
it { should respond_to(:document) }
|
10
|
+
it { should respond_to(:phone) }
|
11
|
+
|
12
|
+
describe 'presence validations' do
|
13
|
+
it { should validate_presence_of(:name) }
|
14
|
+
it { should validate_presence_of(:birthdate) }
|
15
|
+
it { should validate_presence_of(:document) }
|
16
|
+
it { should validate_presence_of(:phone) }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Installment do
|
4
|
+
let(:installment) { PagSeguro::Installment.new(12, 100) }
|
5
|
+
subject { installment }
|
6
|
+
|
7
|
+
it { should respond_to(:quantity) }
|
8
|
+
it { should respond_to(:value) }
|
9
|
+
|
10
|
+
describe 'presence validations' do
|
11
|
+
it { should validate_presence_of(:quantity) }
|
12
|
+
it { should validate_presence_of(:value) }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Item do
|
4
|
+
let(:item) { PagSeguro::Item.new('id', 'my item', 10) }
|
5
|
+
subject { item }
|
6
|
+
|
7
|
+
it { should respond_to(:id) }
|
8
|
+
it { should respond_to(:description) }
|
9
|
+
it { should respond_to(:amount) }
|
10
|
+
it { should respond_to(:quantity) }
|
11
|
+
|
12
|
+
describe 'presence validations' do
|
13
|
+
it { should validate_presence_of(:id) }
|
14
|
+
it { should validate_presence_of(:description) }
|
15
|
+
it { should validate_presence_of(:amount) }
|
16
|
+
it { should validate_presence_of(:quantity) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'numericality validations' do
|
20
|
+
it { should validate_numericality_of(:amount).is_greater_than(0) }
|
21
|
+
it { should validate_numericality_of(:quantity).is_greater_than(0) }
|
22
|
+
it { should validate_numericality_of(:quantity).only_integer }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'set default country' do
|
26
|
+
its(:quantity) { should eq(1) }
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Items do
|
4
|
+
let(:items) { PagSeguro::Items.new }
|
5
|
+
subject { items }
|
6
|
+
|
7
|
+
it { should respond_to(:<<) }
|
8
|
+
it { should respond_to(:size) }
|
9
|
+
it { should respond_to(:clear) }
|
10
|
+
it { should respond_to(:empty?) }
|
11
|
+
it { should respond_to(:any?) }
|
12
|
+
it { should respond_to(:each) }
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Notification::Address do
|
4
|
+
let(:xml) { MultiXml.parse(xml_file) }
|
5
|
+
|
6
|
+
let(:address) do
|
7
|
+
PagSeguro::Notification::Address.new(xml['address'])
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { address }
|
11
|
+
|
12
|
+
its(:street) { should eq('Av. Brig. Faria Lima') }
|
13
|
+
its(:number) { should eq('1384') }
|
14
|
+
its(:complement) { should eq('5o andar') }
|
15
|
+
its(:district) { should eq('Jardim Paulistano') }
|
16
|
+
its(:postal_code) { should eq('01452002') }
|
17
|
+
its(:city) { should eq('Sao Paulo') }
|
18
|
+
its(:state) { should eq('SP') }
|
19
|
+
its(:country) { should eq('BRA') }
|
20
|
+
|
21
|
+
let(:xml_file) {
|
22
|
+
"<address>
|
23
|
+
<street>Av. Brig. Faria Lima</street>
|
24
|
+
<number>1384</number>
|
25
|
+
<complement>5o andar</complement>
|
26
|
+
<district>Jardim Paulistano</district>
|
27
|
+
<postalCode>01452002</postalCode>
|
28
|
+
<city>Sao Paulo</city>
|
29
|
+
<state>SP</state>
|
30
|
+
<country>BRA</country>
|
31
|
+
</address>"
|
32
|
+
}
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Notification::Item do
|
4
|
+
let(:item) do
|
5
|
+
PagSeguro::Notification::Item.new('0001', 'Notebook Prata',
|
6
|
+
'1', '24300.00')
|
7
|
+
end
|
8
|
+
|
9
|
+
subject { item }
|
10
|
+
|
11
|
+
its(:id) { should eq('0001') }
|
12
|
+
its(:description) { should eq('Notebook Prata') }
|
13
|
+
its(:quantity) { should eq('1') }
|
14
|
+
its(:amount) { should eq('24300.00') }
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Notification::Items do
|
4
|
+
let(:xml) { MultiXml.parse(xml_file) }
|
5
|
+
|
6
|
+
let(:items) do
|
7
|
+
PagSeguro::Notification::Items.new(xml['items'], '2')
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { items }
|
11
|
+
|
12
|
+
its(:items) { should be_a_kind_of(Array) }
|
13
|
+
its(:count) { should eq('2') }
|
14
|
+
|
15
|
+
let(:xml_file) {
|
16
|
+
"<items>
|
17
|
+
<item>
|
18
|
+
<id>0001</id>
|
19
|
+
<description>Notebook Prata</description>
|
20
|
+
<quantity>1</quantity>
|
21
|
+
<amount>24300.00</amount>
|
22
|
+
</item>
|
23
|
+
<item>
|
24
|
+
<id>0002</id>
|
25
|
+
<description>Notebook Rosa</description>
|
26
|
+
<quantity>1</quantity>
|
27
|
+
<amount>25600.00</amount>
|
28
|
+
</item>
|
29
|
+
</items>"
|
30
|
+
}
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Notification::PaymentMethod do
|
4
|
+
let(:xml) { MultiXml.parse(xml_file) }
|
5
|
+
|
6
|
+
let(:payment_method) do
|
7
|
+
PagSeguro::Notification::PaymentMethod.new(xml['paymentMethod'])
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { payment_method }
|
11
|
+
|
12
|
+
its(:payment_type) { should eq('1') }
|
13
|
+
its(:payment_code) { should eq('101') }
|
14
|
+
|
15
|
+
let(:xml_file) {
|
16
|
+
"<paymentMethod>
|
17
|
+
<type>1</type>
|
18
|
+
<code>101</code>
|
19
|
+
</paymentMethod>"
|
20
|
+
}
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Notification::Phone do
|
4
|
+
let(:xml) { MultiXml.parse(xml_file) }
|
5
|
+
|
6
|
+
let(:phone) do
|
7
|
+
PagSeguro::Notification::Phone.new(xml['phone'])
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { phone }
|
11
|
+
|
12
|
+
its(:area_code) { should eq('11') }
|
13
|
+
its(:number) { should eq('56273440') }
|
14
|
+
|
15
|
+
let(:xml_file) {
|
16
|
+
"<phone>
|
17
|
+
<areaCode>11</areaCode>
|
18
|
+
<number>56273440</number>
|
19
|
+
</phone>"
|
20
|
+
}
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Notification::Sender do
|
4
|
+
let(:xml) { MultiXml.parse(xml_file) }
|
5
|
+
|
6
|
+
let(:sender) do
|
7
|
+
PagSeguro::Notification::Sender.new(xml['sender'])
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { sender }
|
11
|
+
|
12
|
+
its(:name) { should eq('José Comprador') }
|
13
|
+
its(:email) { should eq('comprador@uol.com.br') }
|
14
|
+
its(:phone) { should be_a_kind_of(PagSeguro::Notification::Phone) }
|
15
|
+
|
16
|
+
let(:xml_file) {
|
17
|
+
"<sender>
|
18
|
+
<name>José Comprador</name>
|
19
|
+
<email>comprador@uol.com.br</email>
|
20
|
+
<phone>
|
21
|
+
<areaCode>11</areaCode>
|
22
|
+
<number>56273440</number>
|
23
|
+
</phone>
|
24
|
+
</sender>"
|
25
|
+
}
|
26
|
+
end
|