class Stall::Atos::PaymentParams

Attributes

gateway[R]

Public Class Methods

new(gateway) click to toggle source
# File lib/stall/atos/payment_params.rb, line 10
def initialize(gateway)
  @gateway = gateway
end

Private Class Methods

calculate_seal_for(data) click to toggle source
# File lib/stall/atos/payment_params.rb, line 47
def self.calculate_seal_for(data)
  Digest::SHA256.hexdigest([data, Stall::Atos::Gateway.secret_key].join)
end
serialize(hash) click to toggle source

Transforms the provided hash to the following Atos accepted format :

key1=value1|key2=value2|...|keyN=valueN
# File lib/stall/atos/payment_params.rb, line 36
def self.serialize(hash)
  hash.map { |item| item.map(&:to_s).join('=') }.join('|')
end
unserialize(string) click to toggle source
# File lib/stall/atos/payment_params.rb, line 40
def self.unserialize(string)
  string.split('|').each_with_object({}.with_indifferent_access) do |str, hash|
    key, value = str.split('=')
    hash[key] = value
  end
end

Public Instance Methods

data() click to toggle source
# File lib/stall/atos/payment_params.rb, line 14
def data
  @data ||= self.class.serialize(
    amount: cart.total_price.cents,
    currencyCode: cart.currency.iso_numeric,
    merchantId: gateway.merchant_id,
    transactionReference: gateway.transaction_id(refresh: true),
    keyVersion: gateway.key_version,
    automaticResponseUrl: gateway.payment_urls.payment_notification_url,
    normalReturnUrl: gateway.payment_urls.payment_success_return_url
  )
end
seal() click to toggle source
# File lib/stall/atos/payment_params.rb, line 26
def seal
  @seal ||= self.class.calculate_seal_for(data)
end