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
Branches
No related tags found
No related merge requests found
Pipeline #6028 passed
...@@ -13,6 +13,7 @@ sub create ($c ) { ...@@ -13,6 +13,7 @@ sub create ($c ) {
my $args = $c->req->json; my $args = $c->req->json;
my @products = @{ $args->{products} }; my @products = @{ $args->{products} };
my @responses = @{ $args->{responses} }; my @responses = @{ $args->{responses} };
my $claims;
my $group; my $group;
my $url = sprintf ('%s/organizers/%s/events/%s/orders/', my $url = sprintf ('%s/organizers/%s/events/%s/orders/',
...@@ -24,7 +25,7 @@ sub create ($c ) { ...@@ -24,7 +25,7 @@ sub create ($c ) {
if ( $args->{token} ) { if ( $args->{token} ) {
$c->oauth_token($args->{token}); $c->oauth_token($args->{token});
my $claims = $c->oauth_claims; $claims = $c->oauth_claims;
return $c->error(403, 'Invalid token') if ! $claims; return $c->error(403, 'Invalid token') if ! $claims;
$group = $c->oauth_main_group; $group = $c->oauth_main_group;
...@@ -61,6 +62,7 @@ sub create ($c ) { ...@@ -61,6 +62,7 @@ sub create ($c ) {
email => $args->{email}, email => $args->{email},
locale => 'en', locale => 'en',
payment_provider => 'manual', payment_provider => 'manual',
testmode => $c->config->{pretix_testmode} ? 'true' : 'false',
positions => [], positions => [],
fees => [], fees => [],
}; };
...@@ -88,16 +90,45 @@ sub create ($c ) { ...@@ -88,16 +90,45 @@ sub create ($c ) {
push @{ $order->{positions} }, $item; 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, my $rc = $ua->post( $url,
{ Authorization => 'Token ' . $c->config->{pretix_token} }, { Authorization => 'Token ' . $c->config->{pretix_token} },
json => $order 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; 1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment