pagseguro-oficial 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +17 -1
  4. data/Gemfile +0 -2
  5. data/README.md +1 -1
  6. data/docs/transparent_checkout.md +3 -3
  7. data/examples/authorization/create_authorization.rb +32 -0
  8. data/examples/authorization/create_authorization_with_account.rb +56 -0
  9. data/examples/authorization/{authorization_by_code.rb → search/search_authorization_by_code.rb} +4 -4
  10. data/examples/authorization/search/search_authorization_by_date.rb +35 -0
  11. data/examples/authorization/{authorization_by_notification_code.rb → search/search_authorization_by_notification_code.rb} +4 -5
  12. data/examples/authorization/search/search_authorization_by_reference.rb +31 -0
  13. data/examples/{payment_request.rb → checkout/create_payment_request.rb} +5 -7
  14. data/examples/{transaction/abandoned_transactions.rb → checkout/search/search_abandoned_transactions.rb} +6 -3
  15. data/examples/{transaction/transaction_by_code.rb → checkout/search/search_transaction_by_code.rb} +3 -3
  16. data/examples/{transaction/transaction_by_notification_code.rb → checkout/search/search_transaction_by_notification_code.rb} +3 -3
  17. data/examples/{transaction/transaction_by_reference.rb → checkout/search/search_transaction_by_reference.rb} +3 -3
  18. data/examples/{transaction/transaction_status_history.rb → checkout/search/search_transaction_status_history.rb} +2 -2
  19. data/examples/{transaction/transactions_by_date.rb → checkout/search/search_transactions_by_date.rb} +3 -3
  20. data/examples/{transaction/boleto_transaction_request.rb → direct/create_transaction_using_boleto.rb} +1 -1
  21. data/examples/{transaction/credit_card_transaction_request.rb → direct/create_transaction_using_credit_card.rb} +1 -1
  22. data/examples/{transaction/online_debit_transaction.rb → direct/create_transaction_using_online_debit.rb} +1 -1
  23. data/examples/{installment.rb → get_installments.rb} +3 -3
  24. data/examples/{transaction/transaction_cancellation.rb → request_transaction_cancellation.rb} +2 -2
  25. data/examples/{authorization/authorization.rb → split_payment/create_authorization.rb} +5 -4
  26. data/examples/split_payment/create_payment_request.rb +71 -0
  27. data/lib/pagseguro.rb +14 -8
  28. data/lib/pagseguro/account.rb +29 -0
  29. data/lib/pagseguro/authorization.rb +10 -4
  30. data/lib/pagseguro/authorization/collection.rb +3 -1
  31. data/lib/pagseguro/authorization/request_serializer.rb +6 -6
  32. data/lib/pagseguro/authorization/response.rb +2 -2
  33. data/lib/pagseguro/authorization_request.rb +16 -4
  34. data/lib/pagseguro/authorization_request/request_serializer.rb +127 -15
  35. data/lib/pagseguro/authorization_request/response.rb +2 -2
  36. data/lib/pagseguro/company.rb +41 -0
  37. data/lib/pagseguro/document.rb +4 -0
  38. data/lib/pagseguro/documents.rb +5 -0
  39. data/lib/pagseguro/errors.rb +27 -5
  40. data/lib/pagseguro/extensions/collection_object.rb +34 -0
  41. data/lib/pagseguro/item.rb +4 -0
  42. data/lib/pagseguro/items.rb +10 -17
  43. data/lib/pagseguro/partner.rb +20 -0
  44. data/lib/pagseguro/payment_request.rb +30 -2
  45. data/lib/pagseguro/payment_request/{serializer.rb → request_serializer.rb} +86 -1
  46. data/lib/pagseguro/person.rb +40 -0
  47. data/lib/pagseguro/phone.rb +8 -0
  48. data/lib/pagseguro/phones.rb +5 -0
  49. data/lib/pagseguro/receiver.rb +17 -0
  50. data/lib/pagseguro/receiver_split.rb +15 -0
  51. data/lib/pagseguro/request.rb +25 -1
  52. data/lib/pagseguro/transaction.rb +7 -5
  53. data/lib/pagseguro/transaction_cancellation.rb +3 -6
  54. data/lib/pagseguro/transaction_cancellation/response.rb +7 -6
  55. data/lib/pagseguro/{refund.rb → transaction_refund.rb} +2 -2
  56. data/lib/pagseguro/{refund → transaction_refund}/request_serializer.rb +1 -1
  57. data/lib/pagseguro/{refund → transaction_refund}/response.rb +9 -9
  58. data/lib/pagseguro/{refund → transaction_refund}/response_serializer.rb +1 -1
  59. data/lib/pagseguro/transaction_request.rb +1 -4
  60. data/lib/pagseguro/transaction_request/response.rb +8 -7
  61. data/lib/pagseguro/version.rb +1 -1
  62. data/locales/pt-BR.yml +1 -0
  63. data/pagseguro-oficial.gemspec +13 -13
  64. data/spec/fixtures/authorization/search_authorization.xml +47 -0
  65. data/spec/fixtures/authorization_request/authorization_request.xml +11 -0
  66. data/spec/fixtures/authorization_request/authorization_request_with_account.xml +47 -0
  67. data/spec/pagseguro/account_spec.rb +27 -0
  68. data/spec/pagseguro/authorization/collection_spec.rb +3 -3
  69. data/spec/pagseguro/authorization/request_serializer_spec.rb +1 -2
  70. data/spec/pagseguro/authorization/response_spec.rb +70 -15
  71. data/spec/pagseguro/authorization_request/request_serializer_spec.rb +314 -14
  72. data/spec/pagseguro/authorization_request_spec.rb +96 -31
  73. data/spec/pagseguro/authorization_spec.rb +52 -10
  74. data/spec/pagseguro/company_spec.rb +12 -0
  75. data/spec/pagseguro/documents_spec.rb +37 -0
  76. data/spec/pagseguro/errors_spec.rb +45 -6
  77. data/spec/pagseguro/extensions/collection_object_spec.rb +77 -0
  78. data/spec/pagseguro/features/create_transaction_request_spec.rb +2 -2
  79. data/spec/pagseguro/installment/response_spec.rb +5 -3
  80. data/spec/pagseguro/installment_spec.rb +5 -2
  81. data/spec/pagseguro/items_spec.rb +104 -12
  82. data/spec/pagseguro/pagseguro_spec.rb +8 -8
  83. data/spec/pagseguro/partner_spec.rb +8 -0
  84. data/spec/pagseguro/payment_request/request_serializer_spec.rb +251 -0
  85. data/spec/pagseguro/payment_request_spec.rb +67 -11
  86. data/spec/pagseguro/person_spec.rb +10 -0
  87. data/spec/pagseguro/phones_spec.rb +38 -0
  88. data/spec/pagseguro/receiver_spec.rb +6 -0
  89. data/spec/pagseguro/receiver_split_spec.rb +7 -0
  90. data/spec/pagseguro/request_spec.rb +27 -4
  91. data/spec/pagseguro/session/response_spec.rb +6 -2
  92. data/spec/pagseguro/session_spec.rb +5 -2
  93. data/spec/pagseguro/transaction/response_spec.rb +14 -8
  94. data/spec/pagseguro/transaction/search_spec.rb +15 -8
  95. data/spec/pagseguro/transaction_cancellation/response_spec.rb +6 -3
  96. data/spec/pagseguro/transaction_cancellation_spec.rb +7 -5
  97. data/spec/pagseguro/{refund → transaction_refund}/request_serializer_spec.rb +3 -3
  98. data/spec/pagseguro/{refund → transaction_refund}/response_serializer_spec.rb +1 -1
  99. data/spec/pagseguro/{refund → transaction_refund}/response_spec.rb +3 -3
  100. data/spec/pagseguro/{refund_spec.rb → transaction_refund_spec.rb} +15 -7
  101. data/spec/pagseguro/transaction_request/request_serializer_spec.rb +9 -9
  102. data/spec/pagseguro/transaction_request/response_spec.rb +5 -2
  103. data/spec/pagseguro/transaction_request_spec.rb +14 -9
  104. data/spec/pagseguro/transaction_spec.rb +37 -30
  105. data/spec/spec_helper.rb +0 -3
  106. data/spec/support/ensure_type_macro.rb +20 -2
  107. data/{examples/refund.rb → transaction/transaction_refund.rb} +1 -1
  108. metadata +112 -96
  109. data/examples/transaction/invalid_transaction_by_notification_code.rb +0 -22
  110. data/lib/pagseguro/refund/serializer.rb +0 -24
  111. data/lib/pagseguro/transaction_cancellation/serializer.rb +0 -18
  112. data/spec/pagseguro/payment_request/serializer_spec.rb +0 -166
  113. data/spec/pagseguro/refund/serializer_spec.rb +0 -15
  114. data/spec/pagseguro/transaction_cancellation/serializer_spec.rb +0 -13
