add mollie plugin

This commit is contained in:
Philipp Rothmann 2023-10-02 22:46:46 +02:00
parent 55234b4e27
commit c59eefd219
21 changed files with 1117 additions and 0 deletions

View file

@ -0,0 +1,35 @@
# require 'Mollie/API/Client'
require 'mollie-api-ruby'
require 'foodsoft_mollie/engine'
module FoodsoftMollie
# Enabled when configured, but can still be disabled by +use_mollie+ option.
def self.enabled?
FoodsoftConfig[:use_mollie] != false and FoodsoftConfig[:mollie]
end
# Compute payment transaction fee.
#
# Transaction fee is specified in foodcoop config under +mollie+, +fee+ as a
# hash of fee per payment method, e.g. as "0.30" for a fixed flat fee, "5%"
# for a percentage, or "0.30 + 5%" for both. Multiple flat fees and percentages
# can appear in a single line, so "0.12 + 2% + 0.56 + 3% + 1%" is valid, e.g.
# when multiple payment providers add different fees.
#
# @param amount [Number] Amount payed
# @param method [String] Payment method used
# @return [Number] Transaction fee for payment, or +nil+ if no fee details known.
def self.payment_fee(amount, method)
spec = FoodsoftConfig[:mollie]['fee'] or return
unless spec = spec[method]
Rails.logger.warn "Mollie: transaction fee for method #{method} not configured."
return
end
# parse
return spec if spec.is_a? Numeric
spec.split('+').inject(0) do |sum, c|
sum + (c =~ /^(.*)\s*%\s*$/ ? (::Regexp.last_match(1).to_f / 100 * amount.to_f) : c.to_f)
end
end
end

View file

@ -0,0 +1,4 @@
module FoodsoftMollie
class Engine < ::Rails::Engine
end
end

View file

@ -0,0 +1,3 @@
module FoodsoftMollie
VERSION = "0.0.1"
end