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,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SubscriptionDiscount::RequestSerializer do
|
4
|
+
context '#to_xml_params' do
|
5
|
+
subject { described_class.new(discount) }
|
6
|
+
|
7
|
+
let(:discount) { PagSeguro::SubscriptionDiscount.new }
|
8
|
+
|
9
|
+
it 'should serializer type' do
|
10
|
+
discount.type = 'DISCOUNT_AMOUNT'
|
11
|
+
|
12
|
+
expect(subject.to_xml_params).to match %r[
|
13
|
+
<directPreApproval>
|
14
|
+
.*<type>DISCOUNT_AMOUNT
|
15
|
+
]xm
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should serializer value' do
|
19
|
+
discount.value = 50
|
20
|
+
|
21
|
+
expect(subject.to_xml_params).to match %r[
|
22
|
+
<directPreApproval>
|
23
|
+
.*<value>50.00
|
24
|
+
]xm
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe PagSeguro::SubscriptionDiscount::Response do
|
4
|
+
subject { described_class.new(response, discount) }
|
5
|
+
|
6
|
+
let(:discount) { PagSeguro::SubscriptionDiscount.new }
|
7
|
+
|
8
|
+
context '#success?' do
|
9
|
+
let(:response) do
|
10
|
+
double(:HttpResponse, xml?: true)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'delegate to response' do
|
14
|
+
allow(response).to receive(:success?).and_return(true)
|
15
|
+
expect(subject).to be_success
|
16
|
+
|
17
|
+
allow(response).to receive(:success?).and_return(false)
|
18
|
+
expect(subject).not_to be_success
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#serialize' do
|
23
|
+
let(:response) do
|
24
|
+
double(:HttpResponse, xml?: true, success?: true)
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when request succeeds' do
|
28
|
+
it 'not change discount errors' do
|
29
|
+
expect { subject.serialize }.not_to change { discount.errors.empty? }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when request fails' do
|
34
|
+
let(:response) do
|
35
|
+
double(
|
36
|
+
:HttpResponse,
|
37
|
+
data: parsed_xml,
|
38
|
+
error: Aitch::BadRequestError,
|
39
|
+
error?: true,
|
40
|
+
success?: false,
|
41
|
+
xml?: true
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:raw_xml) do
|
46
|
+
File.read('./spec/fixtures/subscription_discount/fail.xml')
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:parsed_xml) do
|
50
|
+
Nokogiri::XML(raw_xml)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'change discount errors' do
|
54
|
+
expect { subject.serialize }.to change { discount.errors.empty? }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SubscriptionDiscount do
|
4
|
+
it_assigns_attribute :type
|
5
|
+
it_assigns_attribute :value
|
6
|
+
|
7
|
+
context 'errors attribute' do
|
8
|
+
it 'should start with errors' do
|
9
|
+
expect(subject.errors).to be_a PagSeguro::Errors
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should start with empty errors' do
|
13
|
+
expect(subject.errors).to be_empty
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#create' do
|
18
|
+
before do
|
19
|
+
subject.code = '1234'
|
20
|
+
subject.credentials = credentials
|
21
|
+
|
22
|
+
FakeWeb.register_uri(
|
23
|
+
:put,
|
24
|
+
'https://ws.pagseguro.uol.com.br/pre-approvals/1234/discount?email=user@example.com&token=TOKEN',
|
25
|
+
body: ''
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:credentials) do
|
30
|
+
PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN')
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:request) do
|
34
|
+
double(
|
35
|
+
:Request,
|
36
|
+
success?: true,
|
37
|
+
xml?: true,
|
38
|
+
body: '<preApprovalRequest><code>1234</code></preApprovalRequest>'
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'sends it to correct url' do
|
43
|
+
expect(PagSeguro).to receive(:api_url).with(
|
44
|
+
'pre-approvals/1234/discount?email=user@example.com&token=TOKEN'
|
45
|
+
).and_return('https://ws.pagseguro.uol.com.br/pre-approvals/1234/discount?email=user@example.com&token=TOKEN')
|
46
|
+
|
47
|
+
subject.create
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when parsing' do
|
51
|
+
it 'create a discount' do
|
52
|
+
expect(PagSeguro::Request).to receive(:put_xml).with(
|
53
|
+
'pre-approvals/1234/discount', credentials, a_string_matching(/<directPreApproval>/)
|
54
|
+
).and_return(request)
|
55
|
+
|
56
|
+
subject.create
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SubscriptionPaymentOrder::ResponseSerializer do
|
4
|
+
let(:xml) { Nokogiri::XML(source) }
|
5
|
+
let(:source) { File.read('./spec/fixtures/subscription_payment_order/success.xml') }
|
6
|
+
|
7
|
+
subject { described_class.new(xml) }
|
8
|
+
|
9
|
+
context '#serialize' do
|
10
|
+
let(:data) { subject.serialize }
|
11
|
+
|
12
|
+
it { expect(data[:code]).to eq 'D2579C9461BA45F880419FE535763EFE' }
|
13
|
+
it { expect(data[:status]).to eq :paid }
|
14
|
+
it { expect(data[:amount]).to eq '80.00' }
|
15
|
+
it { expect(data[:gross_amount]).to eq '230' }
|
16
|
+
it { expect(data[:last_event_date]).to eq Time.new(2016,3,30,0,50,11, '-03:00') }
|
17
|
+
it { expect(data[:discount][:type]).to eq 'DISCOUNT_PERCENT' }
|
18
|
+
it { expect(data[:discount][:value]).to eq '0' }
|
19
|
+
it { expect(data[:scheduling_date]).to eq Time.new(2016,4,14,15,14,29, '-03:00') }
|
20
|
+
it { expect(data[:transactions][0][:code]).to eq 'DBFABA621D734DCDA471F592E964A39E' }
|
21
|
+
it { expect(data[:transactions][0][:date]).to eq Time.new(2016,3,30,0,48,49, '-03:00') }
|
22
|
+
it { expect(data[:transactions][0][:status]).to eq :paid }
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SubscriptionPaymentOrder::Response do
|
4
|
+
subject { described_class.new(response, object) }
|
5
|
+
|
6
|
+
let(:object) { PagSeguro::SubscriptionPaymentOrder.new }
|
7
|
+
|
8
|
+
let(:response) do
|
9
|
+
double(
|
10
|
+
:HttpResponse,
|
11
|
+
xml?: true
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when response has errors' do
|
16
|
+
before do
|
17
|
+
allow(response).
|
18
|
+
to receive_messages(
|
19
|
+
success?: false,
|
20
|
+
error?: true,
|
21
|
+
error: Aitch::ResponseError
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'must respond false to success?' do
|
26
|
+
expect(subject).not_to be_success
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'object must have errors' do
|
30
|
+
expect{ subject.serialize }.to change{ object.errors }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when response succeeds' do
|
35
|
+
before do
|
36
|
+
allow(response).
|
37
|
+
to receive_messages(
|
38
|
+
success?: true,
|
39
|
+
data: File.read('./spec/fixtures/subscription_payment_order/success.xml')
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'must respond true to success?' do
|
44
|
+
expect(subject).to be_success
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'object must not have errors' do
|
48
|
+
expect{ subject.serialize }.not_to change{ object.errors.empty? }
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'object must be updated with serialized attributes' do
|
52
|
+
expect{ subject.serialize }.to change{ object.code }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SubscriptionPaymentOrder do
|
4
|
+
it_assigns_attribute :code
|
5
|
+
it_assigns_attribute :status
|
6
|
+
it_assigns_attribute :amount
|
7
|
+
it_assigns_attribute :gross_amount
|
8
|
+
it_assigns_attribute :last_event_date
|
9
|
+
it_assigns_attribute :scheduling_date
|
10
|
+
|
11
|
+
it_ensures_type PagSeguro::SubscriptionDiscount, :discount
|
12
|
+
it_ensures_collection_type PagSeguro::SubscriptionTransaction, :transactions, [{code: '1234'}]
|
13
|
+
|
14
|
+
it '#udpate_attributes' do
|
15
|
+
expect{ subject.update_attributes(code: '1234') }.to change{ subject.code }.to '1234'
|
16
|
+
end
|
17
|
+
|
18
|
+
context '#status_code' do
|
19
|
+
before do
|
20
|
+
subject.status = :scheduled
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'must return the code related' do
|
24
|
+
expect(subject.status_code).to eq 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagSeguro::SubscriptionPlan::RequestSerializer do
|
4
|
+
context '#to_xml_params' do
|
5
|
+
subject { described_class.new(plan) }
|
6
|
+
|
7
|
+
let(:plan) { PagSeguro::SubscriptionPlan.new }
|
8
|
+
|
9
|
+
it 'should serializer max users' do
|
10
|
+
plan.max_users = 300
|
11
|
+
|
12
|
+
expect(subject.to_xml_params).to match %r[
|
13
|
+
<preApprovalRequest>
|
14
|
+
.*<maxUsers>300
|
15
|
+
]xm
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should serializer name' do
|
19
|
+
plan.name = 'Private channel access'
|
20
|
+
|
21
|
+
expect(subject.to_xml_params).to match %r[
|
22
|
+
<preApprovalRequest>
|
23
|
+
.*<preApproval>
|
24
|
+
.*<name>Private.channel.access
|
25
|
+
]xm
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should serializer details' do
|
29
|
+
plan.details = 'To have access.'
|
30
|
+
|
31
|
+
expect(subject.to_xml_params).to match %r[
|
32
|
+
<preApprovalRequest>
|
33
|
+
.*<preApproval>
|
34
|
+
.*<details>To.have.access.
|
35
|
+
]xm
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should serializer charge' do
|
39
|
+
plan.charge = 'AUTO'
|
40
|
+
|
41
|
+
expect(subject.to_xml_params).to match %r[
|
42
|
+
<preApprovalRequest>
|
43
|
+
.*<preApproval>
|
44
|
+
.*<charge>AUTO
|
45
|
+
]xm
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should serializer period' do
|
49
|
+
plan.period = 'MONTHLY'
|
50
|
+
|
51
|
+
expect(subject.to_xml_params).to match %r[
|
52
|
+
<preApprovalRequest>
|
53
|
+
.*<preApproval>
|
54
|
+
.*<period>MONTHLY
|
55
|
+
]xm
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should serializer amount' do
|
59
|
+
plan.amount = 80
|
60
|
+
|
61
|
+
expect(subject.to_xml_params).to match %r[
|
62
|
+
<preApprovalRequest>
|
63
|
+
.*<preApproval>
|
64
|
+
.*<amountPerPayment>80.00
|
65
|
+
]xm
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should serializer max total amount' do
|
69
|
+
plan.max_total_amount = 35_000
|
70
|
+
|
71
|
+
expect(subject.to_xml_params).to match %r[
|
72
|
+
<preApprovalRequest>
|
73
|
+
.*<preApproval>
|
74
|
+
.*<maxTotalAmount>35000.00
|
75
|
+
]xm
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should serializer max amount per payment' do
|
79
|
+
plan.max_amount_per_payment = 321
|
80
|
+
|
81
|
+
expect(subject.to_xml_params).to match %r[
|
82
|
+
<preApprovalRequest>
|
83
|
+
.*<preApproval>
|
84
|
+
.*<maxAmountPerPayment>321.00
|
85
|
+
]xm
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should not serializer max payments per period if its value is nil' do
|
89
|
+
plan.max_payments_per_period = nil
|
90
|
+
|
91
|
+
expect(subject.to_xml_params).not_to match %r[.*<maxPaymentsPerPeriod>]xm
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should serializer max payments per period' do
|
95
|
+
plan.max_payments_per_period = 3
|
96
|
+
|
97
|
+
expect(subject.to_xml_params).to match %r[
|
98
|
+
<preApprovalRequest>
|
99
|
+
.*<preApproval>
|
100
|
+
.*<maxPaymentsPerPeriod>3
|
101
|
+
]xm
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should not use floating number to serializer max payments per period' do
|
105
|
+
plan.max_payments_per_period = 3
|
106
|
+
|
107
|
+
expect(subject.to_xml_params).not_to match %r[
|
108
|
+
<preApprovalRequest>
|
109
|
+
.*<preApproval>
|
110
|
+
.*<maxPaymentsPerPeriod>3.00
|
111
|
+
]xm
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should serializer max amount per period' do
|
115
|
+
plan.max_amount_per_period = 300
|
116
|
+
|
117
|
+
expect(subject.to_xml_params).to match %r[
|
118
|
+
<preApprovalRequest>
|
119
|
+
.*<preApproval>
|
120
|
+
.*<maxAmountPerPeriod>300.00
|
121
|
+
]xm
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should serializer initial date' do
|
125
|
+
plan.initial_date = Time.new(2016, 1, 31, 18, 59)
|
126
|
+
|
127
|
+
expect(subject.to_xml_params).to match %r[
|
128
|
+
<preApprovalRequest>
|
129
|
+
.*<preApproval>
|
130
|
+
.*<initialDate>2016-01-31T.*
|
131
|
+
]xm
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should serializer final date' do
|
135
|
+
plan.final_date = Time.new(2020, 12, 31, 18, 59)
|
136
|
+
|
137
|
+
expect(subject.to_xml_params).to match %r[
|
138
|
+
<preApprovalRequest>
|
139
|
+
.*<preApproval>
|
140
|
+
.*<finalDate>2020-12-31T.*
|
141
|
+
]xm
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should serializer membership fee' do
|
145
|
+
plan.membership_fee = 150
|
146
|
+
|
147
|
+
expect(subject.to_xml_params).to match %r[
|
148
|
+
<preApprovalRequest>
|
149
|
+
.*<preApproval>
|
150
|
+
.*<membershipFee>150.00
|
151
|
+
]xm
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should serializer trial duration' do
|
155
|
+
plan.trial_duration = 30.0
|
156
|
+
|
157
|
+
expect(subject.to_xml_params).to match %r[
|
158
|
+
<preApprovalRequest>
|
159
|
+
.*<preApproval>
|
160
|
+
.*<trialPeriodDuration>30
|
161
|
+
]xm
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should serializer redirect url' do
|
165
|
+
plan.redirect_url = 'http://example.com/redirect'
|
166
|
+
|
167
|
+
expect(subject.to_xml_params).to match %r[
|
168
|
+
<preApprovalRequest>
|
169
|
+
.*<redirectURL>http://example.com/redirect
|
170
|
+
]xm
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should serializer review url' do
|
174
|
+
plan.review_url = 'http://example.com/review'
|
175
|
+
|
176
|
+
expect(subject.to_xml_params).to match %r[
|
177
|
+
<preApprovalRequest>
|
178
|
+
.*<reviewURL>http://example.com/review
|
179
|
+
]xm
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should serializer reference' do
|
183
|
+
plan.reference = 'ref1234'
|
184
|
+
|
185
|
+
expect(subject.to_xml_params).to match %r[
|
186
|
+
<preApprovalRequest>
|
187
|
+
.*<reference>ref1234
|
188
|
+
]xm
|
189
|
+
end
|
190
|
+
|
191
|
+
context "should serializer sender's" do
|
192
|
+
before do
|
193
|
+
plan.sender = {
|
194
|
+
name: 'John',
|
195
|
+
email: 'john@example.com',
|
196
|
+
phone: { area_code: 11, number: 123 },
|
197
|
+
address: {
|
198
|
+
street: 'Park Street',
|
199
|
+
number: 12,
|
200
|
+
complement: 'Complement here',
|
201
|
+
district: 'Neighborhood',
|
202
|
+
postal_code: '123456',
|
203
|
+
city: 'Sao Paulo',
|
204
|
+
state: 'SP',
|
205
|
+
country: 'BRA'
|
206
|
+
}
|
207
|
+
}
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'name' do
|
211
|
+
expect(subject.to_xml_params).to match %r[
|
212
|
+
<preApprovalRequest>
|
213
|
+
.*<sender>
|
214
|
+
.*<name>John
|
215
|
+
]xm
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'email' do
|
219
|
+
expect(subject.to_xml_params).to match %r[
|
220
|
+
<preApprovalRequest>
|
221
|
+
.*<sender>
|
222
|
+
.*<email>john@example.com
|
223
|
+
]xm
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'phone' do
|
227
|
+
expect(subject.to_xml_params).to match %r[
|
228
|
+
<preApprovalRequest>
|
229
|
+
.*<sender>
|
230
|
+
.*<phone>
|
231
|
+
.*<areaCode>11</areaCode>
|
232
|
+
.*<number>123
|
233
|
+
]xm
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'address' do
|
237
|
+
expect(subject.to_xml_params).to match %r[
|
238
|
+
<preApprovalRequest>
|
239
|
+
.*<sender>
|
240
|
+
.*<address>
|
241
|
+
.*<street>Park.Street</street>
|
242
|
+
.*<number>12</number>
|
243
|
+
.*<complement>Complement.here</complement>
|
244
|
+
.*<district>Neighborhood</district>
|
245
|
+
.*<postalCode>123456</postalCode>
|
246
|
+
.*<city>Sao.Paulo</city>
|
247
|
+
.*<state>SP</state>
|
248
|
+
.*<country>BRA</country>
|
249
|
+
]xm
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|