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,152 @@
|
|
1
|
+
require_relative "../boot"
|
2
|
+
|
3
|
+
# Create Transaction Using Credit Card
|
4
|
+
#
|
5
|
+
# You need to set your AccountCredentials (EMAIL, TOKEN) in the application config
|
6
|
+
#
|
7
|
+
# P.S: See the boot file example for more details.
|
8
|
+
|
9
|
+
app_id = 'APP_ID'
|
10
|
+
app_key = 'APP_KEY'
|
11
|
+
|
12
|
+
payment = PagSeguro::CreditCardTransactionRequest.new
|
13
|
+
payment.notification_url = "http://www.lojateste.com.br/notification"
|
14
|
+
payment.payment_mode = "default"
|
15
|
+
payment.credentials = PagSeguro::ApplicationCredentials.new(app_id, app_key)
|
16
|
+
|
17
|
+
payment.items << {
|
18
|
+
id: 1234,
|
19
|
+
description: %[Televisão 19" Sony],
|
20
|
+
amount: 100.0,
|
21
|
+
weight: 0
|
22
|
+
}
|
23
|
+
|
24
|
+
payment.reference = "REF1234-credit-card"
|
25
|
+
payment.sender = {
|
26
|
+
hash: "9aff5821b4a6f5a1dc9e15d3a3b02ac666a1629fcb90e2bbf6b7da661b344094",
|
27
|
+
name: "Joao Comprador",
|
28
|
+
email: "EMAIL_FROM@sandbox.pagseguro.com.br",
|
29
|
+
document: { type: "CPF", value: "75073461100" },
|
30
|
+
phone: {
|
31
|
+
area_code: 11,
|
32
|
+
number: "12345678"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
payment.shipping = {
|
37
|
+
type_name: "sedex",
|
38
|
+
address: {
|
39
|
+
street: "Av. Brig. Faria Lima",
|
40
|
+
number: "1384",
|
41
|
+
complement: "5º andar",
|
42
|
+
city: "São Paulo",
|
43
|
+
state: "SP",
|
44
|
+
district: "Jardim Paulistano",
|
45
|
+
postal_code: "01452002"
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
payment.receivers = [
|
50
|
+
{
|
51
|
+
public_key: 'PUBLIC_KEY',
|
52
|
+
split: {
|
53
|
+
amount: 20.0,
|
54
|
+
rate_percent: 50.0,
|
55
|
+
fee_percent: 50.0
|
56
|
+
}
|
57
|
+
}
|
58
|
+
]
|
59
|
+
|
60
|
+
payment.billing_address = {
|
61
|
+
street: "Av. Brig. Faria Lima",
|
62
|
+
number: "1384",
|
63
|
+
complement: "5º andar",
|
64
|
+
city: "São Paulo",
|
65
|
+
state: "SP",
|
66
|
+
district: "Jardim Paulistano",
|
67
|
+
postal_code: "01452002"
|
68
|
+
}
|
69
|
+
|
70
|
+
payment.credit_card_token = "CREDIT_CARD_TOKEN"
|
71
|
+
payment.holder = {
|
72
|
+
name: "João Comprador",
|
73
|
+
birth_date: "07/05/1981",
|
74
|
+
document: {
|
75
|
+
type: "CPF",
|
76
|
+
value: "00000000191"
|
77
|
+
},
|
78
|
+
phone: {
|
79
|
+
area_code: 11,
|
80
|
+
number: "123456789"
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
payment.installment = {
|
85
|
+
value: 100.0,
|
86
|
+
quantity: 1
|
87
|
+
}
|
88
|
+
|
89
|
+
# Add extras params to request
|
90
|
+
# payment.extra_params << { paramName: 'paramValue' }
|
91
|
+
# payment.extra_params << { senderBirthDate: '07/05/1981' }
|
92
|
+
|
93
|
+
# Edit the lines above.
|
94
|
+
|
95
|
+
puts "=> REQUEST"
|
96
|
+
puts PagSeguro::TransactionRequest::RequestSerializer.new(payment).to_params
|
97
|
+
puts
|
98
|
+
|
99
|
+
payment.create
|
100
|
+
|
101
|
+
if payment.errors.any?
|
102
|
+
puts "=> ERRORS"
|
103
|
+
puts payment.errors.join("\n")
|
104
|
+
else
|
105
|
+
puts "=> Transaction"
|
106
|
+
puts " code: #{payment.code}"
|
107
|
+
puts " reference: #{payment.reference}"
|
108
|
+
puts " type: #{payment.type_id}"
|
109
|
+
puts " payment link: #{payment.payment_link}"
|
110
|
+
puts " status: #{payment.status}"
|
111
|
+
puts " payment method type: #{payment.payment_method}"
|
112
|
+
puts " created at: #{payment.created_at}"
|
113
|
+
puts " updated at: #{payment.updated_at}"
|
114
|
+
puts " gross amount: #{payment.gross_amount.to_f}"
|
115
|
+
puts " discount amount: #{payment.discount_amount.to_f}"
|
116
|
+
puts " net amount: #{payment.net_amount.to_f}"
|
117
|
+
puts " extra amount: #{payment.extra_amount.to_f}"
|
118
|
+
puts " installment count: #{payment.installment_count}"
|
119
|
+
|
120
|
+
puts " => Items"
|
121
|
+
puts " items count: #{payment.items.size}"
|
122
|
+
payment.items.each do |item|
|
123
|
+
puts " item id: #{item.id}"
|
124
|
+
puts " description: #{item.description}"
|
125
|
+
puts " quantity: #{item.quantity}"
|
126
|
+
puts " amount: #{item.amount.to_f}"
|
127
|
+
end
|
128
|
+
|
129
|
+
puts " => Receivers"
|
130
|
+
puts " receivers count: #{payment.receivers.size}"
|
131
|
+
payment.receivers.each do |receiver|
|
132
|
+
puts " email: #{receiver.email}"
|
133
|
+
puts " amount: #{receiver.split.amount}"
|
134
|
+
end
|
135
|
+
|
136
|
+
puts " => Sender"
|
137
|
+
puts " name: #{payment.sender.name}"
|
138
|
+
puts " email: #{payment.sender.email}"
|
139
|
+
puts " phone: (#{payment.sender.phone.area_code}) #{payment.sender.phone.number}"
|
140
|
+
puts " document: #{payment.sender.document}: #{payment.sender.document}"
|
141
|
+
|
142
|
+
puts " => Shipping"
|
143
|
+
puts " street: #{payment.shipping.address.street}, #{payment.shipping.address.number}"
|
144
|
+
puts " complement: #{payment.shipping.address.complement}"
|
145
|
+
puts " postal code: #{payment.shipping.address.postal_code}"
|
146
|
+
puts " district: #{payment.shipping.address.district}"
|
147
|
+
puts " city: #{payment.shipping.address.city}"
|
148
|
+
puts " state: #{payment.shipping.address.state}"
|
149
|
+
puts " country: #{payment.shipping.address.country}"
|
150
|
+
puts " type: #{payment.shipping.type_name}"
|
151
|
+
puts " cost: #{payment.shipping.cost}"
|
152
|
+
end
|
data/lib/pagseguro.rb
CHANGED
@@ -47,6 +47,10 @@ require "pagseguro/item"
|
|
47
47
|
require "pagseguro/items"
|
48
48
|
require "pagseguro/bank"
|
49
49
|
require "pagseguro/holder"
|
50
|
+
require "pagseguro/manual_subscription_charger"
|
51
|
+
require "pagseguro/manual_subscription_charger/request_serializer"
|
52
|
+
require "pagseguro/manual_subscription_charger/response"
|
53
|
+
require "pagseguro/manual_subscription_charger/response_serializer"
|
50
54
|
require "pagseguro/payment_method"
|
51
55
|
require "pagseguro/payment_release"
|
52
56
|
require "pagseguro/payment_releases"
|
@@ -66,15 +70,25 @@ require "pagseguro/sender"
|
|
66
70
|
require "pagseguro/session"
|
67
71
|
require "pagseguro/session/response"
|
68
72
|
require "pagseguro/session/response_serializer"
|
73
|
+
require "pagseguro/subscription_discount"
|
74
|
+
require "pagseguro/subscription_discount/request_serializer"
|
75
|
+
require "pagseguro/subscription_discount/response"
|
69
76
|
require "pagseguro/notification"
|
70
77
|
require "pagseguro/notification/authorization"
|
71
78
|
require "pagseguro/notification/transaction"
|
79
|
+
require "pagseguro/subscription_canceller"
|
80
|
+
require "pagseguro/subscription_canceller/response"
|
81
|
+
require "pagseguro/subscription_plan"
|
82
|
+
require "pagseguro/subscription_plan/request_serializer"
|
83
|
+
require "pagseguro/subscription_plan/response"
|
84
|
+
require "pagseguro/subscription_plan/response_serializer"
|
85
|
+
require "pagseguro/subscription_retry"
|
86
|
+
require "pagseguro/subscription_retry/response"
|
72
87
|
require "pagseguro/transaction"
|
73
88
|
require "pagseguro/transaction_status"
|
74
89
|
require "pagseguro/transaction/response"
|
75
90
|
require "pagseguro/transaction/serializer"
|
76
91
|
require "pagseguro/transaction/collection"
|
77
|
-
require "pagseguro/transaction/status_collection"
|
78
92
|
require "pagseguro/transaction_cancellation"
|
79
93
|
require "pagseguro/transaction_cancellation/request_serializer"
|
80
94
|
require "pagseguro/transaction_cancellation/response"
|
@@ -91,6 +105,24 @@ require "pagseguro/transaction_request/request_serializer"
|
|
91
105
|
require "pagseguro/boleto_transaction_request"
|
92
106
|
require "pagseguro/online_debit_transaction_request"
|
93
107
|
require "pagseguro/credit_card_transaction_request"
|
108
|
+
require "pagseguro/subscription_payment_method"
|
109
|
+
require "pagseguro/subscription"
|
110
|
+
require "pagseguro/subscription/request_serializer"
|
111
|
+
require "pagseguro/subscription/response_serializer"
|
112
|
+
require "pagseguro/subscription/response"
|
113
|
+
require "pagseguro/subscription/subscription_search"
|
114
|
+
require "pagseguro/subscription_change_payment"
|
115
|
+
require "pagseguro/subscription_change_payment/request_serializer"
|
116
|
+
require "pagseguro/subscription_change_payment/response"
|
117
|
+
require "pagseguro/subscription_change_status/request_serializer"
|
118
|
+
require "pagseguro/subscription_change_status/response"
|
119
|
+
require "pagseguro/subscription_change_status"
|
120
|
+
require "pagseguro/subscription_transaction"
|
121
|
+
require "pagseguro/subscription_transactions"
|
122
|
+
require "pagseguro/subscription_payment_order"
|
123
|
+
require "pagseguro/subscription_payment_order/response_serializer"
|
124
|
+
require "pagseguro/subscription_payment_order/response"
|
125
|
+
require "pagseguro/subscription_search_payment_orders"
|
94
126
|
|
95
127
|
I18n.load_path += Dir[File.expand_path("../../locales/*.yml", __FILE__)]
|
96
128
|
|
data/lib/pagseguro/document.rb
CHANGED
data/lib/pagseguro/holder.rb
CHANGED
@@ -15,6 +15,9 @@ module PagSeguro
|
|
15
15
|
# Get the phone.
|
16
16
|
attr_reader :phone
|
17
17
|
|
18
|
+
# Get the billing address
|
19
|
+
attr_reader :billing_address
|
20
|
+
|
18
21
|
# Set the document.
|
19
22
|
def document=(document)
|
20
23
|
@document = ensure_type(Document, document)
|
@@ -24,5 +27,10 @@ module PagSeguro
|
|
24
27
|
def phone=(phone)
|
25
28
|
@phone = ensure_type(Phone, phone)
|
26
29
|
end
|
30
|
+
|
31
|
+
# Set the billing address
|
32
|
+
def billing_address=(billing_address)
|
33
|
+
@billing_address = ensure_type(Address, billing_address)
|
34
|
+
end
|
27
35
|
end
|
28
36
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class ManualSubscriptionCharger
|
3
|
+
include Extensions::Credentiable
|
4
|
+
include Extensions::EnsureType
|
5
|
+
include Extensions::MassAssignment
|
6
|
+
|
7
|
+
API_VERSION = :v2
|
8
|
+
|
9
|
+
# Set reference
|
10
|
+
attr_accessor :reference
|
11
|
+
|
12
|
+
# Set subscription code of a manual subscription
|
13
|
+
attr_accessor :subscription_code
|
14
|
+
|
15
|
+
# Set transaction code, it is within the response
|
16
|
+
attr_accessor :transaction_code
|
17
|
+
|
18
|
+
# Set items
|
19
|
+
attr_reader :items
|
20
|
+
|
21
|
+
# Set errors
|
22
|
+
def errors
|
23
|
+
@errors ||= Errors.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def items=(items=[])
|
27
|
+
@items = items.map do |item|
|
28
|
+
ensure_type(Item, item)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Update all attributes
|
33
|
+
def update_attributes(attrs)
|
34
|
+
attrs.each { |name, value| send("#{name}=", value) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def create
|
38
|
+
request = Request.post_xml('pre-approvals/payment', API_VERSION, credentials, xml_params)
|
39
|
+
|
40
|
+
Response.new(request, self).serialize
|
41
|
+
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def xml_params
|
48
|
+
RequestSerializer.new(self).to_xml_params
|
49
|
+
end
|
50
|
+
|
51
|
+
def before_initialize
|
52
|
+
@items ||= Items.new
|
53
|
+
end
|
54
|
+
|
55
|
+
def after_initialize
|
56
|
+
@errors = Errors.new
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class ManualSubscriptionCharger
|
3
|
+
class RequestSerializer
|
4
|
+
attr_reader :object
|
5
|
+
|
6
|
+
def initialize(object)
|
7
|
+
@object = object
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_xml_params
|
11
|
+
xml_builder.to_xml(
|
12
|
+
save_with:
|
13
|
+
Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS |
|
14
|
+
Nokogiri::XML::Node::SaveOptions::FORMAT
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def to_amount(amount = 0.0)
|
21
|
+
"%.2f" % BigDecimal(amount.to_s).round(2).to_s("F")
|
22
|
+
end
|
23
|
+
|
24
|
+
def xml_serialize_items(xml, items = [])
|
25
|
+
return if items.empty?
|
26
|
+
|
27
|
+
xml.send(:items) do
|
28
|
+
items.each do |item|
|
29
|
+
xml.send(:item) do
|
30
|
+
xml.send(:id, item.id)
|
31
|
+
xml.send(:description, item.description)
|
32
|
+
xml.send(:quantity, item.quantity)
|
33
|
+
xml.send(:amount, to_amount(item.amount))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def xml_builder
|
40
|
+
Nokogiri::XML::Builder.new(encoding: PagSeguro.encoding) do |xml|
|
41
|
+
xml.send(:payment) {
|
42
|
+
xml.send(:reference, object.reference)
|
43
|
+
xml.send(:preApprovalCode, object.subscription_code)
|
44
|
+
xml_serialize_items(xml, object.items)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class ManualSubscriptionCharger
|
3
|
+
class Response
|
4
|
+
# The http response.
|
5
|
+
attr_reader :response
|
6
|
+
|
7
|
+
# Set the boject 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
|
+
if success?
|
17
|
+
object.update_attributes(ResponseSerializer.new(xml).serialize)
|
18
|
+
else
|
19
|
+
object.errors.add response
|
20
|
+
end
|
21
|
+
|
22
|
+
object
|
23
|
+
end
|
24
|
+
|
25
|
+
def success?
|
26
|
+
response.success? && response.xml?
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def xml
|
32
|
+
Nokogiri::XML(response.body)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class ManualSubscriptionCharger
|
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[:transaction_code] = xml.css('result > transactionCode').text
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -68,11 +68,20 @@ module PagSeguro
|
|
68
68
|
|
69
69
|
data[:senderEmail] = sender.email
|
70
70
|
data[:senderName] = sender.name
|
71
|
-
data[:senderCPF] = sender.cpf
|
72
71
|
|
72
|
+
serialize_documents(data, sender.documents)
|
73
73
|
serialize_phone(data, sender.phone)
|
74
74
|
end
|
75
75
|
|
76
|
+
def serialize_documents(data, documents)
|
77
|
+
return if documents.empty?
|
78
|
+
|
79
|
+
documents.each do |document|
|
80
|
+
data[:senderCPF] = document.value if document.cpf?
|
81
|
+
data[:senderCNPJ] = document.value if document.cnpj?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
76
85
|
def serialize_phone(data, phone)
|
77
86
|
return unless phone
|
78
87
|
|
@@ -143,6 +152,19 @@ module PagSeguro
|
|
143
152
|
}
|
144
153
|
end
|
145
154
|
|
155
|
+
def xml_serialize_documents(xml, documents)
|
156
|
+
return if documents.empty?
|
157
|
+
|
158
|
+
xml.send(:documents) {
|
159
|
+
documents.each do |document|
|
160
|
+
xml.send(:document) {
|
161
|
+
xml.send(:type, document.type)
|
162
|
+
xml.send(:value, document.value)
|
163
|
+
}
|
164
|
+
end
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
146
168
|
def xml_serialize_sender(xml, sender)
|
147
169
|
return unless sender
|
148
170
|
|
@@ -155,6 +177,8 @@ module PagSeguro
|
|
155
177
|
xml.send(:number, sender.phone.number)
|
156
178
|
}
|
157
179
|
end
|
180
|
+
|
181
|
+
xml_serialize_documents(xml, sender.documents)
|
158
182
|
}
|
159
183
|
end
|
160
184
|
|