Bitlair changes

This commit is contained in:
polyfloyd 2022-06-12 21:36:56 +02:00
parent 3600e2b6db
commit fc410035ca
13 changed files with 133 additions and 13 deletions

26
plugins/bitlair_3dprint Normal file
View file

@ -0,0 +1,26 @@
#!perl
HELP "3dprint <gram>" => "3D-print filament afrekenen";
use Scalar::Util qw(looks_like_number);
sub command :Tab(3dprint) ($self, $cart, $command, @) {
return NEXT if $command ne '3dprint';
return "Gewicht in gram, inclusief supports en purges", \&gram;
}
sub gram($self, $cart, $input, @) {
looks_like_number($input) and $input == int($input) or return REJECT, "Invalid number!";
my $gram = int($input);
return REJECT, "$input: Invalid amount." if $gram <= 0;
my $beneficiary = "3dprinter";
my $amount = 0.10 + $gram * 0.03;
$cart
->add(-$amount, "Given to $beneficiary ($gram g)")
->add_contra($beneficiary, +$amount, "Received from \$you (${gram} g)");
return ACCEPT;
}

17
plugins/bitlair_bigmoney Normal file
View file

@ -0,0 +1,17 @@
#!perl
sub command :Tab(bigmoney) {
my ($self, $cart, $command) = @_;
return NEXT if $command ne "bigmoney";
my @list = sort {
(split " ", $b)[1] <=> (split " ", $a)[1]
} grep {
not RevBank::Users::is_hidden($_)
} slurp("revbank.accounts");
print join "", @list[0..9];
return ACCEPT;
}

19
plugins/bitlair_git Normal file
View file

@ -0,0 +1,19 @@
#!perl
use Cwd ();
sub command { NEXT }
sub hook_checkout_done {
my ($class, $cart, $username, $transaction_id) = @_;
my @cart_printed = map { "\n-> $_" } map { $_->as_printable } $cart->entries;
my $fn = "/tmp/revbank$$.commit";
open my $fh, ">", $fn or warn $!;
print $fh "$username ($transaction_id)\n@cart_printed";
close $fh or warn $!;
my $output = `(cp revbank.accounts revbank.market revbank.products ~/data.git/ && cd ~/data.git/ && git commit -a -F $fn) 2>&1`;
warn "Meh, gitfaal: $output" if $?;
}

19
plugins/bitlair_mqtt Normal file
View file

@ -0,0 +1,19 @@
#!perl
use Cwd ();
use Net::MQTT::Simple;
my $mqtt = Net::MQTT::Simple->new("mqtt.bitlair.nl");
sub command { NEXT }
sub hook_checkout {
my ($class, $cart, $user, $transaction_id) = @_;
my @entries = $cart->entries('product_id') or return;
for my $entry (@entries) {
$mqtt->publish("bitlair/pos/product" => $entry->{description})
for 1..$entry->quantity;
}
}

15
plugins/bitlair_nomunnie Normal file
View file

@ -0,0 +1,15 @@
#!perl
use IO::Socket::IP;
use Net::MQTT::Simple "mqtt.bitlair.nl";
sub command { NEXT }
sub hook_user_balance {
my ($class, $user, $old, $delta, $new, $transaction_id) = @_;
return if $new >= -13.37;
return if RevBank::Users::is_hidden($user);
publish "bitlair/bank/shame" => "NO MUNNIE?";
}

View file

@ -37,6 +37,10 @@ sub amount :Tab(13.37,42) ($self, $cart, $input, @) {
sub how :Tab(&how_tab) ($self, $cart, $input, @) {
my %methods = %{ $self->{deposit_methods} };
if ($input eq "iban") {
return ABORT, "\nBank transactions now go via iDeal:\n\n >>> https://deposit.bitlair.nl <<<\n\n"
}
my $how = $self->{how} = $methods{$input}
or return REJECT, "'$input' is not a valid answer.";

View file

@ -20,8 +20,8 @@
use IPC::Open2 qw(open2);
use List::Util qw(sum);
my $iban = "NL99ABCD1234567890";
my $beneficiary = "Account Name";
my $iban = "NL89RABO0111741386";
my $beneficiary = "Stichting Bitlair";
sub hook_checkout($class, $cart, $account, $transaction_id, @) {
my @entries = $cart->entries("is_deposit");
@ -57,6 +57,8 @@ sub hook_checkout($class, $cart, $account, $transaction_id, @) {
$lines[3] =~ s/$/ EPC QR codes. N26 also works./;
$lines[5] =~ s/$/ For manual transfers, use this/;
$lines[6] =~ s/$/ IBAN: $iban/;
$lines[7] =~ s/$/ Benificiary: $beneficiary/;
$lines[8] =~ s/$/ Description: Deposit $user/;
print @lines;
}

View file

@ -5,10 +5,11 @@ sub hook_deposit_methods($class, $message, $hash, @) {
Please type one of the following:
'iban': IBAN transfer (NL 69 ABNA 0431 1582 07)
'iban': Deprecated. Abort and go to https://deposit.bitlair.nl instead
'cash': Cash in the cash box
'reimburse': Reimbursement of expenses agreed upon in advance
Note: we require an invoice or receipt with this exact amount!
Note #1: we require an invoice or receipt with this exact amount!
Note #2: please do not use this plugin for amounts >20 EUR
'other': Provide a manual description
END

8
plugins/revspace_cokeurl Normal file
View file

@ -0,0 +1,8 @@
# Accept the odd QR-codes on Coke (and Fanta, etc.) cans, as they also contain the EAN.
# For this plugin to be useful, it needs to be BEFORE "users" in "revbank.plugins".
sub command {
$_[2] =~ s@^https?://(coke|fanta)url.com/q/srn@@gi; # input is actually a mutable string
return NEXT;
}

View file

@ -3,7 +3,7 @@ use LWP::UserAgent;
use JSON;
my $ua = LWP::UserAgent->new(agent => "revbank");
my $backend_url = "https://deposit.revspace.nl/mollie.php";
my $backend_url = "https://deposit.bitlair.nl/revbank_plugin_backend";
sub backend_call($hash) {
#$hash->{test} = 1; # use mollie test environment

View file

@ -17,7 +17,7 @@ sub hook_checkout_done($class, $cart, $account, $transaction_id, @) {
my $balance = RevBank::Accounts::balance($account) or return;
my $since = RevBank::Accounts::since($account);
if ($balance < -22.00) {
if ($balance < -13.37) {
_box(
"Hoi $account,",
"",