Skip to content

Commit

Permalink
Merge pull request #53 from pagseguro/sender-documents
Browse files Browse the repository at this point in the history
Sender documents
  • Loading branch information
lucasrenan committed Mar 19, 2015
2 parents 55a1929 + 7d541bc commit 87899d3
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/transaction_by_notification_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
puts " name: #{transaction.sender.name}"
puts " email: #{transaction.sender.email}"
puts " phone: (#{transaction.sender.phone.area_code}) #{transaction.sender.phone.number}"
puts " document: #{transaction.sender.document.type}: #{transaction.sender.document.value}"

puts " => Shipping"
puts " street: #{transaction.shipping.address.street}, #{transaction.shipping.address.number}"
Expand Down
1 change: 1 addition & 0 deletions lib/pagseguro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require "pagseguro/errors"
require "pagseguro/exceptions"
require "pagseguro/address"
require "pagseguro/document"
require "pagseguro/shipping"
require "pagseguro/phone"
require "pagseguro/installment"
Expand Down
11 changes: 11 additions & 0 deletions lib/pagseguro/document.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module PagSeguro
class Document
include Extensions::MassAssignment

# the type of the document
attr_accessor :type

# the value of the document
attr_accessor :value
end
end
8 changes: 8 additions & 0 deletions lib/pagseguro/sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class Sender
# Get the sender phone.
attr_reader :phone

# Get the sender document
attr_reader :document

# Set the sender name.
attr_accessor :name

Expand All @@ -19,5 +22,10 @@ class Sender
def phone=(phone)
@phone = ensure_type(Phone, phone)
end

# Set the sender document.
def document=(document)
@document = ensure_type(Document, document)
end
end
end
2 changes: 2 additions & 0 deletions lib/pagseguro/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ def shipping=(shipping)
@shipping = ensure_type(Shipping, shipping)
end

# Hold the transaction's payments
def payment_releases
@payment_releases ||= PaymentReleases.new
end

# Normalize the transaction's payments list
def payment_releases=(_payments)
_payments.each { |payment| payment_releases << payment }
end
Expand Down
8 changes: 8 additions & 0 deletions lib/pagseguro/transaction/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,17 @@ def serialize_sender(data)
}

serialize_phone(sender)
serialize_document(sender)
data[:sender] = sender
end

def serialize_document(data)
data[:document] = {
type: xml.css("sender > documents > document > type").text,
value: xml.css("sender > documents > document > value").text
}
end

def serialize_phone(data)
data[:phone] = {
area_code: xml.css("sender > phone > areaCode").text,
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/transactions/success.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
<areaCode>11</areaCode>
<number>12345678</number>
</phone>
<documents>
<document>
<type>CPF</type>
<value>65647162142</value>
</document>
</documents>
</sender>
<shipping>
<address>
Expand Down
6 changes: 6 additions & 0 deletions spec/pagseguro/document_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

describe PagSeguro::Document do
it_assigns_attribute :type
it_assigns_attribute :value
end
1 change: 1 addition & 0 deletions spec/pagseguro/sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
it_assigns_attribute :email
it_assigns_attribute :cpf
it_ensures_type PagSeguro::Phone, :phone
it_ensures_type PagSeguro::Document, :document
end

2 changes: 2 additions & 0 deletions spec/pagseguro/transaction/serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
it { expect(data[:sender]).to include(email: "[email protected]") }
it { expect(data[:sender][:phone]).to include(area_code: "11") }
it { expect(data[:sender][:phone]).to include(number: "12345678") }
it { expect(data[:sender][:document]).to include(type: "CPF") }
it { expect(data[:sender][:document]).to include(value: "65647162142") }

it { expect(data[:shipping]).to include(type_id: "2") }

Expand Down

0 comments on commit 87899d3

Please sign in to comment.