Class: PagSeguro::PaymentRequest::RequestSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/pagseguro/payment_request/request_serializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payment_request) ⇒ RequestSerializer

Returns a new instance of RequestSerializer.



7
8
9
# File 'lib/pagseguro/payment_request/request_serializer.rb', line 7

def initialize(payment_request)
  @payment_request = payment_request
end

Instance Attribute Details

#payment_requestObject (readonly)

The payment request that will be serialized.



5
6
7
# File 'lib/pagseguro/payment_request/request_serializer.rb', line 5

def payment_request
  @payment_request
end

Instance Method Details

#to_paramsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pagseguro/payment_request/request_serializer.rb', line 19

def to_params
  {}.tap do |data|
    data[:receiverEmail] = PagSeguro.receiver_email
    data[:currency] = payment_request.currency
    data[:reference] = payment_request.reference
    data[:extraAmount] = to_amount(payment_request.extra_amount)
    data[:redirectURL] = payment_request.redirect_url
    data[:notificationURL] = payment_request.notification_url
    data[:abandonURL] = payment_request.abandon_url
    data[:maxUses] = payment_request.max_uses
    data[:maxAge] = payment_request.max_age
    data[:credentials] = payment_request.credentials
    payment_request.items.each_with_index do |item, index|
      serialize_item(data, item, index.succ)
    end

    serialize_sender(data, payment_request.sender)
    serialize_shipping(data, payment_request.shipping)
    serialize_receivers(data, payment_request.receivers)
    serialize_extra_params(data, payment_request.extra_params)
  end.delete_if { |_, value| value.nil? }
end

#to_xml_paramsObject



11
12
13
14
15
16
17
# File 'lib/pagseguro/payment_request/request_serializer.rb', line 11

def to_xml_params
  xml_builder.to_xml(
    save_with:
    Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS |
    Nokogiri::XML::Node::SaveOptions::FORMAT
  )
end