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