@@ -1,6 +1,6 @@
1
- require_relative "../boot"
1
+ require_relative "boot"
2
2
 
3
- # Transaction cancellation
3
+ # Request Transaction Cancellation
4
4
  #
5
5
  # You need:
6
6
  # - give TRANSACTION CODE to TransactionCancellation#transaction_code
@@ -1,6 +1,6 @@
1
1
  require_relative "../boot"
2
2
 
3
- # Authorization
3
+ # Create Authorization
4
4
  #
5
5
  # You need to give:
6
6
  # - notification_url
@@ -8,7 +8,7 @@ require_relative "../boot"
8
8
  # - permissions defaults to all permissions
9
9
  # - applications credentials (APP_ID, APP_KEY)
10
10
  #
11
- # You can pass this parameters to PagSeguro::AuthorizationRequest#new
11
+ # You can pass these parameters to PagSeguro::AuthorizationRequest#new
12
12
  #
13
13
  # PS: For more details look the class PagSeguro::AuthorizationRequest
14
14
 
@@ -16,9 +16,10 @@ credentials = PagSeguro::ApplicationCredentials.new('APP_ID', 'APP_KEY')
16
16
 
17
17
  options = {
18
18
  credentials: credentials, # Unnecessary if you set in application config
19
- permissions: [:searches, :notifications],
19
+ permissions: [:checkouts],
20
20
  notification_url: 'http://example.com/',
21
- redirect_url: 'http://example.com/'
21
+ redirect_url: 'http://example.com/',
22
+ reference: 'REF4321' # optional
22
23
  }
