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,137 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Subscription find' do |path|
|
4
|
+
let(:base_url) { PagSeguro.root_uri(:api) }
|
5
|
+
let(:extended_url) { [base_url, path].join }
|
6
|
+
|
7
|
+
before do
|
8
|
+
FakeWeb.register_uri(
|
9
|
+
:get,
|
10
|
+
extended_url,
|
11
|
+
body: 'OK'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'must send to correct URL' do
|
16
|
+
expect(PagSeguro).
|
17
|
+
to receive(:api_url).
|
18
|
+
with(path).
|
19
|
+
and_return(extended_url)
|
20
|
+
|
21
|
+
search
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'must to call response and serialize' do
|
25
|
+
response = double(:Response)
|
26
|
+
|
27
|
+
expect(PagSeguro::Subscription::Response).
|
28
|
+
to receive(:new).
|
29
|
+
with(any_args).
|
30
|
+
and_return(response)
|
31
|
+
|
32
|
+
allow(response).to receive(:serialize)
|
33
|
+
|
34
|
+
search
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'must return a PagSeguro::Subscription object' do
|
38
|
+
expect(search).to be_a PagSeguro::Subscription
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe PagSeguro::Subscription do
|
43
|
+
it_assigns_attribute :code
|
44
|
+
it_assigns_attribute :name
|
45
|
+
it_assigns_attribute :date
|
46
|
+
it_assigns_attribute :tracker
|
47
|
+
it_assigns_attribute :status
|
48
|
+
it_assigns_attribute :charge
|
49
|
+
it_assigns_attribute :plan
|
50
|
+
it_assigns_attribute :reference
|
51
|
+
it_assigns_attribute :last_event_date
|
52
|
+
|
53
|
+
it_ensures_type PagSeguro::Sender, :sender
|
54
|
+
it_ensures_type PagSeguro::SubscriptionPaymentMethod, :payment_method
|
55
|
+
|
56
|
+
context 'errors attribute' do
|
57
|
+
it 'should start with errors' do
|
58
|
+
expect(subject.errors).to be_a PagSeguro::Errors
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should start with empty errors' do
|
62
|
+
expect(subject.errors).to be_empty
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context '#create' do
|
67
|
+
before do
|
68
|
+
subject.credentials = credentials
|
69
|
+
|
70
|
+
FakeWeb.register_uri(
|
71
|
+
:post,
|
72
|
+
'https://ws.pagseguro.uol.com.br/pre-approvals?email=user@example.com&token=TOKEN',
|
73
|
+
body: ''
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:credentials) { PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN') }
|
78
|
+
|
79
|
+
let(:request) do
|
80
|
+
double(
|
81
|
+
:Request,
|
82
|
+
xml?: true,
|
83
|
+
success?: true,
|
84
|
+
body: '<directPreApproval><code>12345</code></directPreApproval>'
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'sends it to correct url' do
|
89
|
+
expect(PagSeguro).
|
90
|
+
to receive(:api_url).
|
91
|
+
with('pre-approvals?email=user@example.com&token=TOKEN').
|
92
|
+
and_return('https://ws.pagseguro.uol.com.br/pre-approvals?email=user@example.com&token=TOKEN')
|
93
|
+
|
94
|
+
subject.create
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when parsing' do
|
98
|
+
it 'create a subscription' do
|
99
|
+
expect(PagSeguro::Request).
|
100
|
+
to receive(:post_xml).
|
101
|
+
with(
|
102
|
+
'pre-approvals',
|
103
|
+
nil,
|
104
|
+
credentials,
|
105
|
+
a_string_matching(/<directPreApproval>/),
|
106
|
+
{:headers=>{"Accept"=>"application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1"}}).
|
107
|
+
and_return(request)
|
108
|
+
|
109
|
+
subject.create
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'update subscription with the new code' do
|
113
|
+
allow(PagSeguro::Request).to receive(:post_xml).and_return(request)
|
114
|
+
expect { subject.create }.to change { subject.code }.to('12345')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'find subscriptions' do
|
119
|
+
let(:code) { 12345 }
|
120
|
+
let(:request) { double(:Request, success?: true, xml?: true, body: '') }
|
121
|
+
|
122
|
+
context 'by notification code' do
|
123
|
+
let(:search) { PagSeguro::Subscription.find_by_notification_code(code, credentials: credentials) }
|
124
|
+
|
125
|
+
it_behaves_like 'Subscription find',
|
126
|
+
'v2/pre-approvals/notifications/12345?email=user@example.com&token=TOKEN'
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'subscription code' do
|
130
|
+
let(:search) { PagSeguro::Subscription.find_by_code(code, credentials: credentials) }
|
131
|
+
|
132
|
+
it_behaves_like 'Subscription find',
|
133
|
+
'v2/pre-approvals/12345?email=user@example.com&token=TOKEN'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SubscriptionTransaction do
|
4
|
+
it_assigns_attribute :code
|
5
|
+
it_assigns_attribute :status
|
6
|
+
it_assigns_attribute :date
|
7
|
+
|
8
|
+
context '#status_code' do
|
9
|
+
before do
|
10
|
+
subject.status = :waiting_payment
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'must return the code related' do
|
14
|
+
expect(subject.status_code).to eq 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'comparison' do
|
19
|
+
let(:params) { {code: '1234', status: :paid, date: Time.new(2016,1,1)} }
|
20
|
+
subject { described_class.new(params) }
|
21
|
+
|
22
|
+
it { expect(subject).to eq(PagSeguro::SubscriptionTransaction.new(params)) }
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SubscriptionTransactions do
|
4
|
+
[
|
5
|
+
:size,
|
6
|
+
:clear,
|
7
|
+
:empty?,
|
8
|
+
:any?,
|
9
|
+
:each,
|
10
|
+
:map
|
11
|
+
].each do |method|
|
12
|
+
it { is_expected.to respond_to(method) }
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should initialize empty' do
|
16
|
+
expect(subject).to be_empty
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'adding a new transaction' do
|
20
|
+
let(:transaction) { { code: '1234' } }
|
21
|
+
|
22
|
+
it "shouldn't add the same transaction" do
|
23
|
+
subject << transaction
|
24
|
+
expect{ subject << transaction }.to_not change{ subject.size }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'ensures type the new transaction' do
|
28
|
+
it 'can be a hash' do
|
29
|
+
expect{ subject << transaction }.to change{ subject.size }.to(1)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'can be a PagSeguro::Document' do
|
33
|
+
expect{ subject << PagSeguro::SubscriptionTransaction.new(code: '1234') }.to change{ subject.size }.to(1)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Transaction::Collection do
|
4
|
+
let(:transactions) { [PagSeguro::Transaction.new] }
|
5
|
+
|
6
|
+
it "should have a PagSeguro::Errors instance" do
|
7
|
+
expect(subject.errors).to be_a(PagSeguro::Errors)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when there are no transactions" do
|
11
|
+
before do
|
12
|
+
subject.transactions = []
|
13
|
+
end
|
14
|
+
|
15
|
+
it "is blank" do
|
16
|
+
expect(subject).to be_empty
|
17
|
+
end
|
18
|
+
|
19
|
+
it "doesn't have any transaction" do
|
20
|
+
expect(subject).not_to be_any
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when there are transactions" do
|
25
|
+
before do
|
26
|
+
subject.transactions = transactions
|
27
|
+
end
|
28
|
+
|
29
|
+
it "is not blank" do
|
30
|
+
expect(subject).not_to be_empty
|
31
|
+
end
|
32
|
+
|
33
|
+
it "has any transaction" do
|
34
|
+
expect(subject).to be_any
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has PagSeguro::Transaction instances" do
|
38
|
+
subject.each do |transaction|
|
39
|
+
expect(transaction).to be_a(PagSeguro::Transaction)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Transaction::Response do
|
4
|
+
subject { PagSeguro::Transaction::Response.new(http_response, object) }
|
5
|
+
|
6
|
+
context "#success?" do
|
7
|
+
let(:object) { double(:Object) }
|
8
|
+
let(:http_response) { double(:HttpResponse, xml?: true) }
|
9
|
+
|
10
|
+
it "delegates to response" do
|
11
|
+
allow(http_response).to receive(:success?).and_return(true)
|
12
|
+
expect(subject).to be_success
|
13
|
+
|
14
|
+
allow(http_response).to receive(:success?).and_return(false)
|
15
|
+
expect(subject).not_to be_success
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#serialize" do
|
20
|
+
let(:object) { PagSeguro::Transaction.new }
|
21
|
+
let(:http_response) do
|
22
|
+
double(:Response, xml?: true, success?: true, unauthorized?: false,
|
23
|
+
bad_request?: false, body: raw_xml, data: parsed_xml)
|
24
|
+
end
|
25
|
+
let(:parsed_xml) { Nokogiri::XML(raw_xml) }
|
26
|
+
|
27
|
+
context "when request succeeds" do
|
28
|
+
let(:raw_xml) { File.read("./spec/fixtures/transactions/success.xml") }
|
29
|
+
|
30
|
+
it "returns a transaction" do
|
31
|
+
expect(subject.serialize).to be_a(PagSeguro::Transaction)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "not change errors" do
|
35
|
+
expect { subject.serialize }.not_to change { object.errors.empty? }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when request fails" do
|
40
|
+
before do
|
41
|
+
allow(http_response).to receive_messages(
|
42
|
+
success?: false,
|
43
|
+
error?: true,
|
44
|
+
error: Aitch::BadRequestError,
|
45
|
+
body: raw_xml
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
50
|
+
|
51
|
+
it "returns the transaction" do
|
52
|
+
expect(subject.serialize).to be_a(PagSeguro::Transaction)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "change transaction errors" do
|
56
|
+
expect { subject.serialize }.to change { object.errors.empty? }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SearchAbandoned do
|
4
|
+
subject do
|
5
|
+
PagSeguro::SearchAbandoned.new("transactions/abandoned", options, 1)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:source) { File.read("./spec/fixtures/transactions/search.xml") }
|
9
|
+
let(:body) { Nokogiri::XML(source) }
|
10
|
+
|
11
|
+
describe 'it searches abandoned transactions' do
|
12
|
+
before do
|
13
|
+
FakeWeb.register_uri :get,
|
14
|
+
%r{https://ws.pagseguro.uol.com.br/v2/transactions/abandoned.*finalDate=2015-11-12T16%3A59.*initialDate=2015-11-12T15%3A34.*page=1},
|
15
|
+
body: body
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:options) do
|
19
|
+
{
|
20
|
+
starts_at: Time.new(2015, 11, 12, 15, 34),
|
21
|
+
ends_at: Time.new(2015, 11, 12, 16, 59),
|
22
|
+
page: 1,
|
23
|
+
per_page: 10
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'the search abandoned' do
|
28
|
+
it 'returns an array of transactions' do
|
29
|
+
expect(subject.transactions.size).to eq(2)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'it searches abandoned transactions using credentials' do
|
35
|
+
before do
|
36
|
+
FakeWeb.register_uri :get,
|
37
|
+
%r{https://ws.pagseguro.uol.com.br/v2/transactions/abandoned.*appId=APP_ID.*appKey=APP_KEY.*finalDate=2015-11-12T16%3A59.*initialDate=2015-11-12T15%3A34.*},
|
38
|
+
body: body
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:options) do
|
42
|
+
{
|
43
|
+
starts_at: Time.new(2015, 11, 12, 15, 34),
|
44
|
+
ends_at: Time.new(2015, 11, 12, 16, 59),
|
45
|
+
page: 1,
|
46
|
+
per_page: 10,
|
47
|
+
credentials: PagSeguro::ApplicationCredentials.new('APP_ID', 'APP_KEY')
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns an array with given credentials' do
|
52
|
+
expect(subject.transactions.size).to eq(2)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SearchByDate do
|
4
|
+
subject do
|
5
|
+
PagSeguro::SearchByDate.new("transactions", options, 1)
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
FakeWeb.register_uri :get,
|
10
|
+
%r{https://ws.pagseguro.uol.com.br/v3/transactions.*finalDate=2015-11-12T16%3A59.*initialDate=2015-11-12T15%3A34.*page=1},
|
11
|
+
body: body
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:options) do
|
15
|
+
{
|
16
|
+
starts_at: Time.new(2015, 11, 12, 15, 34),
|
17
|
+
ends_at: Time.new(2015, 11, 12, 16, 59),
|
18
|
+
per_page: 1
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:source) { File.read("./spec/fixtures/transactions/search.xml") }
|
23
|
+
let(:body) { Nokogiri::XML(source) }
|
24
|
+
|
25
|
+
it 'searches transactions by date' do
|
26
|
+
expect(subject.transactions.size).to eq(2)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SearchByReference do
|
4
|
+
subject do
|
5
|
+
PagSeguro::SearchByReference.new("transactions", options, 1)
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
FakeWeb.register_uri :get,
|
10
|
+
%r{https://ws.pagseguro.uol.com.br/v3/transactions.*reference=ref1234.*},
|
11
|
+
body: body
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:options) { { reference: "ref1234" } }
|
15
|
+
let(:source) { File.read("./spec/fixtures/transactions/search.xml") }
|
16
|
+
let(:body) { Nokogiri::XML(source) }
|
17
|
+
|
18
|
+
it 'searches transactions by reference' do
|
19
|
+
expect(subject.transactions.size).to eq(2)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::Search do
|
4
|
+
let(:search) { PagSeguro::Search.new("foo", "bar", 1) }
|
5
|
+
let(:source) { File.read("./spec/fixtures/transactions/search.xml") }
|
6
|
+
let(:xml) { Nokogiri::XML(source) }
|
7
|
+
let(:response) do
|
8
|
+
double(
|
9
|
+
:response,
|
10
|
+
data: xml,
|
11
|
+
error?: false,
|
12
|
+
error: nil
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when being initialized' do
|
17
|
+
it 'initializes with passed page number' do
|
18
|
+
search = PagSeguro::Search.new('/foo/bar', 'options', 1)
|
19
|
+
expect(search.page).to eq(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'initializes with default page number' do
|
23
|
+
search = PagSeguro::Search.new('/foo/bar', 'options')
|
24
|
+
expect(search.page).to eq(0)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'methods that parse xml' do
|
29
|
+
before do
|
30
|
+
search.instance_exec(response) do |response|
|
31
|
+
@response = response
|
32
|
+
@errors = PagSeguro::Errors.new(response)
|
33
|
+
end
|
34
|
+
|
35
|
+
allow(search).to receive(:perform_request_and_serialize)
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#transactions' do
|
39
|
+
it 'returns an array of transactions' do
|
40
|
+
expect(search.transactions.size).to eq(2)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#created_at' do
|
45
|
+
it 'returns the created date' do
|
46
|
+
expect(search.created_at).to eq(Time.parse("2011-02-16T20:14:35.000-02:00"))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#results' do
|
51
|
+
it 'returns the number of results' do
|
52
|
+
expect(search.results).to eq(10)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#total_pages' do
|
57
|
+
it 'returns the number of pages' do
|
58
|
+
expect(search.total_pages).to eq(1)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#next_page?' do
|
64
|
+
context 'when there is a next page' do
|
65
|
+
search = PagSeguro::Search.new('foo', 'bar', 0)
|
66
|
+
it 'is page 0' do
|
67
|
+
expect(search).to be_next_page
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'is not page 0, but page < total_pages' do
|
71
|
+
allow(search).to receive(:total_pages).and_return(3)
|
72
|
+
expect(search).to be_next_page
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when there is no next page' do
|
77
|
+
it 'is not page 0, but page == total_pages' do
|
78
|
+
allow(search).to receive(:total_pages).and_return(1)
|
79
|
+
expect(search).not_to be_next_page
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#previous_page?' do
|
85
|
+
context 'when there is a previous page' do
|
86
|
+
search = PagSeguro::Search.new('foo', 'bar', 2)
|
87
|
+
it { expect(search).to be_previous_page }
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when there is no previous page' do
|
91
|
+
it { expect(search).not_to be_previous_page }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#next_page!' do
|
96
|
+
it 'has next page' do
|
97
|
+
allow(search).to receive(:next_page?).and_return(true)
|
98
|
+
search.next_page!
|
99
|
+
expect(search.page).to eq(2)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "doesn't have next page" do
|
103
|
+
allow(search).to receive(:next_page?).and_return(false)
|
104
|
+
search.next_page!
|
105
|
+
expect(search.page).to eq(1)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#previous_page!' do
|
110
|
+
it 'has previous page' do
|
111
|
+
search = PagSeguro::Search.new("foo", "bar", 2)
|
112
|
+
search.previous_page!
|
113
|
+
expect(search.page).to eq(1)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "does't have previous page" do
|
117
|
+
search.previous_page!
|
118
|
+
expect(search.page).to eq(1)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#valid?' do
|
123
|
+
it 'is valid' do
|
124
|
+
allow(search).to receive(:fetch).and_return(true)
|
125
|
+
expect(search).to be_valid
|
126
|
+
end
|
127
|
+
|
128
|
+
it "isn't valid" do
|
129
|
+
allow(search).to receive(:fetch).and_return(false)
|
130
|
+
expect(search).not_to be_valid
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|