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,46 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Address
|
3
|
+
include ActiveModel::Validations
|
4
|
+
validates_presence_of :postal_code, :street, :number
|
5
|
+
validates_presence_of :district, :city, :state, :country
|
6
|
+
|
7
|
+
validates_length_of :country, is: 3
|
8
|
+
validates_length_of :state, is: 2
|
9
|
+
validates_length_of :postal_code, is: 8
|
10
|
+
# Set the postal_code.
|
11
|
+
# 8 digit number represeting a valid CEP i.e 01452002
|
12
|
+
attr_accessor :postal_code
|
13
|
+
|
14
|
+
# Set the street name.
|
15
|
+
attr_accessor :street
|
16
|
+
|
17
|
+
# Set the number.
|
18
|
+
attr_accessor :number
|
19
|
+
|
20
|
+
# Get the complement.
|
21
|
+
attr_accessor :complement
|
22
|
+
|
23
|
+
# Get the district.
|
24
|
+
attr_accessor :district
|
25
|
+
|
26
|
+
# Get the city.
|
27
|
+
attr_accessor :city
|
28
|
+
|
29
|
+
# Get the state.
|
30
|
+
attr_accessor :state
|
31
|
+
|
32
|
+
# Get the country.
|
33
|
+
attr_accessor :country
|
34
|
+
|
35
|
+
def initialize(options = {})
|
36
|
+
@country = "BRA"
|
37
|
+
@postal_code = options[:postal_code]
|
38
|
+
@street = options[:street]
|
39
|
+
@number = options[:number]
|
40
|
+
@complement = options[:complement]
|
41
|
+
@district = options[:district]
|
42
|
+
@city = options[:city]
|
43
|
+
@state = options[:state]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Bank
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
validates_presence_of :name
|
6
|
+
validates_inclusion_of :name, in: %w(bradesco itau bancodobrasil banrisul hsbc)
|
7
|
+
# Set the bank name
|
8
|
+
# Should be a valid bank: bradesco, itau, bancodobrasil, banrisul ou hsbc
|
9
|
+
attr_accessor :name
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
@name = name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class CreditCard
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
validates_presence_of :token, :installment, :holder, :billing_address
|
6
|
+
|
7
|
+
# Set the token that represents the credit card.
|
8
|
+
attr_accessor :token
|
9
|
+
|
10
|
+
# Set the CPF document.
|
11
|
+
attr_accessor :installment
|
12
|
+
|
13
|
+
# Get the sender phone.
|
14
|
+
attr_accessor :holder
|
15
|
+
|
16
|
+
# Get the sender phone.
|
17
|
+
attr_accessor :billing_address
|
18
|
+
|
19
|
+
def initialize(token)
|
20
|
+
@token = token
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Document
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
validates_presence_of :type, :value
|
6
|
+
|
7
|
+
# Set the document type
|
8
|
+
# Only CPF is acceptable
|
9
|
+
attr_accessor :type
|
10
|
+
|
11
|
+
# Set the document number.
|
12
|
+
# Must have 7-9 numbers.
|
13
|
+
attr_accessor :value
|
14
|
+
|
15
|
+
def initialize(value)
|
16
|
+
@type = 'CPF'
|
17
|
+
@value = value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
|
3
|
+
class InvalidTransaction < StandardError; end
|
4
|
+
|
5
|
+
class InvalidShipping < StandardError; end
|
6
|
+
|
7
|
+
class InvalidItem < StandardError; end
|
8
|
+
|
9
|
+
class InvalidSender < StandardError; end
|
10
|
+
|
11
|
+
class InvalidPhone < StandardError; end
|
12
|
+
|
13
|
+
class InvalidBank < StandardError; end
|
14
|
+
|
15
|
+
class InvalidCreditCard < StandardError; end
|
16
|
+
|
17
|
+
class InvalidInstallment < StandardError; end
|
18
|
+
|
19
|
+
class InvalidHolder < StandardError; end
|
20
|
+
|
21
|
+
class InvalidAddress < StandardError; end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Holder
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
validates_presence_of :name, :birthdate, :document, :phone
|
6
|
+
|
7
|
+
# Set the credit card holder name.
|
8
|
+
attr_accessor :name
|
9
|
+
|
10
|
+
# Set the credit card holder bithdate.
|
11
|
+
attr_accessor :birthdate
|
12
|
+
|
13
|
+
# Set the credit card holder document.
|
14
|
+
attr_accessor :document
|
15
|
+
|
16
|
+
# Get the sender phone.
|
17
|
+
attr_accessor :phone
|
18
|
+
|
19
|
+
def initialize(name, birthdate)
|
20
|
+
@name = name
|
21
|
+
@birthdate = birthdate
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Installment
|
3
|
+
include ActiveModel::Validations
|
4
|
+
validates_presence_of :quantity, :value
|
5
|
+
|
6
|
+
# Set the total of installments
|
7
|
+
attr_accessor :quantity
|
8
|
+
|
9
|
+
# Set the installment value.
|
10
|
+
attr_accessor :value
|
11
|
+
|
12
|
+
def initialize(quantity, value)
|
13
|
+
@quantity = quantity
|
14
|
+
@value = value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Item
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
validates_presence_of :id, :description, :amount, :quantity
|
6
|
+
validates_numericality_of :amount, :quantity, greater_than: 0
|
7
|
+
validates_numericality_of :quantity, only_integer: true
|
8
|
+
|
9
|
+
# Set the product identifier, such as SKU.
|
10
|
+
attr_accessor :id
|
11
|
+
|
12
|
+
# Set the product description.
|
13
|
+
attr_accessor :description
|
14
|
+
|
15
|
+
# Set the amount per unit.
|
16
|
+
attr_accessor :amount
|
17
|
+
|
18
|
+
# Set the quantity.
|
19
|
+
# Defaults to 1.
|
20
|
+
attr_accessor :quantity
|
21
|
+
|
22
|
+
def initialize(id, description, amount, quantity = 1)
|
23
|
+
@id = id
|
24
|
+
@description = description
|
25
|
+
@amount = amount
|
26
|
+
@quantity = quantity
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Notification
|
3
|
+
class Address
|
4
|
+
attr_reader :address
|
5
|
+
|
6
|
+
def initialize(address)
|
7
|
+
@address = address
|
8
|
+
end
|
9
|
+
|
10
|
+
def street
|
11
|
+
address['street']
|
12
|
+
end
|
13
|
+
|
14
|
+
def number
|
15
|
+
address['number']
|
16
|
+
end
|
17
|
+
|
18
|
+
def complement
|
19
|
+
address['complement']
|
20
|
+
end
|
21
|
+
|
22
|
+
def district
|
23
|
+
address['district']
|
24
|
+
end
|
25
|
+
|
26
|
+
def postal_code
|
27
|
+
address['postalCode']
|
28
|
+
end
|
29
|
+
|
30
|
+
def city
|
31
|
+
address['city']
|
32
|
+
end
|
33
|
+
|
34
|
+
def state
|
35
|
+
address['state']
|
36
|
+
end
|
37
|
+
|
38
|
+
def country
|
39
|
+
address['country']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Notification
|
3
|
+
class Item
|
4
|
+
attr_accessor :id, :description, :quantity, :amount
|
5
|
+
|
6
|
+
def initialize(id, description, quantity, amount)
|
7
|
+
@id = id
|
8
|
+
@description = description
|
9
|
+
@quantity = quantity
|
10
|
+
@amount = amount
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Notification
|
3
|
+
class Items
|
4
|
+
attr_reader :count
|
5
|
+
|
6
|
+
def initialize(store, count)
|
7
|
+
@store = store
|
8
|
+
@count = count
|
9
|
+
end
|
10
|
+
|
11
|
+
def items
|
12
|
+
@store['item'].map do |i|
|
13
|
+
Item.new(i['id'], i['description'], i['quantity'], i['amount'])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Notification
|
3
|
+
class PaymentMethod
|
4
|
+
attr_reader :payment_method
|
5
|
+
|
6
|
+
def initialize(payment_method)
|
7
|
+
@payment_method = payment_method
|
8
|
+
end
|
9
|
+
|
10
|
+
def payment_type
|
11
|
+
payment_method['type']
|
12
|
+
end
|
13
|
+
|
14
|
+
def payment_code
|
15
|
+
payment_method['code']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Notification
|
3
|
+
class Sender
|
4
|
+
attr_reader :sender
|
5
|
+
|
6
|
+
def initialize(sender)
|
7
|
+
@sender = sender
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
sender['name']
|
12
|
+
end
|
13
|
+
|
14
|
+
def email
|
15
|
+
sender['email']
|
16
|
+
end
|
17
|
+
|
18
|
+
def phone
|
19
|
+
Phone.new(sender['phone'])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Notification
|
3
|
+
class Shipping
|
4
|
+
attr_reader :shipping
|
5
|
+
|
6
|
+
def initialize(shipping)
|
7
|
+
@shipping = shipping
|
8
|
+
end
|
9
|
+
|
10
|
+
def address
|
11
|
+
Address.new(shipping['address'])
|
12
|
+
end
|
13
|
+
|
14
|
+
def type
|
15
|
+
shipping['type']
|
16
|
+
end
|
17
|
+
|
18
|
+
def cost
|
19
|
+
shipping['cost']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Notification
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def date
|
10
|
+
transaction['date']
|
11
|
+
end
|
12
|
+
|
13
|
+
def last_event_date
|
14
|
+
transaction['lastEventDate']
|
15
|
+
end
|
16
|
+
|
17
|
+
def code
|
18
|
+
transaction['code']
|
19
|
+
end
|
20
|
+
|
21
|
+
def reference
|
22
|
+
transaction['reference']
|
23
|
+
end
|
24
|
+
|
25
|
+
def type
|
26
|
+
transaction['type']
|
27
|
+
end
|
28
|
+
|
29
|
+
def status
|
30
|
+
transaction['status']
|
31
|
+
end
|
32
|
+
|
33
|
+
def payment_method
|
34
|
+
PaymentMethod.new(transaction['paymentMethod'])
|
35
|
+
end
|
36
|
+
|
37
|
+
def payment_link
|
38
|
+
transaction['paymentLink']
|
39
|
+
end
|
40
|
+
|
41
|
+
def gross_amount
|
42
|
+
transaction['grossAmount']
|
43
|
+
end
|
44
|
+
|
45
|
+
def discount_amount
|
46
|
+
transaction['discountAmount']
|
47
|
+
end
|
48
|
+
|
49
|
+
def fee_amount
|
50
|
+
transaction['feeAmount']
|
51
|
+
end
|
52
|
+
|
53
|
+
def net_amount
|
54
|
+
transaction['netAmount']
|
55
|
+
end
|
56
|
+
|
57
|
+
def extra_amount
|
58
|
+
transaction['extraAmount']
|
59
|
+
end
|
60
|
+
|
61
|
+
def installment_count
|
62
|
+
transaction['installmentCount']
|
63
|
+
end
|
64
|
+
|
65
|
+
def items
|
66
|
+
Items.new(transaction['paymentMethod'], transaction['itemCount'])
|
67
|
+
end
|
68
|
+
|
69
|
+
def sender
|
70
|
+
Sender.new(transaction['sender'])
|
71
|
+
end
|
72
|
+
|
73
|
+
def shipping
|
74
|
+
Shipping.new(transaction['shipping'])
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
def transaction
|
79
|
+
response['transaction']
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Phone
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
validates_presence_of :area_code, :number
|
6
|
+
validates_length_of :area_code, is: 2
|
7
|
+
validates_length_of :number, in: 7..9
|
8
|
+
|
9
|
+
# Set the area code.
|
10
|
+
attr_accessor :area_code
|
11
|
+
|
12
|
+
# Set the phone number.
|
13
|
+
# Must have 7-9 numbers.
|
14
|
+
attr_accessor :number
|
15
|
+
|
16
|
+
def initialize(area_code, number)
|
17
|
+
@area_code = area_code
|
18
|
+
@number = number
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module PagSeguro
|
4
|
+
class Request
|
5
|
+
include HTTParty
|
6
|
+
debug_output $stderr
|
7
|
+
|
8
|
+
base_uri "https://ws.pagseguro.uol.com.br/v2/"
|
9
|
+
|
10
|
+
def get(path, options = {})
|
11
|
+
self.class.get(path, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(path, params = {})
|
15
|
+
options = { body: { email: PagSeguro.email, token: PagSeguro.token} }
|
16
|
+
options[:body].merge!(params)
|
17
|
+
response = self.class.post(path, options)
|
18
|
+
response.parsed_response
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Sender
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
validates_presence_of :email, :name, :hash_id, :document, :phone
|
6
|
+
|
7
|
+
# Set the sender e-mail.
|
8
|
+
attr_accessor :email
|
9
|
+
|
10
|
+
# Set the sender name.
|
11
|
+
attr_accessor :name
|
12
|
+
|
13
|
+
# Set the hash identifier.
|
14
|
+
attr_accessor :hash_id
|
15
|
+
|
16
|
+
# Set the CPF document.
|
17
|
+
attr_accessor :document
|
18
|
+
|
19
|
+
# Get the sender phone.
|
20
|
+
attr_accessor :phone
|
21
|
+
|
22
|
+
def initialize(options = {})
|
23
|
+
@email = options[:email]
|
24
|
+
@name = options[:name]
|
25
|
+
@hash_id = options[:hash_id]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Shipping
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
validates_presence_of :address
|
6
|
+
validates_inclusion_of :type_id, in: %w( 1 2 3 ), allow_blank: true
|
7
|
+
validates_numericality_of :cost, greater_than: 0
|
8
|
+
|
9
|
+
# Set the shipping type
|
10
|
+
attr_accessor :type_id
|
11
|
+
|
12
|
+
# Set the credit card holder bithdate.
|
13
|
+
attr_accessor :cost
|
14
|
+
|
15
|
+
# Get the sender address.
|
16
|
+
attr_accessor :address
|
17
|
+
|
18
|
+
def initialize(type_id = nil, cost = nil)
|
19
|
+
@type_id = type_id
|
20
|
+
@cost = cost
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|