Class: OffsitePayments::Integrations::Migs::TransactionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/offsite_payments/integrations/migs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TransactionBuilder

Returns a new instance of TransactionBuilder.



189
190
191
192
# File 'lib/offsite_payments/integrations/migs.rb', line 189

def initialize(options)
  @options = options
  @post = {}
end

Instance Attribute Details

#postObject (readonly)

Returns the value of attribute post.



187
188
189
# File 'lib/offsite_payments/integrations/migs.rb', line 187

def post
  @post
end

Instance Method Details

#add_advanced_userObject



213
214
215
216
# File 'lib/offsite_payments/integrations/migs.rb', line 213

def add_advanced_user
  post[:User] = @options[:advanced_login]
  post[:Password] = @options[:advanced_password]
end

#add_amount(cents) ⇒ Object



198
199
200
# File 'lib/offsite_payments/integrations/migs.rb', line 198

def add_amount(cents)
  post[:Amount] = cents.to_s
end

#add_creditcard(creditcard) ⇒ Object



202
203
204
205
206
# File 'lib/offsite_payments/integrations/migs.rb', line 202

def add_creditcard(creditcard)
  post[:CardNum] = creditcard.number
  post[:CardSecurityCode] = creditcard.verification_value if creditcard.verification_value?
  post[:CardExp] = format(creditcard.year) + format(creditcard.month)
end

#add_creditcard_type(card_type) ⇒ Object



208
209
210
211
# File 'lib/offsite_payments/integrations/migs.rb', line 208

def add_creditcard_type(card_type)
  post[:Gateway] = 'ssl'
  post[:card] = CARD_TYPES.detect{|ct| ct.am_code == card_type}.migs_long_code
end

#add_invoice(options) ⇒ Object



194
195
196
# File 'lib/offsite_payments/integrations/migs.rb', line 194

def add_invoice(options)
  post[:OrderInfo] = options.fetch(:order_id)
end

#add_standard_parameters(action, unique_id = nil) ⇒ Object



218
219
220
221
222
223
224
225
226
# File 'lib/offsite_payments/integrations/migs.rb', line 218

def add_standard_parameters(action, unique_id = nil)
  post.merge!(
    :Version     => API_VERSION,
    :Merchant    => @options[:login],
    :AccessCode  => @options[:password],
    :Command     => action,
    :MerchTxnRef => unique_id || SecureRandom.hex(16).slice(0, 40)
  )
end