pagseguro-transparente 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82ce78e0821dd9736276cc6eb93c7797b41ddf66
4
- data.tar.gz: 8ac2777db76a2fcb7a932368887c94a92116dcbb
3
+ metadata.gz: 234a60fab82229142db4d62ea008209a61e4999b
4
+ data.tar.gz: d46919e9d88378d712bae935c342a88b0f839cc0
5
5
  SHA512:
6
- metadata.gz: 217b25a873ee12e50ccfef614d6d323e449af41c9ea7ab55f5118d589ae1bb409bc5e5d7ec0a168aec4197903d5d2920ff7a6ca6f392eb1531f650b28bdf3ef9
7
- data.tar.gz: eb6d1049b728d6b89911faa8b2b9051ce8a4b90a1a4ce30822bdfa1c549f2e14c3c28be887781b505ea15a01fa58af2bfecdc89953723a1a441270a0125e04de
6
+ metadata.gz: dbd8b9392b49ef932faccce27cf2a35f57b06a708229c1bdee6863af8683849a71bd1882d715a11bc3e878ea21e102e81fefc11ddaf400d1c4ebdb4ad78980fe
7
+ data.tar.gz: 9cca0d91346a11e90882a3f347c23f1e94165eb0d6f68673980e383fb65258510176ce951d06c6d5bb28595ada58b3a99570c3ed75c1d9d171538a64d683f6ab
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pagseguro-transparente (0.2.3)
4
+ pagseguro-transparente (0.2.4)
5
5
  activemodel
6
6
  httparty (~> 0.13)
7
7
  i18n (~> 0.6)
@@ -3,18 +3,22 @@ module PagSeguro
3
3
  include ActiveModel::Validations
4
4
 
5
5
  validates_presence_of :type, :value
6
+ validates_inclusion_of :type, in: %w(CPF CNPJ)
6
7
 
7
8
  # Set the document type
8
- # Only CPF is acceptable
9
+ # CPF or CNPJ is acceptable
9
10
  attr_accessor :type
10
11
 
11
12
  # Set the document number.
12
- # Must have 7-9 numbers.
13
13
  attr_accessor :value
14
14
 
15
- def initialize(value)
16
- @type = 'CPF'
15
+ def initialize(value, type = 'CPF')
16
+ @type = type
17
17
  @value = value
18
18
  end
19
+
20
+ def cpf?
21
+ type == "CPF"
22
+ end
19
23
  end
20
24
  end
@@ -67,13 +67,21 @@ module PagSeguro
67
67
  return unless sender
68
68
 
69
69
  params[:senderName] = sender.name
70
- params[:senderCPF] = sender.document.value
71
70
  params[:senderEmail] = sender.email
72
71
  params[:senderHash] = sender.hash_id
73
72
 
73
+ serialize_document(sender.document)
74
74
  serialize_phone(sender.phone)
75
75
  end
76
76
 
77
+ def serialize_document(document)
78
+ if document.cpf?
79
+ params[:senderCPF] = document.value
80
+ else
81
+ params[:senderCNPJ] = document.value
82
+ end
83
+ end
84
+
77
85
  def serialize_phone(phone)
78
86
  return unless phone
79
87
 
@@ -81,6 +89,7 @@ module PagSeguro
81
89
  params[:senderPhone] = phone.number
82
90
  end
83
91
 
92
+
84
93
  def serialize_bank(bank)
85
94
  return unless bank
86
95
 
@@ -1,3 +1,3 @@
1
1
  module PagSeguro
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -6,6 +6,7 @@ describe PagSeguro::Document do
6
6
 
7
7
  it { should respond_to(:type) }
8
8
  it { should respond_to(:value) }
9
+ it { should respond_to(:cpf?) }
9
10
 
10
11
  describe 'presence validations' do
11
12
  it { should validate_presence_of(:type) }
@@ -15,4 +16,20 @@ describe PagSeguro::Document do
15
16
  describe 'set default country' do
16
17
  its(:type) { should eq('CPF') }
17
18
  end
19
+
20
+ describe 'inclusion validations' do
21
+ let(:types) { %w(CPF CNPJ) }
22
+ it { should ensure_inclusion_of(:type).in_array(types) }
23
+ end
24
+
25
+ describe '#cpf' do
26
+ context 'with CPF' do
27
+ its(:cpf?) { should be_true }
28
+ end
29
+
30
+ context 'with CNPJ' do
31
+ let(:document) { PagSeguro::Document.new('017.345.345-00', 'CNPJ') }
32
+ its(:cpf?) { should be_false }
33
+ end
34
+ end
18
35
  end
@@ -144,4 +144,10 @@ describe PagSeguro::Payment::Serializer do
144
144
 
145
145
  it { subject[:creditCardHolderBirthDate].should eq(nil) }
146
146
  end
147
+
148
+ context 'with CNPJ' do
149
+ let(:document) { PagSeguro::Document.new('22111944785', 'CNPJ') }
150
+
151
+ it { subject[:senderCNPJ].should eq('22111944785') }
152
+ end
147
153
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagseguro-transparente
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cirdes Henrique
@@ -277,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
277
  version: '0'
278
278
  requirements: []
279
279
  rubyforge_project:
280
- rubygems_version: 2.2.2
280
+ rubygems_version: 2.4.3
281
281
  signing_key:
282
282
  specification_version: 4
283
283
  summary: Integração com o novo checkout transparente do Pagseguro.