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

(-)a/Koha/REST/V1/Patrons/Account.pm (+34 lines)
Lines 205-208 sub list_debits { Link Here
205
    };
205
    };
206
}
206
}
207
207
208
=head3 add_debit
209
210
=cut
211
212
sub add_debit {
213
    my $c = shift->openapi->valid_input or return;
214
215
    my $patron_id = $c->validation->param('patron_id');
216
    my $patron    = Koha::Patrons->find($patron_id);
217
218
    unless ($patron) {
219
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
220
    }
221
222
    return try {
223
        my $data = Koha::Patron::Account::Debit->new_from_api(
224
            $c->validation->param('body') )->unblessed;
225
226
        $data->{interface} = 'api'; # Should this always be API, or should we allow the API consumer to choose?
227
        $data->{user_id} = $patron->borrowernumber; # Should this be API user OR staff the API may be acting on behalf of?
228
229
        my $debit = $patron->account->add_debit($data);
230
231
        $c->res->headers->location( $c->req->url->to_string . '/' . $debit->id );
232
        return $c->render(
233
            status  => 201,
234
            openapi => $debit->to_api
235
        );
236
    }
237
    catch {
238
        $c->unhandled_exception($_);
239
    };
240
}
241
208
1;
242
1;
(-)a/api/v1/swagger/paths/patrons_account.yaml (-1 / +47 lines)
Lines 177-179 Link Here
177
      permissions:
177
      permissions:
178
        borrowers: edit_borrowers
178
        borrowers: edit_borrowers
179
        updatecharges: remaining_permissions
179
        updatecharges: remaining_permissions
180
- 
180
  post:
181
    x-mojo-to: Patrons::Account#add_debit
182
    operationId: addPatronDebit
183
    tags:
184
      - patrons
185
    summary: Add debit to a patron's account
186
    parameters:
187
      - $ref: "../swagger.yaml#/parameters/patron_id_pp"
188
      - name: body
189
        in: body
190
        description: A JSON object containing debit information
191
        required: true
192
        schema:
193
          $ref: "../swagger.yaml#/definitions/patron_account_debit"
194
    produces:
195
      - application/json
196
    responses:
197
      "201":
198
        description: Debit added
199
        schema:
200
          $ref: "../swagger.yaml#/definitions/account_line"
201
      "401":
202
        description: Authentication required
203
        schema:
204
          $ref: "../swagger.yaml#/definitions/error"
205
      "403":
206
        description: Access forbidden
207
        schema:
208
          $ref: "../swagger.yaml#/definitions/error"
209
      "404":
210
        description: Patron not found
211
        schema:
212
          $ref: "../swagger.yaml#/definitions/error"
213
      "500":
214
        description: |
215
          Internal server error. Possible `error_code` attribute values:
216
217
          * `internal_server_error`
218
        schema:
219
          $ref: "../swagger.yaml#/definitions/error"
220
      "503":
221
        description: Under maintenance
222
        schema:
223
          $ref: "../swagger.yaml#/definitions/error"
224
    x-koha-authorization:
225
      permissions:
226
        updatecharges: remaining_permissions

Return to bug 21043