Business-GoCardless

 view release on metacpan or  search on metacpan

lib/Business/GoCardless/BillingRequest.pm  view on Meta::CPAN

sub fulfilling      { return ( shift->status // '' ) eq 'fulfilling' }
sub fulfilled       { return ( shift->status // '' ) eq 'fulfilled' }
sub cancelled       { return ( shift->status // '' ) eq 'cancelled' }

=head1 Flows and institutions

=head2 create_flow

Create a L<Business::GoCardless::BillingRequestFlow> for the billing request,
which provides the C<authorisation_url> to send the customer to:

    my $Flow = $BillingRequest->create_flow(
        redirect_uri => 'https://example.com/complete',
        exit_uri     => 'https://example.com/exit',
    );

    my $url = $Flow->authorisation_url;

=head2 institutions

Get a list of L<Business::GoCardless::Institution> objects for the billing
request, for use with L</select_institution>:

    my @institutions = $BillingRequest->institutions( country_code => 'GB' );

=head1 Links

Shortcut methods to get the IDs of the resources created by the billing request:

    customer_id
    mandate_id
    payment_id
    subscription_id
    instalment_schedule_id

=cut

sub create_flow {
    my ( $self,%params ) = @_;

    my $data = $self->client->api_post(
        '/billing_request_flows',
        { billing_request_flows => {
            %params,
            links => {
                %{ $params{links} // {} },
                billing_request => $self->id,
            },
        } },
    );

    return Business::GoCardless::BillingRequestFlow->new(
        client => $self->client,
        %{ $data->{billing_request_flows} },
    );
}

sub institutions {
    my ( $self,%filters ) = @_;

    my $uri = sprintf( $self->endpoint,$self->id ) . '/institutions';
    $uri .= '?' . $self->client->normalize_params( \%filters ) if keys %filters;

    my $data = $self->client->api_get( $uri );

    return map {
        Business::GoCardless::Institution->new( client => $self->client,%{ $_ } )
    } @{ $data->{institutions} // [] };
}

sub customer_id            { return shift->_link( 'customer' ) }
sub mandate_id             { return shift->_link( 'mandate_request_mandate' ) }
sub payment_id             { return shift->_link( 'payment_request_payment' ) }
sub subscription_id        { return shift->_link( 'subscription_request_subscription' ) }
sub instalment_schedule_id { return shift->_link( 'instalment_schedule_request_instalment_schedule' ) }

sub _link {
    my ( $self,$link ) = @_;
    return ( $self->links // {} )->{$link};
}

=head1 AUTHOR

Lee Johnson - C<lee@payprop.com>

This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself. If you would like to contribute documentation,
features, bug fixes, or anything else then please raise an issue / pull request:

    https://github.com/payprop/business-gocardless

=cut

1;

# vim: ts=4:sw=4:et



( run in 0.655 second using v1.01-cache-2.11-cpan-99fa8243a42 )