Class: OffsitePayments::Integrations::Migs::Helper

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, account, options = {}) ⇒ Helper



15
16
17
18
19
# File 'lib/offsite_payments/integrations/migs.rb', line 15

def initialize(order, , options = {})
  @credentials = { login: , password: options.fetch(:password) }
  @secure_hash = options.fetch(:secure_hash)
  @options = options.merge(order_id: order)
end

Class Method Details

.base_urlObject



11
12
13
# File 'lib/offsite_payments/integrations/migs.rb', line 11

def self.base_url
  'https://migs.mastercard.com.au/vpcpay'
end

Instance Method Details

#credential_based_urlObject

Generates a URL to redirect user to MiGS to process payment Once user is finished MiGS will redirect back to specified URL With a response hash which can be turned into a Response object with purchase_offsite_response

Options

  • :order_id – A reference for tracking the order (REQUIRED)

  • :locale – Change the language of the redirected page Values are 2 digit locale, e.g. en, es

  • :return_url – the URL to return to once the payment is complete

  • :card_type – Providing this skips the card type step. Values are ActiveMerchant formats: e.g. master, visa, american_express, diners_club

  • :unique_id – Unique id of transaction to find. If not supplied one will be generated.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/offsite_payments/integrations/migs.rb', line 36

def credential_based_url
  cents = @options.fetch(:cents)
  builder = TransactionBuilder.new(@credentials)
  builder.add_invoice(@options)
  builder.add_creditcard_type(@options[:card_type]) if @options[:card_type]
  builder.add_amount(cents)
  builder.add_standard_parameters('pay', @options[:unique_id])
  post = builder.post.merge(
    Locale: @options[:locale] || 'en',
    ReturnURL: @options.fetch(:return_url)
  )
  post[:SecureHash] = SecureHash.calculate(@secure_hash, post)
  post[:SecureHashType] = 'SHA256'

  self.class.base_url + '?' + post_data(post)
end