module EbsPayment

Constants

VERSION

Attributes

configuration[RW]

Public Class Methods

configure() { |configuration| ... } click to toggle source
# File lib/ebs_payment.rb, line 10
def self.configure
  self.configuration ||= Configration.new
  yield(configuration)
end
format_request(options) click to toggle source
# File lib/ebs_payment.rb, line 20
def self.format_request(options)
  begin
    valid_params = {
      account_id: options[:account_id],
      address: options[:address],
      amount: options[:amount],
      bank_code: options[:bank_code],
      card_brand: options[:card_brand],
      channel: options[:channel],
      city: options[:city],
      country: options[:country],
      currency: options[:currency],
      description: options[:description],
      email: options[:email],
      emi: options[:emi],
      mode: options[:mode],
      name: options[:name],
      page_id: options[:page_id],
      payment_mode: options[:payment_mode],
      payment_option: options[:payment_option],
      phone: options[:phone],
      postal_code: options[:postal_code],
      reference_no: options[:reference_no],
      return_url: options[:return_url],
      ship_address: options[:ship_address],
      ship_city: options[:ship_city],
      ship_country: options[:ship_country],
      ship_name: options[:ship_name],
      ship_phone: options[:ship_phone],
      ship_postal_code: options[:ship_postal_code],
      ship_state: options[:ship_state],
      state: options[:state]
    }

    secret = self.configuration.secret
    submit_url = self.configuration.submit_url
    hashing = self.configuration.hash_algorithm.try(:upcase) || 'MD5'
    unless (secret && submit_url )
      throw Error.new
    end

    digest = secret
    valid_params.map do |key, value|
      if value.present?
        value = '|' + value.to_s
        digest += value
      end
    end

    case hashing
    when 'MD5'
      hash = Digest::MD5.hexdigest(digest).upcase
    when 'SHA512'
      hash = Digest::SHA512.hexdigest(digest).upcase
    when 'SHA1'
      hash = Digest::SHA1.hexdigest(digest).upcase
    else
      throw Error.new("hashing not recognised")
    end
    hash

  rescue => e
    e.message
  end
end