23
24
 
24
25
  authorization_request = PagSeguro::AuthorizationRequest.new(options)
@@ -0,0 +1,71 @@
1
+ require_relative "../boot"
2
+
3
+ # Create Split Payment.
4
+ #
5
+ # You need to set your ApplicationCredentials (EMAIL, TOKEN) in the application
6
+ # config.
7
+ #
8
+ # P.S: See the boot file example for more details.
9
+
10
+ payment = PagSeguro::PaymentRequest.new
11
+ payment.abandon_url = "http://example.com/?abandoned"
12
+ payment.notification_url = "http://example.com/?notification"
13
+ payment.redirect_url = "http://example.com/?redirect"
14
+
15
+ # If you don't want to use the application config, you can give your credentials
16
+ # object to payment request.
17
+
18
+ payment.credentials = PagSeguro::ApplicationCredentials.new('APP_ID', 'APP_KEY')
19
+
20
+ payment.items << {
21
+ id: 1234,
22
+ description: %[Televisão 19" Sony],
23
+ quantity: 1,
24
+ amount: 459.50,
25
+ shipping_cost: 0.0,
26
+ weight: 0
27
+ }
28
+
29
+ payment.primary_receiver = 'primary.receiver@example.com'
30
+
31
+ payment.receivers = [
32
+ {
33
+ email: 'other.receiver@example.com',
34
+ split: { amount: '400.00', },
35
+ }
36
+ ]
37
+
38
+ payment.reference = "REF1234"
39
+ payment.sender = {
40
+ name: "Sender One",
41
+ email: "sender@example.com",
42
+ cpf: "21639716866",
43
+ phone: {
44
+ area_code: 11,
45
+ number: "12345678"
46
+ }
47
+ }
48
+
49
+ payment.shipping = {
50
+ type_name: "sedex",
51
+ address: {
52
+ street: "R. Vergueiro",
53
+ number: 1421,
54
+ complement: "Sala 213",
55
+ city: "São Paulo",
56
+ state: "SP",
57
+ district: "Vila Mariana"
58
+ }
59
+ }
60
+
61
+ puts "=> REQUEST"
62
+ puts PagSeguro::PaymentRequest::RequestSerializer.new(payment).to_xml_params
63
+
64
+ response = payment.register
65
+
66
+ puts
67
+ puts "=> RESPONSE"
68
+ puts response.url
69
+ puts response.code
70
+ puts response.created_at
71
+ puts response.errors.to_a
data/lib/pagseguro.rb CHANGED
@@ -9,6 +9,7 @@ require "i18n"
9
9
  require "pagseguro/extensions/mass_assignment"
10
10
  require "pagseguro/extensions/ensure_type"
11
11
  require "pagseguro/extensions/credentiable"
12
+ require "pagseguro/extensions/collection_object"
12
13
 
13
14
  require "pagseguro/version"
14
15
  require "pagseguro/config"
@@ -29,8 +30,14 @@ require "pagseguro/errors"
29
30
  require "pagseguro/exceptions"
30
31
  require "pagseguro/address"
31
32
  require "pagseguro/document"
33
+ require "pagseguro/documents"
32
34
  require "pagseguro/shipping"
33
35
  require "pagseguro/phone"
36
+ require "pagseguro/phones"
37
+ require "pagseguro/person"
38
+ require "pagseguro/partner"
39
+ require "pagseguro/company"
40
+ require "pagseguro/account"
34
41
  require "pagseguro/installment"
35
42
  require "pagseguro/installment/collection"
36
43
  require "pagseguro/installment/response"
@@ -40,21 +47,21 @@ require "pagseguro/item"
40
47
  require "pagseguro/items"
41
48
  require "pagseguro/bank"
42
49
  require "pagseguro/holder"
43
- require "pagseguro/document"
44
50
  require "pagseguro/payment_method"
45
51
  require "pagseguro/payment_release"
46
52
  require "pagseguro/payment_releases"
47
53
  require "pagseguro/payment_request"
48
- require "pagseguro/payment_request/serializer"
54
+ require "pagseguro/payment_request/request_serializer"
49
55
  require "pagseguro/payment_request/response"
50
56
  require "pagseguro/payment_status"
51
57
  require "pagseguro/permission"
52
58
  require "pagseguro/request"
53
- require "pagseguro/refund"
54
- require "pagseguro/refund/request_serializer"
55
- require "pagseguro/refund/response"
56
- require "pagseguro/refund/response_serializer"
57
- require "pagseguro/refund/serializer"
59
+ require "pagseguro/transaction_refund"
60
+ require "pagseguro/transaction_refund/request_serializer"
61
+ require "pagseguro/transaction_refund/response"
62
+ require "pagseguro/transaction_refund/response_serializer"
63
+ require "pagseguro/receiver"
64
+ require "pagseguro/receiver_split"
58
65
  require "pagseguro/sender"
59
66
  require "pagseguro/session"
60
67
  require "pagseguro/session/response"
@@ -72,7 +79,6 @@ require "pagseguro/transaction_cancellation"
72
79
  require "pagseguro/transaction_cancellation/request_serializer"
73
80
  require "pagseguro/transaction_cancellation/response"
74
81
  require "pagseguro/transaction_cancellation/response_serializer"
75
- require "pagseguro/transaction_cancellation/serializer"
76
82
  require "pagseguro/transaction/search"
77
83
  require "pagseguro/transaction/search/search_by_date"
78
84
  require "pagseguro/transaction/search/search_by_reference"
@@ -0,0 +1,29 @@
1
+ module PagSeguro
2
+ class Account
3
+ include Extensions::MassAssignment
4
+ include Extensions::EnsureType
5
+
6
+ # Set the account e-mail.
7
+ attr_accessor :email
8
+
9
+ # Set the account type.
10
+ # Must be PERSONAL, SELLER or COMPANY.
11
+ attr_accessor :type
12
+
13
+ # Get the person account.
14
+ attr_reader :person
15
+
16
+ # Get the company account.
17
+ attr_reader :company
18
+
19
+ def person=(person)
20
+ return if company
21
+ @person = ensure_type(Person, person)
22
+ end
23
+
24
+ def company=(company)
25
+ return if person
26
+ @company = ensure_type(Company, company)
27
+ end
28
+ end
29
+ end
@@ -17,7 +17,7 @@ module PagSeguro
17
17
 
18
18
  # Find an authorization by it's notification code
19
19
  def self.find_by_notification_code(code, options = {})
20
- request = Request.get("authorizations/notifications/#{code}", "v2", options)
20
+ request = Request.get("authorizations/notifications/#{code}", api_version, options)
21
21
  authorization = PagSeguro::Authorization.new
22
22
  Response.new(request, authorization).serialize
23
23
 
@@ -26,15 +26,15 @@ module PagSeguro
26
26
 
27
27
  # Find an authorization by it's code
28
28
  def self.find_by_code(code, options = {})
29
- request = Request.get("authorizations/#{code}", "v2", options)
29
+ request = Request.get("authorizations/#{code}", api_version, options)
30
30
  authorization = PagSeguro::Authorization.new
31
31
  Response.new(request, authorization).serialize
32
32
 
33
33
  authorization
34
34
  end
35
35
 
36
- def self.find_by_date(options)
37
- request = Request.get("authorizations", "v2", RequestSerializer.new(options).to_params)
36
+ def self.find_by(options)
37
+ request = Request.get("authorizations", api_version, RequestSerializer.new(options).to_params)
38
38
  collection = Collection.new
39
39
  Response.new(request, collection).serialize_collection
40
40
 
@@ -48,5 +48,11 @@ module PagSeguro
48
48
  def errors
49
49
  @errors ||= Errors.new
50
50
  end
51
+
52
+ private
53
+
54
+ def self.api_version
55
+ 'v2'
56
+ end
51
57
  end
52
58
  end
@@ -3,9 +3,11 @@ module PagSeguro
3
3
  class Collection
4
4
  extend Forwardable
5
5
 
6
+ attr_writer :authorizations
7
+
6
8
  def_delegators :@authorizations, :each, :empty?, :any?
7
9
 
8
- def initialize(options)
10
+ def initialize(options = {})
9
11
  @errors = options[:errors] if options[:errors]
10
12
  @authorizations = instantiate_authorizations(options[:authorizations])
11
13
  end
@@ -3,15 +3,15 @@ module PagSeguro
3
3
  class RequestSerializer
4
4
  attr_reader :authorization
5
5
 
6
- def initialize(authorization)
7
- @authorization = authorization
6
+ def initialize(options)
7
+ @options = options
8
8
  end
9
9
 
10
10
  def to_params
11
- params[:credentials] = authorization.credentials if authorization.respond_to? :credentials
12
- params[:initialDate] = authorization.initial_date if authorization.respond_to? :initial_date
13
- params[:finalDate] = authorization.final_date if authorization.respond_to? :final_date
14
-
11
+ params[:credentials] = @options[:credentials] if @options[:credentials]
12
+ params[:reference] = @options[:reference] if @options[:reference]
13
+ params[:initialDate] = @options[:initial_date].xmlschema if @options[:initial_date]
14
+ params[:finalDate] = @options[:final_date].xmlschema if @options[:final_date]
15
15
  params
16
16
  end
17
17
 
@@ -29,7 +29,7 @@ module PagSeguro
29
29
  end
30
30
 
31
31
  def success?
32
- (response.success? && response.xml?) ? true : false
32
+ response.success? && response.xml?
33
33
  end
34
34
 
35
35
  private
@@ -41,7 +41,7 @@ module PagSeguro
41
41
 
42
42
  def serialize_authorizations
43
43
  Nokogiri::XML(response.body).css('authorizations > authorization').map do |node|
44
- ResponseSerializer.new(node).serialize
44
+ Authorization.new(ResponseSerializer.new(node).serialize)
45
45
  end
46
46
  end
47
47
  end
@@ -1,6 +1,7 @@
1
1
  module PagSeguro
2
2
  class AuthorizationRequest
3
3
  include Extensions::MassAssignment
4
+ include Extensions::EnsureType
4
5
  include Extensions::Credentiable
5
6
 
6
7
  # The permissions given to the application
@@ -16,6 +17,9 @@ module PagSeguro
16
17
  # The url which the application is going to be redirected after the proccess
17
18
  attr_accessor :redirect_url
18
19
 
20
+ # The account that can be passed to register suggestion
21
+ attr_reader :account
22
+
19
23
  # The code used to confirm the authorization
20
24
  attr_reader :code
21
25
 
@@ -35,10 +39,14 @@ module PagSeguro
35
39
  cancels: 'CANCEL_TRANSACTIONS'
36
40
  }
