Class: Agms::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/agms/request/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(op) ⇒ Request

Returns a new instance of Request.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
73
74
75
76
77
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/agms/request/request.rb', line 3

def initialize(op)
  @op = op
  @validateErrors = 0
  @validateMessages = nil
  @fields = nil
  @required = nil
  @numeric = nil
  @optionable = nil
  @enums = nil
  @date = nil
  @time = nil
  @boolean = nil
  @digit_2 = nil
  @amount = nil

  @needs_account = nil
  @needs_key = nil

  @mapping_alias = nil

  @mapping = {
      :gateway_username => :GatewayUserName,
      :gateway_password => :GatewayPassword,
      :gateway_account => :AccountNumber,
      :gateway_key => :TransactionAPIKey,
      :amount => :Amount,
      :description => :OrderDescription,
      :order_description => :OrderDescription,
      :return_url => :RetURL,
      :enable_ach => :ACHEnabled,
      :transaction_type => :TransactionType,
      :payment_type => :PaymentType,
      :enable_auto_add_to_safe => :AutoSAFE,
      :processing_account_id => :ProcessorID,
      :enable_donation => :Donation,
      :max_link_uses => :UsageCount,
      :cc_number => :CCNumber,
      :cc_exp_date => :CCExpDate,
      :cc_cvv => :CVV,
      :cc_track_1 => :Track1,
      :cc_track_2 => :Track2,
      :cc_track_3 => :Track3,
      :cc_encrypted_data => :MagData,
      :cc_encrypted_hardware => :MagHardware,
      :ach_name => :CheckName,
      :ach_routing_number => :CheckABA,
      :ach_account_number => :CheckAccount,
      :ach_business_or_personal => :AccountHolderType,
      :ach_checking_or_savings => :AccountType,
      :ach_sec_code => :SecCode,
      :safe_action => :SAFE_Action,
      :safe_id => :SAFE_ID,
      :first_name => :FirstName,
      :last_name => :LastName,
      :company_name => :Company,
      :company => :Company,
      :address => :Address1,
      :address_1 => :Address1,
      :address_2 => :Address2,
      :city => :City,
      :state => :State,
      :zip => :Zip,
      :country => :Country,
      :phone => :Phone,
      :fax => :Fax,
      :email => :EMail,
      :website => :Website,
      :tax_amount => :Tax,
      :shipping_amount => :Shipping,
      :tip_amount => :TipAmount,
      :order_id => :OrderID,
      :po_number => :PONumber,
      :clerk_id => :ClerkID,
      :ip_address => :IPAddress,
      :receipt_type => :ReceiptType,
      :shipping_first_name => :ShippingFirstName,
      :shipping_last_name => :ShippingLastName,
      :shipping_company_name => :ShippingCompany,
      :shipping_company => :ShippingCompany,
      :shipping_address => :ShippingAddress1,
      :shipping_address_1 => :ShippingAddress1,
      :shipping_address_2 => :ShippingAddress2,
      :shipping_city => :ShippingCity,
      :shipping_state => :ShippingState,
      :shipping_zip => :ShippingZip,
      :shipping_country => :ShippingCountry,
      :shipping_email => :ShippingEmail,
      :shipping_phone => :ShippingPhone,
      :shipping_fax => :ShippingFax,
      :shipping_tracking_number => :ShippingTrackingNumber,
      :shipping_carrier => :ShippingCarrier,
      :custom_field_1 => :Custom_Field_1,
      :custom_field_2 => :Custom_Field_2,
      :custom_field_3 => :Custom_Field_3,
      :custom_field_4 => :Custom_Field_4,
      :custom_field_5 => :Custom_Field_5,
      :custom_field_6 => :Custom_Field_6,
      :custom_field_7 => :Custom_Field_7,
      :custom_field_8 => :Custom_Field_8,
      :custom_field_9 => :Custom_Field_9,
      :custom_field_10 => :Custom_Field_10,
      :custom_field_11 => :Custom_Field_11,
      :custom_field_12 => :Custom_Field_12,
      :custom_field_13 => :Custom_Field_13,
      :custom_field_14 => :Custom_Field_14,
      :custom_field_15 => :Custom_Field_15,
      :custom_field_16 => :Custom_Field_16,
      :custom_field_17 => :Custom_Field_17,
      :custom_field_18 => :Custom_Field_18,
      :custom_field_19 => :Custom_Field_19,
      :custom_field_20 => :Custom_Field_20,
      :expiring_in_30_days => :Expiring30,
      :recurring_id => :RecurringID,
      :merchant_id => :MerchantID,
      :initial_amount => :InitialAmount,
      :recurring_amount => :RecurringAmount,
      :frequency => :Frequency,
      :quantity => :Quantity,
      :number_of_times_to_bill => :NumberOfOccurrences,
      :number_of_retries => :NumberOfRetries,
      :hpp_format => :HPPFormat,
      :cc_last_4 => :CreditCardLast4,
      :transaction_id => :TransactionID,
      :start_date => :StartDate,
      :end_date => :EndDate,
      :start_time => :StartTime,
      :end_time => :EndTime,
      :suppress_safe_option => :SupressAutoSAFE
  }

  @states = %w(AL AK AS AZ AR CA CO CT DE DC FM FL GA GU HI ID IL IN IA KS KY LA ME MH MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND MP OH OK OR PW PA PR RI SC SD TN TX UT VT VI VA WA WV WI WY AE AA AP)
end

Instance Method Details

#get(username, password, account, api_key) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/agms/request/request.rb', line 136

def get(username, password, , api_key)
  request_body = getFields()
  request_body[:GatewayUserName] = username
  request_body[:GatewayPassword] = password

  # Adjust for a field name variation in the Reporting API
  if @op == 'TransactionAPI' or @op == 'QuerySAFE'
    request_body.delete(:GatewayUserName)
    request_body[:GatewayUsername] = username
  end

  # Add Account # and API Key field to request when necessary for specific API
  if @needs_account
    request_body[:AccountNumber] = 
  end

  if @needs_key
    # Adjust for a field name variation in the Reporting API
    if @op == 'TransactionAPI'
      request_body[:TransactionAPIKey] = api_key
    elsif @op == 'QuerySAFE'
      request_body[:APIKey] = api_key
    end
  end

  return request_body
end

#getField(name) ⇒ Object



203
204
205
206
# File 'lib/agms/request/request.rb', line 203

def getField(name)
  field_name = mapToField(name)
  return @fields[field_name]
end

#getValidationErrorsObject



208
209
210
# File 'lib/agms/request/request.rb', line 208

def getValidationErrors
  return @validateErrors
end

#getValidationMessagesObject



213
214
215
# File 'lib/agms/request/request.rb', line 213

def getValidationMessages
  return @validateMessages
end

#setField(name, parameter, value) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/agms/request/request.rb', line 164

def setField(name, parameter, value)
  field_name = mapToField(name)
  # Fix for odd capitalization of Email
  if field_name == :Email
    field_name = :EMail
  end

  # Check that field exists
  if not @fields.has_key?(field_name)
    raise InvalidParameterError, "Invalid field name #{name}."
  end

  # Ensure that setting parameters are forced to all lowercase and are case insensitive
  if parameter == :setting
    value = value.downcase
  end

  # Check that it is a valid setting
  if (parameter == :setting and
      value != '' and
      value != 'required' and
      value != 'disabled' and
      value != 'visible' and
      value != 'excluded' and
      value != 'hidden')
    raise InvalidParameterError, "Invalid parameter #{parameter} for #{name}."
  end

  if parameter == :setting
    @fields[field_name][:setting] = value
    return true
  elsif parameter == :value
    @fields[field_name][:value] = value
    return true
  else
    raise InvalidParameterError, "Invalid parameter #{parameter} for #{name}."
  end
end