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,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Session do |variable|
|
4
|
+
describe ".create" do
|
5
|
+
subject { PagSeguro::Session }
|
6
|
+
let(:request) do
|
7
|
+
double(:request, success?: true, xml?: true, data: xml_parsed,
|
8
|
+
body: raw_xml, unauthorized?: false, bad_request?: false,
|
9
|
+
not_found?: false)
|
10
|
+
end
|
11
|
+
let(:xml_parsed) { Nokogiri::XML(raw_xml) }
|
12
|
+
let(:raw_xml) { File.read("./spec/fixtures/session/success.xml") }
|
13
|
+
|
14
|
+
before do
|
15
|
+
allow(PagSeguro::Request).to receive(:post)
|
16
|
+
.with("sessions", "v2")
|
17
|
+
.and_return(request)
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when request succeeds" do
|
21
|
+
it "creates a session" do
|
22
|
+
expect(subject.create).to be_a(PagSeguro::Session)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when request fails" do
|
27
|
+
before do
|
28
|
+
allow(request).to receive_messages(
|
29
|
+
success?: false,
|
30
|
+
error?: true,
|
31
|
+
error: Aitch::BadRequestError
|
32
|
+
)
|
33
|
+
end
|
34
|
+
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
35
|
+
|
36
|
+
it "create a session" do
|
37
|
+
expect(subject.create).to be_a(PagSeguro::Session)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "create a session with errors" do
|
41
|
+
expect(subject.create.errors).not_to be_empty
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Shipping do
|
4
|
+
it_assigns_attribute :cost
|
5
|
+
it_ensures_type PagSeguro::Address, :address
|
6
|
+
|
7
|
+
PagSeguro::Shipping::TYPE.each do |name, id|
|
8
|
+
it "sets id for name (#{id.inspect} => #{name.inspect})" do
|
9
|
+
shipping = PagSeguro::Shipping.new(type_name: name)
|
10
|
+
expect(shipping.type_id).to eql(id)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets name for id (#{name.inspect} => #{id.inspect})" do
|
14
|
+
shipping = PagSeguro::Shipping.new(type_id: id)
|
15
|
+
expect(shipping.type_name).to eql(name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "raises when setting an invalid type id" do
|
20
|
+
shipping = PagSeguro::Shipping.new
|
21
|
+
|
22
|
+
expect {
|
23
|
+
shipping.type_id = 1234
|
24
|
+
}.to raise_error(
|
25
|
+
PagSeguro::Shipping::InvalidShippingTypeError,
|
26
|
+
"invalid 1234 type id"
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises when setting an invalid type name" do
|
31
|
+
shipping = PagSeguro::Shipping.new
|
32
|
+
|
33
|
+
expect {
|
34
|
+
shipping.type_name = :invalid
|
35
|
+
}.to raise_error(
|
36
|
+
PagSeguro::Shipping::InvalidShippingTypeError,
|
37
|
+
"invalid :invalid type name"
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,233 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::Subscription::RequestSerializer do
|
4
|
+
let(:subscription) { PagSeguro::Subscription.new }
|
5
|
+
let(:xml) { described_class.new(subscription).serialize }
|
6
|
+
|
7
|
+
context 'serialize' do
|
8
|
+
it 'plan attribute' do
|
9
|
+
subscription.plan = '89A1108EFEFE7A8EE4065FAD7872DE0D'
|
10
|
+
expect(xml).to match %r[
|
11
|
+
<directPreApproval>
|
12
|
+
.*<plan>89A1108EFEFE7A8EE4065FAD7872DE0D</plan>
|
13
|
+
]xm
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'reference attribute' do
|
17
|
+
subscription.reference = 'ID-CND'
|
18
|
+
expect(xml).to match %r[
|
19
|
+
<directPreApproval>
|
20
|
+
.*<reference>ID-CND</reference>
|
21
|
+
]xm
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'sender attributes' do
|
25
|
+
before do
|
26
|
+
subscription.sender = {
|
27
|
+
name: 'Comprador',
|
28
|
+
email: 'user@example.com',
|
29
|
+
ip: '192.168.0.1',
|
30
|
+
hash: 'hash',
|
31
|
+
phone: {
|
32
|
+
area_code: 12,
|
33
|
+
number: '23456789'
|
34
|
+
},
|
35
|
+
document: { type: 'CPF', value: '23606838450' },
|
36
|
+
address: {
|
37
|
+
street: 'Av Brigadeira Faria Lima',
|
38
|
+
number: '1384',
|
39
|
+
complement: '3 andar',
|
40
|
+
district: 'Jd Paulistano',
|
41
|
+
city: 'Sao Paulo',
|
42
|
+
state: 'SP',
|
43
|
+
country: 'BRA',
|
44
|
+
postal_code: '01452002'
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'name attribute' do
|
50
|
+
expect(xml).to match %r[
|
51
|
+
<directPreApproval>
|
52
|
+
.*<sender>
|
53
|
+
.*<name>Comprador</name>
|
54
|
+
]xm
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'email attribute' do
|
58
|
+
expect(xml).to match %r[
|
59
|
+
<directPreApproval>
|
60
|
+
.*<sender>
|
61
|
+
.*<email>user@example.com</email>
|
62
|
+
]xm
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'ip attribute' do
|
66
|
+
expect(xml).to match %r[
|
67
|
+
<directPreApproval>
|
68
|
+
.*<sender>
|
69
|
+
.*<ip>192.168.0.1</ip>
|
70
|
+
]xm
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'hash attribute' do
|
74
|
+
expect(xml).to match %r[
|
75
|
+
<directPreApproval>
|
76
|
+
.*<sender>
|
77
|
+
.*<hash>hash</hash>
|
78
|
+
]xm
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'phone attribute' do
|
82
|
+
expect(xml).to match %r[
|
83
|
+
<directPreApproval>
|
84
|
+
.*<sender>
|
85
|
+
.*<phone>
|
86
|
+
.*<areaCode>12</areaCode>
|
87
|
+
.*<number>23456789</number>
|
88
|
+
.*</phone>
|
89
|
+
]xm
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'address attribute' do
|
93
|
+
expect(xml).to match %r[
|
94
|
+
<directPreApproval>
|
95
|
+
.*<sender>
|
96
|
+
.*<address>
|
97
|
+
.*<street>Av\ Brigadeira\ Faria\ Lima</street>
|
98
|
+
.*<number>1384</number>
|
99
|
+
.*<complement>3\ andar</complement>
|
100
|
+
.*<district>Jd\ Paulistano</district>
|
101
|
+
.*<city>Sao\ Paulo</city>
|
102
|
+
.*<state>SP</state>
|
103
|
+
.*<country>BRA</country>
|
104
|
+
.*<postalCode>01452002</postalCode>
|
105
|
+
.*</address>
|
106
|
+
]xm
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'documents attribute' do
|
110
|
+
expect(xml).to match %r[
|
111
|
+
<directPreApproval>
|
112
|
+
.*<sender>
|
113
|
+
.*<documents>
|
114
|
+
.*<document>
|
115
|
+
.*<type>CPF</type>
|
116
|
+
.*<value>23606838450</value>
|
117
|
+
.*</document>
|
118
|
+
.*</documents>
|
119
|
+
]xm
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'payment method attributes' do
|
124
|
+
before do
|
125
|
+
subscription.payment_method = {
|
126
|
+
token: 'd05df2a777de4c4f882b3e8aaef09030',
|
127
|
+
holder: {
|
128
|
+
name: 'Nome',
|
129
|
+
birth_date: '11/01/1984',
|
130
|
+
document: { type: 'CPF', value: '00000000191' },
|
131
|
+
billing_address: {
|
132
|
+
street: 'Av Brigadeira Faria Lima',
|
133
|
+
number: '1384',
|
134
|
+
complement: '3 andar',
|
135
|
+
district: 'Jd Paulistano',
|
136
|
+
city: 'Sao Paulo',
|
137
|
+
state: 'SP',
|
138
|
+
country: 'BRA',
|
139
|
+
postal_code: '01452002'
|
140
|
+
},
|
141
|
+
phone: { area_code: '11', number: '988881234' }
|
142
|
+
}
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'type attribute' do
|
147
|
+
expect(xml).to match %r[
|
148
|
+
<directPreApproval>
|
149
|
+
.*<paymentMethod>
|
150
|
+
.*<type>CREDITCARD</type>
|
151
|
+
]xm
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'creditcard attributes' do
|
155
|
+
it 'token attribute' do
|
156
|
+
expect(xml).to match %r[
|
157
|
+
<directPreApproval>
|
158
|
+
.*<paymentMethod>
|
159
|
+
.*<creditCard>
|
160
|
+
.*<token>d05df2a777de4c4f882b3e8aaef09030</token>
|
161
|
+
]xm
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'holder attributes' do
|
165
|
+
it 'name attribute' do
|
166
|
+
expect(xml).to match %r[
|
167
|
+
<directPreApproval>
|
168
|
+
.*<paymentMethod>
|
169
|
+
.*<creditCard>
|
170
|
+
.*<holder>
|
171
|
+
.*<name>Nome</name>
|
172
|
+
]xm
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'birth_date attribute' do
|
176
|
+
expect(xml).to match %r[
|
177
|
+
<directPreApproval>
|
178
|
+
.*<paymentMethod>
|
179
|
+
.*<creditCard>
|
180
|
+
.*<holder>
|
181
|
+
.*<birthDate>11/01/1984</birthDate>
|
182
|
+
]xm
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'document attribute' do
|
186
|
+
expect(xml).to match %r[
|
187
|
+
<directPreApproval>
|
188
|
+
.*<paymentMethod>
|
189
|
+
.*<creditCard>
|
190
|
+
.*<holder>
|
191
|
+
.*<document>
|
192
|
+
.*<type>CPF</type>
|
193
|
+
.*<value>00000000191</value>
|
194
|
+
.*</document>
|
195
|
+
]xm
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'billing_address attributes' do
|
199
|
+
expect(xml).to match %r[
|
200
|
+
<directPreApproval>
|
201
|
+
.*<paymentMethod>
|
202
|
+
.*<creditCard>
|
203
|
+
.*<holder>
|
204
|
+
.*<billingAddress>
|
205
|
+
.*<street>Av\ Brigadeira\ Faria\ Lima</street>
|
206
|
+
.*<number>1384</number>
|
207
|
+
.*<complement>3\ andar</complement>
|
208
|
+
.*<district>Jd\ Paulistano</district>
|
209
|
+
.*<city>Sao\ Paulo</city>
|
210
|
+
.*<state>SP</state>
|
211
|
+
.*<country>BRA</country>
|
212
|
+
.*<postalCode>01452002</postalCode>
|
213
|
+
.*</billingAddress>
|
214
|
+
]xm
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'phone attributes' do
|
218
|
+
expect(xml).to match %r[
|
219
|
+
<directPreApproval>
|
220
|
+
.*<paymentMethod>
|
221
|
+
.*<creditCard>
|
222
|
+
.*<holder>
|
223
|
+
.*<phone>
|
224
|
+
.*<areaCode>11</areaCode>
|
225
|
+
.*<number>988881234</number>
|
226
|
+
.*</phone>
|
227
|
+
]xm
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::Subscription::ResponseSerializer do
|
4
|
+
subject { PagSeguro::Subscription::ResponseSerializer.new(xml) }
|
5
|
+
|
6
|
+
let(:xml) { Nokogiri::XML(source) }
|
7
|
+
|
8
|
+
context 'serializer from normal response' do
|
9
|
+
let(:source) { File.read('./spec/fixtures/subscription/success.xml') }
|
10
|
+
|
11
|
+
it 'must return the code' do
|
12
|
+
expect(subject.serialize).to eq({code: '12345'})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'serializer from a find response' do
|
17
|
+
let(:source) { File.read('./spec/fixtures/subscription/find_success.xml') }
|
18
|
+
|
19
|
+
context 'must a hash with the serialized attributes' do
|
20
|
+
let(:data) { subject.serialize_from_search }
|
21
|
+
|
22
|
+
it { expect(data[:name]).to eq 'Seguro contra roubo do Notebook Prata' }
|
23
|
+
it { expect(data[:code]).to eq 'C08984179E9EDF3DD4023F87B71DE349' }
|
24
|
+
it { expect(data[:date]).to eq '2011-11-23T13:40:23.000-02:00' }
|
25
|
+
it { expect(data[:tracker]).to eq '538C53' }
|
26
|
+
it { expect(data[:status]).to eq 'CANCELLED' }
|
27
|
+
it { expect(data[:reference]).to eq 'REF1234' }
|
28
|
+
it { expect(data[:status]).to eq 'CANCELLED' }
|
29
|
+
it { expect(data[:last_event_date]).to eq '2011-11-25T20:04:23.000-02:00' }
|
30
|
+
it { expect(data[:charge]).to eq 'auto' }
|
31
|
+
it { expect(data[:last_event_date]).to eq '2011-11-25T20:04:23.000-02:00' }
|
32
|
+
it { expect(data[:sender][:name]).to eq 'Comprador Istambul' }
|
33
|
+
it { expect(data[:sender][:email]).to eq 'c@i.com' }
|
34
|
+
it { expect(data[:sender][:phone][:area_code]).to eq '11' }
|
35
|
+
it { expect(data[:sender][:phone][:number]).to eq '30389678' }
|
36
|
+
it { expect(data[:sender][:address][:street]).to eq 'ALAMEDA ITU' }
|
37
|
+
it { expect(data[:sender][:address][:number]).to eq '78' }
|
38
|
+
it { expect(data[:sender][:address][:complement]).to eq 'ap. 2601' }
|
39
|
+
it { expect(data[:sender][:address][:district]).to eq 'Jardim Paulista' }
|
40
|
+
it { expect(data[:sender][:address][:city]).to eq 'SAO PAULO' }
|
41
|
+
it { expect(data[:sender][:address][:state]).to eq 'SP' }
|
42
|
+
it { expect(data[:sender][:address][:country]).to eq 'BRASIL' }
|
43
|
+
it { expect(data[:sender][:address][:postal_code]).to eq '01421000' }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::Subscription::Response do
|
4
|
+
subject { PagSeguro::Subscription::Response.new(http_response, subscription) }
|
5
|
+
let(:subscription) { PagSeguro::Subscription.new }
|
6
|
+
|
7
|
+
context '#success?' do
|
8
|
+
let(:http_response) { double(:HttpResponse, xml?: true) }
|
9
|
+
|
10
|
+
it 'delegate 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
|
+
context '#serialize' do
|
20
|
+
let(:http_response) do
|
21
|
+
double(
|
22
|
+
:Request,
|
23
|
+
success?: true,
|
24
|
+
xml?: true,
|
25
|
+
data: xml_parsed,
|
26
|
+
body: raw_xml,
|
27
|
+
unauthorized?: false,
|
28
|
+
bad_request?: false,
|
29
|
+
not_found?: false
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:xml_parsed) { Nokogiri::XML(raw_xml) }
|
34
|
+
|
35
|
+
context 'when request succeeds' do
|
36
|
+
|
37
|
+
|
38
|
+
context 'and response is normal' do
|
39
|
+
let(:raw_xml) { File.read('./spec/fixtures/subscription/success.xml') }
|
40
|
+
|
41
|
+
it 'not change subscription errors' do
|
42
|
+
expect { subject.serialize }.not_to change { subscription.errors.empty? }
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns a hash with serialized response data' do
|
46
|
+
expect{ subject.serialize }.to change { subscription.code }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'and response is a search' do
|
51
|
+
let(:raw_xml) { File.read('./spec/fixtures/subscription/search_success.xml') }
|
52
|
+
|
53
|
+
it 'not change subscription errors' do
|
54
|
+
expect { subject.serialize }.not_to change { subscription.errors.empty? }
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'return a hash with serialized search response data' do
|
58
|
+
expect{ subject.serialize(:search) }.to change { subscription.name }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when request fails' do
|
64
|
+
before do
|
65
|
+
allow(http_response).to receive_messages(
|
66
|
+
success?: false,
|
67
|
+
error?: true,
|
68
|
+
error: Aitch::BadRequestError
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:raw_xml) { File.read('./spec/fixtures/subscription/fail.xml') }
|
73
|
+
|
74
|
+
it 'errors should be present' do
|
75
|
+
expect { subject.serialize }.to change { subscription.errors }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SubscriptionSearch do
|
4
|
+
let(:path) { 'path-to-search' }
|
5
|
+
let(:credentials) { PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN') }
|
6
|
+
let(:options) do
|
7
|
+
{
|
8
|
+
credentials: credentials
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { PagSeguro::SubscriptionSearch.new(path, options) }
|
13
|
+
|
14
|
+
context 'when search succeeds' do
|
15
|
+
before do
|
16
|
+
FakeWeb.register_uri(
|
17
|
+
:get,
|
18
|
+
"https://ws.pagseguro.uol.com.br/v2/path-to-search?page=1&email=user%40example.com&token=TOKEN&charset=UTF-8",
|
19
|
+
body: response_body,
|
20
|
+
content_type: "text/xml"
|
21
|
+
)
|
22
|
+
|
23
|
+
subject.next_page!
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:response_body) { File.read('./spec/fixtures/subscription/search_success.xml') }
|
27
|
+
|
28
|
+
it 'must have results in page' do
|
29
|
+
expect(subject.results).to eq 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'must have total pages' do
|
33
|
+
expect(subject.total_pages).to eq 1
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'must have date of create' do
|
37
|
+
expect(subject.created_at).to eq Time.new(2011,8,8,16,16,23, '-03:00')
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'subscriptions' do
|
41
|
+
it 'must return a subscription array' do
|
42
|
+
expect(subject.subscriptions).to be_an Array
|
43
|
+
|
44
|
+
subject.subscriptions.each do |subscription|
|
45
|
+
expect(subscription).to be_a PagSeguro::Subscription
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'subscription' do
|
50
|
+
let(:subscription) { subject.subscriptions.first }
|
51
|
+
|
52
|
+
it 'must have name' do
|
53
|
+
expect(subscription.name).to eq 'PagSeguro Pre Approval'
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'must have code' do
|
57
|
+
expect(subscription.code).to eq '12E10BEF5E5EF94004313FB891C8E4CF'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'must have date' do
|
61
|
+
expect(subscription.date).to eq "2011-08-15T11:06:44.000-03:00"
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'must have tracker' do
|
65
|
+
expect(subscription.tracker).to eq '624C17'
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'must have status' do
|
69
|
+
expect(subscription.status).to eq 'INITIATED'
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'must have reference' do
|
73
|
+
expect(subscription.reference).to eq 'R123456'
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'must have last event date' do
|
77
|
+
expect(subscription.last_event_date).to eq "2011-08-08T15:37:30.000-03:00"
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'must have charge' do
|
81
|
+
expect(subscription.charge).to eq 'auto'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when search fails' do
|
88
|
+
before do
|
89
|
+
FakeWeb.register_uri(
|
90
|
+
:get,
|
91
|
+
"https://ws.pagseguro.uol.com.br/v2/path-to-search?page=1&email=user%40example.com&token=TOKEN&charset=UTF-8",
|
92
|
+
body: response_body,
|
93
|
+
status: ['400', 'ERROR'],
|
94
|
+
content_type: "text/xml"
|
95
|
+
)
|
96
|
+
|
97
|
+
subject.next_page!
|
98
|
+
end
|
99
|
+
|
100
|
+
let(:response_body) { File.read('./spec/fixtures/subscription/fail.xml') }
|
101
|
+
|
102
|
+
it 'must do not be valid' do
|
103
|
+
expect(subject).to_not be_valid
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'errors must not be empty' do
|
107
|
+
expect{ subject.valid? }.to change{ subject.errors.empty? }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'page control' do
|
112
|
+
it 'page default should be 1' do
|
113
|
+
expect(subject.page).to eq 0
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'search can begin with other page' do
|
117
|
+
options[:page] = 2
|
118
|
+
expect(subject.page).to eq 2
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'next page' do
|
122
|
+
it 'should increment the page by 1' do
|
123
|
+
allow(subject).to receive(:total_pages).and_return(10)
|
124
|
+
expect{ subject.next_page! }.to change{ subject.page }.from(0).to(1)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'not increment if no have more pages' do
|
128
|
+
subject.next_page!
|
129
|
+
allow(subject).to receive(:total_pages).and_return(1)
|
130
|
+
expect{ subject.next_page! }.to_not change{ subject.page }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'previous page' do
|
135
|
+
it 'should decrement the page by 1' do
|
136
|
+
options[:page] = 3
|
137
|
+
expect{ subject.previous_page! }.to change{ subject.page }.from(3).to(2)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'not decrement unless current page be more than 1' do
|
141
|
+
expect{ subject.previous_page! }.not_to change{ subject.page }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when page changes' do
|
146
|
+
it 'fetched clear! should be called' do
|
147
|
+
allow(subject).to receive(:total_pages).and_return(10)
|
148
|
+
expect(subject).to receive(:clear!).with(no_args)
|
149
|
+
subject.next_page!
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|