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

Kontrola duplicit

parent 4490def3
No related branches found
No related tags found
No related merge requests found
Pipeline #6028 passed
......@@ -13,6 +13,7 @@ sub create ($c ) {
my $args = $c->req->json;
my @products = @{ $args->{products} };
my @responses = @{ $args->{responses} };
my $claims;
my $group;
my $url = sprintf ('%s/organizers/%s/events/%s/orders/',
......@@ -24,7 +25,7 @@ sub create ($c ) {
if ( $args->{token} ) {
$c->oauth_token($args->{token});
my $claims = $c->oauth_claims;
$claims = $c->oauth_claims;
return $c->error(403, 'Invalid token') if ! $claims;
$group = $c->oauth_main_group;
......@@ -61,6 +62,7 @@ sub create ($c ) {
email => $args->{email},
locale => 'en',
payment_provider => 'manual',
testmode => $c->config->{pretix_testmode} ? 'true' : 'false',
positions => [],
fees => [],
};
......@@ -88,16 +90,45 @@ sub create ($c ) {
push @{ $order->{positions} }, $item;
}
my $ua = Mojo::UserAgent->new;
# kontrola duplicity
my $exists = $c->schema->resultset('Order')->search({
email => $order->{email},
api => $url,
})->count;
$exists ||= $c->schema->resultset('Order')->search({
sso_uuid => $claims->{sub},
api => $url,
})->count if $claims;
###### KONTROLA DUPLICITY
return $c->error(400, 'Duplicity' ) if $exists;
# odeslani do pretixu
my $ua = Mojo::UserAgent->new;
my $rc = $ua->post( $url,
{ Authorization => 'Token ' . $c->config->{pretix_token} },
json => $order
)->result->json;
)->result;
$c->render(json => $rc);
return $c->error(400, $rc->json) if ! $rc->is_success;
# ukladani do lokalni databazi
$c->schema->resultset('Order')->create({
ip => $c->tx->remote_address,
sso_uuid => $claims->{sub},
email => $order->{email},
api => $url,
request => $order,
response => $rc->json,
});
$c->render(
status => 201,
json => $rc->json,
);
}
1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment