Class: NFGClient::Client

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/nfg-client/client.rb

Instance Method Summary collapse

Methods included from Utils

#build_nfg_soap_request, #encode_if_text, #format_headers, #get_nfg_soap_request_template, #hash_to_xml, #host, #nfg_soap_request, #parse_result, #requires!, #ssl_post, #url

Constructor Details

#initialize(partner_id, partner_password, partner_source, partner_campaign, use_sandbox) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
# File 'lib/nfg-client/client.rb', line 10

def initialize(partner_id, partner_password, partner_source, partner_campaign, use_sandbox)
  @partner_id = partner_id
  @partner_password = partner_password
  @partner_source = partner_source
  @partner_campaign = partner_campaign
  @use_sandbox = use_sandbox
end

Instance Method Details

#create_cof(params) ⇒ Object

Creates a card on file for the given donor token

Arguments:

params: (Hash)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nfg-client/client.rb', line 22

def create_cof(params)
  requires!(params, :DonorToken, :DonorFirstName, :DonorLastName, :DonorEmail, :DonorAddress1, :DonorAddress2, :DonorCity, :DonorState, :DonorZip, :DonorCountry, :DonorPhone, :CardType, :NameOnCard, :CardNumber, :ExpMonth, :ExpYear, :CSC)
  call_params = add_credentials_to_params(params)
  response = nfg_soap_request('CreateCOF', call_params)
  if response.is_a? REXML::Element
    {
      'StatusCode' => response.elements['StatusCode'].get_text.to_s,
      'Message' => response.elements['Message'].get_text.to_s,
      'ErrorDetails' => response.elements['ErrorDetails'].get_text.to_s,
      'CallDuration' => response.elements['CallDuration'].get_text.to_s,
      'DonorToken' => response.elements['DonorToken'].get_text.to_s,
      'COFId' => response.elements['CofId'].get_text.to_s
    }
  else
    response
  end
end

#delete_donor_cof(params) ⇒ Object

Deletes a card on file for the given donor token

Arguments:

params: (Hash)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/nfg-client/client.rb', line 44

def delete_donor_cof(params)
  requires!(params, :DonorToken, :COFId)
  call_params = add_credentials_to_params(params)
  response = nfg_soap_request('DeleteDonorCOF', call_params)
  if response.is_a? REXML::Element
    if response.elements['StatusCode'].get_text.to_s == 'Success'
      {
        'StatusCode' => response.elements['StatusCode'].get_text.to_s,
        'Message' => response.elements['Message'].get_text.to_s,
        'ErrorDetails' => response.elements['ErrorDetails'].get_text.to_s,
        'CallDuration' => response.elements['CallDuration'].get_text.to_s
      }
    else
      {
        'StatusCode' => response.elements['StatusCode'].get_text.to_s,
        'Message' => response.elements['Message'].get_text.to_s,
        'ErrorDetails' => {
          'ErrorInfo' => {
            'ErrCode' => response.elements['ErrorDetails'].andand.elements.andand['ErrorInfo'].andand.elements.andand['ErrCode'].andand.get_text.andand.to_s,
            'ErrData' => response.elements['ErrorDetails'].andand.elements.andand['ErrorInfo'].andand.elements.andand['ErrData'].andand.get_text.andand.to_s
          }
        },
        'CallDuration' => response.elements['CallDuration'].get_text.to_s
      }
    end
  else
    response
  end
end

#get_donation_report(params) ⇒ Object

Retrieves the donation history by date

Arguments:

params: (Hash)


264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/nfg-client/client.rb', line 264

