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.



184
185
186
187
188
189
190
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 184

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.



170
171
172
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 170

def type
  @type
end

#xmlObject (readonly)

Returns the value of attribute xml.



170
171
172
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 170

def xml
  @xml
end

Instance Method Details

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



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 228

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



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 252

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



219
220
221
222
223
224
225
226
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 219

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



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 269

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



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 196

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



295
296
297
298
299
300
301
302
303
# File 'lib/active_merchant/billing/gateways/barclays_epdq.rb', line 295

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



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

def to_xml
  @xml.target!
end