pagseguro-sdk 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/.gitignore +204 -0
- data/.github/ISSUE_TEMPLATE/relatorio-de-bug.md +29 -0
- data/.github/workflows/codacy-analysis.yml +46 -0
- data/.gitignore +28 -0
- data/.rspec +1 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +95 -0
- data/CONTRIBUTING.md +39 -0
- data/Dockerfile +20 -0
- data/Gemfile +2 -0
- data/LICENSE-2.0.txt +177 -0
- data/README.md +436 -0
- data/Rakefile +5 -0
- data/docker-compose.yml +5 -0
- data/docs/transparent_checkout.md +201 -0
- data/examples/authorization/create_authorization.rb +32 -0
- data/examples/authorization/create_authorization_with_account.rb +56 -0
- data/examples/authorization/search/search_authorization_by_code.rb +29 -0
- data/examples/authorization/search/search_authorization_by_date.rb +35 -0
- data/examples/authorization/search/search_authorization_by_notification_code.rb +29 -0
- data/examples/authorization/search/search_authorization_by_reference.rb +31 -0
- data/examples/boot.rb +26 -0
- data/examples/checkout/create_payment_request.rb +63 -0
- data/examples/checkout/search/search_abandoned_transactions.rb +41 -0
- data/examples/checkout/search/search_transaction_by_code.rb +76 -0
- data/examples/checkout/search/search_transaction_by_notification_code.rb +76 -0
- data/examples/checkout/search/search_transaction_by_reference.rb +36 -0
- data/examples/checkout/search/search_transactions_by_date.rb +45 -0
- data/examples/create_session.rb +19 -0
- data/examples/direct/create_transaction_using_boleto.rb +100 -0
- data/examples/direct/create_transaction_using_credit_card.rb +128 -0
- data/examples/direct/create_transaction_using_online_debit.rb +104 -0
- data/examples/get_installments.rb +40 -0
- 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/request_transaction_cancellation.rb +19 -0
- data/examples/split_payment/create_authorization.rb +32 -0
- data/examples/split_payment/create_payment_request.rb +71 -0
- 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-oficial.rb +1 -0
- data/lib/pagseguro.rb +221 -0
- data/lib/pagseguro/account.rb +29 -0
- data/lib/pagseguro/account_credentials.rb +14 -0
- data/lib/pagseguro/address.rb +40 -0
- data/lib/pagseguro/application_credentials.rb +18 -0
- data/lib/pagseguro/authorization.rb +61 -0
- data/lib/pagseguro/authorization/collection.rb +28 -0
- data/lib/pagseguro/authorization/request_serializer.rb +24 -0
- data/lib/pagseguro/authorization/response.rb +49 -0
- data/lib/pagseguro/authorization/response_serializer.rb +40 -0
- data/lib/pagseguro/authorization_request.rb +84 -0
- data/lib/pagseguro/authorization_request/request_serializer.rb +142 -0
- data/lib/pagseguro/authorization_request/response.rb +26 -0
- data/lib/pagseguro/authorization_request/response_serializer.rb +18 -0
- data/lib/pagseguro/bank.rb +8 -0
- data/lib/pagseguro/boleto_transaction_request.rb +8 -0
- data/lib/pagseguro/company.rb +41 -0
- data/lib/pagseguro/config.rb +34 -0
- data/lib/pagseguro/credit_card_transaction_request.rb +39 -0
- data/lib/pagseguro/creditor_fee.rb +23 -0
- data/lib/pagseguro/document.rb +23 -0
- data/lib/pagseguro/documents.rb +5 -0
- data/lib/pagseguro/errors.rb +57 -0
- data/lib/pagseguro/exceptions.rb +3 -0
- data/lib/pagseguro/extensions/collection_object.rb +34 -0
- data/lib/pagseguro/extensions/credentiable.rb +17 -0
- data/lib/pagseguro/extensions/ensure_type.rb +9 -0
- data/lib/pagseguro/extensions/mass_assignment.rb +11 -0
- data/lib/pagseguro/holder.rb +36 -0
- data/lib/pagseguro/installment.rb +57 -0
- data/lib/pagseguro/installment/collection.rb +25 -0
- data/lib/pagseguro/installment/request_serializer.rb +24 -0
- data/lib/pagseguro/installment/response.rb +37 -0
- data/lib/pagseguro/installment/response_serializer.rb +22 -0
- data/lib/pagseguro/item.rb +34 -0
- data/lib/pagseguro/items.rb +23 -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/notification.rb +11 -0
- data/lib/pagseguro/notification/authorization.rb +15 -0
- data/lib/pagseguro/notification/transaction.rb +15 -0
- data/lib/pagseguro/online_debit_transaction_request.rb +17 -0
- data/lib/pagseguro/partner.rb +20 -0
- data/lib/pagseguro/payment_method.rb +39 -0
- data/lib/pagseguro/payment_release.rb +21 -0
- data/lib/pagseguro/payment_releases.rb +28 -0
- data/lib/pagseguro/payment_request.rb +117 -0
- data/lib/pagseguro/payment_request/request_serializer.rb +203 -0
- data/lib/pagseguro/payment_request/response.rb +35 -0
- data/lib/pagseguro/payment_status.rb +39 -0
- data/lib/pagseguro/permission.rb +13 -0
- data/lib/pagseguro/person.rb +40 -0
- data/lib/pagseguro/phone.rb +20 -0
- data/lib/pagseguro/phones.rb +5 -0
- data/lib/pagseguro/receiver.rb +20 -0
- data/lib/pagseguro/receiver_split.rb +15 -0
- data/lib/pagseguro/request.rb +170 -0
- data/lib/pagseguro/sender.rb +53 -0
- data/lib/pagseguro/session.rb +34 -0
- data/lib/pagseguro/session/response.rb +32 -0
- data/lib/pagseguro/session/response_serializer.rb +18 -0
- data/lib/pagseguro/shipping.rb +57 -0
- 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 +215 -0
- data/lib/pagseguro/transaction/collection.rb +20 -0
- data/lib/pagseguro/transaction/response.rb +45 -0
- data/lib/pagseguro/transaction/search.rb +121 -0
- data/lib/pagseguro/transaction/search/search_abandoned.rb +20 -0
- data/lib/pagseguro/transaction/search/search_by_date.rb +16 -0
- data/lib/pagseguro/transaction/search/search_by_reference.rb +13 -0
- data/lib/pagseguro/transaction/serializer.rb +181 -0
- data/lib/pagseguro/transaction_cancellation.rb +37 -0
- data/lib/pagseguro/transaction_cancellation/request_serializer.rb +18 -0
- data/lib/pagseguro/transaction_cancellation/response.rb +33 -0
- data/lib/pagseguro/transaction_cancellation/response_serializer.rb +17 -0
- data/lib/pagseguro/transaction_installment.rb +11 -0
- data/lib/pagseguro/transaction_refund.rb +44 -0
- data/lib/pagseguro/transaction_refund/request_serializer.rb +24 -0
- data/lib/pagseguro/transaction_refund/response.rb +33 -0
- data/lib/pagseguro/transaction_refund/response_serializer.rb +17 -0
- data/lib/pagseguro/transaction_request.rb +165 -0
- data/lib/pagseguro/transaction_request/request_serializer.rb +311 -0
- data/lib/pagseguro/transaction_request/response.rb +33 -0
- data/lib/pagseguro/transaction_request/response_serializer.rb +117 -0
- data/lib/pagseguro/transaction_status.rb +14 -0
- data/lib/pagseguro/version.rb +3 -0
- data/locales/pt-BR.yml +130 -0
- data/pagseguro-oficial.gemspec +31 -0
- data/spec/fixtures/authorization/find_authorization.xml +17 -0
- data/spec/fixtures/authorization/search_authorization.xml +47 -0
- data/spec/fixtures/authorization_request/authorization_request.xml +11 -0
- data/spec/fixtures/authorization_request/authorization_request_with_account.xml +47 -0
- data/spec/fixtures/authorization_request/success.xml +4 -0
- data/spec/fixtures/by_date/success.xml +85 -0
- data/spec/fixtures/installment/success.xml +24 -0
- data/spec/fixtures/invalid_code.xml +7 -0
- data/spec/fixtures/manual_subscription_charger/fail.xml +6 -0
- data/spec/fixtures/manual_subscription_charger/success.xml +4 -0
- data/spec/fixtures/payment_request/failure.xml +7 -0
- data/spec/fixtures/payment_request/success.xml +5 -0
- data/spec/fixtures/refund/success.xml +2 -0
- data/spec/fixtures/session/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/transaction_cancellation/success.xml +2 -0
- data/spec/fixtures/transaction_request/success.xml +58 -0
- data/spec/fixtures/transactions/additional.xml +53 -0
- data/spec/fixtures/transactions/search.xml +40 -0
- data/spec/fixtures/transactions/success.xml +75 -0
- data/spec/fixtures/transactions/without_status_and_type.xml +71 -0
- data/spec/pagseguro/account_credentials_spec.rb +10 -0
- data/spec/pagseguro/account_spec.rb +27 -0
- data/spec/pagseguro/address_spec.rb +17 -0
- data/spec/pagseguro/application_credentials_spec.rb +11 -0
- data/spec/pagseguro/authorization/collection_spec.rb +49 -0
- data/spec/pagseguro/authorization/request_serializer_spec.rb +10 -0
- data/spec/pagseguro/authorization/response_serializer_spec.rb +19 -0
- data/spec/pagseguro/authorization/response_spec.rb +90 -0
- data/spec/pagseguro/authorization_request/request_serializer_spec.rb +323 -0
- data/spec/pagseguro/authorization_request/response_serializer_spec.rb +15 -0
- data/spec/pagseguro/authorization_request/response_spec.rb +36 -0
- data/spec/pagseguro/authorization_request_spec.rb +127 -0
- data/spec/pagseguro/authorization_spec.rb +111 -0
- data/spec/pagseguro/bank_spec.rb +5 -0
- data/spec/pagseguro/boleto_transaction_request_spec.rb +9 -0
- data/spec/pagseguro/company_spec.rb +12 -0
- data/spec/pagseguro/config_spec.rb +5 -0
- data/spec/pagseguro/credit_card_transaction_request_spec.rb +36 -0
- data/spec/pagseguro/creditor_fee_spec.rb +10 -0
- data/spec/pagseguro/document_spec.rb +21 -0
- data/spec/pagseguro/documents_spec.rb +37 -0
- data/spec/pagseguro/errors_spec.rb +145 -0
- data/spec/pagseguro/extensions/collection_object_spec.rb +77 -0
- data/spec/pagseguro/features/create_session_spec.rb +52 -0
- data/spec/pagseguro/features/create_transaction_request_spec.rb +58 -0
- data/spec/pagseguro/holder_spec.rb +10 -0
- data/spec/pagseguro/installment/collection_spec.rb +43 -0
- data/spec/pagseguro/installment/request_serializer_spec.rb +16 -0
- data/spec/pagseguro/installment/response_serializer_spec.rb +33 -0
- data/spec/pagseguro/installment/response_spec.rb +56 -0
- data/spec/pagseguro/installment_spec.rb +50 -0
- data/spec/pagseguro/item_spec.rb +20 -0
- data/spec/pagseguro/items_spec.rb +148 -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/notification_spec.rb +6 -0
- data/spec/pagseguro/online_debit_transaction_request_spec.rb +18 -0
- data/spec/pagseguro/pagseguro_spec.rb +82 -0
- data/spec/pagseguro/partner_spec.rb +8 -0
- data/spec/pagseguro/payment_method_spec.rb +42 -0
- data/spec/pagseguro/payment_release_spec.rb +9 -0
- data/spec/pagseguro/payment_releases_spec.rb +34 -0
- data/spec/pagseguro/payment_request/request_serializer_spec.rb +283 -0
- data/spec/pagseguro/payment_request/response_spec.rb +13 -0
- data/spec/pagseguro/payment_request_spec.rb +148 -0
- data/spec/pagseguro/payment_status_spec.rb +33 -0
- data/spec/pagseguro/permission_spec.rb +7 -0
- data/spec/pagseguro/person_spec.rb +10 -0
- data/spec/pagseguro/phone_spec.rb +6 -0
- data/spec/pagseguro/phones_spec.rb +38 -0
- data/spec/pagseguro/receiver_spec.rb +7 -0
- data/spec/pagseguro/receiver_split_spec.rb +7 -0
- data/spec/pagseguro/request_spec.rb +114 -0
- data/spec/pagseguro/sender_spec.rb +25 -0
- data/spec/pagseguro/session/response_serializer_spec.rb +12 -0
- data/spec/pagseguro/session/response_spec.rb +57 -0
- data/spec/pagseguro/session_spec.rb +45 -0
- data/spec/pagseguro/shipping_spec.rb +40 -0
- 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/collection_spec.rb +43 -0
- data/spec/pagseguro/transaction/response_spec.rb +60 -0
- data/spec/pagseguro/transaction/search/search_abandoned_spec.rb +55 -0
- data/spec/pagseguro/transaction/search/search_by_date_spec.rb +28 -0
- data/spec/pagseguro/transaction/search/search_by_reference_spec.rb +21 -0
- data/spec/pagseguro/transaction/search_spec.rb +133 -0
- data/spec/pagseguro/transaction/serializer_spec.rb +86 -0
- data/spec/pagseguro/transaction_cancellation/request_serializer_spec.rb +13 -0
- data/spec/pagseguro/transaction_cancellation/response_serializer_spec.rb +9 -0
- data/spec/pagseguro/transaction_cancellation/response_spec.rb +45 -0
- data/spec/pagseguro/transaction_cancellation_spec.rb +60 -0
- data/spec/pagseguro/transaction_installment_spec.rb +6 -0
- data/spec/pagseguro/transaction_refund/request_serializer_spec.rb +15 -0
- data/spec/pagseguro/transaction_refund/response_serializer_spec.rb +12 -0
- data/spec/pagseguro/transaction_refund/response_spec.rb +39 -0
- data/spec/pagseguro/transaction_refund_spec.rb +71 -0
- data/spec/pagseguro/transaction_request/request_serializer_spec.rb +677 -0
- data/spec/pagseguro/transaction_request/response_serializer_spec.rb +52 -0
- data/spec/pagseguro/transaction_request/response_spec.rb +63 -0
- data/spec/pagseguro/transaction_request_spec.rb +156 -0
- data/spec/pagseguro/transaction_spec.rb +265 -0
- data/spec/pagseguro/transaction_status_spec.rb +7 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/support/ensure_type_macro.rb +35 -0
- data/spec/support/helpers.rb +14 -0
- data/spec/support/mass_assignment_macro.rb +11 -0
- data/spec/support/shared_examples_for_configuration.rb +10 -0
- data/transaction/transaction_refund.rb +25 -0
- metadata +641 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionPaymentOrder
|
3
|
+
include Extensions::MassAssignment
|
4
|
+
include Extensions::EnsureType
|
5
|
+
|
6
|
+
STATUSES = {
|
7
|
+
scheduled: 1,
|
8
|
+
processing: 2,
|
9
|
+
not_processed: 3,
|
10
|
+
suspended: 4,
|
11
|
+
paid: 5,
|
12
|
+
not_paid: 6
|
13
|
+
}
|
14
|
+
|
15
|
+
attr_accessor :errors
|
16
|
+
|
17
|
+
attr_accessor :code
|
18
|
+
attr_accessor :status
|
19
|
+
attr_accessor :amount
|
20
|
+
attr_accessor :gross_amount
|
21
|
+
attr_accessor :last_event_date
|
22
|
+
attr_accessor :scheduling_date
|
23
|
+
attr_reader :discount
|
24
|
+
|
25
|
+
def discount=(discount)
|
26
|
+
@discount = ensure_type(PagSeguro::SubscriptionDiscount, discount)
|
27
|
+
end
|
28
|
+
|
29
|
+
def transactions
|
30
|
+
@transactions ||= SubscriptionTransactions.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def transactions=(attrs)
|
34
|
+
attrs.each do |params|
|
35
|
+
transactions << SubscriptionTransaction.new(params)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def status_code
|
40
|
+
STATUSES[@status.to_sym]
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_attributes(attrs)
|
44
|
+
attrs.each {|name, value| send("#{name}=", value) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.load_from_xml(xml)
|
48
|
+
new ResponseSerializer.new(xml).serialize
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def after_initialize
|
54
|
+
@errors ||= Errors.new
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionPaymentOrder
|
3
|
+
class Response
|
4
|
+
def initialize(response, object)
|
5
|
+
@response = response
|
6
|
+
@object = object
|
7
|
+
end
|
8
|
+
|
9
|
+
def serialize
|
10
|
+
if success?
|
11
|
+
object.update_attributes serialized_data
|
12
|
+
else
|
13
|
+
object.errors.add response
|
14
|
+
end
|
15
|
+
|
16
|
+
object
|
17
|
+
end
|
18
|
+
|
19
|
+
def success?
|
20
|
+
response.success? && response.xml?
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :response
|
26
|
+
attr_reader :object
|
27
|
+
|
28
|
+
def serialized_data
|
29
|
+
ResponseSerializer.new(xml).serialize
|
30
|
+
end
|
31
|
+
|
32
|
+
def xml
|
33
|
+
Nokogiri::XML(response.data)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionPaymentOrder
|
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.at_css('code').text
|
13
|
+
data[:status] = SubscriptionPaymentOrder::STATUSES.key(xml.at_css('status').text.to_i)
|
14
|
+
data[:amount] = to_amount xml.at_css('amount').text
|
15
|
+
data[:gross_amount] = xml.at_css('grossAmount').text
|
16
|
+
data[:scheduling_date] = Time.parse(xml.css('schedulingDate').text)
|
17
|
+
data[:last_event_date] = Time.parse(xml.css('lastEventDate').text)
|
18
|
+
data[:discount] = serialize_discount if xml.at_css('discount')
|
19
|
+
data[:transactions] = serialize_transactions if xml.css('transactions').any?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def serialize_discount
|
26
|
+
{}.tap do |data|
|
27
|
+
data[:type] = xml.css('discount > type').text
|
28
|
+
data[:value] = xml.css('discount > value').text
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def serialize_transactions
|
33
|
+
xml.css('transactions').map do |node|
|
34
|
+
serialize_transaction(node)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def serialize_transaction(node)
|
39
|
+
{}.tap do |data|
|
40
|
+
data[:code] = node.css('> code').text
|
41
|
+
data[:date] = Time.parse(node.css('> date').text)
|
42
|
+
data[:status] = SubscriptionTransaction::STATUSES.key(node.css('> status').text.to_i)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_amount(amount)
|
47
|
+
"%.2f" % BigDecimal(amount.to_s.to_f.to_s).round(2).to_s("F") if amount
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionPlan
|
3
|
+
API_VERSION = 'v2'
|
4
|
+
|
5
|
+
include Extensions::MassAssignment
|
6
|
+
include Extensions::Credentiable
|
7
|
+
include Extensions::EnsureType
|
8
|
+
|
9
|
+
attr_accessor :max_users
|
10
|
+
attr_accessor :name
|
11
|
+
attr_accessor :charge
|
12
|
+
attr_accessor :period
|
13
|
+
attr_accessor :amount
|
14
|
+
attr_accessor :max_total_amount
|
15
|
+
attr_accessor :max_amount_per_period
|
16
|
+
attr_accessor :max_payments_per_period
|
17
|
+
attr_accessor :max_amount_per_payment
|
18
|
+
attr_accessor :final_date
|
19
|
+
attr_accessor :initial_date
|
20
|
+
attr_accessor :membership_fee
|
21
|
+
attr_accessor :trial_duration
|
22
|
+
attr_accessor :code
|
23
|
+
attr_accessor :reference
|
24
|
+
attr_accessor :redirect_url
|
25
|
+
attr_accessor :review_url
|
26
|
+
attr_accessor :details
|
27
|
+
|
28
|
+
attr_reader :sender
|
29
|
+
|
30
|
+
# Set errors
|
31
|
+
def errors
|
32
|
+
@errors ||= Errors.new
|
33
|
+
end
|
34
|
+
|
35
|
+
# Update all attributes
|
36
|
+
def update_attributes(attrs)
|
37
|
+
attrs.each { |name, value| send("#{name}=", value) }
|
38
|
+
end
|
39
|
+
|
40
|
+
# Set sender
|
41
|
+
def sender=(sender)
|
42
|
+
@sender = ensure_type(Sender, sender)
|
43
|
+
end
|
44
|
+
|
45
|
+
def create
|
46
|
+
request = Request.post_xml('pre-approvals/request', API_VERSION, credentials, xml_params)
|
47
|
+
|
48
|
+
Response.new(request, self).serialize
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def url
|
54
|
+
return unless code
|
55
|
+
|
56
|
+
"#{PagSeguro.uris[PagSeguro.environment][:site]}v2/pre-approvals/request.html?code=#{code}"
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def xml_params
|
62
|
+
RequestSerializer.new(self).to_xml_params
|
63
|
+
end
|
64
|
+
|
65
|
+
def after_initialize
|
66
|
+
@errors = Errors.new
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionPlan
|
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)
|
21
|
+
"%.2f" % BigDecimal(amount.to_s.to_f.to_s).round(2).to_s("F") if amount
|
22
|
+
end
|
23
|
+
|
24
|
+
def xml_serialize_sender(xml)
|
25
|
+
return unless object.sender
|
26
|
+
|
27
|
+
xml.send(:sender) {
|
28
|
+
xml.send(:name, object.sender.name)
|
29
|
+
xml.send(:email, object.sender.email)
|
30
|
+
if object.sender.phone
|
31
|
+
xml.send(:phone) {
|
32
|
+
xml.send(:areaCode, object.sender.phone.area_code)
|
33
|
+
xml.send(:number, object.sender.phone.number)
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
if object.sender.address
|
38
|
+
xml.send(:address) {
|
39
|
+
xml.send(:street, object.sender.address.street)
|
40
|
+
xml.send(:number, object.sender.address.number)
|
41
|
+
xml.send(:complement, object.sender.address.complement)
|
42
|
+
xml.send(:district, object.sender.address.district)
|
43
|
+
xml.send(:postalCode, object.sender.address.postal_code)
|
44
|
+
xml.send(:city, object.sender.address.city)
|
45
|
+
xml.send(:state, object.sender.address.state)
|
46
|
+
xml.send(:country, object.sender.address.country)
|
47
|
+
}
|
48
|
+
end
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def xml_builder
|
53
|
+
Nokogiri::XML::Builder.new(encoding: PagSeguro.encoding) do |xml|
|
54
|
+
xml.send(:preApprovalRequest) {
|
55
|
+
xml.send(:redirectURL, object.redirect_url)
|
56
|
+
xml.send(:reviewURL, object.review_url)
|
57
|
+
xml.send(:reference, object.reference)
|
58
|
+
xml.send(:maxUsers, object.max_users)
|
59
|
+
xml_serialize_sender(xml)
|
60
|
+
|
61
|
+
xml.send(:preApproval) {
|
62
|
+
xml.send(:name, object.name)
|
63
|
+
xml.send(:details, object.details)
|
64
|
+
xml.send(:charge, object.charge)
|
65
|
+
xml.send(:period, object.period)
|
66
|
+
xml.send(:amountPerPayment, to_amount(object.amount))
|
67
|
+
xml.send(:maxTotalAmount, to_amount(object.max_total_amount))
|
68
|
+
xml.send(:maxPaymentsPerPeriod, object.max_payments_per_period.to_i) if object.max_payments_per_period
|
69
|
+
xml.send(:maxAmountPerPeriod, to_amount(object.max_amount_per_period))
|
70
|
+
xml.send(:maxAmountPerPayment, to_amount(object.max_amount_per_payment))
|
71
|
+
xml.send(:finalDate, object.final_date.xmlschema) if object.final_date
|
72
|
+
xml.send(:initialDate, object.initial_date.xmlschema) if object.initial_date
|
73
|
+
xml.send(:membershipFee, to_amount(object.membership_fee))
|
74
|
+
xml.send(:trialPeriodDuration, object.trial_duration.to_i) if object.trial_duration.present?
|
75
|
+
}
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class SubscriptionPlan
|
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 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
|