def get_donation_report(params)
  requires!(params, :StartDate, :EndDate, :DonationReportType)
  call_params = add_credentials_to_params(params)
  response = nfg_soap_request('GetDonationReport', call_params)
  if response.is_a? REXML::Element
    response_hash = {
      'StatusCode' => response.elements['StatusCode'].get_text.to_s,
      'Message' => response.elements['Message'].get_text.to_s,
      'ErrorDetails' => response.elements['ErrorDetails'].get_text.to_s,
      'CallDuration' => response.elements['CallDuration'].get_text.to_s,
      'ReturnCount' => response.elements['ReturnCount'].get_text.to_s
    }
    response_hash['ReportResults'] = Array.new
    response.elements.each('ReportResults/DonationReportResult') do |donation|
      response_hash['ReportResults'] << {
        'Source' => donation.elements['Source'].get_text.to_s,
        'Campaign' => donation.elements['Campaign'].get_text.to_s,
        'ChargeId' => donation.elements['ChargeId'].get_text.to_s,
        'ShareWithCharity' => donation.elements['ShareWithCharity'].get_text.to_s,
        'DonorEmail' => donation.elements['DonorEmail'].get_text.to_s,
        'DonorFirstName' => donation.elements['DonorFirstName'].get_text.to_s,
        'DonorLastName' => donation.elements['DonorLastName'].get_text.to_s,
        'DonorAddress1' => donation.elements['DonorAddress1'].get_text.to_s,
        'DonorAddress2' => donation.elements['DonorAddress2'].get_text.to_s,
        'DonorCity' => donation.elements['DonorCity'].get_text.to_s,
        'DonorState' => donation.elements['DonorState'].get_text.to_s,
        'DonorZip' => donation.elements['DonorZip'].get_text.to_s,
        'DonorCountry' => donation.elements['DonorCountry'].get_text.to_s,
        'DonorPhone' => donation.elements['DonorPhone'].get_text.to_s,
        'Designation' => donation.elements['Designation'].get_text.to_s,
        'DonateInName' => donation.elements['DonateInName'].get_text.to_s,
        'RecurringPeriod' => donation.elements['RecurringPeriod'].get_text.to_s,
        'EventDate' => donation.elements['EventDate'].get_text.to_s,
        'NpoEIN' => donation.elements['NpoEIN'].get_text.to_s,
        'NpoName' => donation.elements['NpoName'].get_text.to_s,
        'ChargeStatus' => donation.elements['ChargeStatus'].get_text.to_s,
        'ChargeAmount' => donation.elements['ChargeAmount'].get_text.to_s,
        'NpoTPC' => donation.elements['NpoTPC'].get_text.to_s,
        'DonationItemAmount' => donation.elements['DonationItemAmount'].get_text.to_s,
        'TotalDonationAmount' => donation.elements['TotalDonationAmount'].get_text.to_s,
        'HistoryRecordId' => donation.elements['HistoryRecordId'].get_text.to_s
      }
    end
    response_hash
  else
    response
  end
end

#get_donor_cofs(params) ⇒ Object

Gets a list of the given donor token’s cards on file

Arguments:

params: (Hash)


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/nfg-client/client.rb', line 78

def get_donor_cofs(params)
  requires!(params, :DonorToken)
  call_params = add_credentials_to_params(params)
  response = nfg_soap_request('GetDonorCOFs', call_params)
  if response.is_a? REXML::Element
    response_hash = {
      'StatusCode' => response.elements['StatusCode'].get_text.to_s,
      'Message' => response.elements['Message'].get_text.to_s,
      'ErrorDetails' => response.elements['ErrorDetails'].get_text.to_s,
      'CallDuration' => response.elements['CallDuration'].get_text.to_s,
      'DonorToken' => response.elements['DonorToken'].get_text.to_s
    }
    response_hash['Cards'] = Array.new
    response.elements.each('Cards/COFRecord') do |card|
      response_hash['Cards'] << {
        'COFId' => card.elements['COFId'].get_text.to_s,
        'CardType' => card.elements['CardType'].get_text.to_s,
        'CCSuffix' => card.elements['CCSuffix'].get_text.to_s,
        'CCExpMonth' => card.elements['CCExpMonth'].get_text.to_s,
        'CCExpYear' => card.elements['CCExpYear'].get_text.to_s,
        'bInUseByLiveRD' => card.elements['bInUseByLiveRD'].get_text.to_s,
        'COFEmailAddress' => card.elements['COFEmailAddress'].get_text.to_s
      }
    end
    response_hash
  else
    response
  end
end

#get_donor_donation_history(params) ⇒ Object

Retrieves the donation history for a specified donor token

Arguments:

params: (Hash)


229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/nfg-client/client.rb', line 229

def get_donor_donation_history(params)
  requires!(params, :DonorToken)
  call_params = add_credentials_to_params(params)
  response = nfg_soap_request('GetDonorDonationHistory', call_params)
  if response.is_a? REXML::Element
    response_hash = {
      'StatusCode' => response.elements['StatusCode'].get_text.to_s,
      'Message' => response.elements['Message'].get_text.to_s,
      'ErrorDetails' => response.elements['ErrorDetails'].get_text.to_s,
      'CallDuration' => response.elements['CallDuration'].get_text.to_s,
      'DonorToken' => response.elements['DonorToken'].get_text.to_s
    }
    response_hash['Donations'] = Array.new
    response.elements.each('Donations/DonationItemData') do |donation|
      response_hash['Donations'] << {
        'DonationDate' => donation.elements['DonationDate'].get_text.to_s,
        'RecurType' => donation.elements['RecurType'].get_text.to_s,
        'IsTpcAddOnFee' => donation.elements['IsTpcAddOnFee'].get_text.to_s,
        'NpoName' => donation.elements['NpoName'].get_text.to_s,
        'Designation' => donation.elements['Designation'].get_text.to_s,
        'Dedication' => donation.elements['Dedication'].get_text.to_s,
        'Amount' => donation.elements['Amount'].get_text.to_s,
        'ChargeId' => donation.elements['ChargeId'].get_text.to_s,
      }
    end
    response_hash
  else
    response
  end
end

#get_fee(params) ⇒ Object

Calculates fee tied to transaction

Arguments:

params: (Hash)


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/nfg-client/client.rb', line 112

def get_fee(params)
  requires!(params, :DonationLineItems, :TipAmount, :CardType)
  call_params = add_credentials_to_params(params)
  response = nfg_soap_request('GetFee', call_params)
  if response.is_a? REXML::Element
    if response.elements['ErrorDetails'].elements['ErrorInfo'].nil?
      {
        'StatusCode' => 'Success',
        'Message' => response.elements['Message'].get_text.to_s,
        'ErrorDetails' => response.elements['ErrorDetails'].get_text.to_s,
        'CallDuration' => response.elements['CallDuration'].get_text.to_s,
        'TotalChargeAmount' => response.elements['TotalChargeAmount'].get_text.to_s,
        'TotalAddFee' => response.elements['TotalAddFee'].get_text.to_s,
        'TotalDeductFee' => response.elements['TotalDeductFee'].get_text.to_s,
        'TipAmount' => response.elements['TipAmount'].get_text.to_s
      }
    else
      {
        'StatusCode' => 'ValidationFailed',
        'Message' => response.elements['Message'].get_text.to_s,
        'ErrorDetails' => {
          'ErrorInfo' => {
            'ErrCode' => response.elements['ErrorDetails'].andand.elements.andand['ErrorInfo'].andand.elements.andand['ErrCode'].andand.get_text.andand.to_s,
            'ErrData' => response.elements['ErrorDetails'].andand.elements.andand['ErrorInfo'].andand.elements.andand['ErrData'].andand.get_text.andand.to_s
          }
        },
        'CallDuration' => response.elements['CallDuration'].get_text.to_s,
        'TotalChargeAmount' => response.elements['TotalChargeAmount'].get_text.to_s,
        'TotalAddFee' => response.elements['TotalAddFee'].get_text.to_s,
        'TotalDeductFee' => response.elements['TotalDeductFee'].get_text.to_s,
        'TipAmount' => response.elements['TipAmount'].get_text.to_s
      }
    end
  else
    response
  end
end

#make_cof_donation(params) ⇒ Object

Makes a donation using the given COF

Arguments:

params: (Hash)


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/nfg-client/client.rb', line 153

