pagseguro-oficial 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/CONTRIBUTING.md +39 -0
- data/Dockerfile +20 -0
- data/README.md +22 -0
- data/docker-compose.yml +5 -0
- data/examples/checkout/create_payment_request.rb +1 -1
- data/examples/direct/create_transaction_using_boleto.rb +1 -1
- data/examples/direct/create_transaction_using_credit_card.rb +1 -1
- data/examples/direct/create_transaction_using_online_debit.rb +1 -1
- 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/split_payment/create_payment_request.rb +1 -1
- 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.rb +33 -1
- data/lib/pagseguro/credit_card_transaction_request.rb +1 -1
- data/lib/pagseguro/document.rb +8 -0
- data/lib/pagseguro/holder.rb +8 -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/payment_request/request_serializer.rb +25 -1
- data/lib/pagseguro/receiver.rb +3 -0
- data/lib/pagseguro/request.rb +32 -2
- data/lib/pagseguro/sender.rb +21 -3
- 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 +0 -10
- data/lib/pagseguro/transaction/serializer.rb +19 -2
- data/lib/pagseguro/transaction_request.rb +26 -1
- data/lib/pagseguro/transaction_request/request_serializer.rb +164 -1
- data/lib/pagseguro/version.rb +1 -1
- data/spec/fixtures/manual_subscription_charger/fail.xml +6 -0
- data/spec/fixtures/manual_subscription_charger/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/transactions/without_status_and_type.xml +71 -0
- data/spec/pagseguro/credit_card_transaction_request_spec.rb +1 -1
- data/spec/pagseguro/document_spec.rb +15 -0
- data/spec/pagseguro/holder_spec.rb +1 -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/payment_request/request_serializer_spec.rb +54 -22
- data/spec/pagseguro/receiver_spec.rb +1 -0
- data/spec/pagseguro/sender_spec.rb +16 -2
- 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/response_spec.rb +0 -42
- data/spec/pagseguro/transaction/serializer_spec.rb +5 -6
- data/spec/pagseguro/transaction_request/request_serializer_spec.rb +623 -159
- data/spec/pagseguro/transaction_request_spec.rb +26 -0
- data/spec/pagseguro/transaction_spec.rb +0 -48
- data/spec/spec_helper.rb +1 -0
- metadata +154 -8
- data/examples/checkout/search/search_transaction_status_history.rb +0 -22
- data/lib/pagseguro/transaction/status_collection.rb +0 -20
- data/spec/fixtures/transactions/status_history.xml +0 -12
- data/spec/pagseguro/transaction/status_collection_spec.rb +0 -43
data/lib/pagseguro/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
<preApproval>
|
2
|
+
<name>Seguro contra roubo do Notebook Prata</name>
|
3
|
+
<code>C08984179E9EDF3DD4023F87B71DE349</code>
|
4
|
+
<date>2011-11-23T13:40:23.000-02:00</date>
|
5
|
+
<tracker>538C53</tracker>
|
6
|
+
<status>CANCELLED</status>
|
7
|
+
<reference>REF1234</reference>
|
8
|
+
<lastEventDate>2011-11-25T20:04:23.000-02:00</lastEventDate>
|
9
|
+
<charge>auto</charge>
|
10
|
+
<sender>
|
11
|
+
<name>Comprador Istambul</name>
|
12
|
+
<email>c@i.com</email>
|
13
|
+
<phone>
|
14
|
+
<areaCode>11</areaCode>
|
15
|
+
<number>30389678</number>
|
16
|
+
</phone>
|
17
|
+
<address>
|
18
|
+
<street>ALAMEDA ITU</street>
|
19
|
+
<number>78</number>
|
20
|
+
<complement>ap. 2601</complement>
|
21
|
+
<district>Jardim Paulista</district>
|
22
|
+
<city>SAO PAULO</city>
|
23
|
+
<state>SP</state>
|
24
|
+
<country>BRASIL</country>
|
25
|
+
<postalCode>01421000</postalCode>
|
26
|
+
</address>
|
27
|
+
</sender>
|
28
|
+
</preApproval>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<preApprovalSearchResult>
|
2
|
+
<resultsInThisPage>1</resultsInThisPage>
|
3
|
+
<currentPage>1</currentPage>
|
4
|
+
<totalPages>1</totalPages>
|
5
|
+
<date>2011-08-08T16:16:23.000-03:00</date>
|
6
|
+
<preApprovals>
|
7
|
+
<preApproval>
|
8
|
+
<name>PagSeguro Pre Approval</name>
|
9
|
+
<code>12E10BEF5E5EF94004313FB891C8E4CF</code>
|
10
|
+
<date>2011-08-15T11:06:44.000-03:00</date>
|
11
|
+
<tracker>624C17</tracker>
|
12
|
+
<status>INITIATED</status>
|
13
|
+
<reference>R123456</reference>
|
14
|
+
<lastEventDate>2011-08-08T15:37:30.000-03:00</lastEventDate>
|
15
|
+
<charge>auto</charge>
|
16
|
+
</preApproval>
|
17
|
+
</preApprovals>
|
18
|
+
</preApprovalSearchResult>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
|
2
|
+
<paymentOrder>
|
3
|
+
<code>D2579C9461BA45F880419FE535763EFE</code>
|
4
|
+
<status>5</status>
|
5
|
+
<amount>80.00</amount>
|
6
|
+
<grossAmount>230</grossAmount>
|
7
|
+
<lastEventDate>2016-03-30T00:50:11-03:00</lastEventDate>
|
8
|
+
<discount>
|
9
|
+
<type>DISCOUNT_PERCENT</type>
|
10
|
+
<value>0</value>
|
11
|
+
</discount>
|
12
|
+
<schedulingDate>2016-04-14T15:14:29-03:00</schedulingDate>
|
13
|
+
<transactions>
|
14
|
+
<code>DBFABA621D734DCDA471F592E964A39E</code>
|
15
|
+
<date>2016-03-30T00:48:49-0300</date>
|
16
|
+
<status>3</status>
|
17
|
+
</transactions>
|
18
|
+
</paymentOrder>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
|
2
|
+
<paymentOrdersResult>
|
3
|
+
<date>2016-03-30T18:59:53-03:00</date>
|
4
|
+
<resultsInThisPage>2</resultsInThisPage>
|
5
|
+
<currentPage>1</currentPage>
|
6
|
+
<totalPages>1</totalPages>
|
7
|
+
<paymentOrders>
|
8
|
+
<paymentOrder>
|
9
|
+
<code>D2579C9461BA45F880419FE535763EFE</code>
|
10
|
+
<status>5</status>
|
11
|
+
<amount>80.00</amount>
|
12
|
+
<grossAmount>230</grossAmount>
|
13
|
+
<lastEventDate>2016-03-30T00:50:11-03:00</lastEventDate>
|
14
|
+
<discount>
|
15
|
+
<type>DISCOUNT_PERCENT</type>
|
16
|
+
<value>0</value>
|
17
|
+
</discount>
|
18
|
+
<schedulingDate>2016-04-14T15:14:29-03:00</schedulingDate>
|
19
|
+
<transactions>
|
20
|
+
<code>DBFABA621D734DCDA471F592E964A39E</code>
|
21
|
+
<date>2016-03-30T00:48:49-0300</date>
|
22
|
+
<status>3</status>
|
23
|
+
</transactions>
|
24
|
+
</paymentOrder>
|
25
|
+
<paymentOrder>
|
26
|
+
<code>C735289AF87F4CAA8D661DC977C0D383</code>
|
27
|
+
<status>5</status>
|
28
|
+
<amount>80.00</amount>
|
29
|
+
<grossAmount>80</grossAmount>
|
30
|
+
<lastEventDate>2016-03-30T00:50:48-03:00</lastEventDate>
|
31
|
+
<discount>
|
32
|
+
<type>DISCOUNT_PERCENT</type>
|
33
|
+
<value>0</value>
|
34
|
+
</discount>
|
35
|
+
<schedulingDate>2016-05-14T22:14:29-03:00</schedulingDate>
|
36
|
+
<transactions>
|
37
|
+
<code>129A62902B01421993504EF4954A60FD</code>
|
38
|
+
<date>2016-03-30T00:49:07-0300</date>
|
39
|
+
<status>3</status>
|
40
|
+
</transactions>
|
41
|
+
</paymentOrder>
|
42
|
+
</paymentOrders>
|
43
|
+
</paymentOrdersResult>
|
@@ -0,0 +1,71 @@
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
|
2
|
+
<transaction>
|
3
|
+
<date>2013-05-01T01:40:27.000-03:00</date>
|
4
|
+
<code>667A3914-4F9F-4705-0EB6-CA6FA0DF8A19</code>
|
5
|
+
<reference>REF1234</reference>
|
6
|
+
<lastEventDate>2013-05-01T01:41:20.000-03:00</lastEventDate>
|
7
|
+
<paymentMethod>
|
8
|
+
<type>2</type>
|
9
|
+
<code>202</code>
|
10
|
+
</paymentMethod>
|
11
|
+
<paymentLink>https://pagseguro.uol.com.br/checkout/imprimeBoleto.jhtml?code=667D39144F9F47059FB6CA6FA0DF8A20</paymentLink>
|
12
|
+
<grossAmount>459.50</grossAmount>
|
13
|
+
<discountAmount>0.00</discountAmount>
|
14
|
+
<creditorFees>
|
15
|
+
<operationalFeeAmount>0.00</operationalFeeAmount>
|
16
|
+
<installmentFeeAmount>0.00</installmentFeeAmount>
|
17
|
+
<intermediationRateAmount>0.40</intermediationRateAmount>
|
18
|
+
<intermediationFeeAmount>1644.80</intermediationFeeAmount>
|
19
|
+
<commissionFeeAmount>1.98</commissionFeeAmount>
|
20
|
+
<efrete>1.98</efrete>
|
21
|
+
</creditorFees>
|
22
|
+
<netAmount>445.77</netAmount>
|
23
|
+
<extraAmount>0.00</extraAmount>
|
24
|
+
<installmentCount>1</installmentCount>
|
25
|
+
<paymentReleases>
|
26
|
+
<paymentRelease>
|
27
|
+
<installment>1</installment>
|
28
|
+
<totalAmount>202.92</totalAmount>
|
29
|
+
<releaseAmount>202.92</releaseAmount>
|
30
|
+
<status>OPENED</status>
|
31
|
+
<releaseDate>2015-03-25T16:14:23-03:00</releaseDate>
|
32
|
+
</paymentRelease>
|
33
|
+
</paymentReleases>
|
34
|
+
<itemCount>1</itemCount>
|
35
|
+
<items>
|
36
|
+
<item>
|
37
|
+
<id>1234</id>
|
38
|
+
<description>Some product</description>
|
39
|
+
<quantity>1</quantity>
|
40
|
+
<amount>459.50</amount>
|
41
|
+
</item>
|
42
|
+
</items>
|
43
|
+
<sender>
|
44
|
+
<name>JOHN DOE</name>
|
45
|
+
<email>john@example.com</email>
|
46
|
+
<phone>
|
47
|
+
<areaCode>11</areaCode>
|
48
|
+
<number>12345678</number>
|
49
|
+
</phone>
|
50
|
+
<documents>
|
51
|
+
<document>
|
52
|
+
<type>CPF</type>
|
53
|
+
<value>65647162142</value>
|
54
|
+
</document>
|
55
|
+
</documents>
|
56
|
+
</sender>
|
57
|
+
<shipping>
|
58
|
+
<address>
|
59
|
+
<street>AV. BRIG. FARIA LIMA</street>
|
60
|
+
<number>1384</number>
|
61
|
+
<complement>5 ANDAR</complement>
|
62
|
+
<district>JARDIM PAULISTANO</district>
|
63
|
+
<postalCode>01452002</postalCode>
|
64
|
+
<city>SAO PAULO</city>
|
65
|
+
<state>SP</state>
|
66
|
+
<country>BRA</country>
|
67
|
+
</address>
|
68
|
+
<type>2</type>
|
69
|
+
<cost>0.00</cost>
|
70
|
+
</shipping>
|
71
|
+
</transaction>
|
@@ -3,4 +3,19 @@ require "spec_helper"
|
|
3
3
|
describe PagSeguro::Document do
|
4
4
|
it_assigns_attribute :type
|
5
5
|
it_assigns_attribute :value
|
6
|
+
|
7
|
+
it '==' do
|
8
|
+
document = PagSeguro::Document.new(type: 'TYPE', value: 'VALUE')
|
9
|
+
expect(document).to eq PagSeguro::Document.new(type: 'TYPE', value: 'VALUE')
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'helpers' do
|
13
|
+
it 'cpf?' do
|
14
|
+
expect{ subject.type = 'CPF' }.to change{ subject.cpf? }.to true
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'cnpj?' do
|
18
|
+
expect{ subject.type = 'CNPJ' }.to change{ subject.cnpj? }.to true
|
19
|
+
end
|
20
|
+
end
|
6
21
|
end
|
@@ -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
|