Add starting price.

This commit is contained in:
Sergiotarxz 2024-11-12 23:48:58 +01:00
parent ebb2fd6cff
commit ef43cfc335

View File

@ -17,12 +17,13 @@ use MakeThemPay::DB;
sub price($self) {
my $uuid = $self->param('uuid');
my ( $price, $discount );
my ( $price, $discount, $starting_price );
eval { $self->_insert_license( $uuid, 0 ); };
if ($@) {
warn $@;
}
eval { ( $price, $discount ) = $self->_get_real_price; };
eval { ( $price, $discount, $starting_price ) = $self->_get_real_price; };
say $starting_price;
if ($@) {
warn $@;
$self->res->code(500);
@ -31,8 +32,9 @@ sub price($self) {
}
return $self->render(
json => {
price => $price,
discount => $discount,
price => $price,
discount => $discount,
starting_price => $starting_price,
}
);
}
@ -48,11 +50,11 @@ sub _get_real_price($self) {
die
"Bad price and/or discount format price: $price discount: $discount";
}
my $discounted_price = int($price - ( ( $price * $discount ) / 100 ));
if (!wantarray) {
my $discounted_price = int( $price - ( ( $price * $discount ) / 100 ) );
if ( !wantarray ) {
return $discounted_price;
}
return ( $discounted_price, $discount );
return ( $discounted_price, $discount, $price );
}
sub get_paid($self) {
@ -71,7 +73,7 @@ sub get_paid($self) {
}
sub _insert_license( $self, $uuid, $is_paid ) {
my $dbh = MakeThemPay::DB->connect;
my $dbh = MakeThemPay::DB->connect;
$dbh->do( 'REPLACE INTO licenses (uuid, paid) VALUES (?, ?);',
{}, $uuid, $is_paid );
}
@ -114,7 +116,7 @@ sub get_url ($self) {
},
form => {
currency => 'eur',
unit_amount => int($self->_get_real_price),
unit_amount => int( $self->_get_real_price ),
product => $product_id,
}
)->result;