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,135 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionSearch
|
3
|
+
# Set the report options.
|
4
|
+
#
|
5
|
+
# # +per_page+: the page size.
|
6
|
+
# # +starts_at+: the report's starting date. Can't be older than 6 months.
|
7
|
+
# # +ends_at+: the report's ending date. Can't be greater than 30 days from the starting date.
|
8
|
+
#
|
9
|
+
attr_reader :options
|
10
|
+
|
11
|
+
# Set the errors from the report request.
|
12
|
+
attr_reader :errors
|
13
|
+
|
14
|
+
# Return the current page.
|
15
|
+
attr_reader :page
|
16
|
+
|
17
|
+
def initialize(path, options)
|
18
|
+
@path = path
|
19
|
+
@page = options.delete(:page) || 0
|
20
|
+
@options = options
|
21
|
+
@errors = Errors.new
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return the list of subscriptions.
|
25
|
+
# Each item will be wrapped in a PagSeguro::Subscription instance.
|
26
|
+
# Notice that subscriptions instantiated by the report won't have all attributes.
|
27
|
+
# If you need additional attributes, do a PagSeguro::Subscription.find_by_code
|
28
|
+
# call. Remember that this will perform an additional HTTP request.
|
29
|
+
def subscriptions
|
30
|
+
xml do |xml|
|
31
|
+
xml.css("preApprovalSearchResult > preApprovals > preApproval").map do |node|
|
32
|
+
Subscription.load_from_xml(node)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# The report's creation date.
|
38
|
+
def created_at
|
39
|
+
xml do |xml|
|
40
|
+
@created_at ||= Time.parse xml.css("preApprovalSearchResult > date").text
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# How many results the report returned on the given page.
|
45
|
+
def results
|
46
|
+
xml do |xml|
|
47
|
+
@results = xml.css("preApprovalSearchResult > resultsInThisPage").text.to_i
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# How many pages the report returned.
|
52
|
+
def total_pages
|
53
|
+
xml do |xml|
|
54
|
+
@total_pages ||= xml.css("preApprovalSearchResult > totalPages").text.to_i
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Detect if the report has a next page.
|
59
|
+
def next_page?
|
60
|
+
page.zero? || page < total_pages
|
61
|
+
end
|
62
|
+
|
63
|
+
# Detect if the report has a previous page.
|
64
|
+
def previous_page?
|
65
|
+
page > 1
|
66
|
+
end
|
67
|
+
|
68
|
+
# Move the page pointer to the next page.
|
69
|
+
def next_page!
|
70
|
+
return unless next_page?
|
71
|
+
@page += 1
|
72
|
+
clear!
|
73
|
+
end
|
74
|
+
|
75
|
+
# Move the page pointer to the previous page.
|
76
|
+
def previous_page!
|
77
|
+
return unless previous_page?
|
78
|
+
@page -= 1
|
79
|
+
clear!
|
80
|
+
end
|
81
|
+
|
82
|
+
# Detect if the report request returned errors.
|
83
|
+
def valid?
|
84
|
+
fetch { errors.empty? }
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def perform_request_and_serialize
|
89
|
+
@response = Request.get(@path, api_version, params)
|
90
|
+
@errors = Errors.new(@response)
|
91
|
+
end
|
92
|
+
|
93
|
+
# The params that will be sent
|
94
|
+
def params
|
95
|
+
{}.tap do |param|
|
96
|
+
param[:credentials] = options[:credentials]
|
97
|
+
param[:page] = page unless page.zero?
|
98
|
+
param[:maxPageResults] = options[:per_page]
|
99
|
+
param[:initialDate] = options[:starts_at].xmlschema if options[:starts_at]
|
100
|
+
param[:finalDate] = options[:ends_at].xmlschema if options[:ends_at]
|
101
|
+
param[:interval] = options[:interval] if options[:interval]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# The default PagSeguro API version
|
106
|
+
def api_version
|
107
|
+
:v2
|
108
|
+
end
|
109
|
+
|
110
|
+
def fetched?
|
111
|
+
@fetched
|
112
|
+
end
|
113
|
+
|
114
|
+
def fetched!
|
115
|
+
@fetched = true
|
116
|
+
end
|
117
|
+
|
118
|
+
def clear!
|
119
|
+
@fetched = false
|
120
|
+
end
|
121
|
+
|
122
|
+
def fetch(&block)
|
123
|
+
unless fetched?
|
124
|
+
perform_request_and_serialize
|
125
|
+
fetched!
|
126
|
+
end
|
127
|
+
|
128
|
+
instance_eval(&block)
|
129
|
+
end
|
130
|
+
|
131
|
+
def xml(&block)
|
132
|
+
valid? && block.call(@response.data)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionCanceller
|
3
|
+
API_VERSION = :v2
|
4
|
+
|
5
|
+
include Extensions::MassAssignment
|
6
|
+
include Extensions::Credentiable
|
7
|
+
|
8
|
+
# The code of subscription, not the plan
|
9
|
+
attr_accessor :subscription_code
|
10
|
+
|
11
|
+
# Set errors
|
12
|
+
def errors
|
13
|
+
@errors ||= Errors.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def save
|
17
|
+
request = Request.get_with_auth_on_url("pre-approvals/cancel/#{subscription_code}", API_VERSION, credentials)
|
18
|
+
|
19
|
+
Response.new(request, self).serialize
|
20
|
+
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def after_initialize
|
27
|
+
@errors = Errors.new
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionCanceller
|
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,46 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionChangePayment
|
3
|
+
include Extensions::Credentiable
|
4
|
+
include Extensions::EnsureType
|
5
|
+
include Extensions::MassAssignment
|
6
|
+
|
7
|
+
attr_accessor :subscription_code
|
8
|
+
|
9
|
+
attr_reader :sender
|
10
|
+
attr_reader :subscription_payment_method
|
11
|
+
|
12
|
+
def sender=(sender)
|
13
|
+
@sender = ensure_type(Sender, sender)
|
14
|
+
end
|
15
|
+
|
16
|
+
def holder=(holder)
|
17
|
+
@holder = ensure_type(Holder, holder)
|
18
|
+
end
|
19
|
+
|
20
|
+
def subscription_payment_method=(payment_method)
|
21
|
+
@subscription_payment_method = ensure_type(SubscriptionPaymentMethod, payment_method)
|
22
|
+
end
|
23
|
+
|
24
|
+
def errors
|
25
|
+
@errors ||= Errors.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
request = Request.put_xml("pre-approvals/#{subscription_code}/payment-method", credentials, params)
|
30
|
+
|
31
|
+
Response.new(request, self).serialize
|
32
|
+
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def params
|
39
|
+
RequestSerializer.new(self).serialize
|
40
|
+
end
|
41
|
+
|
42
|
+
def after_initialize
|
43
|
+
@errors = Errors.new
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionChangePayment
|
3
|
+
class RequestSerializer
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
def_delegators :object, :subscription_payment_method
|
7
|
+
def_delegators :subscription_payment_method, :holder
|
8
|
+
def_delegators :holder, :billing_address
|
9
|
+
|
10
|
+
attr_reader :object
|
11
|
+
|
12
|
+
def initialize(object)
|
13
|
+
@object = object
|
14
|
+
end
|
15
|
+
|
16
|
+
def serialize
|
17
|
+
build.to_xml(save_with:
|
18
|
+
Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS |
|
19
|
+
Nokogiri::XML::Node::SaveOptions::FORMAT
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def build
|
26
|
+
Nokogiri::XML::Builder.new(encoding: PagSeguro.encoding) do |xml|
|
27
|
+
xml.send(:paymentMethod) {
|
28
|
+
xml.send(:type, 'CREDITCARD')
|
29
|
+
|
30
|
+
if object.sender
|
31
|
+
xml.send(:sender) {
|
32
|
+
xml.send(:hash_, object.sender.hash)
|
33
|
+
xml.send(:ip, object.sender.ip)
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
if object.subscription_payment_method
|
38
|
+
xml.send(:creditCard) {
|
39
|
+
xml.send(:token, subscription_payment_method.token)
|
40
|
+
if holder
|
41
|
+
xml.send(:holder) {
|
42
|
+
xml.send(:name, holder.name)
|
43
|
+
xml.send(:birthDate, holder.birth_date.strftime("%d/%m/%Y"))
|
44
|
+
|
45
|
+
if holder.phone
|
46
|
+
xml.send(:phone) {
|
47
|
+
xml.send(:areaCode, holder.phone.area_code)
|
48
|
+
xml.send(:number, holder.phone.number)
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
if holder.document
|
53
|
+
xml.send(:document) {
|
54
|
+
xml.send(:type, holder.document.type)
|
55
|
+
xml.send(:value, holder.document.value)
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
if billing_address
|
60
|
+
xml.send(:billingAddress) {
|
61
|
+
xml.send(:street, billing_address.street)
|
62
|
+
xml.send(:number, billing_address.number)
|
63
|
+
xml.send(:complement, billing_address.complement)
|
64
|
+
xml.send(:district, billing_address.district)
|
65
|
+
xml.send(:city, billing_address.city)
|
66
|
+
xml.send(:state, billing_address.state)
|
67
|
+
xml.send(:country, billing_address.country)
|
68
|
+
xml.send(:postalCode, billing_address.postal_code)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
}
|
72
|
+
end
|
73
|
+
}
|
74
|
+
end
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionChangePayment
|
3
|
+
class Response
|
4
|
+
|
5
|
+
attr_reader :response
|
6
|
+
attr_reader :object
|
7
|
+
|
8
|
+
def initialize(response, object)
|
9
|
+
@response = response
|
10
|
+
@object = object
|
11
|
+
end
|
12
|
+
|
13
|
+
def serialize
|
14
|
+
unless success?
|
15
|
+
object.errors.add response
|
16
|
+
end
|
17
|
+
|
18
|
+
object
|
19
|
+
end
|
20
|
+
|
21
|
+
def success?
|
22
|
+
response.success? && response.xml?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionChangeStatus
|
3
|
+
include Extensions::MassAssignment
|
4
|
+
include Extensions::Credentiable
|
5
|
+
|
6
|
+
# Now, just available ACTIVE and SUSPENDED
|
7
|
+
STATUSES = {
|
8
|
+
active: 'ACTIVE',
|
9
|
+
suspended: 'SUSPENDED'
|
10
|
+
}
|
11
|
+
|
12
|
+
# Subscription's code that will be changed
|
13
|
+
attr_reader :code
|
14
|
+
|
15
|
+
# The status that will be set
|
16
|
+
attr_reader :status
|
17
|
+
|
18
|
+
def initialize(code, status)
|
19
|
+
@code = code
|
20
|
+
@status = status
|
21
|
+
end
|
22
|
+
|
23
|
+
# Set errors
|
24
|
+
def errors
|
25
|
+
@errors ||= Errors.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def save
|
29
|
+
request = Request.put_xml("pre-approvals/#{code}/status", credentials, params)
|
30
|
+
|
31
|
+
Response.new(request, self).serialize
|
32
|
+
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def status_text
|
37
|
+
STATUSES[status]
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def params
|
43
|
+
RequestSerializer.new(self).serialize
|
44
|
+
end
|
45
|
+
|
46
|
+
def after_initialize
|
47
|
+
@errors = Errors.new
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionChangeStatus
|
3
|
+
class RequestSerializer
|
4
|
+
attr_reader :object
|
5
|
+
|
6
|
+
def initialize(object)
|
7
|
+
@object = object
|
8
|
+
end
|
9
|
+
|
10
|
+
def serialize
|
11
|
+
build.to_xml(save_with:
|
12
|
+
Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS |
|
13
|
+
Nokogiri::XML::Node::SaveOptions::FORMAT
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def build
|
20
|
+
Nokogiri::XML::Builder.new(encoding: PagSeguro.encoding) do |xml|
|
21
|
+
xml.send(:directPreApproval) {
|
22
|
+
xml.send(:status, object.status_text)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionChangeStatus
|
3
|
+
class Response
|
4
|
+
|
5
|
+
attr_reader :response
|
6
|
+
attr_reader :object
|
7
|
+
|
8
|
+
def initialize(response, object)
|
9
|
+
@response = response
|
10
|
+
@object = object
|
11
|
+
end
|
12
|
+
|
13
|
+
def serialize
|
14
|
+
unless success?
|
15
|
+
object.errors.add response
|
16
|
+
end
|
17
|
+
|
18
|
+
object
|
19
|
+
end
|
20
|
+
|
21
|
+
def success?
|
22
|
+
response.success? && response.xml?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|