View | Details | Raw Unified | Return to bug 21043
Collapse All | Expand All

(-)a/Koha/REST/V1/Patrons/Account.pm (-4 / +27 lines)
Lines 243-252 sub add_debit { Link Here
243
          Koha::Account::Debit->new_from_api( $c->validation->param('body') )
243
          Koha::Account::Debit->new_from_api( $c->validation->param('body') )
244
          ->unblessed;
244
          ->unblessed;
245
245
246
        $data->{library_id}    = $data->{branchcode};
246
        $data->{library_id}       = delete $data->{branchcode};
247
        $data->{cash_register} = $data->{cash_register_id};
247
        $data->{type}             = delete $data->{debit_type_code};
248
        $data->{item_id}       = $data->{itemnumber};
248
        $data->{cash_register}    = delete $data->{cash_register_id};
249
        $data->{interface}     = 'api'
249
        $data->{item_id}          = delete $data->{itemnumber};
250
        $data->{transaction_type} = delete $data->{payment_type};
251
        $data->{interface}        = 'api'
250
          ; # Should this always be API, or should we allow the API consumer to choose?
252
          ; # Should this always be API, or should we allow the API consumer to choose?
251
        $data->{user_id} = $patron->borrowernumber
253
        $data->{user_id} = $patron->borrowernumber
252
          ; # Should this be API user OR staff the API may be acting on behalf of?
254
          ; # Should this be API user OR staff the API may be acting on behalf of?
Lines 263-268 sub add_debit { Link Here
263
        );
265
        );
264
    }
266
    }
265
    catch {
267
    catch {
268
        if ( blessed $_ ) {
269
            if ( $_->isa('Koha::Exceptions::Account::RegisterRequired') ) {
270
                return $c->render(
271
                    status  => 400,
272
                    openapi => { error => "$_" }
273
                );
274
            }
275
            elsif ( $_->isa('Koha::Exceptions::Account::AmountNotPositive') ) {
276
                return $c->render(
277
                    status => 400,
278
                    openapi => { error => "$_" }
279
                );
280
            }
281
            elsif ( $_->isa('Koha::Exceptions::Account::UnrecognisedType') ) {
282
                return $c->render(
283
                    status => 400,
284
                    openapi => { error => "$_" }
285
                );
286
            }
287
        }
288
266
        $c->unhandled_exception($_);
289
        $c->unhandled_exception($_);
267
    };
290
    };
268
}
291
}
(-)a/api/v1/swagger/paths/patrons_account.yaml (-1 / +5 lines)
Lines 197-203 Link Here
197
      "201":
197
      "201":
198
        description: Debit added
198
        description: Debit added
199
        schema:
199
        schema:
200
          $ref: "../swagger.yaml#/definitions/account_line"
200
          $ref: "../swagger.yaml#/definitions/debit"
201
      "400":
202
        description: Bad parameter
203
        schema:
204
          $ref: "../swagger.yaml#/definitions/error"
201
      "401":
205
      "401":
202
        description: Authentication required
206
        description: Authentication required
203
        schema:
207
        schema:
(-)a/t/db_dependent/api/v1/patrons_accounts.t (-2 / +17 lines)
Lines 322-328 subtest 'add_debit() tests' => sub { Link Here
322
    my $debit = {
322
    my $debit = {
323
        amount      => 100,
323
        amount      => 100,
324
        description => "A description",
324
        description => "A description",
325
        debit_type  => "NEW_CARD",
325
        type        => "NEW_CARD",
326
        user_id     => $patron->borrowernumber,
326
        user_id     => $patron->borrowernumber,
327
        interface   => 'test',
327
        interface   => 'test',
328
        library_id  => $library->id,
328
        library_id  => $library->id,
Lines 368-372 subtest 'add_debit() tests' => sub { Link Here
368
    is( $account->outstanding_debits->total_outstanding,
368
    is( $account->outstanding_debits->total_outstanding,
369
        175, "Debit added to total outstanding debits" );
369
        175, "Debit added to total outstanding debits" );
370
370
371
    # Cash register handling and PAYOUTs
372
    t::lib::Mocks::mock_preference( 'UseCashRegisters', 1 );
373
    my $payout = {
374
        amount      => 10,
375
        description => "A description",
376
        type        => "PAYOUT",
377
        payout_type => "CASH",
378
        user_id     => $patron->borrowernumber,
379
        interface   => 'test',
380
        library_id  => $library->id,
381
    };
382
383
    $t->post_ok(
384
        "//$userid:$password@/api/v1/patrons/$patron_id/account/debits" =>
385
          json => $payout )->status_is(201);
386
371
    $schema->storage->txn_rollback;
387
    $schema->storage->txn_rollback;
372
};
388
};
373
- 

Return to bug 21043