class Paynl::Helper
Public Class Methods
calculateTaxClass(amountInclTax, taxAmount)
click to toggle source
# File lib/paynl/helper.rb, line 34 def self.calculateTaxClass(amountInclTax, taxAmount) # Setup basic taxClasses (like in the PHP SDK) taxClasses = Hash.new taxClasses.store(0, 'N') taxClasses.store(9, 'L') taxClasses.store(21, 'H') if (taxAmount == 0 || amountInclTax == 0) return taxClasses[0] end amountExclTax = amountInclTax - taxAmount taxRate = (taxAmount / amountExclTax) * 100 nearestTaxRate = self.nearest(taxRate, taxClasses) return nearestTaxRate end
nearest(number, numbers)
click to toggle source
# File lib/paynl/helper.rb, line 25 def self.nearest(number, numbers) if (numbers.is_a? Hash) # numbers is a, I suppose, hash, not an array, for this piece of magick I need an array numbers = numbers.to_a end # And this is the reason why Ruby is more interesting than PHP, we can do this in 1 line of code return numbers.min_by{ |x| (x.first.to_f - number).abs } end
requireApiToken()
click to toggle source
# File lib/paynl/helper.rb, line 3 def self.requireApiToken apiToken = Paynl::Config::getApiToken tokenCode = Paynl::Config::getTokenCode # Hmm, porting PHP to Ruby is crap if you want to keep the structure if apiToken == nil? or apiToken == '' raise Paynl::Error::Required::ApiTokenError, 'Api token is required' end if tokenCode == nil? or tokenCode == '' raise Paynl::Error::Required::ApiTokenError, 'Api token code (AT-code) is required' end end
requireServiceId()
click to toggle source
# File lib/paynl/helper.rb, line 18 def self.requireServiceId serviceId = Paynl::Config::getServiceId if serviceId == nil? or serviceId == '' raise Paynl::Error::Required::ServiceIdError, 'No Service Id is set' end end
transactionIsCanceled(transaction)
click to toggle source
# File lib/paynl/helper.rb, line 78 def self.transactionIsCanceled(transaction) unless transaction.is_a? Hash raise('Please give me the output of the Paynl::Transaction::getTransaction function') end if transaction['paymentDetails']['stateName'] == 'CANCEL' return true end return false end
transactionIsPaid(transaction)
click to toggle source
# File lib/paynl/helper.rb, line 51 def self.transactionIsPaid(transaction) unless transaction.is_a? Hash raise('Please give me the output of the Paynl::Transaction::getTransaction function') end if transaction['paymentDetails']['stateName'] == 'PAID' return true end return false end
transactionIsPending(transaction)
click to toggle source
# File lib/paynl/helper.rb, line 63 def self.transactionIsPending(transaction) unless transaction.is_a? Hash raise('Please give me the output of the Paynl::Transaction::getTransaction function') end if transaction['paymentDetails']['stateName'] == 'PENDING' return true end if transaction['paymentDetails']['stateName'] == 'VERIFY' return true end return false end