Class: ActiveMerchant::Billing::BarclaysEpdqGateway::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/barclays_epdq.rb

Constant Summary collapse

PAYMENT_INTERVALS =
{
  :days => 'D',
  :months => 'M'
}
EPDQ_CARD_TYPES =
{
  :visa => 1,
  :master => 2,
  :switch => 9,
  :maestro => 10,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gateway, options = {}, document_options = {}, &block) ⇒ Document

Returns a new instance of Document.



190
191
192
193
194
195
196
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 190

def initialize(gateway, options = {}, document_options = {}, &block)
  @gateway = gateway
  @options = options
  @document_options = document_options
  @xml = Builder::XmlMarkup.new(:indent => 2)
  build(&block)
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



176
177
178
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 176

def type
  @type
end

#xmlObject (readonly)

Returns the value of attribute xml.



176
177
178
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 176

def xml
  @xml
end

Instance Method Details

#add_consumer(options = nil, &block) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 234

def add_consumer(options=nil, &block)
  xml.Consumer do
    if options
      xml.Email(options[:email]) if options[:email]
      billing_address = options[:billing_address] || options[:address]
      if billing_address
        xml.BillTo do
          xml.Location do
            xml.Address do
              xml.Street1 billing_address[:address1]
              xml.Street2 billing_address[:address2]
              xml.City billing_address[:city]
              xml.StateProv billing_address[:state]
              xml.PostalCode billing_address[:zip]
              xml.Country billing_address[:country_code]
            end
          end
        end
      end
    end
    instance_eval(&block)
  end
end

#add_creditcard(creditcard) ⇒ Object



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 258

def add_creditcard(creditcard)
  xml.PaymentMech do
    xml.CreditCard do
      xml.Type({ :DataType => 'S32' }, EPDQ_CARD_TYPES[creditcard.brand.to_sym])
      xml.Number creditcard.number
      xml.Expires({ :DataType => 'ExpirationDate', :Locale => 826 }, format_expiry_date(creditcard))
      if creditcard.verification_value.present?
        xml.Cvv2Indicator 1
        xml.Cvv2Val creditcard.verification_value
      else
        xml.Cvv2Indicator 5
      end
      xml.IssueNum(creditcard.issue_number) if creditcard.issue_number.present?
    end
  end
end

#add_order_form(order_id = nil, group_id = nil, &block) ⇒ Object



225
226
227
228
229
230
231
232
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 225

def add_order_form(order_id=nil, group_id=nil, &block)
  xml.OrderFormDoc do
    xml.Mode 'P'
    xml.Id(order_id) if order_id
    xml.GroupId(group_id) if group_id
    instance_eval(&block)
  end
end

#add_transaction(auth_type, amount = nil, options = {}) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 275

def add_transaction(auth_type, amount = nil, options = {})
  @auth_type = auth_type
  xml.Transaction do
    xml.Type @auth_type.to_s
    if options[:payment_number] && options[:payment_number] > 1
      xml.CardholderPresentCode({ :DataType => 'S32' }, 8)
    else
      xml.CardholderPresentCode({ :DataType => 'S32' }, 7)
    end
    if options[:payment_number]
      xml.PaymentNumber({ :DataType => 'S32' }, options[:payment_number])
    end
    if options[:total_payments]
      xml.TotalNumberPayments({ :DataType => 'S32' }, options[:total_payments])
    end
    if amount
      xml.CurrentTotals do
        xml.Totals do
          xml.Total({ :DataType => 'Money', :Currency => 826 }, amount)
        end
      end
    end
  end
end

#build(&block) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 202

def build(&block)
  xml.instruct!(:xml, :version => '1.0')
  xml.EngineDocList do
    xml.DocVersion "1.0"
    xml.EngineDoc do
      xml.ContentType "OrderFormDoc"
      xml.User do
        xml.Name(@options[:login])
        xml.Password(@options[:password])
        xml.ClientId({ :DataType => "S32" }, @options[:client_id])
      end
      xml.Instructions do
        if @document_options[:no_fraud]
          xml.Pipeline "PaymentNoFraud"
        else
          xml.Pipeline "Payment"
        end
      end
      instance_eval(&block)
    end
  end
end

#format_expiry_date(creditcard) ⇒ Object

date must be formatted MM/YY



301
302
303
304
305
306
307
308
309
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 301

def format_expiry_date(creditcard)
  month_str = "%02d" % creditcard.month
  if match = creditcard.year.to_s.match(/^\d{2}(\d{2})$/)
    year_str = "%02d" % match[1].to_i
  else
    year_str = "%02d" % creditcard.year
  end
  "#{month_str}/#{year_str}"
end

#to_xmlObject



198
199
200
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 198

def to_xml
  @xml.target!
end