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,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::TransactionRequest::ResponseSerializer do
|
4
|
+
context "for existing transactions" do
|
5
|
+
let(:source) { File.read("./spec/fixtures/transaction_request/success.xml") }
|
6
|
+
let(:xml) { Nokogiri::XML(source) }
|
7
|
+
let(:serializer) { described_class.new(xml.css("transaction").first) }
|
8
|
+
subject(:data) { serializer.serialize }
|
9
|
+
|
10
|
+
it { expect(data).to include(created_at: Time.parse("2011-02-05T15:46:12.000-02:00")) }
|
11
|
+
it { expect(data).to include(updated_at: Time.parse("2011-02-15T17:39:14.000-03:00")) }
|
12
|
+
it { expect(data).to include(code: "9E884542-81B3-4419-9A75-BCC6FB495EF1") }
|
13
|
+
it { expect(data).to include(reference: "REF1234") }
|
14
|
+
it { expect(data).to include(type_id: "1") }
|
15
|
+
it { expect(data).to include(status: "3") }
|
16
|
+
it { expect(data).to include(payment_method: {type_id: "1", code: "101"}) }
|
17
|
+
it { expect(data).to include(payment_link: "https://pagseguro.uol.com.br/checkout/imprimeBoleto.jhtml?code=314601B208B24A5CA5
|
18
|
+
3260000F7BB0D0") }
|
19
|
+
it { expect(data).to include(gross_amount: BigDecimal("49900.00")) }
|
20
|
+
it { expect(data).to include(discount_amount: BigDecimal("0.00")) }
|
21
|
+
it { expect(data).to include(net_amount: BigDecimal("49900.50")) }
|
22
|
+
it { expect(data).to include(extra_amount: BigDecimal("0.00")) }
|
23
|
+
it { expect(data).to include(installment_count: 1) }
|
24
|
+
|
25
|
+
it { expect(data[:items].size).to eq(2) }
|
26
|
+
it { expect(data[:items].first).to include(id: "0001") }
|
27
|
+
it { expect(data[:items].first).to include(description: "Notebook Prata") }
|
28
|
+
it { expect(data[:items].first).to include(quantity: 1) }
|
29
|
+
it { expect(data[:items].first).to include(amount: BigDecimal("24300.00")) }
|
30
|
+
it { expect(data[:items][1]).to include(id: "0002") }
|
31
|
+
it { expect(data[:items][1]).to include(description: "Notebook Rosa") }
|
32
|
+
it { expect(data[:items][1]).to include(quantity: 1) }
|
33
|
+
it { expect(data[:items][1]).to include(amount: BigDecimal("25600.00")) }
|
34
|
+
|
35
|
+
it { expect(data[:sender]).to include(name: "Jose Comprador") }
|
36
|
+
it { expect(data[:sender]).to include(email: "comprador@uol.com.br") }
|
37
|
+
it { expect(data[:sender][:phone]).to include(area_code: "11") }
|
38
|
+
it { expect(data[:sender][:phone]).to include(number: "56273440") }
|
39
|
+
|
40
|
+
it { expect(data[:shipping]).to include(type_id: "1") }
|
41
|
+
it { expect(data[:shipping]).to include(cost: BigDecimal("21.50")) }
|
42
|
+
|
43
|
+
it { expect(data[:shipping][:address]).to include(street: "Av. Brig. Faria Lima") }
|
44
|
+
it { expect(data[:shipping][:address]).to include(number: "1384") }
|
45
|
+
it { expect(data[:shipping][:address]).to include(complement: "5o andar") }
|
46
|
+
it { expect(data[:shipping][:address]).to include(district: "Jardim Paulistano") }
|
47
|
+
it { expect(data[:shipping][:address]).to include(city: "Sao Paulo") }
|
48
|
+
it { expect(data[:shipping][:address]).to include(state: "SP") }
|
49
|
+
it { expect(data[:shipping][:address]).to include(country: "BRA") }
|
50
|
+
it { expect(data[:shipping][:address]).to include(postal_code: "01452002") }
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::TransactionRequest::Response do
|
4
|
+
let(:transaction_request) do
|
5
|
+
PagSeguro::TransactionRequest.new
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { PagSeguro::TransactionRequest::Response.new(http_response, transaction_request) }
|
9
|
+
|
10
|
+
context "#success?" do
|
11
|
+
let(:http_response) do
|
12
|
+
double(:HttpResponse, xml?: true)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "delegate to response" do
|
16
|
+
allow(http_response).to receive(:success?).and_return(true)
|
17
|
+
expect(subject).to be_success
|
18
|
+
|
19
|
+
allow(http_response).to receive(:success?).and_return(false)
|
20
|
+
expect(subject).not_to be_success
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "#serialize" do
|
25
|
+
let(:http_response) do
|
26
|
+
double(:HttpResponse, data: xml_parsed, body: raw_xml, success?: true, xml?: true, unauthorized?: false, bad_request?: false, not_found?: false)
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:xml_parsed) { Nokogiri::XML(raw_xml) }
|
30
|
+
|
31
|
+
context "with success request" do
|
32
|
+
let(:raw_xml) { File.read("./spec/fixtures/transaction_request/success.xml") }
|
33
|
+
|
34
|
+
it "return transaction_request instance" do
|
35
|
+
expect(subject.serialize).to eq transaction_request
|
36
|
+
end
|
37
|
+
|
38
|
+
it "change code" do
|
39
|
+
expect { subject.serialize }.to change { transaction_request.code }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when request fails" do
|
44
|
+
before do
|
45
|
+
allow(http_response).to receive_messages(
|
46
|
+
success?: false,
|
47
|
+
error?: true,
|
48
|
+
error: Aitch::BadRequestError
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
53
|
+
|
54
|
+
it "return transaction_request instance" do
|
55
|
+
expect(subject.serialize).to eq transaction_request
|
56
|
+
end
|
57
|
+
|
58
|
+
it "assign errors" do
|
59
|
+
expect { subject.serialize }.to change { transaction_request.errors.empty? }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::TransactionRequest do |variable|
|
4
|
+
let(:xml_parsed) { Nokogiri::XML(raw_xml) }
|
5
|
+
|
6
|
+
it_assigns_attribute :currency
|
7
|
+
it_assigns_attribute :primary_receiver
|
8
|
+
it_assigns_attribute :extra_amount
|
9
|
+
it_assigns_attribute :reference
|
10
|
+
it_assigns_attribute :notification_url
|
11
|
+
it_assigns_attribute :payment_mode
|
12
|
+
it_assigns_attribute :extra_params
|
13
|
+
|
14
|
+
it_ensures_type PagSeguro::Sender, :sender
|
15
|
+
it_ensures_type PagSeguro::Shipping, :shipping
|
16
|
+
|
17
|
+
it { is_expected.to respond_to(:code) }
|
18
|
+
it { is_expected.to respond_to(:type_id) }
|
19
|
+
it { is_expected.to respond_to(:payment_link) }
|
20
|
+
it { is_expected.to respond_to(:status) }
|
21
|
+
it { is_expected.to respond_to(:payment_method) }
|
22
|
+
it { is_expected.to respond_to(:gross_amount) }
|
23
|
+
it { is_expected.to respond_to(:discount_amount) }
|
24
|
+
it { is_expected.to respond_to(:net_amount) }
|
25
|
+
it { is_expected.to respond_to(:installment_count) }
|
26
|
+
it { is_expected.to respond_to(:created_at) }
|
27
|
+
it { is_expected.to respond_to(:updated_at) }
|
28
|
+
|
29
|
+
it "sets the sender" do
|
30
|
+
sender = PagSeguro::Sender.new
|
31
|
+
payment = PagSeguro::TransactionRequest.new(sender: sender)
|
32
|
+
|
33
|
+
expect(payment.sender).to eql(sender)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "sets shipping" do
|
37
|
+
shipping = PagSeguro::Shipping.new
|
38
|
+
payment = PagSeguro::TransactionRequest.new(shipping: shipping)
|
39
|
+
|
40
|
+
expect(payment.shipping).to eql(shipping)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "sets the items" do
|
44
|
+
payment = PagSeguro::TransactionRequest.new
|
45
|
+
expect(payment.items).to be_a(PagSeguro::Items)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "sets default currency" do
|
49
|
+
payment = PagSeguro::TransactionRequest.new
|
50
|
+
expect(payment.currency).to eql("BRL")
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#payment_method" do
|
54
|
+
it "raises not implemented error" do
|
55
|
+
expect { subject.payment_method }.to raise_error(NotImplementedError)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#extra_params" do
|
60
|
+
it "is empty before initialization" do
|
61
|
+
expect(subject.extra_params).to be_empty
|
62
|
+
end
|
63
|
+
|
64
|
+
it "allows extra parameter addition" do
|
65
|
+
subject.extra_params << { extraParam: 'value' }
|
66
|
+
subject.extra_params << { itemParam1: 'value1' }
|
67
|
+
|
68
|
+
expect(subject.extra_params).to eql([
|
69
|
+
{ extraParam: 'value' },
|
70
|
+
{ itemParam1: 'value1' }
|
71
|
+
])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#receivers' do
|
76
|
+
subject do
|
77
|
+
PagSeguro::TransactionRequest.new receivers: receivers
|
78
|
+
end
|
79
|
+
|
80
|
+
let(:receivers) do
|
81
|
+
[
|
82
|
+
{ email: 'a@example.com', split: { amount: 1 } },
|
83
|
+
{ email: 'b@example.com', split: { amount: 1 } }
|
84
|
+
]
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'ensure receivers' do
|
88
|
+
it 'are PagSeguro::Receiver' do
|
89
|
+
subject.receivers.each do |receiver|
|
90
|
+
expect(receiver).to be_a(PagSeguro::Receiver)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'have correct keys' do
|
95
|
+
expect(subject.receivers[0].email).to eq 'a@example.com'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#create" do
|
101
|
+
let(:transaction_request) { PagSeguro::TransactionRequest.new }
|
102
|
+
let(:request) { double(:request, success?: true, xml?: true, body: raw_xml) }
|
103
|
+
let(:params) do
|
104
|
+
{receiverEmail: "RECEIVER", currency: "BRL", paymentMethod: "credit_card"}
|
105
|
+
end
|
106
|
+
|
107
|
+
before do
|
108
|
+
PagSeguro.configuration.receiver_email = "RECEIVER"
|
109
|
+
|
110
|
+
allow(transaction_request).to receive(:payment_method).and_return("credit_card")
|
111
|
+
|
112
|
+
allow(PagSeguro::Request).to receive(:post)
|
113
|
+
.with("transactions", "v2", params)
|
114
|
+
.and_return(request)
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when request succeeds" do
|
118
|
+
let(:raw_xml) { File.read("./spec/fixtures/transaction_request/success.xml") }
|
119
|
+
|
120
|
+
it "creates a transaction request" do
|
121
|
+
expect(transaction_request.create).to be_a(PagSeguro::TransactionRequest)
|
122
|
+
expect(transaction_request.code).to eq("9E884542-81B3-4419-9A75-BCC6FB495EF1")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "when request fails" do
|
127
|
+
let :response_request do
|
128
|
+
double(
|
129
|
+
:ResponseRequest,
|
130
|
+
success?: false,
|
131
|
+
error?: true,
|
132
|
+
bad_request?: true,
|
133
|
+
error: Aitch::BadRequestError,
|
134
|
+
xml?: true,
|
135
|
+
data: xml_parsed,
|
136
|
+
body: raw_xml
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
140
|
+
before do
|
141
|
+
allow(PagSeguro::Request).to receive(:post)
|
142
|
+
.and_return(response_request)
|
143
|
+
end
|
144
|
+
|
145
|
+
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
146
|
+
|
147
|
+
it "does not create a transaction request" do
|
148
|
+
expect { transaction_request.create }.not_to change { transaction_request.code }
|
149
|
+
end
|
150
|
+
|
151
|
+
it "add errors" do
|
152
|
+
expect { transaction_request.create }.to change { transaction_request.errors.empty? }
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,265 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::Transaction do
|
4
|
+
describe ".find_by_notification_code" do
|
5
|
+
before do
|
6
|
+
allow(PagSeguro::Request).to receive(:get)
|
7
|
+
.with("transactions/notifications/CODE", "v3", {})
|
8
|
+
.and_return(request)
|
9
|
+
end
|
10
|
+
let(:parsed_xml) { Nokogiri::XML(raw_xml) }
|
11
|
+
let(:request) do
|
12
|
+
double(:Request, xml?: true, success?: true, unauthorized?: false,
|
13
|
+
bad_request?: false, body: raw_xml, data: parsed_xml)
|
14
|
+
end
|
15
|
+
subject { PagSeguro::Transaction.find_by_notification_code("CODE") }
|
16
|
+
|
17
|
+
context "when request succeds" do
|
18
|
+
let(:raw_xml) { File.read("./spec/fixtures/transactions/success.xml") }
|
19
|
+
|
20
|
+
it "returns an instance of transaction" do
|
21
|
+
expect(subject).to be_a(PagSeguro::Transaction)
|
22
|
+
end
|
23
|
+
|
24
|
+
context "returns transaction with correct attributes" do
|
25
|
+
it { expect(subject.code).to eq("667A3914-4F9F-4705-0EB6-CA6FA0DF8A19") }
|
26
|
+
it { expect(subject.reference).to eq("REF1234") }
|
27
|
+
it { expect(subject.type_id).to eq("1") }
|
28
|
+
it { expect(subject.payment_link).to eq("https://pagseguro.uol.com.br/checkout/imprimeBoleto.jhtml?code=667D39144F9F47059FB6CA6FA0DF8A20") }
|
29
|
+
it { expect(subject.status).to be_a(PagSeguro::PaymentStatus) }
|
30
|
+
it { expect(subject.status.id).to eq("1") }
|
31
|
+
it { expect(subject.payment_method.type).to eq(:boleto) }
|
32
|
+
it { expect(subject.gross_amount).to eq(459.5) }
|
33
|
+
it { expect(subject.discount_amount).to eq(0.0) }
|
34
|
+
it { expect(subject.net_amount).to eq(445.77) }
|
35
|
+
it { expect(subject.extra_amount).to eq(0.0) }
|
36
|
+
it { expect(subject.installments).to eq(1) }
|
37
|
+
it { expect(subject.sender.name).to eq("JOHN DOE") }
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns a collection with errors object" do
|
41
|
+
expect(subject.errors).to be_a(PagSeguro::Errors)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns a collection with no errors" do
|
45
|
+
expect(subject.errors).to be_empty
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when request fails" do
|
50
|
+
before do
|
51
|
+
allow(request).to receive_messages(
|
52
|
+
success?: false,
|
53
|
+
error?: true,
|
54
|
+
error: Aitch::BadRequestError
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
59
|
+
|
60
|
+
it "returns an instance of Transaction" do
|
61
|
+
expect(subject).to be_a(PagSeguro::Transaction)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns a collection with errors" do
|
65
|
+
expect(subject.errors).not_to be_empty
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe ".find_by_code" do
|
71
|
+
before do
|
72
|
+
allow(PagSeguro::Request).to receive(:get)
|
73
|
+
.with("transactions/CODE", "v3", {})
|
74
|
+
.and_return(request)
|
75
|
+
end
|
76
|
+
let(:parsed_xml) { Nokogiri::XML(raw_xml) }
|
77
|
+
let(:request) do
|
78
|
+
double(:Request, xml?: true, success?: true, error?: false,
|
79
|
+
bad_request?: false, body: raw_xml, data: parsed_xml)
|
80
|
+
end
|
81
|
+
subject { PagSeguro::Transaction.find_by_code("CODE") }
|
82
|
+
|
83
|
+
context "when request succeds" do
|
84
|
+
let(:raw_xml) { File.read("./spec/fixtures/transactions/success.xml") }
|
85
|
+
|
86
|
+
it "returns an instance of transaction" do
|
87
|
+
expect(subject).to be_a(PagSeguro::Transaction)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns a collection with errors object" do
|
91
|
+
expect(subject.errors).to be_a(PagSeguro::Errors)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns a collection with no errors" do
|
95
|
+
expect(subject.errors).to be_empty
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when request fails" do
|
100
|
+
before do
|
101
|
+
allow(request).to receive_messages(
|
102
|
+
success?: false,
|
103
|
+
error?: true,
|
104
|
+
error: Aitch::BadRequestError
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
|
109
|
+
|
110
|
+
it "returns an instance of Transaction" do
|
111
|
+
expect(subject).to be_a(PagSeguro::Transaction)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "returns a collection with errors" do
|
115
|
+
expect(subject.errors).not_to be_empty
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe ".find_by_code" do
|
121
|
+
it 'finds a transaction by its code' do
|
122
|
+
allow(PagSeguro::Transaction).to receive(:load_from_response)
|
123
|
+
|
124
|
+
expect(PagSeguro::Request)
|
125
|
+
.to receive(:get)
|
126
|
+
.with("transactions/CODE", 'v3', {})
|
127
|
+
.and_return(double.as_null_object)
|
128
|
+
|
129
|
+
PagSeguro::Transaction.find_by_code("CODE")
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe ".find_by_date" do
|
134
|
+
it "initializes search with default options" do
|
135
|
+
now = Time.now
|
136
|
+
allow(Time).to receive(:now).and_return(now)
|
137
|
+
|
138
|
+
expect(PagSeguro::SearchByDate)
|
139
|
+
.to receive(:new)
|
140
|
+
.with("transactions",
|
141
|
+
hash_including(starts_at: now - 86400, ends_at: now, per_page: 50), 0)
|
142
|
+
|
143
|
+
PagSeguro::Transaction.find_by_date
|
144
|
+
end
|
145
|
+
|
146
|
+
it "initializes search with given options" do
|
147
|
+
starts_at = Time.now - 3600
|
148
|
+
ends_at = starts_at + 180
|
149
|
+
page = 0
|
150
|
+
|
151
|
+
expect(PagSeguro::SearchByDate)
|
152
|
+
.to receive(:new)
|
153
|
+
.with(
|
154
|
+
"transactions",
|
155
|
+
hash_including(per_page: 10, starts_at: starts_at, ends_at: ends_at),
|
156
|
+
page
|
157
|
+
)
|
158
|
+
|
159
|
+
PagSeguro::Transaction.find_by_date(
|
160
|
+
{per_page: 10, starts_at: starts_at, ends_at: ends_at},
|
161
|
+
page
|
162
|
+
)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe ".find_by_reference" do
|
167
|
+
it 'initializes search with given reference code' do
|
168
|
+
now = Time.now
|
169
|
+
allow(Time).to receive(:now).and_return(now)
|
170
|
+
|
171
|
+
expect(PagSeguro::SearchByReference)
|
172
|
+
.to receive(:new)
|
173
|
+
.with(
|
174
|
+
"transactions",
|
175
|
+
hash_including(reference: 'ref1234'),
|
176
|
+
)
|
177
|
+
|
178
|
+
PagSeguro::Transaction.find_by_reference('ref1234')
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe ".find_abandoned" do
|
183
|
+
it "initializes search with default options" do
|
184
|
+
now = Time.now
|
185
|
+
allow(Time).to receive(:now).and_return(now)
|
186
|
+
|
187
|
+
expect(PagSeguro::SearchAbandoned)
|
188
|
+
.to receive(:new)
|
189
|
+
.with(
|
190
|
+
"transactions/abandoned",
|
191
|
+
hash_including(per_page: 50, starts_at: now - 86400, ends_at: now - 900),
|
192
|
+
0
|
193
|
+
)
|
194
|
+
|
195
|
+
PagSeguro::Transaction.find_abandoned
|
196
|
+
end
|
197
|
+
|
198
|
+
it "initializes search with given options" do
|
199
|
+
starts_at = Time.now - 3600
|
200
|
+
ends_at = starts_at + 180
|
201
|
+
page = 1
|
202
|
+
|
203
|
+
expect(PagSeguro::SearchAbandoned)
|
204
|
+
.to receive(:new)
|
205
|
+
.with(
|
206
|
+
"transactions/abandoned",
|
207
|
+
hash_including(per_page: 10, starts_at: starts_at, ends_at: ends_at),
|
208
|
+
page
|
209
|
+
)
|
210
|
+
|
211
|
+
PagSeguro::Transaction.find_abandoned(
|
212
|
+
{ per_page: 10, starts_at: starts_at, ends_at: ends_at },
|
213
|
+
page
|
214
|
+
)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "initializes search with given credential option" do
|
218
|
+
credentials = PagSeguro::AccountCredentials.new('email@example.com', 'token')
|
219
|
+
starts_at = Time.now - 3600
|
220
|
+
ends_at = starts_at + 180
|
221
|
+
page = 1
|
222
|
+
|
223
|
+
expect(PagSeguro::SearchAbandoned)
|
224
|
+
.to receive(:new)
|
225
|
+
.with(
|
226
|
+
"transactions/abandoned",
|
227
|
+
hash_including(per_page: 10, starts_at: starts_at, ends_at: ends_at, credentials: credentials),
|
228
|
+
page
|
229
|
+
)
|
230
|
+
|
231
|
+
PagSeguro::Transaction.find_abandoned(
|
232
|
+
{ per_page: 10, starts_at: starts_at, ends_at: ends_at, credentials: credentials },
|
233
|
+
page
|
234
|
+
)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "attributes" do
|
239
|
+
before do
|
240
|
+
body = File.read("./spec/fixtures/transactions/success.xml")
|
241
|
+
FakeWeb.register_uri :get, %r[.+], body: body, content_type: "text/xml"
|
242
|
+
end
|
243
|
+
|
244
|
+
subject(:transaction) { PagSeguro::Transaction.find_by_notification_code("CODE") }
|
245
|
+
|
246
|
+
it { expect(transaction.sender).to be_a(PagSeguro::Sender) }
|
247
|
+
it { expect(transaction.shipping).to be_a(PagSeguro::Shipping) }
|
248
|
+
it { expect(transaction.items).to be_a(PagSeguro::Items) }
|
249
|
+
it { expect(transaction.payment_method).to be_a(PagSeguro::PaymentMethod) }
|
250
|
+
it { expect(transaction.status).to be_a(PagSeguro::PaymentStatus) }
|
251
|
+
it { expect(transaction.items.size).to eq(1) }
|
252
|
+
it { expect(transaction).to respond_to(:escrow_end_date) }
|
253
|
+
end
|
254
|
+
|
255
|
+
it "always set errors" do
|
256
|
+
expect(subject.errors).to be_a(PagSeguro::Errors)
|
257
|
+
end
|
258
|
+
|
259
|
+
it "#update_attributes" do
|
260
|
+
subject = PagSeguro::Transaction.new
|
261
|
+
expect(subject).to receive(:code=).with("1234")
|
262
|
+
|
263
|
+
subject.update_attributes(code: "1234")
|
264
|
+
end
|
265
|
+
end
|