37
41
 
42
+ def account=(account)
43
+ @account = ensure_type(Account, account)
44
+ end
45
+
38
46
  # Post and create an Authorization.
39
47
  # Return Boolean.
40
48
  def create
41
- request = Request.post('authorizations/request', 'v2', params)
49
+ request = Request.post_xml('authorizations/request', api_version, credentials, xml)
42
50
  response = Response.new(request)
43
51
  update_attributes(response.serialize)
44
52
 
@@ -47,7 +55,7 @@ module PagSeguro
47
55
 
48
56
  # URL to confirm authorization after create one.
49
57
  def url
50
- PagSeguro.site_url("v2/authorization/request.jhtml?code=#{code}") if code
58
+ PagSeguro.site_url("#{api_version}/authorization/request.jhtml?code=#{code}") if code
51
59
  end
52
60
 
53
61
  def errors
@@ -61,12 +69,16 @@ module PagSeguro
61
69
  self.permissions = PERMISSIONS.keys
62
70
  end
63
71
 
64
- def params
65
- RequestSerializer.new(self).to_params
72
+ def xml
73
+ RequestSerializer.new(self).build_xml
66
74
  end
67
75
 
68
76
  def update_attributes(attrs)
69
77
  attrs.each { |method, value| send("#{method}=", value) }
