|
Lines 207-220
sub add_debit {
Link Here
|
| 207 |
my $c = shift->openapi->valid_input or return; |
207 |
my $c = shift->openapi->valid_input or return; |
| 208 |
|
208 |
|
| 209 |
my $patron = Koha::Patrons->find( $c->param('patron_id') ); |
209 |
my $patron = Koha::Patrons->find( $c->param('patron_id') ); |
|
|
210 |
my $user = $c->stash('koha.user'); |
| 210 |
|
211 |
|
| 211 |
return $c->render_resource_not_found("Patron") |
212 |
return $c->render_resource_not_found("Patron") |
| 212 |
unless $patron; |
213 |
unless $patron; |
| 213 |
|
214 |
|
| 214 |
return try { |
215 |
return try { |
| 215 |
my $data = |
216 |
my $data = |
| 216 |
Koha::Account::Debit->new_from_api( $c->req->json ) |
217 |
Koha::Account::Debit->new_from_api( $c->req->json )->unblessed; |
| 217 |
->unblessed; |
|
|
| 218 |
|
218 |
|
| 219 |
$data->{library_id} = delete $data->{branchcode}; |
219 |
$data->{library_id} = delete $data->{branchcode}; |
| 220 |
$data->{type} = delete $data->{debit_type_code}; |
220 |
$data->{type} = delete $data->{debit_type_code}; |
|
Lines 223-233
sub add_debit {
Link Here
|
| 223 |
$data->{transaction_type} = delete $data->{payment_type}; |
223 |
$data->{transaction_type} = delete $data->{payment_type}; |
| 224 |
$data->{interface} = 'api' |
224 |
$data->{interface} = 'api' |
| 225 |
; # Should this always be API, or should we allow the API consumer to choose? |
225 |
; # Should this always be API, or should we allow the API consumer to choose? |
| 226 |
$data->{user_id} = $patron->borrowernumber |
226 |
$data->{user_id} = delete $data->{manager_id} || $user->id; |
| 227 |
; # Should this be API user OR staff the API may be acting on behalf of? |
|
|
| 228 |
|
227 |
|
| 229 |
my $debit = $patron->account->add_debit($data); |
228 |
my $debit = $patron->account->add_debit($data); |
| 230 |
$debit = Koha::Account::Debit->_new_from_dbic($debit->{_result}); |
229 |
$debit = Koha::Account::Debit->_new_from_dbic( $debit->{_result} ); |
| 231 |
|
230 |
|
| 232 |
$c->res->headers->location( |
231 |
$c->res->headers->location( |
| 233 |
$c->req->url->to_string . '/' . $debit->id ); |
232 |
$c->req->url->to_string . '/' . $debit->id ); |
|
Lines 248-260
sub add_debit {
Link Here
|
| 248 |
} |
247 |
} |
| 249 |
elsif ( $_->isa('Koha::Exceptions::Account::AmountNotPositive') ) { |
248 |
elsif ( $_->isa('Koha::Exceptions::Account::AmountNotPositive') ) { |
| 250 |
return $c->render( |
249 |
return $c->render( |
| 251 |
status => 400, |
250 |
status => 400, |
| 252 |
openapi => { error => $_->description } |
251 |
openapi => { error => $_->description } |
| 253 |
); |
252 |
); |
| 254 |
} |
253 |
} |
| 255 |
elsif ( $_->isa('Koha::Exceptions::Account::UnrecognisedType') ) { |
254 |
elsif ( $_->isa('Koha::Exceptions::Account::UnrecognisedType') ) { |
| 256 |
return $c->render( |
255 |
return $c->render( |
| 257 |
status => 400, |
256 |
status => 400, |
| 258 |
openapi => { error => $_->description } |
257 |
openapi => { error => $_->description } |
| 259 |
); |
258 |
); |
| 260 |
} |
259 |
} |
| 261 |
- |
|
|