nfg-client 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'unit/response_stubs/create_cof_stubs'
3
+
4
+ describe NFGClient::Client do
5
+ let(:nfg_client) { NFGClient.new('aiduuad', 'aooaid', 'sosois', 'ksidi', true) }
6
+ subject { nfg_client.create_cof(create_cof_params) }
7
+ describe "#create_cof" do
8
+ context "with a successful response" do
9
+ it "should return a hash with a new COFId" do
10
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',successful_create_cof_response('ISUDUD')))
11
+ expect(subject['StatusCode']).to eq('Success')
12
+ expect(subject['DonorToken']).to eq('ISUDUD')
13
+ expect(subject['COFId']).to eq('1111111')
14
+ end
15
+ end
16
+
17
+ context "with a server error" do
18
+ it "should return an UnexpectedError" do
19
+ nfg_client.expects(:ssl_post).returns(nfg_response('500',server_error_response))
20
+ expect(subject['StatusCode']).to eq('UnexpectedError')
21
+ end
22
+ end
23
+
24
+ context "with an unsuccessful response" do
25
+ it "should return the appropriate error with new COFid" do
26
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',unsuccessful_create_cof_response('ISUDUD')))
27
+ expect(subject['StatusCode']).to eq('ChargeFailed')
28
+ expect(subject['DonorToken']).to eq('ISUDUD')
29
+
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'unit/response_stubs/delete_donor_cof_stubs'
3
+
4
+ describe NFGClient::Client do
5
+ let(:nfg_client) { NFGClient.new('aiduuad', 'aooaid', 'sosois', 'ksidi', true) }
6
+ subject { nfg_client.delete_donor_cof(delete_donor_cof_params) }
7
+ describe "#delete_donor_cof" do
8
+ context "with a successful response" do
9
+ it "should return a hash with a status code of success" do
10
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',successful_delete_donor_cof_response))
11
+ expect(subject['StatusCode']).to eq('Success')
12
+ end
13
+ end
14
+
15
+ context "with a server error" do
16
+ it "should return an UnexpectedError" do
17
+ nfg_client.expects(:ssl_post).returns(nfg_response('500',server_error_response))
18
+ expect(subject['StatusCode']).to eq('UnexpectedError')
19
+ end
20
+ end
21
+
22
+ context "with an unsuccessful response" do
23
+ it "should return the appropriate error with new COFid" do
24
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',unsuccessful_delete_donor_cof_response))
25
+ expect(subject['StatusCode']).to eq('ValidationFailed')
26
+ expect(subject['Message']).to eq('COFAlreadyDeleted - Attempt made to delete a Card on File that has already been deleted')
27
+
28
+ end
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'unit/response_stubs/get_donation_report_stubs'
3
+
4
+ describe NFGClient::Client do
5
+ let(:nfg_client) { NFGClient.new('aiduuad', 'aooaid', 'sosois', 'ksidi', true) }
6
+ subject { nfg_client.get_donation_report(get_donation_report_params) }
7
+
8
+ describe "#get_donation_report" do
9
+ context "with a successful response" do
10
+ it "should return a hash with a new TotalChargeAmount" do
11
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',successful_get_donation_report_response))
12
+ expect(subject['StatusCode']).to eq('Success')
13
+ expect(subject['ReturnCount']).to eq("2")
14
+ expect(subject['ReportResults'].length).to eq(2)
15
+ expect(subject['ReportResults'].first['ChargeId']).to eq('123587')
16
+ expect(subject['ReportResults'].last['ChargeId']).to eq('5555846')
17
+ end
18
+ end
19
+
20
+ context "with a server error" do
21
+ it "should return an UnexpectedError" do
22
+ nfg_client.expects(:ssl_post).returns(nfg_response('500',server_error_response))
23
+ expect(subject['StatusCode']).to eq('UnexpectedError')
24
+ end
25
+ end
26
+
27
+ context "with an unsuccessful response" do
28
+ it "should return the appropriate error with new COFid" do
29
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',unsuccessful_get_donation_report_response))
30
+ expect(subject['StatusCode']).to eq('ValidationFailed')
31
+ expect(subject['ReportResults'].length).to eq(0)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'unit/response_stubs/get_donor_cofs_stubs'
3
+
4
+ describe NFGClient::Client do
5
+ let(:nfg_client) { NFGClient.new('aiduuad', 'aooaid', 'sosois', 'ksidi', true) }
6
+ subject { nfg_client.get_donor_cofs(get_donor_cofs_params) }
7
+ describe "#get_donor_cofs" do
8
+ context "with a successful response" do
9
+ it "should return a hash with a an array of COFs" do
10
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',successful_get_donor_cofs_response('ISUDUD')))
11
+ expect(subject['StatusCode']).to eq('Success')
12
+ expect(subject['DonorToken']).to eq('ISUDUD')
13
+ expect(subject['Cards'].length).to eq(2)
14
+ expect(subject['Cards'].first['COFId']).to eq('33333333')
15
+ expect(subject['Cards'].last['COFId']).to eq('44444444')
16
+ end
17
+ end
18
+
19
+ context "with a server error" do
20
+ it "should return an UnexpectedError" do
21
+ nfg_client.expects(:ssl_post).returns(nfg_response('500',server_error_response))
22
+ expect(subject['StatusCode']).to eq('UnexpectedError')
23
+ end
24
+ end
25
+
26
+ context "with an unsuccessful response" do
27
+ it "should return the appropriate error with the DonorToken" do
28
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',unsuccessful_get_donor_cofs_response('ISUDUD')))
29
+ expect(subject['StatusCode']).to eq('ValidationFailed')
30
+ expect(subject['DonorToken']).to eq('ISUDUD')
31
+
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'unit/response_stubs/get_donor_donation_history_stubs'
3
+
4
+ describe NFGClient::Client do
5
+ let(:nfg_client) { NFGClient.new('aiduuad', 'aooaid', 'sosois', 'ksidi', true) }
6
+ subject { nfg_client.get_donor_donation_history(get_donor_donation_history_params) }
7
+
8
+ describe "#get_donor_donation_history" do
9
+ context "with a successful response" do
10
+ it "should return a hash with a new TotalChargeAmount" do
11
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',successful_get_donor_donation_history_response))
12
+ expect(subject['StatusCode']).to eq('Success')
13
+ expect(subject['DonorToken']).to eq('1828282')
14
+ expect(subject['Donations'].length).to eq(2)
15
+ expect(subject['Donations'].first['ChargeId']).to eq('292929')
16
+ expect(subject['Donations'].last['ChargeId']).to eq('8939399')
17
+ end
18
+ end
19
+
20
+ context "with a server error" do
21
+ it "should return an UnexpectedError" do
22
+ nfg_client.expects(:ssl_post).returns(nfg_response('500',server_error_response))
23
+ expect(subject['StatusCode']).to eq('UnexpectedError')
24
+ end
25
+ end
26
+
27
+ context "with an unsuccessful response" do
28
+ it "should return the appropriate error with new COFid" do
29
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',unsuccessful_get_donor_donation_history_response))
30
+ expect(subject['StatusCode']).to eq('Success')
31
+ expect(subject['Donations'].length).to eq(0)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'unit/response_stubs/get_fee_stubs'
3
+
4
+ describe NFGClient::Client do
5
+ let(:nfg_client) { NFGClient.new('aiduuad', 'aooaid', 'sosois', 'ksidi', true) }
6
+ subject { nfg_client.get_fee(get_fee_params) }
7
+
8
+ describe "#get_fee" do
9
+ context "with a successful response" do
10
+ it "should return a hash with a new TotalChargeAmount" do
11
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',successful_get_fee_response))
12
+ expect(subject['StatusCode']).to eq('Success')
13
+ expect(subject['TotalChargeAmount']).to eq("110.00")
14
+ end
15
+ end
16
+
17
+ context "with a server error" do
18
+ it "should return an UnexpectedError" do
19
+ nfg_client.expects(:ssl_post).returns(nfg_response('500',server_error_response))
20
+ expect(subject['StatusCode']).to eq('UnexpectedError')
21
+ end
22
+ end
23
+
24
+ context "with an unsuccessful response" do
25
+ it "should return the appropriate error with new COFid" do
26
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',unsuccessful_get_fee_response))
27
+ expect(subject['StatusCode']).to eq('ValidationFailed')
28
+ expect(subject['TotalChargeAmount']).to eq('0.0')
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'unit/response_stubs/make_cof_donation_stubs'
3
+
4
+ describe NFGClient::Client do
5
+ let(:nfg_client) { NFGClient.new('aiduuad', 'aooaid', 'sosois', 'ksidi', true) }
6
+ subject { nfg_client.make_cof_donation(make_cof_donation_params) }
7
+
8
+ describe "#make_cof_donation" do
9
+ context "with a successful response" do
10
+ it "should return a hash with a new COFId" do
11
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',successful_make_cof_donation_response))
12
+ expect(subject['StatusCode']).to eq('Success')
13
+ expect(subject['COFId']).to eq('1111111')
14
+ end
15
+
16
+ it "should return a hash with a transaction Id" do
17
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',successful_make_cof_donation_response))
18
+ expect(subject['StatusCode']).to eq('Success')
19
+ expect(subject['ChargeId']).to eq('3333333')
20
+ end
21
+ end
22
+
23
+ context "with a server error" do
24
+ it "should return an UnexpectedError" do
25
+ nfg_client.expects(:ssl_post).returns(nfg_response('500',server_error_response))
26
+ expect(subject['StatusCode']).to eq('UnexpectedError')
27
+ end
28
+ end
29
+
30
+ context "with an unsuccessful response" do
31
+ it "should return the appropriate error with new COFid" do
32
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',unsuccessful_make_cof_donation_response))
33
+ expect(subject['StatusCode']).to eq('ChargeFailed')
34
+ expect(subject['DonorToken']).to_not be
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'unit/response_stubs/make_donation_add_cof_stubs'
3
+
4
+ describe NFGClient::Client do
5
+ let(:nfg_client) { NFGClient.new('aiduuad', 'aooaid', 'sosois', 'ksidi', true) }
6
+ subject { nfg_client.make_donation_add_cof(make_donation_add_cof_params) }
7
+
8
+ describe "#make_donation_add_cof" do
9
+ context "with a successful response" do
10
+ it "should return a hash with a new COFId" do
11
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',successful_make_donation_add_cof_response('ISUDUD')))
12
+ expect(subject['StatusCode']).to eq('Success')
13
+ expect(subject['COFId']).to eq('1111111')
14
+ end
15
+
16
+ it "should return a hash with a transaction Id" do
17
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',successful_make_donation_add_cof_response('ISUDUD')))
18
+ expect(subject['StatusCode']).to eq('Success')
19
+ expect(subject['ChargeId']).to eq('3333333')
20
+ end
21
+ end
22
+
23
+ context "with a server error" do
24
+ it "should return an UnexpectedError" do
25
+ nfg_client.expects(:ssl_post).returns(nfg_response('500',server_error_response))
26
+ expect(subject['StatusCode']).to eq('UnexpectedError')
27
+ end
28
+ end
29
+
30
+ context "with an unsuccessful response" do
31
+ it "should return the appropriate error with new COFid" do
32
+ nfg_client.expects(:ssl_post).returns(nfg_response('200',unsuccessful_make_donation_add_cof_response('ISUDUD')))
33
+ expect(subject['StatusCode']).to eq('ChargeFailed')
34
+ expect(subject['DonorToken']).to_not be
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,46 @@
1
+ require 'unit/response_stubs/spec_response_helpers'
2
+
3
+ def successful_create_cof_response(donor_token)
4
+ <<-XML
5
+ <?xml version="1.0" encoding="utf-8"?>
6
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
7
+ <soap:Body>
8
+ <CreateCOFResponse xmlns="http://api.networkforgood.org/partnerdonationservice">
9
+ <CreateCOFResult>
10
+ <DonorToken>#{donor_token}</DonorToken>
11
+ <CofId>1111111</CofId>
12
+ <StatusCode>Success</StatusCode>
13
+ <Message></Message>
14
+ <ErrorDetails></ErrorDetails>
15
+ <CallDuration>0.051235</CallDuration>
16
+ </CreateCOFResult>
17
+ </CreateCOFResponse>
18
+ </soap:Body>
19
+ </soap:Envelope>
20
+ XML
21
+ end
22
+
23
+ def unsuccessful_create_cof_response(donor_token)
24
+ <<-XML
25
+ <?xml version="1.0" encoding="utf-8"?>
26
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
27
+ <soap:Body>
28
+ <CreateCOFResponse xmlns="http://api.networkforgood.org/partnerdonationservice">
29
+ <CreateCOFResult>
30
+ <DonorToken>#{donor_token}</DonorToken>
31
+ <StatusCode>ChargeFailed</StatusCode>
32
+ <CofId></CofId>
33
+ <Message>InvalidCreditCardNumber - Credit Card Number failed validation</Message>
34
+ <ErrorDetails>
35
+ <ErrorInfo>
36
+ <ErrCode>InvalidCreditCardNumber</ErrCode>
37
+ <ErrData></ErrData>
38
+ </ErrorInfo>
39
+ </ErrorDetails>
40
+ <CallDuration>0.051235</CallDuration>
41
+ </CreateCOFResult>
42
+ </CreateCOFResponse>
43
+ </soap:Body>
44
+ </soap:Envelope>
45
+ XML
46
+ end
@@ -0,0 +1,42 @@
1
+ require 'unit/response_stubs/spec_response_helpers'
2
+
3
+ def successful_delete_donor_cof_response
4
+ <<-XML
5
+ <?xml version="1.0" encoding="utf-8"?>
6
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
7
+ <soap:Body>
8
+ <DeleteDonorCOFResponse xmlns="http://api.networkforgood.org/partnerdonationservice">
9
+ <DeleteDonorCOFResult>
10
+ <StatusCode>Success</StatusCode>
11
+ <Message></Message>
12
+ <ErrorDetails></ErrorDetails>
13
+ <CallDuration>0.051235</CallDuration>
14
+ </DeleteDonorCOFResult>
15
+ </DeleteDonorCOFResponse>
16
+ </soap:Body>
17
+ </soap:Envelope>
18
+ XML
19
+ end
20
+
21
+ def unsuccessful_delete_donor_cof_response
22
+ <<-XML
23
+ <?xml version="1.0" encoding="utf-8"?>
24
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
25
+ <soap:Body>
26
+ <DeleteDonorCOFResponse xmlns="http://api.networkforgood.org/partnerdonationservice">
27
+ <DeleteDonorCOFResult>
28
+ <StatusCode>ValidationFailed</StatusCode>
29
+ <Message>COFAlreadyDeleted - Attempt made to delete a Card on File that has already been deleted</Message>
30
+ <ErrorDetails>
31
+ <ErrorInfo>
32
+ <ErrCode>COFAlreadyDeleted</ErrCode>
33
+ <ErrData></ErrData>
34
+ </ErrorInfo>
35
+ </ErrorDetails>
36
+ <CallDuration>0.051235</CallDuration>
37
+ </DeleteDonorCOFResult>
38
+ </DeleteDonorCOFResponse>
39
+ </soap:Body>
40
+ </soap:Envelope>
41
+ XML
42
+ end
@@ -0,0 +1,99 @@
1
+ require 'unit/response_stubs/spec_response_helpers'
2
+
3
+ def successful_get_donation_report_response
4
+ <<-XML
5
+ <?xml version="1.0" encoding="utf-8"?>
6
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
7
+ <soap:Body>
8
+ <GetDonationReportResponse xmlns="http://api.networkforgood.org/partnerdonationservice">
9
+ <GetDonationReportResult>
10
+ <ReportResults>
11
+ <DonationReportResult>
12
+ <Source>GiveCorps</Source>
13
+ <Campaign>GivingDay</Campaign>
14
+ <ChargeId>123587</ChargeId>
15
+ <ShareWithCharity>Yes</ShareWithCharity>
16
+ <DonorEmail>jimmy@smith.com</DonorEmail>
17
+ <DonorFirstName>Jimmy</DonorFirstName>
18
+ <DonorLastName>Smith</DonorLastName>
19
+ <DonorAddress1>123 This Street</DonorAddress1>
20
+ <DonorAddress2></DonorAddress2>
21
+ <DonorCity>Baltimore</DonorCity>
22
+ <DonorState>MD</DonorState>
23
+ <DonorZip>21210</DonorZip>
24
+ <DonorCountry>US</DonorCountry>
25
+ <DonorPhone>410-555-5555</DonorPhone>
26
+ <Designation>Annual Giving</Designation>
27
+ <DonateInName></DonateInName>
28
+ <RecurringPeriod></RecurringPeriod>
29
+ <EventDate></EventDate>
30
+ <NpoEIN>45-454545</NpoEIN>
31
+ <NpoName>My Charity</NpoName>
32
+ <ChargeStatus>Accepted</ChargeStatus>
33
+ <ChargeAmount>100.00</ChargeAmount>
34
+ <NpoTPC>0.00</NpoTPC>
35
+ <DonationItemAmount>100.00</DonationItemAmount>
36
+ <TotalDonationAmount>100.00</TotalDonationAmount>
37
+ <HistoryRecordId>132588</HistoryRecordId>
38
+ </DonationReportResult>
39
+ <DonationReportResult>
40
+ <Source>GiveCorps</Source>
41
+ <Campaign>Christmas</Campaign>
42
+ <ChargeId>5555846</ChargeId>
43
+ <ShareWithCharity>No</ShareWithCharity>
44
+ <DonorEmail>janet@smith.com</DonorEmail>
45
+ <DonorFirstName>Janet</DonorFirstName>
46
+ <DonorLastName>Smith</DonorLastName>
47
+ <DonorAddress1>456 That Street</DonorAddress1>
48
+ <DonorAddress2></DonorAddress2>
49
+ <DonorCity>Glen Burnie</DonorCity>
50
+ <DonorState>MD</DonorState>
51
+ <DonorZip>21564</DonorZip>
52
+ <DonorCountry>US</DonorCountry>
53
+ <DonorPhone>410-444-5585</DonorPhone>
54
+ <Designation>Boat Race</Designation>
55
+ <DonateInName>Doris Smith</DonateInName>
56
+ <RecurringPeriod>Monthly</RecurringPeriod>
57
+ <EventDate></EventDate>
58
+ <NpoEIN>56-89898</NpoEIN>
59
+ <NpoName>Great Foundation</NpoName>
60
+ <ChargeStatus>Accepted</ChargeStatus>
61
+ <ChargeAmount>50.00</ChargeAmount>
62
+ <NpoTPC>2.50</NpoTPC>
63
+ <DonationItemAmount>50.00</DonationItemAmount>
64
+ <TotalDonationAmount>50.00</TotalDonationAmount>
65
+ <HistoryRecordId>12355</HistoryRecordId>
66
+ </DonationReportResult>
67
+ </ReportResults>
68
+ <ReturnCount>2</ReturnCount>
69
+ <ErrorDetails/>
70
+ <Message/>
71
+ <CallDuration>0.0312504</CallDuration>
72
+ <StatusCode>Success</StatusCode>
73
+ </GetDonationReportResult>
74
+ </GetDonationReportResponse>
75
+ </soap:Body>
76
+ </soap:Envelope>
77
+ XML
78
+ end
79
+
80
+ def unsuccessful_get_donation_report_response
81
+ <<-XML
82
+ <?xml version="1.0" encoding="utf-8"?>
83
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
84
+ <soap:Body>
85
+ <GetDonationReportResponse xmlns="http://api.networkforgood.org/partnerdonationservice">
86
+ <GetDonationReportResult>
87
+ <Message>Report query range is greater than 24 hours.</Message>
88
+ <CallDuration>0.0312504</CallDuration>
89
+ <StatusCode>ValidationFailed</StatusCode>
90
+ <ReportResults/>
91
+ <ReturnCount>0</ReturnCount>
92
+ <ErrorDetails/>
93
+ </GetDonationReportResult>
94
+ </GetDonationReportResponse>
95
+ </soap:Body>
96
+ </soap:Envelope>
97
+ XML
98
+ end
99
+