From ad54918c3d977bd3fae1ed9c74088afb191b8847 Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Sun, 12 May 2019 21:35:33 +0200 Subject: [PATCH] Rename plugin; Add text to side of QR code --- plugins/deposit_epc_qr | 41 --------------------------------- plugins/deposit_iban_qr | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 41 deletions(-) delete mode 100644 plugins/deposit_epc_qr create mode 100644 plugins/deposit_iban_qr diff --git a/plugins/deposit_epc_qr b/plugins/deposit_epc_qr deleted file mode 100644 index a4ec575..0000000 --- a/plugins/deposit_epc_qr +++ /dev/null @@ -1,41 +0,0 @@ -#!perl - -use List::Util qw(sum); - -sub command { NEXT } - -sub hook_deposit_methods { - my ($class, $message, $hash) = @_; - - $$message=~s/('iban'.*)$/$1\n'mobile': IBAN transfer via an EPC QR code\n Note: Only ING and Bunq support this method in the NL currently./gm; - - $hash->{mobile} = { description => "Deposit (IBAN transfer using QR)"}; -} - -sub hook_checkout { - my ($class, $cart, $user, $transaction_id) = @_; - - my @items = $cart->select_items("is_deposit"); - - my $amount = sum map $_->{amount}, grep $_->{method} eq "mobile", @items; - - if (defined $amount && $amount > 0) { - print "Here's your EPC QR code:\n"; - open my $pipe, "| qrencode -t ansiutf8 -m 2" - or die "Couldn't run qrencode"; - - print $pipe join( - "\n", - "BCD", "002", 1, "SCT", - "", - "Your Hackerspace", # Account name - "NL12ABCD1234567890", # IBAN Number - "EUR" . $amount, # Amount - "", - "", - "deposit", # $user (T: $transaction_id)", # Description - "", - ); - close $pipe; - } -} diff --git a/plugins/deposit_iban_qr b/plugins/deposit_iban_qr new file mode 100644 index 0000000..884b9ec --- /dev/null +++ b/plugins/deposit_iban_qr @@ -0,0 +1,50 @@ +#!perl + +use IPC::Open2 qw(open2); +use List::Util qw(sum); + +my $iban = "NL99ABCD1234567890"; +my $benificiary = "Account Name"; + +sub command { NEXT } + +sub hook_checkout { + my ($class, $cart, $user, $transaction_id) = @_; + + my @items = $cart->select_items("is_deposit"); + + my $amount = sum map $_->{amount}, grep $_->{method} eq "iban", @items; + + if (defined $amount && $amount > 0) { + my $pid = open2 my $out, my $in, qw(qrencode -t ansiutf8 -m 2) + or die "Couldn't run qrencode"; + + print $in join( + "\n", + "BCD", "002", 1, "SCT", + "", + $benificiary, + $iban, + "EUR" . $amount, # Amount + "", + "", + "rb $user", + "", + ); + close $in; + + local $/ = "\n"; + my @lines = readline $out; + close $out; + + waitpid($pid, 0); + + $lines[1] =~ s/$/ Note: ING and Bunq are the only/; + $lines[2] =~ s/$/ Dutch banks that support these/; + $lines[3] =~ s/$/ EPC QR codes./; + $lines[5] =~ s/$/ For manual transfers, use this/; + $lines[6] =~ s/$/ IBAN: $iban/; + + print @lines; + } +}