70
78
  end
79
+
80
+ def api_version
81
+ 'v2'
82
+ end
71
83
  end
72
84
  end
@@ -1,29 +1,141 @@
1
1
  module PagSeguro
2
2
  class AuthorizationRequest
3
3
  class RequestSerializer
4
- attr_reader :authorization_request
5
4
 
6
- def initialize(authorization_request)
7
- @authorization_request = authorization_request
8
- end
5
+ attr_accessor :request
9
6
 
10
- def to_params
11
- params[:credentials] = authorization_request.credentials if authorization_request.credentials
12
- params[:notificationURL] = authorization_request.notification_url
13
- params[:redirectURL] = authorization_request.redirect_url
14
- params[:permissions] = serialize_permissions(authorization_request.permissions)
15
- params[:reference] = authorization_request.reference if authorization_request.reference
7
+ def initialize(request)
8
+ @request = request
9
+ @builder = Nokogiri::XML::Builder
10
+ end
16
11
 
17
- params
12
+ def build_xml
13
+ build.to_xml(save_with:
14
+ Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS |
15
+ Nokogiri::XML::Node::SaveOptions::FORMAT
16
+ )
18
17
  end
19
18
 
20
19
  private
21
- def params
22
- @params ||= {}
20
+
21
+ attr_reader :builder
22
+
23
+ def build
24
+ builder.new(encoding: PagSeguro.encoding) do |xml|
25
+ xml.send(:authorizationRequest) {
26
+ xml.send(:reference, request.reference) if request.reference
27
+ xml.send(:redirectURL, request.redirect_url)
28
+ xml.send(:notificationURL, request.notification_url)
29
+ serialize_permissions(xml, request.permissions)
30
+ serialize_account(xml, request.account)
31
+ }
32
+ end
33
+ end
34
+
35
+ def serialize_permissions(xml, permissions)
36
+ return unless permissions.any?
37
+ xml.send(:permissions) {
38
+ format_permissions(permissions).each do |permission|
39
+ xml.send(:code, permission)
40
+ end
41
+ }
42
+ end
43
+
44
+ def format_permissions(permissions)
45
+ permissions.map { |value| PagSeguro::AuthorizationRequest::PERMISSIONS[value] }
46
+ end
47
+
48
+ def serialize_account(xml, account)
49
+ return unless account
50
+
51
+ xml.send(:account) {
52
+ xml.send(:email, account.email) if account.email
53
+ xml.send(:type, account.type) if account.type
54
+
55
+ if account.person
56
+ serialize_person(xml, account.person)
57
+ elsif account.company
58
+ serialize_company(xml, account.company)
59
+ end
60
+ }
61
+ end
62
+
63
+ def serialize_person(xml, person)
64
+ return unless person
65
+
66
+ xml.send(:person) {
67
+ xml.send(:name, person.name) if person.name
68
+ xml.send(:birthDate, person.birth_date.to_s) if person.birth_date
69
+ serialize_address(xml, person.address)
70
+ serialize_documents(xml, person.documents)
71
+ serialize_phones(xml, person.phones)
72
+ }
73
+ end
74
+
75
+ def serialize_company(xml, company)
76
+ return unless company
77
+
78
+ xml.send(:company) {
79
+ xml.send(:name, company.name) if company.name
80
+ xml.send(:displayName, company.display_name) if company.display_name
81
+ xml.send(:websiteURL, company.website_url) if company.website_url
82
+ serialize_partner(xml, company.partner)
83
+ serialize_phones(xml, company.phones)
84
+ serialize_documents(xml, company.documents)
85
+ serialize_address(xml, company.address)
86
+ }
87
+ end
88
+
89
+ def serialize_address(xml, address)
90
+ return unless address
91
+
92
+ xml.send(:address) {
93
+ xml.send(:postalCode, address.postal_code) if address.postal_code
94
+ xml.send(:street, address.street) if address.street
95
+ xml.send(:number, address.number) if address.number
96
+ xml.send(:complement, address.complement) if address.complement
97
+ xml.send(:district, address.district) if address.district
98
+ xml.send(:city, address.city) if address.city
99
+ xml.send(:state, address.state) if address.state
100
+ xml.send(:country, address.country) if address.country
101
+ }
23
102
  end
24
103
 
25
- def serialize_permissions(permissions)
26
- permissions.map { |value| PagSeguro::AuthorizationRequest::PERMISSIONS[value] }.join(',')
104
+ def serialize_phones(xml, phones)
105
+ return unless phones.any?
106
+
107
+ xml.send(:phones) {
108
+ phones.each do |phone|
109
+ xml.send(:phone) {
110
+ xml.send(:type, phone.type)
111
+ xml.send(:areaCode, phone.area_code)
112
+ xml.send(:number, phone.number)
113
+ }
114
+ end
115
+ }
116
+ end
117
+
118
+ def serialize_documents(xml, documents)
119
+ return unless documents.any?
120
+
121
+ xml.send(:documents) {
122
+ documents.each do |document|
123
+ xml.send(:document) {
124
+ xml.send(:type, document.type)
125
+ xml.send(:value, document.value)
126
+ }
127
+ end
128
+ }
129
+ end
130
+
131
+ def serialize_partner(xml, partner)
132
+ return unless partner
133
+
134
+ xml.send(:partner) {
135
+ xml.send(:name, partner.name) if partner.name
136
+ xml.send(:birthDate, partner.birth_date.to_s) if partner.birth_date
137
+ serialize_documents(xml, partner.documents)
138
+ }
27
139
  end
28
140
  end
29
141
  end