Skip to content
Snippets Groups Projects
Verified Commit f39d7ba3 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Podpora QR pro platbu

parent b9b1b9df
No related branches found
No related tags found
No related merge requests found
Pipeline #11753 passed
......@@ -2,7 +2,7 @@ image: docker:20.10.9
variables:
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 0.12.1
IMAGE_VER: 0.13.0
services:
- docker:20.10.9-dind
......
......@@ -13,9 +13,11 @@ RUN apt-get update && apt-get install -y \
libio-socket-ssl-perl \
libjson-perl \
libyaml-perl \
libpng-dev \
libyaml-dev
RUN cpanm \
Image::PNG::QRCode \
Mojolicious \
Mojo::Pg \
Mojo::Redis \
......
......@@ -79,6 +79,7 @@ sub startup {
# Router
my $r = $self->routes;
$r->get('/')->to(cb => sub { shift->redirect_to('/api.html');});
$r->get('/api/orders/:id/payment.png')->to('Orders#qr');
}
......
......@@ -2,12 +2,16 @@ package CF2022::Controller::Orders;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::UserAgent;
use Mojo::Asset::File;
use Image::PNG::QRCode 'qrpng';
use constant MAIN_PRODUCTS => qr/^(1|2|3)$/; # typy akreditace
use constant NONFREE_PRODUCTS => qr/^(1)$/; # akreditace vyzadujici token
use constant SUBSIDY_PRODUCTS => qr/^(58)$/; # prispevkove polozky
use constant FALLBACK_PRODUCT => 2; # fallback akreditace
use constant TPL_VS => '%d%07d';
use constant TPL_PAYMENT => 'SPD*1.0*ACC:%s*AM:%f*MSG:%s, %s*X-ID:%s*X-VS:%d*X-SS:%d*X-KS:%d';
use feature 'signatures';
no warnings qw{ experimental::signatures };
......@@ -167,6 +171,14 @@ sub create ($c ) {
order_id => $rc->json->{code},
});
$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},
};
$c->render(
status => 201,
json => $rc->json,
......@@ -206,7 +218,7 @@ sub get ($c ) {
return $c->error(404, 'NOT FOUND') if ! $order;
# datas z pretixu
# data z pretixu (kvuli stavu, jinak je to v databazi???)
$c->app->log->error($order->api . $order->order_id);
my $ua = Mojo::UserAgent->new;
......@@ -222,6 +234,31 @@ sub get ($c ) {
);
}
sub qr ($c) {
my $order = $c->schema->resultset('Order')->find({
id => $c->stash->{id},
deleted => undef,
});
return $c->error(404, 'NOT FOUND') if ! $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},
$order->order_id,
sprintf(TPL_VS, $c->cfg->{payment_vs_prefix}, $order->id ),
$c->cfg->{payment_ss},
$c->cfg->{payment_ks},
);
my $png = qrpng (text => $payment, level => 4);
$c->res->headers->content_type('image/png');
$c->render( data => $png );
}
sub _upload_photo ($c, $username ) {
my $ua = Mojo::UserAgent->new;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment