class OffsitePayments::Integrations::Pay2goCvs::Fetcher

Attributes

params[RW]

Public Class Methods

new(params) click to toggle source
# File lib/offsite_payments/integrations/pay2go_cvs.rb, line 275
def initialize(params)
  raise 'parameter missmatch' if params['CheckValue'] != OffsitePayments::Integrations::Pay2goCvs.fetch_url_encode_data(params)
  @params = pay2go_params(params)
end

Private Class Methods

encrypted_data(data) click to toggle source
# File lib/offsite_payments/integrations/pay2go_cvs.rb, line 304
def self.encrypted_data(data)
  cipher = OpenSSL::Cipher::AES.new(256, :CBC)
  cipher.encrypt
  cipher.padding = 0
  cipher.key = OffsitePayments::Integrations::Pay2goCvs.hash_key[0..31]
  cipher.iv = OffsitePayments::Integrations::Pay2goCvs.hash_iv
  data = self.padding(data)
  encrypted = cipher.update(data) + cipher.final
  encrypted.unpack('H*').first
end
padding(str, blocksize = 32) click to toggle source
# File lib/offsite_payments/integrations/pay2go_cvs.rb, line 298
def self.padding(str, blocksize = 32)
  len = str.size
  pad = blocksize - (len % blocksize)
  str += pad.chr * pad
end

Public Instance Methods

fetch() click to toggle source
# File lib/offsite_payments/integrations/pay2go_cvs.rb, line 280
def fetch
  result = RestClient.post OffsitePayments::Integrations::Pay2goCvs.gateway_url, {
    MerchantID_: OffsitePayments::Integrations::Pay2goCvs.merchant_id,
    PostData_: self.class.encrypted_data(@params.to_query)
  }
  if @params['RespondType'] == 'JSON'
    JSON.parse(result)
  else
    result
  end
end

Private Instance Methods

pay2go_params(params) click to toggle source
# File lib/offsite_payments/integrations/pay2go_cvs.rb, line 294
def pay2go_params(params)
  params.slice(:RespondType, :TimeStamp, :Version, :MerchantOrderNo, :Amt, :ProdDesc, :AllowStore, :NotifyURL, :ExpireDate, :ExpireTime, :Email)
end