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,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::Extensions::CollectionObject do
|
4
|
+
before(:all) do
|
5
|
+
# Collection
|
6
|
+
class MyItems
|
7
|
+
include PagSeguro::Extensions::CollectionObject
|
8
|
+
end
|
9
|
+
|
10
|
+
# Item
|
11
|
+
class MyItem
|
12
|
+
attr_accessor :name
|
13
|
+
|
14
|
+
def ==(other)
|
15
|
+
name.eql?(other.name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:collection) do
|
21
|
+
MyItems.new
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:object) do
|
25
|
+
item = MyItem.new
|
26
|
+
item.name = 'Item1'
|
27
|
+
item
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when was included in a new class" do
|
31
|
+
it "new class must be include PagSeguro::Extensions::CollectionObject" do
|
32
|
+
expect(MyItems.included_modules).to include(PagSeguro::Extensions::CollectionObject)
|
33
|
+
end
|
34
|
+
|
35
|
+
context "and when this class is instantiated" do
|
36
|
+
it "must be initialized empty" do
|
37
|
+
expect(collection).to be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
context "must respond to" do
|
41
|
+
[
|
42
|
+
:size,
|
43
|
+
:clear,
|
44
|
+
:empty?,
|
45
|
+
:any?,
|
46
|
+
:each,
|
47
|
+
:include?,
|
48
|
+
:<<
|
49
|
+
].each do |method|
|
50
|
+
it "#{method}" do
|
51
|
+
expect(collection).to respond_to(method)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "object type must be the class name singularized" do
|
57
|
+
expect(collection.collection_type).to eq MyItem
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'collection operations' do
|
63
|
+
it "when add a new object it must be incremented" do
|
64
|
+
expect{ collection << object }.to change{ collection.size }.by(1)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "when add an object already added" do
|
68
|
+
collection << object
|
69
|
+
expect{ collection << object }.to_not change{ collection.size }
|
70
|
+
end
|
71
|
+
|
72
|
+
it "must to include an object before added" do
|
73
|
+
collection << object
|
74
|
+
expect(collection).to include(object)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Creating Session" do
|
4
|
+
let(:session) { PagSeguro::Session.create }
|
5
|
+
|
6
|
+
context "when request succeeds" do
|
7
|
+
before do
|
8
|
+
body = %[<?xml version="1.0"?><session>
|
9
|
+
<id>620f99e348c24f07877c927b353e49d3</id></session>]
|
10
|
+
FakeWeb.register_uri :post, PagSeguro.api_url("v2/sessions"), body: body,
|
11
|
+
content_type: "text/xml"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a session object" do
|
15
|
+
expect(session).to be_a(PagSeguro::Session)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#errors" do
|
19
|
+
it "is an errors object" do
|
20
|
+
expect(session.errors).to be_a(PagSeguro::Errors)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has no errors" do
|
24
|
+
expect(session.errors).to be_empty
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when request fails" do
|
30
|
+
before do
|
31
|
+
body = %[<?xml version="1.0"?><errors><error><code>1234</code>
|
32
|
+
<message>Sample error</message></error></errors>]
|
33
|
+
FakeWeb.register_uri :post, PagSeguro.api_url("v2/sessions"),
|
34
|
+
status: [400, "Bad Request"], body: body, content_type: "text/xml"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns a session object" do
|
38
|
+
expect(session).to be_a(PagSeguro::Session)
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#errors" do
|
42
|
+
it "is an errors object" do
|
43
|
+
expect(session.errors).to be_a(PagSeguro::Errors)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has errors" do
|
47
|
+
expect(session.errors).to_not be_empty
|
48
|
+
expect(session.errors).to include("Sample error")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Creating Transaction Request" do
|
4
|
+
let(:transaction) { PagSeguro::OnlineDebitTransactionRequest.new }
|
5
|
+
|
6
|
+
context "when request succeeds" do
|
7
|
+
before do
|
8
|
+
body = File.read("./spec/fixtures/transaction_request/success.xml")
|
9
|
+
FakeWeb.register_uri :post, PagSeguro.api_url("v2/transactions"),
|
10
|
+
body: body, content_type: "text/xml"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns true" do
|
14
|
+
expect(transaction.create).to be_truthy
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#errors" do
|
18
|
+
before do
|
19
|
+
transaction.create
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is an errors object" do
|
23
|
+
expect(transaction.errors).to be_a(PagSeguro::Errors)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has no errors" do
|
27
|
+
expect(transaction.errors).to be_empty
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when request fails" do
|
33
|
+
before do
|
34
|
+
body = %[<?xml version="1.0"?><errors><error><code>1234</code>
|
35
|
+
<message>Sample error</message></error></errors>]
|
36
|
+
FakeWeb.register_uri :post, PagSeguro.api_url("v2/transactions"),
|
37
|
+
status: [400, "Bad Request"], body: body, content_type: "text/xml"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "does not change attributes" do
|
41
|
+
expect { transaction.create }.not_to change { transaction.code }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#errors" do
|
45
|
+
before do
|
46
|
+
transaction.create
|
47
|
+
end
|
48
|
+
|
49
|
+
it "is an errors object" do
|
50
|
+
expect(transaction.errors).to be_a(PagSeguro::Errors)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "has errors" do
|
54
|
+
expect(transaction.errors).to_not be_empty
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Holder do
|
4
|
+
it_assigns_attribute :name
|
5
|
+
it_assigns_attribute :birth_date
|
6
|
+
|
7
|
+
it_ensures_type PagSeguro::Document, :document
|
8
|
+
it_ensures_type PagSeguro::Phone, :phone
|
9
|
+
it_ensures_type PagSeguro::Address, :billing_address
|
10
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Installment::Collection do
|
4
|
+
let(:installments) do
|
5
|
+
[
|
6
|
+
{ amount: "100", card_brand: "visa" },
|
7
|
+
{ amount: "110", card_brand: "visa" }
|
8
|
+
]
|
9
|
+
end
|
10
|
+
subject { PagSeguro::Installment::Collection.new }
|
11
|
+
|
12
|
+
describe "initialization" do
|
13
|
+
it "errors should be a instance of PagSeguro::Errors" do
|
14
|
+
expect(subject.errors).to be_a(PagSeguro::Errors)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "delegate empty? to @installments" do
|
18
|
+
subject.installments = []
|
19
|
+
expect(subject).to be_empty
|
20
|
+
|
21
|
+
subject.installments = installments
|
22
|
+
expect(subject).not_to be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
it "delegate any? to @installments" do
|
26
|
+
subject.installments = []
|
27
|
+
expect(subject).not_to be_any
|
28
|
+
|
29
|
+
subject.installments = installments
|
30
|
+
expect(subject).to be_any
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "#installments=" do
|
35
|
+
it "turns array of hash into installments" do
|
36
|
+
subject.installments = installments
|
37
|
+
|
38
|
+
subject.each do |installment|
|
39
|
+
expect(installment).to be_a(PagSeguro::Installment)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Installment::RequestSerializer do
|
4
|
+
let(:data) { { amount: "100.00", card_brand: "visa" } }
|
5
|
+
let(:params) { serializer.to_params }
|
6
|
+
subject(:serializer) { described_class.new(data) }
|
7
|
+
|
8
|
+
it { expect(params).to include(amount: "100.00") }
|
9
|
+
it { expect(params).to include(cardBrand: "visa") }
|
10
|
+
|
11
|
+
context "when card brand is not present" do
|
12
|
+
let(:data) { { amount: "100.00" } }
|
13
|
+
|
14
|
+
it { expect(params).to_not include(cardBrand: "visa") }
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Installment::ResponseSerializer do
|
4
|
+
context "when there are installments" do
|
5
|
+
let(:source) { File.read("./spec/fixtures/installment/success.xml") }
|
6
|
+
let(:xml) { Nokogiri::XML(source) }
|
7
|
+
subject(:data) do
|
8
|
+
xml.css("installments > installment").map do |xml|
|
9
|
+
described_class.new(xml).serialize
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it { expect(data.size).to eq(3) }
|
14
|
+
|
15
|
+
it { expect(data[0]).to include(card_brand: "visa") }
|
16
|
+
it { expect(data[0]).to include(quantity: "1") }
|
17
|
+
it { expect(data[0]).to include(amount: "500.00") }
|
18
|
+
it { expect(data[0]).to include(total_amount: "500.00") }
|
19
|
+
it { expect(data[0]).to include(interest_free: "true") }
|
20
|
+
|
21
|
+
it { expect(data[1]).to include(card_brand: "visa") }
|
22
|
+
it { expect(data[1]).to include(quantity: "2") }
|
23
|
+
it { expect(data[1]).to include(amount: "261.28") }
|
24
|
+
it { expect(data[1]).to include(total_amount: "522.55") }
|
25
|
+
it { expect(data[1]).to include(interest_free: "false") }
|
26
|
+
|
27
|
+
it { expect(data[2]).to include(card_brand: "visa") }
|
28
|
+
it { expect(data[2]).to include(quantity: "3") }
|
29
|
+
it { expect(data[2]).to include(amount: "176.73") }
|
30
|
+
it { expect(data[2]).to include(total_amount: "530.20") }
|
31
|
+
it { expect(data[2]).to include(interest_free: "false") }
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe PagSeguro::Installment::Response do
|
4
|
+
let(:http_response) do
|
5
|
+
double(:request, success?: true, xml?: true, data: xml_parsed,
|
6
|
+
body: raw_xml, unauthorized?: false, :not_found? => false)
|
7
|
+
end
|
8
|
+
let(:xml_parsed) { Nokogiri::XML(raw_xml) }
|
9
|
+
let(:collection) { PagSeguro::Installment::Collection.new }
|
10
|
+
subject { PagSeguro::Installment::Response.new(http_response, collection) }
|
11
|
+
|
12
|
+
context "#success?" do
|
13
|
+
let(:http_response) do
|
14
|
+
double(:HttpResponse, xml?: true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "delegate to response" do
|
18
|
+
allow(http_response).to receive(:success?).and_return(true)
|
19
|
+
expect(subject).to be_success
|
20
|
+
|
21
|
+
allow(http_response).to receive(:success?).and_return(false)
|
22
|
+
expect(subject).not_to be_success
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#serialize" do
|
27
|
+
context "when request succeeds" do
|
28
|
+
let(:serializer) { double(:serializer) }
|
29
|
+
let(:raw_xml) { File.read("./spec/fixtures/installment/success.xml") }
|
30
|
+
|
31
|
+
it "not change errors" do
|
32
|
+
expect { subject.serialize }.not_to change { collection.errors.empty? }
|
33
|
+
end
|
34
|
+
|
35
|
+
it "return a collection instance" do
|
36
|
+
expect(subject.serialize).to be_a(PagSeguro::Installment::Collection)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when request fails" do
|
41
|
+
before do
|
42
|
+
allow(http_response).to receive_messages(
|
43
|
+
success?: false,
|
44
|
+
error?: true,
|
45
|
+
error: Aitch::BadRequestError
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
50
|
+
|
51
|
+
it "update collection errors" do
|
52
|
+
expect { subject.serialize }.to change { collection.errors.empty? }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Installment do
|
4
|
+
it_assigns_attribute :card_brand
|
5
|
+
it_assigns_attribute :quantity
|
6
|
+
it_assigns_attribute :amount
|
7
|
+
it_assigns_attribute :total_amount
|
8
|
+
it_assigns_attribute :interest_free
|
9
|
+
|
10
|
+
let(:request) do
|
11
|
+
double(:request, success?: true, xml?: true, body: raw_xml, data: xml_parsed, unauthorized?: false, not_found?: false)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:xml_parsed) { Nokogiri::XML(raw_xml) }
|
15
|
+
|
16
|
+
describe ".find" do
|
17
|
+
subject { PagSeguro::Installment }
|
18
|
+
let(:params) { { amount: "100.00", cardBrand: "visa" } }
|
19
|
+
|
20
|
+
before do
|
21
|
+
allow(PagSeguro::Request).to receive(:get)
|
22
|
+
.with("installments", "v2", params)
|
23
|
+
.and_return(request)
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when request succeeds" do
|
27
|
+
let(:raw_xml) { File.read("./spec/fixtures/installment/success.xml") }
|
28
|
+
|
29
|
+
it "returns a instance of collection" do
|
30
|
+
expect(subject.find("100.00", "visa")).to be_a(PagSeguro::Installment::Collection)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when request fails" do
|
35
|
+
before do
|
36
|
+
allow(request).to receive_messages(
|
37
|
+
success?: false,
|
38
|
+
error?: true,
|
39
|
+
error: Aitch::BadRequestError
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
44
|
+
|
45
|
+
it "returns collection with error" do
|
46
|
+
expect(subject.find("100.00", "visa").errors).not_to be_empty
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Item do
|
4
|
+
it_assigns_attribute :id
|
5
|
+
it_assigns_attribute :description
|
6
|
+
it_assigns_attribute :amount
|
7
|
+
it_assigns_attribute :quantity
|
8
|
+
it_assigns_attribute :weight
|
9
|
+
it_assigns_attribute :shipping_cost
|
10
|
+
|
11
|
+
it "sets default quantity" do
|
12
|
+
item = PagSeguro::Item.new
|
13
|
+
expect(item.quantity).to eql(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "sets default weight" do
|
17
|
+
item = PagSeguro::Item.new
|
18
|
+
expect(item.weight).to be_zero
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Items do
|
4
|
+
it "implements #each" do
|
5
|
+
expect(PagSeguro::Items.new).to respond_to(:each)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "implements #any" do
|
9
|
+
expect(PagSeguro::Items.new).to respond_to(:any?)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "includes Enumerable" do
|
13
|
+
expect(PagSeguro::Items.included_modules).to include(Enumerable)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "sets item" do
|
17
|
+
item = PagSeguro::Item.new
|
18
|
+
items = PagSeguro::Items.new
|
19
|
+
items << item
|
20
|
+
|
21
|
+
expect(items.size).to eql(1)
|
22
|
+
expect(items).to include(item)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets item from Hash" do
|
26
|
+
item = PagSeguro::Item.new(id: 1234)
|
27
|
+
|
28
|
+
expect(PagSeguro::Item)
|
29
|
+
.to receive(:new)
|
30
|
+
.with({id: 1234})
|
31
|
+
.and_return(item)
|
32
|
+
|
33
|
+
items = PagSeguro::Items.new
|
34
|
+
items << {id: 1234}
|
35
|
+
|
36
|
+
expect(items).to include(item)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "empties items" do
|
40
|
+
items = PagSeguro::Items.new
|
41
|
+
items << {id: 1234}
|
42
|
+
items.clear
|
43
|
+
|
44
|
+
expect(items).to be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
context "#<<" do
|
48
|
+
before do
|
49
|
+
subject << item
|
50
|
+
end
|
51
|
+
|
52
|
+
subject do
|
53
|
+
PagSeguro::Items.new
|
54
|
+
end
|
55
|
+
|
56
|
+
let(:item) do
|
57
|
+
PagSeguro::Item.new(id: 1234, description: "Tea", quantity: 1, amount: 300.0)
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when add same item" do
|
61
|
+
context "and no quantity is informed" do
|
62
|
+
let(:other_item) do
|
63
|
+
{ id: 1234, description: "Tea", amount: 300.0 }
|
64
|
+
end
|
65
|
+
|
66
|
+
it "increases one in item quantity" do
|
67
|
+
expect { subject << other_item }.to change { item.quantity }.by(1)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "does not increase items size" do
|
71
|
+
expect { subject << other_item }.not_to change { subject.size }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "and quantity is informed" do
|
76
|
+
let(:other_item) do
|
77
|
+
{ id: 1234, description: "Tea", quantity: 20, amount: 300.0 }
|
78
|
+
end
|
79
|
+
|
80
|
+
it "increases item quantity" do
|
81
|
+
expect { subject << other_item }.to change { item.quantity }.by(20)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "does not increase items size" do
|
85
|
+
expect { subject << other_item }.not_to change { subject.size }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when add different item" do
|
91
|
+
context "with only description equals" do
|
92
|
+
let(:other_item) do
|
93
|
+
{ id: 4321, description: "Tea" }
|
94
|
+
end
|
95
|
+
|
96
|
+
it "does not increase item quantity" do
|
97
|
+
expect { subject << other_item }.not_to change { item.quantity }
|
98
|
+
end
|
99
|
+
|
100
|
+
it "increases items size" do
|
101
|
+
expect { subject << other_item }.to change { subject.size }.by(1)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "with only id equals" do
|
106
|
+
let(:other_item) do
|
107
|
+
{ id: 1234, description: "Coffee" }
|
108
|
+
end
|
109
|
+
|
110
|
+
it "does not increase item quantity" do
|
111
|
+
expect { subject << other_item }.not_to change { item.quantity }
|
112
|
+
end
|
113
|
+
|
114
|
+
it "increases subject size" do
|
115
|
+
expect { subject << other_item }.to change { subject.size }.by(1)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with only amount equals" do
|
120
|
+
let(:other_item) do
|
121
|
+
{ id: 4321, description: "Coffee", amount: 300.0 }
|
122
|
+
end
|
123
|
+
|
124
|
+
it "does not increase item quantity" do
|
125
|
+
expect { subject << other_item }.not_to change { item.quantity }
|
126
|
+
end
|
127
|
+
|
128
|
+
it "increases subject size" do
|
129
|
+
expect { subject << other_item }.to change { subject.size }.by(1)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with id and description different" do
|
134
|
+
let(:other_item) do
|
135
|
+
{ id: 4321, description: "Coffee" }
|
136
|
+
end
|
137
|
+
|
138
|
+
it "does not increase item quantity" do
|
139
|
+
expect { subject << other_item }.not_to change { item.quantity }
|
140
|
+
end
|
141
|
+
|
142
|
+
it "increases subject size" do
|
143
|
+
expect { subject << other_item }.to change { subject.size }.by(1)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|