pagseguro-oficial 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/CONTRIBUTING.md +39 -0
- data/Dockerfile +20 -0
- data/README.md +22 -0
- data/docker-compose.yml +5 -0
- data/examples/checkout/create_payment_request.rb +1 -1
- data/examples/direct/create_transaction_using_boleto.rb +1 -1
- data/examples/direct/create_transaction_using_credit_card.rb +1 -1
- data/examples/direct/create_transaction_using_online_debit.rb +1 -1
- data/examples/preapproval/cancel_preapproval.rb +26 -0
- data/examples/preapproval/change_preapproval_payment.rb +50 -0
- data/examples/preapproval/change_preapproval_status.rb +29 -0
- data/examples/preapproval/charge_preapproval.rb +36 -0
- data/examples/preapproval/create_preapproval.rb +68 -0
- data/examples/preapproval/create_preapproval_auto.rb +53 -0
- data/examples/preapproval/create_preapproval_discount.rb +30 -0
- data/examples/preapproval/create_preapproval_manual.rb +58 -0
- data/examples/preapproval/create_preapproval_transparent.rb +41 -0
- data/examples/preapproval/preapproval_retry.rb +29 -0
- data/examples/preapproval/search/search_by_date_interval.rb +45 -0
- data/examples/preapproval/search/search_by_days_interval.rb +46 -0
- data/examples/preapproval/search/search_by_notification_code.rb +50 -0
- data/examples/preapproval/search/search_by_subscription_code.rb +50 -0
- data/examples/preapproval/search/search_subscription_payment_orders.rb +53 -0
- data/examples/split_payment/create_payment_request.rb +1 -1
- data/examples/split_payment/create_transaction_using_boleto.rb +118 -0
- data/examples/split_payment/create_transaction_using_credit_card.rb +152 -0
- data/lib/pagseguro.rb +33 -1
- data/lib/pagseguro/credit_card_transaction_request.rb +1 -1
- data/lib/pagseguro/document.rb +8 -0
- data/lib/pagseguro/holder.rb +8 -0
- data/lib/pagseguro/manual_subscription_charger.rb +59 -0
- data/lib/pagseguro/manual_subscription_charger/request_serializer.rb +50 -0
- data/lib/pagseguro/manual_subscription_charger/response.rb +36 -0
- data/lib/pagseguro/manual_subscription_charger/response_serializer.rb +17 -0
- data/lib/pagseguro/payment_request/request_serializer.rb +25 -1
- data/lib/pagseguro/receiver.rb +3 -0
- data/lib/pagseguro/request.rb +32 -2
- data/lib/pagseguro/sender.rb +21 -3
- data/lib/pagseguro/subscription.rb +132 -0
- data/lib/pagseguro/subscription/request_serializer.rb +129 -0
- data/lib/pagseguro/subscription/response.rb +49 -0
- data/lib/pagseguro/subscription/response_serializer.rb +62 -0
- data/lib/pagseguro/subscription/subscription_search.rb +135 -0
- data/lib/pagseguro/subscription_canceller.rb +30 -0
- data/lib/pagseguro/subscription_canceller/response.rb +34 -0
- data/lib/pagseguro/subscription_change_payment.rb +46 -0
- data/lib/pagseguro/subscription_change_payment/request_serializer.rb +80 -0
- data/lib/pagseguro/subscription_change_payment/response.rb +26 -0
- data/lib/pagseguro/subscription_change_status.rb +50 -0
- data/lib/pagseguro/subscription_change_status/request_serializer.rb +28 -0
- data/lib/pagseguro/subscription_change_status/response.rb +26 -0
- data/lib/pagseguro/subscription_discount.rb +41 -0
- data/lib/pagseguro/subscription_discount/request_serializer.rb +34 -0
- data/lib/pagseguro/subscription_discount/response.rb +34 -0
- data/lib/pagseguro/subscription_payment_method.rb +21 -0
- data/lib/pagseguro/subscription_payment_order.rb +57 -0
- data/lib/pagseguro/subscription_payment_order/response.rb +37 -0
- data/lib/pagseguro/subscription_payment_order/response_serializer.rb +51 -0
- data/lib/pagseguro/subscription_plan.rb +69 -0
- data/lib/pagseguro/subscription_plan/request_serializer.rb +81 -0
- data/lib/pagseguro/subscription_plan/response.rb +36 -0
- data/lib/pagseguro/subscription_plan/response_serializer.rb +17 -0
- data/lib/pagseguro/subscription_retry.rb +35 -0
- data/lib/pagseguro/subscription_retry/response.rb +34 -0
- data/lib/pagseguro/subscription_search_payment_orders.rb +131 -0
- data/lib/pagseguro/subscription_transaction.rb +29 -0
- data/lib/pagseguro/subscription_transactions.rb +5 -0
- data/lib/pagseguro/transaction.rb +0 -10
- data/lib/pagseguro/transaction/serializer.rb +19 -2
- data/lib/pagseguro/transaction_request.rb +26 -1
- data/lib/pagseguro/transaction_request/request_serializer.rb +164 -1
- data/lib/pagseguro/version.rb +1 -1
- data/spec/fixtures/manual_subscription_charger/fail.xml +6 -0
- data/spec/fixtures/manual_subscription_charger/success.xml +4 -0
- data/spec/fixtures/subscription/fail.xml +6 -0
- data/spec/fixtures/subscription/find_success.xml +28 -0
- data/spec/fixtures/subscription/search_success.xml +18 -0
- data/spec/fixtures/subscription/success.xml +4 -0
- data/spec/fixtures/subscription_canceller/fail.xml +6 -0
- data/spec/fixtures/subscription_change_payment/fail.xml +7 -0
- data/spec/fixtures/subscription_change_status/fail.xml +7 -0
- data/spec/fixtures/subscription_discount/fail.xml +6 -0
- data/spec/fixtures/subscription_payment_order/success.xml +18 -0
- data/spec/fixtures/subscription_plan/fail.xml +6 -0
- data/spec/fixtures/subscription_plan/success.xml +4 -0
- data/spec/fixtures/subscription_retry/fail.xml +7 -0
- data/spec/fixtures/subscription_search_payment_orders/success.xml +43 -0
- data/spec/fixtures/transactions/without_status_and_type.xml +71 -0
- data/spec/pagseguro/credit_card_transaction_request_spec.rb +1 -1
- data/spec/pagseguro/document_spec.rb +15 -0
- data/spec/pagseguro/holder_spec.rb +1 -0
- data/spec/pagseguro/manual_subscription_charger/request_serializer_spec.rb +79 -0
- data/spec/pagseguro/manual_subscription_charger/response_serializer_spec.rb +10 -0
- data/spec/pagseguro/manual_subscription_charger/response_spec.rb +65 -0
- data/spec/pagseguro/manual_subscription_charger_spec.rb +68 -0
- data/spec/pagseguro/payment_request/request_serializer_spec.rb +54 -22
- data/spec/pagseguro/receiver_spec.rb +1 -0
- data/spec/pagseguro/sender_spec.rb +16 -2
- data/spec/pagseguro/subscription/request_serializer_spec.rb +233 -0
- data/spec/pagseguro/subscription/response_serializer_spec.rb +46 -0
- data/spec/pagseguro/subscription/response_spec.rb +79 -0
- data/spec/pagseguro/subscription/subscription_search_spec.rb +154 -0
- data/spec/pagseguro/subscription_canceller/response_spec.rb +58 -0
- data/spec/pagseguro/subscription_canceller_spec.rb +57 -0
- data/spec/pagseguro/subscription_change_payment/request_serializer_spec.rb +150 -0
- data/spec/pagseguro/subscription_change_payment/response_spec.rb +41 -0
- data/spec/pagseguro/subscription_change_payment_spec.rb +60 -0
- data/spec/pagseguro/subscription_change_status/request_serializer_spec.rb +19 -0
- data/spec/pagseguro/subscription_change_status/response_spec.rb +41 -0
- data/spec/pagseguro/subscription_change_status_spec.rb +53 -0
- data/spec/pagseguro/subscription_discount/request_serializer_spec.rb +27 -0
- data/spec/pagseguro/subscription_discount/response_spec.rb +58 -0
- data/spec/pagseguro/subscription_discount_spec.rb +60 -0
- data/spec/pagseguro/subscription_payment_method_spec.rb +10 -0
- data/spec/pagseguro/subscription_payment_order/response_serializer_spec.rb +24 -0
- data/spec/pagseguro/subscription_payment_order/response_spec.rb +55 -0
- data/spec/pagseguro/subscription_payment_order_spec.rb +27 -0
- data/spec/pagseguro/subscription_plan/request_serializer_spec.rb +253 -0
- data/spec/pagseguro/subscription_plan/response_serializer_spec.rb +10 -0
- data/spec/pagseguro/subscription_plan/response_spec.rb +65 -0
- data/spec/pagseguro/subscription_plan_spec.rb +118 -0
- data/spec/pagseguro/subscription_retry/response_spec.rb +58 -0
- data/spec/pagseguro/subscription_retry_spec.rb +62 -0
- data/spec/pagseguro/subscription_search_payment_order_spec.rb +129 -0
- data/spec/pagseguro/subscription_spec.rb +137 -0
- data/spec/pagseguro/subscription_transaction_spec.rb +24 -0
- data/spec/pagseguro/subscription_transactions_spec.rb +37 -0
- data/spec/pagseguro/transaction/response_spec.rb +0 -42
- data/spec/pagseguro/transaction/serializer_spec.rb +5 -6
- data/spec/pagseguro/transaction_request/request_serializer_spec.rb +623 -159
- data/spec/pagseguro/transaction_request_spec.rb +26 -0
- data/spec/pagseguro/transaction_spec.rb +0 -48
- data/spec/spec_helper.rb +1 -0
- metadata +154 -8
- data/examples/checkout/search/search_transaction_status_history.rb +0 -22
- data/lib/pagseguro/transaction/status_collection.rb +0 -20
- data/spec/fixtures/transactions/status_history.xml +0 -12
- data/spec/pagseguro/transaction/status_collection_spec.rb +0 -43
@@ -0,0 +1,17 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionPlan
|
3
|
+
class ResponseSerializer
|
4
|
+
attr_reader :xml
|
5
|
+
|
6
|
+
def initialize(xml)
|
7
|
+
@xml = xml
|
8
|
+
end
|
9
|
+
|
10
|
+
def serialize
|
11
|
+
{}.tap do |data|
|
12
|
+
data[:code] = xml.css('preApprovalRequest > code').text
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionRetry
|
3
|
+
include Extensions::MassAssignment
|
4
|
+
include Extensions::Credentiable
|
5
|
+
|
6
|
+
attr_accessor :payment_order_code
|
7
|
+
attr_accessor :subscription_code
|
8
|
+
|
9
|
+
def errors
|
10
|
+
@errors ||= Errors.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def save
|
14
|
+
request = Request.post_xml(url, nil, credentials, nil, extra_options)
|
15
|
+
|
16
|
+
Response.new(request, self).serialize
|
17
|
+
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def url
|
24
|
+
"pre-approvals/#{subscription_code}/payment-orders/#{payment_order_code}/payment"
|
25
|
+
end
|
26
|
+
|
27
|
+
def extra_options
|
28
|
+
{ headers: { "Accept" => "application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1" }}
|
29
|
+
end
|
30
|
+
|
31
|
+
def after_initialize
|
32
|
+
@errors = Errors.new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionRetry
|
3
|
+
class Response
|
4
|
+
# The http response.
|
5
|
+
attr_reader :response
|
6
|
+
|
7
|
+
# Set the object that will receive errors or updates
|
8
|
+
attr_reader :object
|
9
|
+
|
10
|
+
def initialize(response, object)
|
11
|
+
@response = response
|
12
|
+
@object = object
|
13
|
+
end
|
14
|
+
|
15
|
+
def serialize
|
16
|
+
unless success?
|
17
|
+
object.errors.add response
|
18
|
+
end
|
19
|
+
|
20
|
+
object
|
21
|
+
end
|
22
|
+
|
23
|
+
def success?
|
24
|
+
response.success? && response.xml?
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def xml
|
30
|
+
Nokogiri::XML(response.body)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionSearchPaymentOrders
|
3
|
+
attr_reader :code
|
4
|
+
attr_reader :options
|
5
|
+
attr_reader :status
|
6
|
+
attr_reader :errors
|
7
|
+
attr_reader :page
|
8
|
+
|
9
|
+
def initialize(code, status, options={})
|
10
|
+
@code = code
|
11
|
+
@status = status
|
12
|
+
@options = options
|
13
|
+
@page = options.delete(:page) || 0
|
14
|
+
@errors = Errors.new
|
15
|
+
end
|
16
|
+
|
17
|
+
# Return the list of subscription payment orders.
|
18
|
+
# Each item will be wrapped in a PagSeguro::SubscriptionPaymentOrder instance.
|
19
|
+
def payment_orders
|
20
|
+
xml do |xml|
|
21
|
+
xml.css("paymentOrdersResult > paymentOrders > paymentOrder").map do |node|
|
22
|
+
SubscriptionPaymentOrder.load_from_xml(node)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# The report's creation date.
|
28
|
+
def created_at
|
29
|
+
xml do |xml|
|
30
|
+
@created_at ||= Time.parse xml.css("paymentOrdersResult > date").text
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# How many results the report returned on the given page.
|
35
|
+
def results
|
36
|
+
xml do |xml|
|
37
|
+
@results = xml.css("paymentOrdersResult > resultsInThisPage").text.to_i
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# How many pages the report returned.
|
42
|
+
def total_pages
|
43
|
+
xml do |xml|
|
44
|
+
@total_pages ||= xml.css("paymentOrdersResult > totalPages").text.to_i
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Detect if the report has a next page.
|
49
|
+
def next_page?
|
50
|
+
page.zero? || page < total_pages
|
51
|
+
end
|
52
|
+
|
53
|
+
# Detect if the report has a previous page.
|
54
|
+
def previous_page?
|
55
|
+
page > 1
|
56
|
+
end
|
57
|
+
|
58
|
+
# Move the page pointer to the next page.
|
59
|
+
def next_page!
|
60
|
+
return unless next_page?
|
61
|
+
@page += 1
|
62
|
+
clear!
|
63
|
+
end
|
64
|
+
|
65
|
+
# Move the page pointer to the previous page.
|
66
|
+
def previous_page!
|
67
|
+
return unless previous_page?
|
68
|
+
@page -= 1
|
69
|
+
clear!
|
70
|
+
end
|
71
|
+
|
72
|
+
# Detect if the report request returned errors.
|
73
|
+
def valid?
|
74
|
+
fetch { errors.empty? }
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
def perform_request_and_serialize
|
79
|
+
@response = Request.get_without_api_version(path, params, header)
|
80
|
+
@errors = Errors.new(@response)
|
81
|
+
end
|
82
|
+
|
83
|
+
def path
|
84
|
+
PagSeguro.api_url "pre-approvals/#{code}/payment-orders"
|
85
|
+
end
|
86
|
+
|
87
|
+
def header
|
88
|
+
{ "Accept" => "application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1" }
|
89
|
+
end
|
90
|
+
|
91
|
+
# The params that will be sent
|
92
|
+
def params
|
93
|
+
{}.tap do |param|
|
94
|
+
param[:status] = SubscriptionPaymentOrder::STATUSES[status.to_sym]
|
95
|
+
param[:page] = page
|
96
|
+
param[:maxPageResults] = options[:per_page]
|
97
|
+
param[:credentials] = options[:credentials]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# The default PagSeguro API version
|
102
|
+
def api_version
|
103
|
+
:v2
|
104
|
+
end
|
105
|
+
|
106
|
+
def fetched?
|
107
|
+
@fetched
|
108
|
+
end
|
109
|
+
|
110
|
+
def fetched!
|
111
|
+
@fetched = true
|
112
|
+
end
|
113
|
+
|
114
|
+
def clear!
|
115
|
+
@fetched = false
|
116
|
+
end
|
117
|
+
|
118
|
+
def fetch(&block)
|
119
|
+
unless fetched?
|
120
|
+
perform_request_and_serialize
|
121
|
+
fetched!
|
122
|
+
end
|
123
|
+
|
124
|
+
instance_eval(&block)
|
125
|
+
end
|
126
|
+
|
127
|
+
def xml(&block)
|
128
|
+
valid? && block.call(@response.data)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionTransaction
|
3
|
+
include Extensions::MassAssignment
|
4
|
+
|
5
|
+
STATUSES = {
|
6
|
+
waiting_payment: 1,
|
7
|
+
in_review: 2,
|
8
|
+
paid: 3,
|
9
|
+
available: 4,
|
10
|
+
in_dispute: 5,
|
11
|
+
returned: 6,
|
12
|
+
canceled: 7,
|
13
|
+
charged: 8,
|
14
|
+
temporary_retention: 9
|
15
|
+
}
|
16
|
+
|
17
|
+
attr_accessor :code
|
18
|
+
attr_accessor :status
|
19
|
+
attr_accessor :date
|
20
|
+
|
21
|
+
def status_code
|
22
|
+
STATUSES[status.to_sym]
|
23
|
+
end
|
24
|
+
|
25
|
+
def ==(object)
|
26
|
+
[code, status, date] == [object.code, object.status, object.date]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -79,16 +79,6 @@ module PagSeguro
|
|
79
79
|
load_from_response send_request("transactions/notifications/#{code}", options)
|
80
80
|
end
|
81
81
|
|
82
|
-
# Find a transaction by status.
|
83
|
-
# Return a PagSeguro::Transaction::Colletion.
|
84
|
-
def self.find_status_history(code)
|
85
|
-
request = send_request("transactions/#{code}/statusHistory")
|
86
|
-
collection = StatusCollection.new
|
87
|
-
Response.new(request, collection).serialize_statuses
|
88
|
-
|
89
|
-
collection
|
90
|
-
end
|
91
|
-
|
92
82
|
# Search transactions within a date range.
|
93
83
|
# Return a PagSeguro::SearchByDate instance
|
94
84
|
#
|
@@ -34,9 +34,10 @@ module PagSeguro
|
|
34
34
|
def serialize_general(data)
|
35
35
|
data[:code] = xml.at_css("code").text
|
36
36
|
data[:reference] = xml.css("reference").text
|
37
|
-
data[:type_id] = xml.at_css("type").text
|
38
37
|
data[:payment_link] = xml.css("paymentLink").text
|
39
|
-
|
38
|
+
|
39
|
+
data[:type_id] = serialize_general_type_id
|
40
|
+
data[:status] = serialize_general_status
|
40
41
|
|
41
42
|
cancellation_source = xml.css("cancellationSource")
|
42
43
|
data[:cancellation_source] = cancellation_source.text if cancellation_source.any?
|
@@ -156,6 +157,22 @@ module PagSeguro
|
|
156
157
|
def address_node
|
157
158
|
@address_node ||= xml.css("shipping > address")
|
158
159
|
end
|
160
|
+
|
161
|
+
def serialize_general_type_id
|
162
|
+
type = xml.css('type').detect do |node|
|
163
|
+
node if node.parent.name == 'transaction'
|
164
|
+
end
|
165
|
+
|
166
|
+
type.text if type
|
167
|
+
end
|
168
|
+
|
169
|
+
def serialize_general_status
|
170
|
+
status = xml.css('status').detect do |node|
|
171
|
+
node if node.parent.name == 'transaction'
|
172
|
+
end
|
173
|
+
|
174
|
+
status.text if status
|
175
|
+
end
|
159
176
|
end
|
160
177
|
end
|
161
178
|
end
|
@@ -2,6 +2,7 @@ module PagSeguro
|
|
2
2
|
class TransactionRequest
|
3
3
|
include Extensions::MassAssignment
|
4
4
|
include Extensions::EnsureType
|
5
|
+
include Extensions::Credentiable
|
5
6
|
|
6
7
|
# Set the payment currency.
|
7
8
|
# Defaults to BRL.
|
@@ -10,6 +11,12 @@ module PagSeguro
|
|
10
11
|
# Get the payment sender.
|
11
12
|
attr_reader :sender
|
12
13
|
|
14
|
+
# Set and get primary receiver email.
|
15
|
+
attr_accessor :primary_receiver
|
16
|
+
|
17
|
+
# Get the payment receivers.
|
18
|
+
attr_reader :receivers
|
19
|
+
|
13
20
|
# Get the shipping info.
|
14
21
|
attr_reader :shipping
|
15
22
|
|
@@ -99,7 +106,12 @@ module PagSeguro
|
|
99
106
|
# Calls the PagSeguro web service and create this request for payment.
|
100
107
|
# Return boolean.
|
101
108
|
def create
|
102
|
-
request =
|
109
|
+
request = if receivers.empty?
|
110
|
+
Request.post('transactions', api_version, params)
|
111
|
+
else
|
112
|
+
Request.post_xml('transactions/', nil, credentials, xml_params)
|
113
|
+
end
|
114
|
+
|
103
115
|
Response.new(request, self).serialize
|
104
116
|
end
|
105
117
|
|
@@ -107,7 +119,15 @@ module PagSeguro
|
|
107
119
|
attrs.map { |name, value| send("#{name}=", value) }
|
108
120
|
end
|
109
121
|
|
122
|
+
# Set the receivers.
|
123
|
+
def receivers=(receivers)
|
124
|
+
@receivers = receivers.map do |receiver|
|
125
|
+
ensure_type(Receiver, receiver)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
110
129
|
private
|
130
|
+
|
111
131
|
attr_writer :code, :type_id, :payment_link, :status, :payment_method,
|
112
132
|
:gross_amount, :discount_amount, :net_amount, :installment_count,
|
113
133
|
:created_at, :updated_at
|
@@ -115,12 +135,17 @@ module PagSeguro
|
|
115
135
|
def before_initialize
|
116
136
|
self.currency = "BRL"
|
117
137
|
self.extra_params = []
|
138
|
+
self.receivers = []
|
118
139
|
end
|
119
140
|
|
120
141
|
def params
|
121
142
|
RequestSerializer.new(self).to_params
|
122
143
|
end
|
123
144
|
|
145
|
+
def xml_params
|
146
|
+
RequestSerializer.new(self).to_xml_params
|
147
|
+
end
|
148
|
+
|
124
149
|
# Used to set response items from api.
|
125
150
|
def items=(items)
|
126
151
|
@items = Items.new
|
@@ -8,6 +8,14 @@ module PagSeguro
|
|
8
8
|
@transaction_request = transaction_request
|
9
9
|
end
|
10
10
|
|
11
|
+
def to_xml_params
|
12
|
+
xml_builder.to_xml(
|
13
|
+
save_with:
|
14
|
+
Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS |
|
15
|
+
Nokogiri::XML::Node::SaveOptions::FORMAT
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
11
19
|
def to_params
|
12
20
|
params[:receiverEmail] = PagSeguro.receiver_email
|
13
21
|
params[:currency] = transaction_request.currency
|
@@ -90,12 +98,21 @@ module PagSeguro
|
|
90
98
|
|
91
99
|
params[:senderEmail] = sender.email
|
92
100
|
params[:senderName] = sender.name
|
93
|
-
params[:senderCPF] = sender.cpf
|
94
101
|
params[:senderHash] = sender.hash
|
95
102
|
|
103
|
+
serialize_sender_documents(sender.documents)
|
96
104
|
serialize_sender_phone(sender.phone)
|
97
105
|
end
|
98
106
|
|
107
|
+
def serialize_sender_documents(documents)
|
108
|
+
return if documents.empty?
|
109
|
+
|
110
|
+
documents.each do |document|
|
111
|
+
params[:senderCPF] = document.value if document.cpf?
|
112
|
+
params[:senderCNPJ] = document.value if document.cnpj?
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
99
116
|
def serialize_sender_phone(phone)
|
100
117
|
return unless phone
|
101
118
|
|
@@ -143,6 +160,152 @@ module PagSeguro
|
|
143
160
|
def to_amount(amount)
|
144
161
|
"%.2f" % BigDecimal(amount.to_s).round(2).to_s("F") if amount
|
145
162
|
end
|
163
|
+
|
164
|
+
def xml_builder
|
165
|
+
Nokogiri::XML::Builder.new(encoding: PagSeguro.encoding) do |xml|
|
166
|
+
xml.send(:payment) {
|
167
|
+
xml.mode transaction_request.payment_mode
|
168
|
+
xml.method_ transaction_request.payment_method
|
169
|
+
xml.currency transaction_request.currency
|
170
|
+
xml.notificationURL transaction_request.notification_url
|
171
|
+
xml.extraAmount to_amount(transaction_request.extra_amount || 0)
|
172
|
+
xml.reference transaction_request.reference
|
173
|
+
|
174
|
+
xml_serialize_sender(xml, transaction_request.sender)
|
175
|
+
xml_serialize_items(xml, transaction_request.items)
|
176
|
+
xml_serialize_receivers(xml, transaction_request.receivers)
|
177
|
+
xml_serialize_shipping(xml, transaction_request.shipping)
|
178
|
+
xml_serialize_credit_card(xml)
|
179
|
+
}
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def xml_serialize_credit_card(xml)
|
184
|
+
return unless transaction_request.is_a?(PagSeguro::CreditCardTransactionRequest)
|
185
|
+
|
186
|
+
xml.send(:creditCard) do
|
187
|
+
xml.send(:token, transaction_request.credit_card_token)
|
188
|
+
|
189
|
+
if transaction_request.installment
|
190
|
+
xml.send(:installment) do
|
191
|
+
xml.send(:quantity, transaction_request.installment.quantity)
|
192
|
+
xml.send(:value, to_amount(transaction_request.installment.value))
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
if transaction_request.billing_address
|
197
|
+
xml.send(:billingAddress) do
|
198
|
+
xml.send(:street, transaction_request.billing_address.street)
|
199
|
+
xml.send(:number, transaction_request.billing_address.number)
|
200
|
+
xml.send(:complement, transaction_request.billing_address.complement)
|
201
|
+
xml.send(:district, transaction_request.billing_address.district)
|
202
|
+
xml.send(:city, transaction_request.billing_address.city)
|
203
|
+
xml.send(:state, transaction_request.billing_address.state)
|
204
|
+
xml.send(:country, transaction_request.billing_address.country)
|
205
|
+
xml.send(:postalCode, transaction_request.billing_address.postal_code)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
if transaction_request.holder
|
210
|
+
xml.send(:holder) do
|
211
|
+
xml.send(:name, transaction_request.holder.name)
|
212
|
+
xml_serialize_documents(xml, [transaction_request.holder.document])
|
213
|
+
|
214
|
+
xml.send(:birthDate, transaction_request.holder.birth_date)
|
215
|
+
xml_serialize_phone(xml, transaction_request.holder.phone)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def xml_serialize_documents(xml, documents = [])
|
222
|
+
documents = documents.reject(&:nil?)
|
223
|
+
|
224
|
+
return if documents.empty?
|
225
|
+
|
226
|
+
xml.send(:documents) {
|
227
|
+
documents.each do |document|
|
228
|
+
xml.send(:document) {
|
229
|
+
xml.send(:type, document.type)
|
230
|
+
xml.send(:value, document.value)
|
231
|
+
}
|
232
|
+
end
|
233
|
+
}
|
234
|
+
end
|
235
|
+
|
236
|
+
def xml_serialize_phone(xml, phone)
|
237
|
+
if phone
|
238
|
+
xml.send(:phone) {
|
239
|
+
xml.send(:areaCode, phone.area_code)
|
240
|
+
xml.send(:number, phone.number)
|
241
|
+
}
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def xml_serialize_shipping(xml, shipping)
|
246
|
+
return unless shipping
|
247
|
+
|
248
|
+
xml.send(:shipping) do
|
249
|
+
if shipping.address
|
250
|
+
xml.send(:address) do
|
251
|
+
xml.send(:street, shipping.address.street)
|
252
|
+
xml.send(:number, shipping.address.number)
|
253
|
+
xml.send(:district, shipping.address.district)
|
254
|
+
xml.send(:country, shipping.address.country)
|
255
|
+
xml.send(:postalCode, shipping.address.postal_code)
|
256
|
+
xml.send(:city, shipping.address.city)
|
257
|
+
xml.send(:state, shipping.address.state)
|
258
|
+
xml.send(:complement, shipping.address.complement)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def xml_serialize_items(xml, items)
|
265
|
+
return unless items
|
266
|
+
|
267
|
+
xml.send(:items) do
|
268
|
+
items.each do |item|
|
269
|
+
xml.send(:item) do
|
270
|
+
xml.send(:id, item.id)
|
271
|
+
xml.send(:description, item.description)
|
272
|
+
xml.send(:quantity, item.quantity)
|
273
|
+
xml.send(:amount, to_amount(item.amount))
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def xml_serialize_sender(xml, sender)
|
280
|
+
return unless sender
|
281
|
+
|
282
|
+
xml.send(:sender) {
|
283
|
+
xml.send(:name, sender.name)
|
284
|
+
xml.send(:email, sender.email)
|
285
|
+
|
286
|
+
xml_serialize_phone(xml, sender.phone)
|
287
|
+
xml_serialize_documents(xml, sender.documents)
|
288
|
+
|
289
|
+
xml.send(:hash_, sender.hash)
|
290
|
+
}
|
291
|
+
end
|
292
|
+
|
293
|
+
def xml_serialize_receivers(xml, receivers)
|
294
|
+
return if receivers.empty?
|
295
|
+
|
296
|
+
xml.send(:receivers) {
|
297
|
+
receivers.each do |receiver|
|
298
|
+
xml.send(:receiver) {
|
299
|
+
xml.send(:publicKey, receiver.public_key)
|
300
|
+
xml.send(:split) {
|
301
|
+
xml.send(:amount, to_amount(receiver.split.amount))
|
302
|
+
xml.send(:ratePercent, to_amount(receiver.split.rate_percent))
|
303
|
+
xml.send(:feePercent, to_amount(receiver.split.fee_percent))
|
304
|
+
}
|
305
|
+
}
|
306
|
+
end
|
307
|
+
}
|
308
|
+
end
|
146
309
|
end
|
147
310
|
end
|
148
311
|
end
|