NAME

WWW::PayPal::Role::OpenAPI - operationId-based dispatch against a cached OpenAPI spec

VERSION

version 0.002

SYNOPSIS

package WWW::PayPal::API::Orders;
use Moo;

has client => ( is => 'ro', required => 1, weak_ref => 1 );

has openapi_operations => (
    is      => 'lazy',
    builder => sub {
        return {
            'orders.create'  => { method => 'POST', path => '/v2/checkout/orders' },
            'orders.capture' => { method => 'POST', path => '/v2/checkout/orders/{id}/capture' },
            # ...
        };
    },
);

with 'WWW::PayPal::Role::OpenAPI';

sub capture {
    my ($self, $id) = @_;
    return $self->call_operation('orders.capture',
        path => { id => $id },
        body => {},
    );
}

DESCRIPTION

Role for API controllers that dispatch by OpenAPI operationId. The consumer ships a pre-computed operation table via "openapi_operations", avoiding any YAML/JSON parsing at runtime. Inspired by Langertha::Role::OpenAPI but trimmed down: no OpenAPI::Modern, no spec loading, just the cached lookup table.

Path parameters in curly braces ({id}, {capture_id}, ...) are substituted from the path argument to "call_operation".

Consumers must provide:

  • client - A WWW::PayPal instance (used for HTTP).

  • openapi_operations - HashRef mapping operationId to { method, path, content_type? }.

get_operation

my $op = $self->get_operation('orders.create');

Returns the operation HashRef (method, path, optional content_type) for the given operationId.

call_operation

my $data = $self->call_operation('orders.capture',
    path => { id => $order_id },
    body => {},
);

Dispatches an OpenAPI operation by operationId, substitutes path parameters, and returns the decoded JSON response.

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/p5-www-paypal/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.