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,29 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Account
|
3
|
+
include Extensions::MassAssignment
|
4
|
+
include Extensions::EnsureType
|
5
|
+
|
6
|
+
# Set the account e-mail.
|
7
|
+
attr_accessor :email
|
8
|
+
|
9
|
+
# Set the account type.
|
10
|
+
# Must be PERSONAL, SELLER or COMPANY.
|
11
|
+
attr_accessor :type
|
12
|
+
|
13
|
+
# Get the person account.
|
14
|
+
attr_reader :person
|
15
|
+
|
16
|
+
# Get the company account.
|
17
|
+
attr_reader :company
|
18
|
+
|
19
|
+
def person=(person)
|
20
|
+
return if company
|
21
|
+
@person = ensure_type(Person, person)
|
22
|
+
end
|
23
|
+
|
24
|
+
def company=(company)
|
25
|
+
return if person
|
26
|
+
@company = ensure_type(Company, company)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
# Set the shipping address information.
|
3
|
+
class Address
|
4
|
+
include Extensions::MassAssignment
|
5
|
+
|
6
|
+
# Set the street name.
|
7
|
+
attr_accessor :street
|
8
|
+
|
9
|
+
# Set the house/building number.
|
10
|
+
attr_accessor :number
|
11
|
+
|
12
|
+
# Set the address complement.
|
13
|
+
# Can be the apartment, suite number or any other qualifier after
|
14
|
+
# the street/number pair.
|
15
|
+
attr_accessor :complement
|
16
|
+
|
17
|
+
# Set the district.
|
18
|
+
# Can be the district, county or neighborhood, if applicable.
|
19
|
+
attr_accessor :district
|
20
|
+
|
21
|
+
# Set the city name.
|
22
|
+
attr_accessor :city
|
23
|
+
|
24
|
+
# Set the state or province.
|
25
|
+
attr_accessor :state
|
26
|
+
|
27
|
+
# Set the postal code.
|
28
|
+
# Must contain 8 numbers.
|
29
|
+
attr_accessor :postal_code
|
30
|
+
|
31
|
+
# Set the country code.
|
32
|
+
# Defaults to +BRA+.
|
33
|
+
attr_accessor :country
|
34
|
+
|
35
|
+
private
|
36
|
+
def before_initialize
|
37
|
+
self.country = "BRA"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class ApplicationCredentials
|
3
|
+
# The application id
|
4
|
+
attr_accessor :app_id
|
5
|
+
|
6
|
+
# The token related to the application
|
7
|
+
attr_accessor :app_key
|
8
|
+
|
9
|
+
# The application authorization code
|
10
|
+
attr_accessor :authorization_code
|
11
|
+
|
12
|
+
def initialize(app_id, app_key, authorization_code = nil)
|
13
|
+
@app_id = app_id
|
14
|
+
@app_key = app_key
|
15
|
+
@authorization_code = authorization_code
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Authorization
|
3
|
+
include Extensions::MassAssignment
|
4
|
+
include Extensions::Credentiable
|
5
|
+
|
6
|
+
# The authorization code
|
7
|
+
attr_accessor :code
|
8
|
+
|
9
|
+
# The authorization creation date
|
10
|
+
attr_accessor :created_at
|
11
|
+
|
12
|
+
# The reference related to the authorization
|
13
|
+
attr_accessor :reference
|
14
|
+
|
15
|
+
# The authorization permissions
|
16
|
+
attr_accessor :permissions
|
17
|
+
|
18
|
+
# The authorization authorizerEmail
|
19
|
+
attr_accessor :authorizer_email
|
20
|
+
|
21
|
+
# Find an authorization by it's notification code
|
22
|
+
def self.find_by_notification_code(code, options = {})
|
23
|
+
request = Request.get("authorizations/notifications/#{code}", api_version, options)
|
24
|
+
authorization = PagSeguro::Authorization.new
|
25
|
+
Response.new(request, authorization).serialize
|
26
|
+
|
27
|
+
authorization
|
28
|
+
end
|
29
|
+
|
30
|
+
# Find an authorization by it's code
|
31
|
+
def self.find_by_code(code, options = {})
|
32
|
+
request = Request.get("authorizations/#{code}", api_version, options)
|
33
|
+
authorization = PagSeguro::Authorization.new
|
34
|
+
Response.new(request, authorization).serialize
|
35
|
+
|
36
|
+
authorization
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.find_by(options)
|
40
|
+
request = Request.get("authorizations", api_version, RequestSerializer.new(options).to_params)
|
41
|
+
collection = Collection.new
|
42
|
+
Response.new(request, collection).serialize_collection
|
43
|
+
|
44
|
+
collection
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_attributes(attrs)
|
48
|
+
attrs.map { |name, value| send("#{name}=", value) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def errors
|
52
|
+
@errors ||= Errors.new
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def self.api_version
|
58
|
+
'v2'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Authorization
|
3
|
+
class Collection
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
attr_writer :authorizations
|
7
|
+
|
8
|
+
def_delegators :@authorizations, :each, :empty?, :any?
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@errors = options[:errors] if options[:errors]
|
12
|
+
@authorizations = instantiate_authorizations(options[:authorizations])
|
13
|
+
end
|
14
|
+
|
15
|
+
def errors
|
16
|
+
@errors ||= Errors.new
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def instantiate_authorizations(authorizations)
|
21
|
+
return [] unless authorizations
|
22
|
+
authorizations.map do |authorization|
|
23
|
+
Authorization.new(authorization)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Authorization
|
3
|
+
class RequestSerializer
|
4
|
+
attr_reader :authorization
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_params
|
11
|
+
params[:credentials] = @options[:credentials] if @options[:credentials]
|
12
|
+
params[:reference] = @options[:reference] if @options[:reference]
|
13
|
+
params[:initialDate] = @options[:initial_date].xmlschema if @options[:initial_date]
|
14
|
+
params[:finalDate] = @options[:final_date].xmlschema if @options[:final_date]
|
15
|
+
params
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def params
|
20
|
+
@params ||= {}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Authorization
|
3
|
+
class Response
|
4
|
+
def initialize(response, object)
|
5
|
+
@response = response
|
6
|
+
@object = object
|
7
|
+
end
|
8
|
+
|
9
|
+
def serialize
|
10
|
+
if success?
|
11
|
+
xml = Nokogiri::XML(response.body).css('authorization').first
|
12
|
+
serializer = ResponseSerializer.new(xml).serialize
|
13
|
+
object.update_attributes(serializer)
|
14
|
+
else
|
15
|
+
object.errors.add(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
object
|
19
|
+
end
|
20
|
+
|
21
|
+
def serialize_collection
|
22
|
+
if success?
|
23
|
+
object.authorizations = serialize_authorizations
|
24
|
+
else
|
25
|
+
object.errors.add(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
object
|
29
|
+
end
|
30
|
+
|
31
|
+
def success?
|
32
|
+
response.success? && response.xml?
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
# The request response.
|
37
|
+
attr_reader :response
|
38
|
+
|
39
|
+
# The PagSeguro::Authorization or PagSeguro::Authorization::Collection object
|
40
|
+
attr_reader :object
|
41
|
+
|
42
|
+
def serialize_authorizations
|
43
|
+
Nokogiri::XML(response.body).css('authorizations > authorization').map do |node|
|
44
|
+
Authorization.new(ResponseSerializer.new(node).serialize)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class Authorization
|
3
|
+
class ResponseSerializer
|
4
|
+
|
5
|
+
def initialize(xml)
|
6
|
+
@xml = xml
|
7
|
+
end
|
8
|
+
|
9
|
+
def serialize
|
10
|
+
{}.tap do |data|
|
11
|
+
serialize_general(data)
|
12
|
+
serialize_permissions(data)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def serialize_general(data)
|
18
|
+
data[:code] = xml.css("> code").text
|
19
|
+
data[:reference] = xml.css("reference").text
|
20
|
+
data[:created_at] = Time.parse xml.css("creationDate").text
|
21
|
+
data[:authorizer_email] = xml.css("authorizerEmail").text
|
22
|
+
end
|
23
|
+
|
24
|
+
def serialize_permissions(data)
|
25
|
+
data[:permissions] = []
|
26
|
+
|
27
|
+
xml.css("permission").each do |node|
|
28
|
+
permission = PagSeguro::Permission.new
|
29
|
+
permission.code = node.css("code").text
|
30
|
+
permission.status = node.css("status").text
|
31
|
+
permission.last_update = node.css("lastUpdate").text
|
32
|
+
|
33
|
+
data[:permissions] << permission
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :xml
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class AuthorizationRequest
|
3
|
+
include Extensions::MassAssignment
|
4
|
+
include Extensions::EnsureType
|
5
|
+
include Extensions::Credentiable
|
6
|
+
|
7
|
+
# The permissions given to the application
|
8
|
+
# Defaults to all permissions
|
9
|
+
attr_accessor :permissions
|
10
|
+
|
11
|
+
# The seller reference (optional)
|
12
|
+
attr_accessor :reference
|
13
|
+
|
14
|
+
# The url which PagSeguro can send notifications
|
15
|
+
attr_accessor :notification_url
|
16
|
+
|
17
|
+
# The url which the application is going to be redirected after the proccess
|
18
|
+
attr_accessor :redirect_url
|
19
|
+
|
20
|
+
# The account that can be passed to register suggestion
|
21
|
+
attr_reader :account
|
22
|
+
|
23
|
+
# The code used to confirm the authorization
|
24
|
+
attr_reader :code
|
25
|
+
|
26
|
+
# The date of authorization creation
|
27
|
+
attr_reader :date
|
28
|
+
|
29
|
+
# Errors object.
|
30
|
+
attr_writer :errors
|
31
|
+
|
32
|
+
PERMISSIONS = {
|
33
|
+
checkouts: 'CREATE_CHECKOUTS',
|
34
|
+
notifications: 'RECEIVE_TRANSACTION_NOTIFICATIONS',
|
35
|
+
searches: 'SEARCH_TRANSACTIONS',
|
36
|
+
pre_approvals: 'MANAGE_PAYMENT_PRE_APPROVALS',
|
37
|
+
payments: 'DIRECT_PAYMENT',
|
38
|
+
refunds: 'REFUND_TRANSACTIONS',
|
39
|
+
cancels: 'CANCEL_TRANSACTIONS'
|
40
|
+
}
|
41
|
+
|
42
|
+
def account=(account)
|
43
|
+
@account = ensure_type(Account, account)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Post and create an Authorization.
|
47
|
+
# Return Boolean.
|
48
|
+
def create
|
49
|
+
request = Request.post_xml('authorizations/request', api_version, credentials, xml)
|
50
|
+
response = Response.new(request)
|
51
|
+
update_attributes(response.serialize)
|
52
|
+
|
53
|
+
response.success?
|
54
|
+
end
|
55
|
+
|
56
|
+
# URL to confirm authorization after create one.
|
57
|
+
def url
|
58
|
+
PagSeguro.site_url("#{api_version}/authorization/request.jhtml?code=#{code}") if code
|
59
|
+
end
|
60
|
+
|
61
|
+
def errors
|
62
|
+
@errors ||= Errors.new
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
attr_writer :code, :date
|
67
|
+
|
68
|
+
def before_initialize
|
69
|
+
self.permissions = PERMISSIONS.keys
|
70
|
+
end
|
71
|
+
|
72
|
+
def xml
|
73
|
+
RequestSerializer.new(self).build_xml
|
74
|
+
end
|
75
|
+
|
76
|
+
def update_attributes(attrs)
|
77
|
+
attrs.each { |method, value| send("#{method}=", value) }
|
78
|
+
end
|
79
|
+
|
80
|
+
def api_version
|
81
|
+
'v2'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module PagSeguro
|
2
|
+
class AuthorizationRequest
|
3
|
+
class RequestSerializer
|
4
|
+
|
5
|
+
attr_accessor :request
|
6
|
+
|
7
|
+
def initialize(request)
|
8
|
+
@request = request
|
9
|
+
@builder = Nokogiri::XML::Builder
|
10
|
+
end
|
11
|
+
|
12
|
+
def build_xml
|
13
|
+
build.to_xml(save_with:
|
14
|
+
Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS |
|
15
|
+
Nokogiri::XML::Node::SaveOptions::FORMAT
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :builder
|
22
|
+
|
23
|
+
def build
|
24
|
+
builder.new(encoding: PagSeguro.encoding) do |xml|
|
25
|
+
xml.send(:authorizationRequest) {
|
26
|
+
xml.send(:reference, request.reference) if request.reference
|
27
|
+
xml.send(:redirectURL, request.redirect_url)
|
28
|
+
xml.send(:notificationURL, request.notification_url)
|
29
|
+
serialize_permissions(xml, request.permissions)
|
30
|
+
serialize_account(xml, request.account)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def serialize_permissions(xml, permissions)
|
36
|
+
return unless permissions.any?
|
37
|
+
xml.send(:permissions) {
|
38
|
+
format_permissions(permissions).each do |permission|
|
39
|
+
xml.send(:code, permission)
|
40
|
+
end
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def format_permissions(permissions)
|
45
|
+
permissions.map { |value| PagSeguro::AuthorizationRequest::PERMISSIONS[value] }
|
46
|
+
end
|
47
|
+
|
48
|
+
def serialize_account(xml, account)
|
49
|
+
return unless account
|
50
|
+
|
51
|
+
xml.send(:account) {
|
52
|
+
xml.send(:email, account.email) if account.email
|
53
|
+
xml.send(:type, account.type) if account.type
|
54
|
+
|
55
|
+
if account.person
|
56
|
+
serialize_person(xml, account.person)
|
57
|
+
elsif account.company
|
58
|
+
serialize_company(xml, account.company)
|
59
|
+
end
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def serialize_person(xml, person)
|
64
|
+
return unless person
|
65
|
+
|
66
|
+
xml.send(:person) {
|
67
|
+
xml.send(:name, person.name) if person.name
|
68
|
+
xml.send(:birthDate, person.birth_date.to_s) if person.birth_date
|
69
|
+
serialize_address(xml, person.address)
|
70
|
+
serialize_documents(xml, person.documents)
|
71
|
+
serialize_phones(xml, person.phones)
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def serialize_company(xml, company)
|
76
|
+
return unless company
|
77
|
+
|
78
|
+
xml.send(:company) {
|
79
|
+
xml.send(:name, company.name) if company.name
|
80
|
+
xml.send(:displayName, company.display_name) if company.display_name
|
81
|
+
xml.send(:websiteURL, company.website_url) if company.website_url
|
82
|
+
serialize_partner(xml, company.partner)
|
83
|
+
serialize_phones(xml, company.phones)
|
84
|
+
serialize_documents(xml, company.documents)
|
85
|
+
serialize_address(xml, company.address)
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def serialize_address(xml, address)
|
90
|
+
return unless address
|
91
|
+
|
92
|
+
xml.send(:address) {
|
93
|
+
xml.send(:postalCode, address.postal_code) if address.postal_code
|
94
|
+
xml.send(:street, address.street) if address.street
|
95
|
+
xml.send(:number, address.number) if address.number
|
96
|
+
xml.send(:complement, address.complement) if address.complement
|
97
|
+
xml.send(:district, address.district) if address.district
|
98
|
+
xml.send(:city, address.city) if address.city
|
99
|
+
xml.send(:state, address.state) if address.state
|
100
|
+
xml.send(:country, address.country) if address.country
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def serialize_phones(xml, phones)
|
105
|
+
return unless phones.any?
|
106
|
+
|
107
|
+
xml.send(:phones) {
|
108
|
+
phones.each do |phone|
|
109
|
+
xml.send(:phone) {
|
110
|
+
xml.send(:type, phone.type)
|
111
|
+
xml.send(:areaCode, phone.area_code)
|
112
|
+
xml.send(:number, phone.number)
|
113
|
+
}
|
114
|
+
end
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
def serialize_documents(xml, documents)
|
119
|
+
return unless documents.any?
|
120
|
+
|
121
|
+
xml.send(:documents) {
|
122
|
+
documents.each do |document|
|
123
|
+
xml.send(:document) {
|
124
|
+
xml.send(:type, document.type)
|
125
|
+
xml.send(:value, document.value)
|
126
|
+
}
|
127
|
+
end
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
def serialize_partner(xml, partner)
|
132
|
+
return unless partner
|
133
|
+
|
134
|
+
xml.send(:partner) {
|
135
|
+
xml.send(:name, partner.name) if partner.name
|
136
|
+
xml.send(:birthDate, partner.birth_date.to_s) if partner.birth_date
|
137
|
+
serialize_documents(xml, partner.documents)
|
138
|
+
}
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|