NAME

Net::Blossom::PaymentRequired - Blossom 402 payment challenge error

SYNOPSIS

my $error = eval { $client->get_blob($sha256); 1 } ? undef : $@;

if (ref($error) && $error->isa('Net::Blossom::PaymentRequired')) {
    my @methods = $error->payment_methods;
    my $cashu   = $error->payment_challenge('cashu');
}

DESCRIPTION

Net::Blossom::PaymentRequired represents a 402 Payment Required response from a Blossom server. It is a subclass of Net::Blossom::Error.

When this object is produced by Net::Blossom::Client, payment challenges are parsed from non-reserved X-* response headers. Known cashu and lightning challenges are validated before being exposed. Unknown future payment methods are preserved when they have a scalar non-empty payload.

CONSTRUCTOR

new

my $error = Net::Blossom::PaymentRequired->new(%args);

Accepts the same required arguments as Net::Blossom::Error->new, but status must be 402. Optional payment_challenges must be a hash reference and defaults to an empty hash reference.

ACCESSORS

method

Returns the HTTP method.

url

Returns the request URL.

status

Returns the HTTP status code.

reason

Returns the HTTP reason phrase.

x_reason

Returns the optional X-Reason diagnostic.

headers

Returns the response headers hash reference.

body

Returns the response body.

payment_challenges

Returns the payment challenge hash reference keyed by normalized method name.

METHODS

payment_methods

my @methods = $error->payment_methods;

Returns sorted payment method names as a list.

payment_challenge

my $challenge = $error->payment_challenge($method);

Returns the challenge string for $method. $method may include an X- prefix. Returns undef when the method is unknown or undefined.

as_string

Inherited from Net::Blossom::Error.