def make_cof_donation(params)
  requires!(params, :DonationLineItems, :TotalAmount, :TipAmount, :DonorIpAddress, :DonorToken, :COFId)
  call_params = add_credentials_to_params(params)
  response = nfg_soap_request('MakeCOFDonation', call_params)
  if response.is_a? REXML::Element
    if response.elements['StatusCode'].get_text.to_s == 'Success'
      {
        'StatusCode' => response.elements['StatusCode'].get_text.to_s,
        'Message' => response.elements['Message'].get_text.to_s,
        'ErrorDetails' => response.elements['ErrorDetails'].get_text.to_s,
        'CallDuration' => response.elements['CallDuration'].get_text.to_s,
        'ChargeId' => response.elements['ChargeId'].get_text.to_s,
        'COFId' => response.elements['CofId'].get_text.to_s
      }
    else
      {
        'StatusCode' => response.elements['StatusCode'].get_text.to_s,
        'Message' => response.elements['Message'].get_text.to_s,
        'ErrorDetails' => {
          'ErrorInfo' => {
            'ErrCode' => response.elements['ErrorDetails'].andand.elements.andand['ErrorInfo'].andand.elements.andand['ErrCode'].andand.get_text.andand.to_s,
            'ErrData' => response.elements['ErrorDetails'].andand.elements.andand['ErrorInfo'].andand.elements.andand['ErrData'].andand.get_text.andand.to_s
          }
        },
        'CallDuration' => response.elements['CallDuration'].get_text.to_s,
        'ChargeId' => response.elements['ChargeId'].get_text.to_s,
        'COFId' => response.elements['CofId'].get_text.to_s
      }
    end
  else
    response
  end
end

#make_donation_add_cof(params) ⇒ Object

Makes a donation and stores a COF for the given donor token

Arguments:

params: (Hash)


191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/nfg-client/client.rb', line 191

def make_donation_add_cof(params)
  requires!(params, :DonationLineItems, :TotalAmount, :TipAmount, :DonorIpAddress, :DonorToken, :DonorFirstName, :DonorLastName, :DonorEmail, :DonorAddress1, :DonorAddress2, :DonorCity, :DonorState, :DonorZip, :DonorCountry, :DonorPhone, :CardType, :NameOnCard, :CardNumber, :ExpMonth, :ExpYear, :CSC)
  call_params = add_credentials_to_params(params)
  response = nfg_soap_request('MakeDonationAddCOF', call_params)
  if response.is_a? REXML::Element
    if (response.elements['StatusCode'].get_text.to_s == 'Success') || ((response.elements['StatusCode'].get_text.to_s != 'Success') && response.elements['ErrorDetails'].elements['ErrorInfo'].nil?)
      {
        'StatusCode' => response.elements['StatusCode'].get_text.to_s,
        'Message' => response.elements['Message'].get_text.to_s,
        'ErrorDetails' => response.elements['ErrorDetails'].get_text.to_s,
        'CallDuration' => response.elements['CallDuration'].get_text.to_s,
        'ChargeId' => response.elements['ChargeId'].get_text.to_s,
        'COFId' => response.elements['CofId'].get_text.to_s
      }
    else
      {
        'StatusCode' => response.elements['StatusCode'].get_text.to_s,
        'Message' => response.elements['Message'].get_text.to_s,
        'ErrorDetails' => {
          'ErrorInfo' => {
            'ErrCode' => response.elements['ErrorDetails'].andand.elements.andand['ErrorInfo'].andand.elements.andand['ErrCode'].andand.get_text.andand.to_s,
            'ErrData' => response.elements['ErrorDetails'].andand.elements.andand['ErrorInfo'].andand.elements.andand['ErrData'].andand.get_text.andand.to_s
          }
        },
        'CallDuration' => response.elements['CallDuration'].get_text.to_s,
        'ChargeId' => response.elements['ChargeId'].get_text.to_s,
        'COFId' => response.elements['CofId'].get_text.to_s
      }
    end
  else
    response
  end
end