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,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::ManualSubscriptionCharger::RequestSerializer do
|
4
|
+
context '#to_xml_params' do
|
5
|
+
subject { described_class.new(charger) }
|
6
|
+
|
7
|
+
let(:charger) { PagSeguro::ManualSubscriptionCharger.new }
|
8
|
+
|
9
|
+
it 'should serializer reference' do
|
10
|
+
charger.reference = 'ref-1234'
|
11
|
+
|
12
|
+
expect(subject.to_xml_params).to match %r[
|
13
|
+
<payment>
|
14
|
+
.*<reference>ref-1234
|
15
|
+
]xm
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should serializer subscription code' do
|
19
|
+
charger.subscription_code = '12345'
|
20
|
+
|
21
|
+
expect(subject.to_xml_params).to match %r[
|
22
|
+
<payment>
|
23
|
+
.*<preApprovalCode>12345
|
24
|
+
]xm
|
25
|
+
end
|
26
|
+
|
27
|
+
context "serialize items'" do
|
28
|
+
before do
|
29
|
+
charger.items = items
|
30
|
+
end
|
31
|
+
|
32
|
+
subject do
|
33
|
+
described_class.new(charger).to_xml_params
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:items) do
|
37
|
+
[
|
38
|
+
{ id: 669, description: 'Insurance', amount: 10.0, quantity: 1 }
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
it do
|
43
|
+
is_expected.to match %r[
|
44
|
+
<payment>
|
45
|
+
.*<items>
|
46
|
+
.*<item>
|
47
|
+
.*<id>669
|
48
|
+
]xm
|
49
|
+
end
|
50
|
+
|
51
|
+
it do
|
52
|
+
is_expected.to match %r[
|
53
|
+
<payment>
|
54
|
+
.*<items>
|
55
|
+
.*<item>
|
56
|
+
.*<description>Insurance
|
57
|
+
]xm
|
58
|
+
end
|
59
|
+
|
60
|
+
it do
|
61
|
+
is_expected.to match %r[
|
62
|
+
<payment>
|
63
|
+
.*<items>
|
64
|
+
.*<item>
|
65
|
+
.*<quantity>1
|
66
|
+
]xm
|
67
|
+
end
|
68
|
+
|
69
|
+
it do
|
70
|
+
is_expected.to match %r[
|
71
|
+
<payment>
|
72
|
+
.*<items>
|
73
|
+
.*<item>
|
74
|
+
.*<amount>10.00
|
75
|
+
]xm
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::ManualSubscriptionCharger::ResponseSerializer do
|
4
|
+
let(:source) { File.read('./spec/fixtures/manual_subscription_charger/success.xml') }
|
5
|
+
let(:xml) { Nokogiri::XML(source) }
|
6
|
+
|
7
|
+
subject { described_class.new(xml) }
|
8
|
+
|
9
|
+
it { expect(subject.serialize[:transaction_code]).to eql('D9AD1EA3DEB544A6A413E33BD4822225') }
|
10
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe PagSeguro::ManualSubscriptionCharger::Response do
|
4
|
+
subject { PagSeguro::ManualSubscriptionCharger::Response.new(http_response, plan) }
|
5
|
+
let(:plan) { PagSeguro::ManualSubscriptionCharger.new }
|
6
|
+
|
7
|
+
context '#success?' do
|
8
|
+
let(:http_response) do
|
9
|
+
double(:HttpResponse, xml?: true)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'delegate to response' do
|
13
|
+
allow(http_response).to receive(:success?).and_return(true)
|
14
|
+
expect(subject).to be_success
|
15
|
+
|
16
|
+
allow(http_response).to receive(:success?).and_return(false)
|
17
|
+
expect(subject).not_to be_success
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#serialize' do
|
22
|
+
let(:http_response) do
|
23
|
+
double(
|
24
|
+
:Request,
|
25
|
+
success?: true,
|
26
|
+
xml?: true,
|
27
|
+
data: xml_parsed,
|
28
|
+
body: raw_xml,
|
29
|
+
unauthorized?: false,
|
30
|
+
bad_request?: false,
|
31
|
+
not_found?: false
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:xml_parsed) { Nokogiri::XML(raw_xml) }
|
36
|
+
|
37
|
+
context 'when request succeeds' do
|
38
|
+
let(:raw_xml) { File.read('./spec/fixtures/manual_subscription_charger/success.xml') }
|
39
|
+
|
40
|
+
it 'returns a hash with serialized response data' do
|
41
|
+
expect { subject.serialize }.to change { plan.transaction_code }
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'not change subscription plan errors' do
|
45
|
+
expect { subject.serialize }.not_to change { plan.errors.empty? }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when request fails' do
|
50
|
+
before do
|
51
|
+
allow(http_response).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/manual_subscription_charger/fail.xml') }
|
59
|
+
|
60
|
+
it 'change subscription plan errors' do
|
61
|
+
expect { subject.serialize }.to change { plan.errors.empty? }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::ManualSubscriptionCharger do
|
4
|
+
it_assigns_attribute :reference
|
5
|
+
it_assigns_attribute :subscription_code
|
6
|
+
it_assigns_attribute :transaction_code
|
7
|
+
|
8
|
+
it_ensures_collection_type PagSeguro::Item, :items, [{id: '123', description: 'abc', amount: 100.00, quantity: 1}]
|
9
|
+
|
10
|
+
context 'errors attribute' do
|
11
|
+
it 'should start with errors' do
|
12
|
+
expect(subject.errors).to be_a PagSeguro::Errors
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should start with empty errors' do
|
16
|
+
expect(subject.errors).to be_empty
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#create' do
|
21
|
+
before do
|
22
|
+
subject.credentials = credentials
|
23
|
+
|
24
|
+
FakeWeb.register_uri(
|
25
|
+
:post,
|
26
|
+
'https://ws.pagseguro.uol.com.br/v2/pre-approvals/payment?email=user@example.com&token=TOKEN',
|
27
|
+
body: ''
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:credentials) do
|
32
|
+
PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN')
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:request) do
|
36
|
+
double(
|
37
|
+
:Request,
|
38
|
+
success?: true,
|
39
|
+
xml?: true,
|
40
|
+
body: '<result><transactionCode>1234</transactionCode><date>2011-08-19T14:47:59.000-03:00</date></result>'
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'sends it to correct url' do
|
45
|
+
expect(PagSeguro).to receive(:api_url).with(
|
46
|
+
'v2/pre-approvals/payment?email=user@example.com&token=TOKEN'
|
47
|
+
).and_return('https://ws.pagseguro.uol.com.br/v2/pre-approvals/payment?email=user@example.com&token=TOKEN')
|
48
|
+
|
49
|
+
subject.create
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when creating' do
|
53
|
+
it 'send to correct url' do
|
54
|
+
expect(PagSeguro::Request).to receive(:post_xml).with(
|
55
|
+
'pre-approvals/payment', :v2, credentials, a_string_matching(/<payment>/)
|
56
|
+
).and_return(request)
|
57
|
+
|
58
|
+
subject.create
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'update with the new transaction_code' do
|
62
|
+
allow(PagSeguro::Request).to receive(:post_xml).and_return(request)
|
63
|
+
|
64
|
+
expect { subject.create }.to change { subject.transaction_code }.to('1234')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::OnlineDebitTransactionRequest do
|
4
|
+
it_ensures_type PagSeguro::Bank, :bank
|
5
|
+
|
6
|
+
describe "#payment_method" do
|
7
|
+
it "is online_debit" do
|
8
|
+
expect(subject.payment_method).to eq("online_debit")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets the bank" do
|
13
|
+
bank = PagSeguro::Bank.new
|
14
|
+
payment = described_class.new(bank: bank)
|
15
|
+
|
16
|
+
expect(payment.bank).to eq(bank)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro do
|
4
|
+
before do
|
5
|
+
PagSeguro.configure do |config|
|
6
|
+
config.app_id = "APP123"
|
7
|
+
config.app_key = "APPTOKEN"
|
8
|
+
config.email = "EMAIL"
|
9
|
+
config.token = "TOKEN"
|
10
|
+
config.receiver_email = "RECEIVER_EMAIL"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
PagSeguro.configuration.environment = :production
|
16
|
+
end
|
17
|
+
|
18
|
+
it { expect(PagSeguro.email).to eql("EMAIL") }
|
19
|
+
it { expect(PagSeguro.token).to eql("TOKEN") }
|
20
|
+
it { expect(PagSeguro.receiver_email).to eql("RECEIVER_EMAIL") }
|
21
|
+
|
22
|
+
context "config delegation" do
|
23
|
+
subject { PagSeguro }
|
24
|
+
it_behaves_like "a configuration"
|
25
|
+
end
|
26
|
+
|
27
|
+
context "configuring library" do
|
28
|
+
it "yields PagSeguro::Config" do
|
29
|
+
expect {|block|
|
30
|
+
PagSeguro.configure(&block)
|
31
|
+
}.to yield_with_args(PagSeguro::Config)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "default settings" do
|
36
|
+
it { expect(PagSeguro.configuration.encoding).to eql("UTF-8") }
|
37
|
+
it { expect(PagSeguro.configuration.environment).to eql(:production) }
|
38
|
+
it { expect(PagSeguro.account_credentials.email).to eql("EMAIL") }
|
39
|
+
it { expect(PagSeguro.account_credentials.token).to eql("TOKEN") }
|
40
|
+
it { expect(PagSeguro.application_credentials.app_id).to eql("APP123") }
|
41
|
+
it { expect(PagSeguro.application_credentials.app_key).to eql("APPTOKEN") }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".api_url" do
|
45
|
+
it "raises when environment has no endpoint" do
|
46
|
+
PagSeguro.configuration.environment = :invalid
|
47
|
+
|
48
|
+
expect {
|
49
|
+
PagSeguro.api_url("/")
|
50
|
+
}.to raise_exception(PagSeguro::InvalidEnvironmentError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns production api url when the environment is :production" do
|
54
|
+
expect(PagSeguro.api_url("v2/some/path")).to eql("https://ws.pagseguro.uol.com.br/v2/some/path")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns sandbox api url when the environment is :sandbox" do
|
58
|
+
PagSeguro.configuration.environment = :sandbox
|
59
|
+
|
60
|
+
expect(PagSeguro.api_url("v2/some/path")).to eql("https://ws.sandbox.pagseguro.uol.com.br/v2/some/path")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe ".site_url" do
|
65
|
+
it "raises when environment has no endpoint" do
|
66
|
+
PagSeguro.configuration.environment = :invalid
|
67
|
+
|
68
|
+
expect {
|
69
|
+
PagSeguro.site_url("/")
|
70
|
+
}.to raise_exception(PagSeguro::InvalidEnvironmentError)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "returns production site url when the environment is production" do
|
74
|
+
expect(PagSeguro.site_url("v2/some/path")).to eql("https://pagseguro.uol.com.br/v2/some/path")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns sandbox site url when the environment is :sandbox" do
|
78
|
+
PagSeguro.configuration.environment = :sandbox
|
79
|
+
expect(PagSeguro.site_url("v2/some/path")).to eql("https://sandbox.pagseguro.uol.com.br/v2/some/path")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
shared_examples_for "type mapping" do |id, type|
|
5
|
+
it "returns #{type.inspect} as type when id is #{id}" do
|
6
|
+
expect(PagSeguro::PaymentMethod.new(type_id: id).type).to eql(type)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe PagSeguro::PaymentMethod do
|
11
|
+
context "type mapping" do
|
12
|
+
it_behaves_like "type mapping", nil, :not_set
|
13
|
+
it_behaves_like "type mapping", 1, :credit_card
|
14
|
+
it_behaves_like "type mapping", 2, :boleto
|
15
|
+
it_behaves_like "type mapping", 3, :online_transfer
|
16
|
+
it_behaves_like "type mapping", 4, :balance
|
17
|
+
it_behaves_like "type mapping", 5, :oi_paggo
|
18
|
+
it_behaves_like "type mapping", 7, :direct_deposit
|
19
|
+
|
20
|
+
it "raises for invalid id" do
|
21
|
+
expect {
|
22
|
+
PagSeguro::PaymentMethod.new(type_id: "invalid").type
|
23
|
+
}.to raise_exception("PagSeguro::PaymentMethod#type_id isn't mapped")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "shortcuts" do
|
28
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 1)).to be_credit_card }
|
29
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 2)).to be_boleto }
|
30
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 3)).to be_online_transfer }
|
31
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 4)).to be_balance }
|
32
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 5)).to be_oi_paggo }
|
33
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 7)).to be_direct_deposit }
|
34
|
+
|
35
|
+
it { expect(PagSeguro::PaymentMethod.new(type_id: 5)).not_to be_credit_card }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "description" do
|
39
|
+
subject(:payment_method) { PagSeguro::PaymentMethod.new(code: 102) }
|
40
|
+
it { expect(payment_method.description).to eql("Cartão de crédito MasterCard") }
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::PaymentReleases do
|
4
|
+
it "implements #each" do
|
5
|
+
expect(PagSeguro::PaymentReleases.new).to respond_to(:each)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "includes Enumerable" do
|
9
|
+
expect(PagSeguro::PaymentReleases.included_modules).to include(Enumerable)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets payment" do
|
13
|
+
payment = PagSeguro::PaymentRelease.new
|
14
|
+
payments = PagSeguro::PaymentReleases.new
|
15
|
+
payments << payment
|
16
|
+
|
17
|
+
expect(payments.size).to eql(1)
|
18
|
+
expect(payments).to include(payment)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets payment releases from Hash" do
|
22
|
+
payment = PagSeguro::PaymentRelease.new(installment: 1)
|
23
|
+
|
24
|
+
expect(PagSeguro::PaymentRelease).to(
|
25
|
+
receive(:new)
|
26
|
+
.with({installment: 1})
|
27
|
+
.and_return(payment))
|
28
|
+
|
29
|
+
payments = PagSeguro::PaymentReleases.new
|
30
|
+
payments << {installment: 1}
|
31
|
+
|
32
|
+
expect(payments).to include(payment)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,283 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PagSeguro::PaymentRequest::RequestSerializer do
|
4
|
+
context '#to_xml_params' do
|
5
|
+
subject { described_class.new(payment) }
|
6
|
+
|
7
|
+
let(:payment) { PagSeguro::PaymentRequest.new }
|
8
|
+
|
9
|
+
it 'should serializer primary receivers' do
|
10
|
+
payment.primary_receiver = 'a@example.com'
|
11
|
+
expect(subject.to_xml_params).to match %r[<primaryReceiver>.*<email>a@example.com<\/email>.*<\/primaryReceiver>]m
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should serializer other receivers' do
|
15
|
+
payment.receivers = [
|
16
|
+
{
|
17
|
+
email: 'a@example.com',
|
18
|
+
split: {
|
19
|
+
amount: 10,
|
20
|
+
fee_percent: 11,
|
21
|
+
rate_percent: 12
|
22
|
+
}
|
23
|
+
}
|
24
|
+
]
|
25
|
+
expect(subject.to_xml_params).to match %r[<receivers>.*<receiver>.*<email>a@example.com<\/email>]m
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should serializer sender' do
|
29
|
+
payment.sender = PagSeguro::Sender.new(
|
30
|
+
name: 'Sender',
|
31
|
+
email: 'b@example.com',
|
32
|
+
phone: PagSeguro::Phone.new(area_code: 51, number: 2)
|
33
|
+
)
|
34
|
+
expect(subject.to_xml_params).to match %r[<sender>.*<name>Sender<\/name>.*<email>b@example.com<\/email>.*<phone>.*<areaCode>51<\/areaCode>.*<number>2<\/number>]m
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'should serialize sender document' do
|
38
|
+
it 'when it was CPF' do
|
39
|
+
payment.sender = PagSeguro::Sender.new(document: PagSeguro::Document.new(type: 'CPF', value: '12312312312'))
|
40
|
+
|
41
|
+
expect(subject.to_xml_params).to match %r[
|
42
|
+
.*<sender>
|
43
|
+
.*<documents>
|
44
|
+
.*<document>
|
45
|
+
.*<type>CPF</type>
|
46
|
+
.*<value>12312312312</value>
|
47
|
+
.*</document>
|
48
|
+
.*</documents>
|
49
|
+
.*</sender>
|
50
|
+
]mx
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'when it was CNPJ' do
|
54
|
+
payment.sender = PagSeguro::Sender.new(document: PagSeguro::Document.new(type: 'CNPJ', value: '12123123000112'))
|
55
|
+
|
56
|
+
expect(subject.to_xml_params).to match %r[
|
57
|
+
.*<sender>
|
58
|
+
.*<documents>
|
59
|
+
.*<document>
|
60
|
+
.*<type>CNPJ</type>
|
61
|
+
.*<value>12123123000112</value>
|
62
|
+
.*</document>
|
63
|
+
.*</documents>
|
64
|
+
.*</sender>
|
65
|
+
]mx
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should serializer currency' do
|
70
|
+
payment.currency = 'BRL'
|
71
|
+
expect(subject.to_xml_params).to match %r[<currency>BRL</currency>]
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should serializer reference' do
|
75
|
+
payment.reference = 'order123'
|
76
|
+
expect(subject.to_xml_params).to match %r[<reference>order123</reference>]
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should serializer redirect url' do
|
80
|
+
payment.redirect_url = 'http://example.com'
|
81
|
+
expect(subject.to_xml_params).to match %r[<redirectURL>http://example.com</redirectURL>]
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should serializer notification url' do
|
85
|
+
payment.notification_url = 'http://example.com'
|
86
|
+
expect(subject.to_xml_params).to match %r[<notificationURL>http://example.com</notificationURL>]
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'should serializer item' do
|
90
|
+
before do
|
91
|
+
payment.items << { id: 1, description: 'Description#1', quantity: 2, amount: 3, weight: 4, shipping_cost: 5 }
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'to include id' do
|
95
|
+
expect(subject.to_xml_params).to match %r[<id>1</id>]
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'to include description' do
|
99
|
+
expect(subject.to_xml_params).to match %r[<description>Description#1</description>]
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'to include quantity' do
|
103
|
+
expect(subject.to_xml_params).to match %r[<quantity>2</quantity>]
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'to include amount' do
|
107
|
+
expect(subject.to_xml_params).to match %r[<amount>3.00</amount>]
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'to include weight' do
|
111
|
+
expect(subject.to_xml_params).to match %r[<weight>4</weight>]
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'to include weight' do
|
115
|
+
expect(subject.to_xml_params).to match %r[<shippingCost>5.00</shippingCost>]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context '#to_params' do
|
121
|
+
let(:payment_request) { PagSeguro::PaymentRequest.new }
|
122
|
+
let(:params) { serializer.to_params }
|
123
|
+
subject(:serializer) { described_class.new(payment_request) }
|
124
|
+
|
125
|
+
context "global configuration serialization" do
|
126
|
+
before do
|
127
|
+
PagSeguro.configuration.receiver_email = "RECEIVER"
|
128
|
+
end
|
129
|
+
|
130
|
+
it { expect(params).to include(receiverEmail: PagSeguro.configuration.receiver_email) }
|
131
|
+
end
|
132
|
+
|
133
|
+
context "generic attributes serialization" do
|
134
|
+
let(:payment_request) do
|
135
|
+
double(:PaymentRequest,
|
136
|
+
currency: "BRL",
|
137
|
+
reference: "REF123",
|
138
|
+
extra_amount: 1234.50,
|
139
|
+
redirect_url: "REDIRECT_URL",
|
140
|
+
notification_url: "NOTIFICATION_URL",
|
141
|
+
abandon_url: "ABANDON_URL",
|
142
|
+
max_uses: 5,
|
143
|
+
max_age: 3600,
|
144
|
+
).as_null_object
|
145
|
+
end
|
146
|
+
|
147
|
+
it { expect(params).to include(currency: "BRL") }
|
148
|
+
it { expect(params).to include(reference: "REF123") }
|
149
|
+
it { expect(params).to include(extraAmount: "1234.50") }
|
150
|
+
it { expect(params).to include(redirectURL: "REDIRECT_URL") }
|
151
|
+
it { expect(params).to include(notificationURL: "NOTIFICATION_URL") }
|
152
|
+
it { expect(params).to include(abandonURL: "ABANDON_URL") }
|
153
|
+
it { expect(params).to include(maxUses: 5) }
|
154
|
+
it { expect(params).to include(maxAge: 3600) }
|
155
|
+
end
|
156
|
+
|
157
|
+
context "shipping serialization" do
|
158
|
+
before do
|
159
|
+
payment_request.shipping = PagSeguro::Shipping.new({
|
160
|
+
type_id: 1,
|
161
|
+
cost: 1234.56
|
162
|
+
})
|
163
|
+
end
|
164
|
+
|
165
|
+
it { expect(params).to include(shippingType: 1) }
|
166
|
+
it { expect(params).to include(shippingCost: "1234.56") }
|
167
|
+
end
|
168
|
+
|
169
|
+
context "address serialization" do
|
170
|
+
let(:address) do
|
171
|
+
PagSeguro::Address.new(
|
172
|
+
street: "STREET",
|
173
|
+
state: "STATE",
|
174
|
+
city: "CITY",
|
175
|
+
postal_code: "POSTAL_CODE",
|
176
|
+
district: "DISTRICT",
|
177
|
+
number: "NUMBER",
|
178
|
+
complement: "COMPLEMENT"
|
179
|
+
)
|
180
|
+
end
|
181
|
+
let(:payment_request) do
|
182
|
+
double(:PaymentRequest, shipping: shipping).as_null_object
|
183
|
+
end
|
184
|
+
let(:shipping) do
|
185
|
+
double(:Shipping, address: address).as_null_object
|
186
|
+
end
|
187
|
+
|
188
|
+
it { expect(params).to include(shippingAddressStreet: "STREET") }
|
189
|
+
it { expect(params).to include(shippingAddressCountry: "BRA") }
|
190
|
+
it { expect(params).to include(shippingAddressState: "STATE") }
|
191
|
+
it { expect(params).to include(shippingAddressCity: "CITY") }
|
192
|
+
it { expect(params).to include(shippingAddressPostalCode: "POSTAL_CODE") }
|
193
|
+
it { expect(params).to include(shippingAddressDistrict: "DISTRICT") }
|
194
|
+
it { expect(params).to include(shippingAddressNumber: "NUMBER") }
|
195
|
+
it { expect(params).to include(shippingAddressComplement: "COMPLEMENT") }
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'sender serialize' do
|
199
|
+
before do
|
200
|
+
sender = PagSeguro::Sender.new(
|
201
|
+
name: 'NAME',
|
202
|
+
email: 'EMAIL',
|
203
|
+
phone: { area_code: 'AREA_CODE', number: 'NUMBER' }
|
204
|
+
)
|
205
|
+
|
206
|
+
allow(payment_request).to receive(:sender).and_return(sender)
|
207
|
+
end
|
208
|
+
|
209
|
+
it { expect(params).to include(senderName: 'NAME') }
|
210
|
+
it { expect(params).to include(senderEmail: 'EMAIL') }
|
211
|
+
|
212
|
+
context "phone" do
|
213
|
+
it { expect(params).to include(senderAreaCode: "AREA_CODE") }
|
214
|
+
it { expect(params).to include(senderPhone: "NUMBER") }
|
215
|
+
end
|
216
|
+
|
217
|
+
context 'documents' do
|
218
|
+
it 'when is CPF' do
|
219
|
+
payment_request.sender.document = PagSeguro::Document.new(type: 'CPF', value: '12312312312')
|
220
|
+
expect(params).to include(senderCPF: '12312312312')
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'when is CNPJ' do
|
224
|
+
payment_request.sender.document = PagSeguro::Document.new(type: 'CNPJ', value: '12123123000112')
|
225
|
+
expect(params).to include(senderCNPJ: '12123123000112')
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context "items serialization" do
|
231
|
+
def build_item(index)
|
232
|
+
PagSeguro::Item.new({
|
233
|
+
id: "ID#{index}",
|
234
|
+
description: "DESC#{index}",
|
235
|
+
quantity: "QTY#{index}",
|
236
|
+
amount: index * 100 + 0.12,
|
237
|
+
weight: "WEIGHT#{index}",
|
238
|
+
shipping_cost: index * 100 + 0.34
|
239
|
+
})
|
240
|
+
end
|
241
|
+
|
242
|
+
shared_examples_for "item serialization" do |index|
|
243
|
+
it { expect(params).to include("itemId#{index}" => "ID#{index}") }
|
244
|
+
it { expect(params).to include("itemDescription#{index}" => "DESC#{index}") }
|
245
|
+
it { expect(params).to include("itemAmount#{index}" => "#{index}00.12") }
|
246
|
+
it { expect(params).to include("itemShippingCost#{index}" => "#{index}00.34") }
|
247
|
+
it { expect(params).to include("itemQuantity#{index}" => "QTY#{index}") }
|
248
|
+
it { expect(params).to include("itemWeight#{index}" => "WEIGHT#{index}") }
|
249
|
+
end
|
250
|
+
|
251
|
+
before do
|
252
|
+
payment_request.items << build_item(1)
|
253
|
+
payment_request.items << build_item(2)
|
254
|
+
end
|
255
|
+
|
256
|
+
it_behaves_like "item serialization", 1
|
257
|
+
it_behaves_like "item serialization", 2
|
258
|
+
end
|
259
|
+
|
260
|
+
context "credentials serialization" do
|
261
|
+
before do
|
262
|
+
credentials = PagSeguro::ApplicationCredentials.new(
|
263
|
+
"app123", "qwerty", "authocode"
|
264
|
+
)
|
265
|
+
|
266
|
+
payment_request.stub(credentials: credentials)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context "extra params serialization" do
|
271
|
+
let(:payment_request) do
|
272
|
+
double(:PaymentRequest,
|
273
|
+
extra_params: [
|
274
|
+
{ extraParam: 'param_value' },
|
275
|
+
{ newExtraParam: 'extra_param_value' }
|
276
|
+
]).as_null_object
|
277
|
+
end
|
278
|
+
|
279
|
+
it { expect(params).to include(extraParam: 'param_value') }
|
280
|
+
it { expect(params).to include(newExtraParam: 'extra_param_value') }
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|