Class: VaultedBilling::Gateways::Ipcommerce

Inherits:
Object
  • Object
show all
Includes:
VaultedBilling::Gateway
Defined in:
lib/vaulted_billing/gateways/ipcommerce.rb

Overview

Interface to IPCommerce.

Example

VaultedBilling::Gateways::IPCommerce.new(:username => 'identity-token', :service_key_store => XXX).tap do |ipc|
  customer = ipc.add_customer(Customer.new)
  credit_card = ipc.add_credit_card(customer, CreditCard.new)
  ipc.purchase(customer, credit_card, 10.00)
end

Defined Under Namespace

Classes: ServiceKeyStore

Constant Summary collapse

AvsResults =
[
  "Not Set", "Not Included", "Match", "No Match", "Issuer Not Certified",
  "No Response From Card Association", "Unknown Response From Card Association", "Not Verified", "Bad Format"
]
Countries =
%w(
  !! AF AX AL DZ AS AD AO AI AQ
  AG AR AM AW AU AT AZ BS BH BD
  BB BY BE BZ BJ BM BT BO BA BW
  BV BR IO BN BG BF BI KH CM CA
  CV KY CF TD CL CN CX CC CO KM
  CG CD CK CR CI HR CU CY CZ DK
  DJ DM DO EC EG SV GQ ER EE ET
  FK FO FJ FI FR FX GF PF TF GA
  GM GE DE GH GI GR GL GD GP GU
  GT GG GN GW GY HT HM VA HN HK
  HU IS IN ID IR IQ IE IM IL IT
  JM JP JE JO KZ KE KI KP KR KW
  KG LA LV LB LS LR LY LI LT LU
  MO MK MG MW MY MV ML MT MH MQ
  MR MU YT MX FM MD MC MN ME MS
  MA MZ MM NA NR NP NL AN NC NZ
  NI NE NG NU NF MP NO OM PK PW
  PS PA PG PY PE PH PN PL PT PR
  QA RE RO RU RW SH KN LC PM VC
  WS SM ST SA SN RS CS SC SL SG
  SK SI SB SO ZA GS ES LK SD SR
  SJ SZ SE CH SY TW TJ TZ TH TL
  TG TK TP TO TT TN TR TM TC TV
  UG UA AE GB US UM UY UZ VU VE
  VN VG VI WF EH YE YU ZM ZW
).freeze
Companies =
{
  2 => /^4\d{12}(\d{3})?$/, # Visa
  3 => /^(5[1-5]\d{4}|677189)\d{10}$/, # MasterCard
  4 => /^3[47]\d{13}$/, # American Express
  5 => /^3(0[0-5]|[68]\d)\d{11}$/, # Diners Club
  6 => /^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/, # Discover
  7 => /^35(28|29|[3-8]\d)\d{12}$/ # JCB
}.freeze
CVResults =
[
  "Not Set", "Match", "No Match", "Not Processed", "Not Included",
  "No Code Present", "Should Have Been Present", "Issuer Not Certified", "Invalid", "No Response",
  "Not Applicable"
].freeze
Endpoints =
[
  "https://cws-01.ipcommerce.com/REST/2.0.15/",
  "https://cws-02.ipcommerce.com/REST/2.0.15/"
].freeze
TestEndpoints =
[
  "https://cws-01.cert.ipcommerce.com/REST/2.0.15/",
  "https://cws-02.cert.ipcommerce.com/REST/2.0.15/"
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Ipcommerce

Returns a new instance of Ipcommerce.



142
143
144
145
146
147
148
149
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 142

def initialize(options = {})
  @identity_token = options[:username] || VaultedBilling.config.ipcommerce.username
  @raw_options = options[:raw_options] || VaultedBilling.config.ipcommerce.raw_options
  @test_mode = options.has_key?(:test) ? options[:test] : (VaultedBilling.config.ipcommerce.test_mode || VaultedBilling.config.test_mode)
  @application_id = options[:application_id] || @raw_options["application_id"]
  @service_id = options[:service_id] || @raw_options["service_id"]
  @service_key_store = options[:service_key_store] || ServiceKeyStore.new(@identity_token, @test_mode)
end

Instance Attribute Details

#service_key_storeObject (readonly)

Returns the value of attribute service_key_store.



140
141
142
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 140

def service_key_store
  @service_key_store
end

Instance Method Details

#add_customer(customer) ⇒ Object

A stub, since the IP Commerce only generates tokens during successful authorization transactions.



156
157
158
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 156

def add_customer(customer)
  respond_with customer.to_vaulted_billing
end

#add_customer_credit_card(customer, credit_card, options = {}) ⇒ Object

A stub, since the IP Commerce only generates tokens during successful authorization transactions.



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 164

def add_customer_credit_card(customer, credit_card, options = {})
  credit_card = credit_card.to_vaulted_billing

  authorization = authorize(customer, credit_card, 1.00, options)
  void = void(authorization.id, options) if authorization.success?

  respond_with(credit_card, authorization.response, { 
      :success => authorization.success?, 
      :transactions => { :void => void, :authorization => authorization }
  }) do |cc|
    cc.vault_id = authorization.response.body['PaymentAccountDataToken'].presence
  end
end

#authorize(customer, credit_card, amount, options = {}) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 178

def authorize(customer, credit_card, amount, options = {})
  credit_card = credit_card.to_vaulted_billing
  data = {
    "__type" => "AuthorizeTransaction:http://schemas.ipcommerce.com/CWS/v2.0/Transactions/Rest",
    :ApplicationProfileId => @application_id,
    :MerchantProfileId => options[:merchant_profile_id],
    :Transaction => {
      :"__type" => "BankcardTransaction:http://schemas.ipcommerce.com/CWS/v2.0/Transactions/Bankcard",
      :TransactionData => {
        :Amount => "%.2f" % amount,
        :ApprovalCode => options[:approval_code],
        :CurrencyCode => 4,
        :TransactionDateTime => Time.now.xmlschema,
        :CustomerPresent => options[:customer_present] || 0, # Not Set
        :EntryMode => options[:entry_mode] || 1, # Keyed
        :GoodsType => options[:goods_type] || 0, # Not Set
        :IndustryType => options[:industry_type] || 2, # Ecommerce
        :SignatureCaptured => options[:signature_captured] || false,
        :OrderNumber => options[:order_id] || generate_order_number,
        :EmployeeId => options[:employee_id]
      },
      :TenderData => card_data(credit_card)
    }
  }

  response = http("Txn", options[:workflow_id] || @service_id).post(data)
  transaction = new_transaction_from_response(response)
  respond_with(transaction,
               response,
               :success => valid_code?(transaction.code))
end

#capture(transaction_id, amount, options = {}) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 210

def capture(transaction_id, amount, options = {})
  data = {
    :"__type" => "Capture:http://schemas.ipcommerce.com/CWS/v2.0/Transactions/Rest",
    :ApplicationProfileId => @application_id,
    :DifferenceData => {
      :"__type" => "BankcardCapture:http://schemas.ipcommerce.com/CWS/v2.0/Transactions/Bankcard",
      :TransactionId => transaction_id,
      :Addendum => nil,
      :Amount => "%.2f" % amount
    }
  }

  response = http("Txn", options[:workflow_id] || @service_id, transaction_id).put(data)
  transaction = new_transaction_from_response(response)
  respond_with(transaction,
               response,
               :success => valid_code?(transaction.code))
end

#purchase(customer, credit_card, amount, options = {}) ⇒ Object



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/vaulted_billing/gateways/ipcommerce.rb', line 229

def purchase(customer, credit_card, amount, options = {})
  credit_card = credit_card.try(:to_vaulted_billing)
  data = {
    "__type" => "AuthorizeAndCaptureTransaction:http://schemas.ipcommerce.com/CWS/v2.0/Transactions/Rest",
    :ApplicationProfileId => @application_id,
    :MerchantProfileId => options[:merchant_profile_id],
    :Transaction => {
      :"__type" => "BankcardTransaction:http://schemas.ipcommerce.com/CWS/v2.0/Transactions/Bankcard",
      :TransactionData => {
        :Amount => "%.2f" % amount,
        :ApprovalCode => options[:approval_code],
        :CurrencyCode => 4,
        :TransactionDateTime => Time.now.xmlschema,
        :CustomerPresent => options[:customer_present] || 0, # Not Set
        :EmployeeId => options[:employee_id],
        :EntryMode => options[:entry_mode] || 1, # Keyed
        :GoodsType => options[:goods_type] || 0, # Not Set
        :IndustryType => options[:industry_type] || 2, # Ecommerce
        :OrderNumber => options[:order_id] || generate_order_number,
        :SignatureCaptured => options[:signature_captured] || false
      },
      :TenderData => card_data(credit_card)
    }
  }
  response = http("Txn", options[:workflow_id] || @service_id).post(data)
  transaction = new_transaction_from_response(response)
  respond_with(transaction,
               response,
               :success => valid_code?(transaction.code))
end

#refund(transaction_id, amount, options = {}) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 260

def refund(transaction_id, amount, options = {})
  data = {
    :"__type" => "ReturnById:http://schemas.ipcommerce.com/CWS/v2.0/Transactions/Rest",
    :ApplicationProfileId => @application_id,
    :MerchantProfileId => options[:merchant_profile_id],
    :DifferenceData => {
      :"__type" => "BankcardReturn:http://schemas.ipcommerce.com/CWS/v2.0/Transactions/Bankcard",
      :TransactionId => transaction_id,
      :Addendum => nil,
      :Amount => "%.2f" % amount
    }
  }

  response = http("Txn", options[:workflow_id] || @service_id).post(data)
  transaction = new_transaction_from_response(response)
  respond_with(transaction,
               response,
               :success => valid_code?(transaction.code))
end

#remove_customer(customer) ⇒ Object

A stub, since the IP Commerce only generates tokens during successful authorization transactions.



284
285
286
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 284

def remove_customer(customer)
  respond_with customer.to_vaulted_billing
end

#remove_customer_credit_card(customer, credit_card) ⇒ Object

A stub, since the IP Commerce only generates tokens during successful authorization transactions.



292
293
294
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 292

def remove_customer_credit_card(customer, credit_card)
  respond_with credit_card.to_vaulted_billing
end

#update_customer(customer) ⇒ Object

A stub, since the IP Commerce only generates tokens during successful authorization transactions.



300
301
302
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 300

def update_customer(customer)
  respond_with customer.to_vaulted_billing
end

#update_customer_credit_card(customer, credit_card, options = {}) ⇒ Object

A stub, since the IP Commerce only generates tokens during successful authorization transactions.



308
309
310
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 308

def update_customer_credit_card(customer, credit_card, options = {})
  add_customer_credit_card(customer, credit_card, options)
end

#void(transaction_id, options = {}) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 312

def void(transaction_id, options = {})
  data = {
    :"__type" => "Undo:http://schemas.ipcommerce.com/CWS/v2.0/Transactions/Rest",
    :ApplicationProfileId => @application_id,
    :DifferenceData => {
      :"__type" => "BankcardUndo:http://schemas.ipcommerce.com/CWS/v2.0/Transactions/Bankcard",
      :TransactionId => transaction_id,
      :Addendum => nil
    }
  }

  response = http("Txn", options[:workflow_id] || @service_id, transaction_id).put(data)
  transaction = new_transaction_from_response(response)
  respond_with(transaction,
               response,
               :success => valid_code?(transaction.code))
end