Class: Paynl::Helper
- Inherits:
-
Object
- Object
- Paynl::Helper
- Defined in:
- lib/paynl/helper.rb
Class Method Summary collapse
- .calculateTaxClass(amountInclTax, taxAmount) ⇒ Object
- .nearest(number, numbers) ⇒ Object
- .requireApiToken ⇒ Object
- .requireServiceId ⇒ Object
- .transactionIsCanceled(transaction) ⇒ Object
- .transactionIsPaid(transaction) ⇒ Object
- .transactionIsPending(transaction) ⇒ Object
Class Method Details
.calculateTaxClass(amountInclTax, taxAmount) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/paynl/helper.rb', line 28 def self.calculateTaxClass(amountInclTax, taxAmount) # Setup basic taxClasses (like in the PHP SDK) taxClasses = Hash.new taxClasses.store(0, 'N') taxClasses.store(6, '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) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/paynl/helper.rb', line 19 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 ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/paynl/helper.rb', line 3 def self.requireApiToken apiToken = Paynl::Config::getApiToken # 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 end |
.requireServiceId ⇒ Object
12 13 14 15 16 17 |
# File 'lib/paynl/helper.rb', line 12 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) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/paynl/helper.rb', line 72 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) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/paynl/helper.rb', line 45 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) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/paynl/helper.rb', line 57 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 |