diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4555bb7f7a723c6e03a80cc16a3ee20b4290967e..4dddc90cb88ff9ca7b0f9cbe5b33b9a83ae1e780 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ image: docker:20.10.9 variables: DOCKER_TLS_CERTDIR: "/certs" - IMAGE_VER: 0.14.0 + IMAGE_VER: 0.15.0 services: - docker:20.10.9-dind diff --git a/lib/CF2022/Controller/Orders.pm b/lib/CF2022/Controller/Orders.pm index dbbafe78733e8003511279d87c3314362acf8945..7a23cb33216da4640e80c3a07a0b0eb032437544 100644 --- a/lib/CF2022/Controller/Orders.pm +++ b/lib/CF2022/Controller/Orders.pm @@ -166,7 +166,6 @@ sub create ($c ) { return $c->error(400, $rc->body) if ! $rc->is_success; # ukladani do lokalni databazi - $order = $c->schema->resultset('Order')->create({ ip => $c->tx->remote_address, sso_uuid => $claims->{sub}, @@ -177,19 +176,11 @@ sub create ($c ) { order_id => $rc->json->{code}, }); - $c->render( status => 201, json => { %{ $rc->json }, - payment_request => { - account => $c->cfg->{payment_account}, - amount => $order->response->{payments}[0]{amount}, - vs => sprintf(TPL_VS, $c->cfg->{payment_vs_prefix}, $order->id ), - ss => $c->cfg->{payment_ss}, - ks => $c->cfg->{payment_ks}, - qr => '/api/orders/' . $order->id . '/payment.png', - }, + payment_request => $c->_payment_request( $order ), } ); } @@ -251,15 +242,17 @@ sub qr ($c) { return $c->error(404, 'NOT FOUND') if ! $order; + my $pr = $c->_payment_request($order); + my $payment = sprintf(TPL_PAYMENT, - $c->cfg->{payment_iban}, - $order->response->{payments}[0]{amount}, - $c->cfg->{payment_msg}, - $order->request->{positions}[0]{attendee_name}, + $pr->{iban}, + $pr->{amount}, + $pr->{message}, + $pr->{payer}, $order->order_id, - sprintf(TPL_VS, $c->cfg->{payment_vs_prefix}, $order->id ), - $c->cfg->{payment_ss}, - $c->cfg->{payment_ks}, + $pr->{vs}, + $pr->{ss}, + $pr->{ks}, ); my $png = qrpng (text => $payment, level => 4); @@ -296,4 +289,26 @@ sub _upload_photo ($c, $username ) { } +sub _payment_request($c, $order) { + + my $ks = $c->cfg->{payment_ks}; + + PRODUCT: + foreach my $pos ( @{ $order->response->{positions}} ) { + $ks |= $c->payment_ks_bit($pos->{item}) + } + + return { + account => $c->cfg->{payment_account}, + iban => $c->cfg->{payment_iban}, + amount => $order->response->{payments}[0]{amount}, + message => $c->cfg->{payment_msg}, + payer => $order->request->{positions}[0]{attendee_name}, + vs => sprintf(TPL_VS, $c->cfg->{payment_vs_prefix}, $order->id ), + ss => $c->cfg->{payment_ss}, + ks => $ks, + qr => '/api/orders/' . $order->id . '/payment.png', + }; +} + 1; diff --git a/lib/CF2022/Helpers/Core.pm b/lib/CF2022/Helpers/Core.pm index a32773f93a9b33b942732e0494d618e2ea292ff3..0d1c279a83f459a5954d7f5d51465dd808756a0f 100644 --- a/lib/CF2022/Helpers/Core.pm +++ b/lib/CF2022/Helpers/Core.pm @@ -79,6 +79,12 @@ sub register ($class, $self, $conf) { my %map = (split /\D+/, $c->cfg->{pretix_variations_map}); return (exists $map{$id}) ? $map{$id} : $id; }); + + $self->helper(payment_ks_bit => sub ($c, $id) { + my %map = (split /\D+/, $c->cfg->{payment_ks_product_map}); + return (exists $map{$id}) ? $map{$id} : 0; + }); + } 1;