fixup! add mollie plugin

Philipp Rothmann 2023-10-04 21:31:44 +02:00
parent 260c51eef5
commit 683753cd16
11 changed files with 66 additions and 31 deletions

View File

@ -4,4 +4,3 @@ source "http://rubygems.org"
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

View File

@ -17,11 +17,8 @@ This project adds support for iDEAL payments using Mollie to Foodsoft.
# example fees from May 2014 incl. 21% VAT (verify before using!)
ideal: 1.20
banktransfer: 0.30
paysafecard: 15%
creditcard: 3.39% + 0.05
paypal: 0.18 + 0.35 + 3.4%
mistercash: 2.18% + 0.30
bitcoin: 0.30
```
The transaction fee is sub will be added on each payment when set; it is not set by default,

5
plugins/mollie/Rakefile 100644 → 100755
View File

@ -20,8 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end
#APP_RAKEFILE = File.expand_path("../../../Rakefile", __FILE__)
#load 'rails/tasks/engine.rake'
# APP_RAKEFILE = File.expand_path("../../../Rakefile", __FILE__)
# load 'rails/tasks/engine.rake'
Bundler::GemHelper.install_tasks

View File

@ -33,13 +33,12 @@ class Payments::MollieIdealController < ApplicationController
# @todo payment_currency
payment_state: 'created',
financial_transaction_type_id: ft_type.id,
note: I18n.t('payments.mollie_ideal.controller.transaction_note', method: nil),
note: I18n.t('payments.mollie_ideal.controller.transaction_note', method: nil)
)
payment = Mollie::Payment.create(
amount: {
value: '%.2f' % [amount], # @todo use format over %
value: format('%.2f', amount),
currency: 'EUR' # @todo payment_currency
},
description: "#{@transaction.id}, #{@ordergroup.id}, #{FoodsoftConfig[:name]}",

View File

@ -8,8 +8,5 @@
= fields.fields_for :fee do |fields|
= config_input fields, :ideal, input_html: {class: 'input-xlarge'}
= config_input fields, :banktransfer, input_html: {class: 'input-xlarge'}
= config_input fields, :paysafecard, input_html: {class: 'input-xlarge'}
= config_input fields, :creditcard, input_html: {class: 'input-xlarge'}
= config_input fields, :paypal, input_html: {class: 'input-xlarge'}
= config_input fields, :mistercash, input_html: {class: 'input-xlarge'}
= config_input fields, :bitcoin, input_html: {class: 'input-xlarge'}
= config_input fields, :paypal, input_html: {class: 'input-xlarge'}

View File

@ -1,8 +1,55 @@
= form_tag payments_mollie_path, method: :post do
- content_for :javascript do
:javascript
// @todo code duplication of foodsoft_mollie.rb
function paymentFee(amount, feeSpec) {
if (typeof feeSpec === 'number') {
return feeSpec;
}
return feeSpec.split('+').reduce((sum, c) => {
const parsed = c.trim().match(/^(.*)\s*%\s*$/);
if (parsed) {
return sum + (parseFloat(parsed[1]) / 100 * parseFloat(amount));
} else {
return sum + parseFloat(c);
}
}, 0).toFixed(2);
}
function handle_error(isError){
if (isError) {
$('#submit_button').attr('disabled', 'disabled')
$('#error_message').css('display', 'block')
} else {
$('#submit_button').removeAttr('disabled')
$('#error_message').css('display', 'none')
}
}
function handle_input_amount(){
var amount = parseFloat($('#amount').val());
$('#fee_list').children('#fee').each(function(){
var fee = $(this).data('fee');
if (amount){
$(this).text(I18n.l("currency", paymentFee(amount, fee)));
} else {
$(this).text(fee);
}
});
}
$('#amount').on('keyup', handle_input_amount);
$(document).ready(handle_input_amount);
%h5= t '.fee'
%dl.dl-horizontal#fee_list
- FoodsoftConfig[:mollie][:fee].each do |k, v|
%dt= k
%dd{id: "fee", data: { fee: v}}"
= form_tag payments_mollie_path, method: :post do
- if params[:text]
.well= params[:text]
.control-group
.control-label
= label_tag 'amount', ((params[:label] or t('.amount_pay')))
@ -18,6 +65,6 @@
= submit_tag t('.submit')
= link_to t('ui.or_cancel'), cancel_payments_mollie_path
-# pass through options to allow reusing on error
- %w(label title fixed min text).each do |k|
= hidden_field_tag k, params[k] if params[k]
-# pass through options to allow reusing on error
- %w(label title fixed min text).each do |k|
= hidden_field_tag k, params[k] if params[k]

View File

@ -12,6 +12,7 @@ en:
method: 'Pay using'
submit: 'Pay at your bank'
financial_transaction_type: 'Financial Transaction Type'
fee: 'The transaction fee depends on your payment method'
controller:
result:
notice: 'Your account was credited %{amount} (transaction fee of %{fee}).'
@ -27,8 +28,5 @@ en:
fee:
ideal: 'Ideal'
banktransfer: 'banktransfer'
paysafecard: 'paysafecard'
creditcard: 'creditcard'
paypal: 'paypal'
mistercash: 'mistercash'
bitcoin: 'bitcoin'
paypal: 'paypal'

View File

@ -12,6 +12,7 @@ nl:
method: 'Hoe te betalen'
submit: 'Betalen'
financial_transaction_type: 'Financiële-transactietype'
fee: 'De transactiekosten van uw betalingsmiddel zijn'
controller:
result:
notice: ' Er is %{amount} bijgeschreven op uw account (transactiekosten van ${fee}).'
@ -25,8 +26,5 @@ nl:
fee:
ideal: 'Ideal'
banktransfer: 'banktransfer'
paysafecard: 'paysafecard'
creditcard: 'creditcard'
paypal: 'paypal'
mistercash: 'mistercash'
bitcoin: 'bitcoin'
paypal: 'paypal'

View File

@ -1,4 +1,4 @@
$:.push File.expand_path("../lib", __FILE__)
$:.push File.expand_path('lib', __dir__)
# Maintain your gem's version:
require "foodsoft_mollie/version"
@ -17,4 +17,5 @@ Gem::Specification.new do |s|
s.add_dependency "rails"
s.add_dependency "mollie-api-ruby"
s.metadata['rubygems_mfa_required'] = 'true'
end

View File

@ -29,7 +29,7 @@ module FoodsoftMollie
return spec if spec.is_a? Numeric
spec.split('+').inject(0) do |sum, c|
sum + (c =~ /^(.*)\s*%\s*$/ ? ($1.to_f/100 * amount.to_f) : c.to_f)
sum + (c =~ /^(.*)\s*%\s*$/ ? (::Regexp.last_match(1).to_f / 100 * amount.to_f) : c.to_f)
end
end
end

View File

@ -1,8 +1,8 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/foodsoft_mollie/engine', __FILE__)
ENGINE_ROOT = File.expand_path('..', __dir_)
ENGINE_PATH = File.expand_path('../lib/foodsoft_mollie/engine', __dir__)
require 'rails/all'
require 'rails/engine/commands'