| 1 | package Business::GoCardless::Merchant; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | =head1 NAME | ||||||||||||||
| 4 | |||||||||||||||
| 5 | Business::GoCardless::Merchant | ||||||||||||||
| 6 | |||||||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||||||
| 8 | |||||||||||||||
| 9 | A class for a gocardless merchant, extends L<Business::GoCardless::Resource> | ||||||||||||||
| 10 | |||||||||||||||
| 11 | =cut | ||||||||||||||
| 12 | |||||||||||||||
| 13 | 55 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 55 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 55 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 55 | extends 'Business::GoCardless::Resource'; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 55 | ▶ | use Carp qw/ carp /; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | |||||||||||||||
| 21 | 55 | ▶ | use Business::GoCardless::Bill; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 55 | ▶ | use Business::GoCardless::PreAuthorization; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | 55 | ▶ | use Business::GoCardless::Payout; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 24 | 55 | ▶ | use Business::GoCardless::User; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 25 | 55 | ▶ | use Business::GoCardless::Paginator; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | =head1 ATTRIBUTES | ||||||||||||||
| 28 | |||||||||||||||
| 29 | balance | ||||||||||||||
| 30 | created_at | ||||||||||||||
| 31 | description | ||||||||||||||
| 32 | |||||||||||||||
| 33 | eur_balance | ||||||||||||||
| 34 | eur_pending_balance | ||||||||||||||
| 35 | first_name | ||||||||||||||
| 36 | gbp_balance | ||||||||||||||
| 37 | gbp_pending_balance | ||||||||||||||
| 38 | hide_variable_amount | ||||||||||||||
| 39 | id | ||||||||||||||
| 40 | last_name | ||||||||||||||
| 41 | name | ||||||||||||||
| 42 | next_payout_amount | ||||||||||||||
| 43 | next_payout_date | ||||||||||||||
| 44 | pending_balance | ||||||||||||||
| 45 | sub_resource_uris | ||||||||||||||
| 46 | uri | ||||||||||||||
| 47 | |||||||||||||||
| 48 | =cut | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 55 | has [ qw/ | |||||||||||||
| 51 | balance | ||||||||||||||
| 52 | created_at | ||||||||||||||
| 53 | description | ||||||||||||||
| 54 | |||||||||||||||
| 55 | eur_balance | ||||||||||||||
| 56 | eur_pending_balance | ||||||||||||||
| 57 | first_name | ||||||||||||||
| 58 | gbp_balance | ||||||||||||||
| 59 | gbp_pending_balance | ||||||||||||||
| 60 | hide_variable_amount | ||||||||||||||
| 61 | id | ||||||||||||||
| 62 | last_name | ||||||||||||||
| 63 | name | ||||||||||||||
| 64 | next_payout_amount | ||||||||||||||
| 65 | next_payout_date | ||||||||||||||
| 66 | pending_balance | ||||||||||||||
| 67 | sub_resource_uris | ||||||||||||||
| 68 | uri | ||||||||||||||
| 69 | / ] => ( | ||||||||||||||
| 70 | is => 'rw', | ||||||||||||||
| 71 | ); | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 7 | ▶ | sub BUILD { | ||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||
| 74 | 7 | my ( $self ) = @_; | |||||||||||||
| 75 | |||||||||||||||
| 76 | 7 | my $data = $self->client->api_get( sprintf( $self->endpoint,$self->id ) ); | |||||||||||||
| 77 | |||||||||||||||
| 78 | 7 | foreach my $attr ( keys( %{ $data } ) ) { | |||||||||||||
| 79 | 113 | eval { $self->$attr( $data->{$attr} ); }; | |||||||||||||
| 80 | 113 | ▶ | $@ && do { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 81 | 0 | carp( "Couldn't set $attr on @{[ ref( $self ) ]}: $@" ); | |||||||||||||
| 82 | }; | ||||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 7 | return $self; | |||||||||||||
| 86 | } | ||||||||||||||
| 87 | |||||||||||||||
| 88 | =head1 List operations on a merchant | ||||||||||||||
| 89 | |||||||||||||||
| 90 | bills | ||||||||||||||
| 91 | pre_authorizations | ||||||||||||||
| 92 | subscriptions | ||||||||||||||
| 93 | payouts | ||||||||||||||
| 94 | users | ||||||||||||||
| 95 | |||||||||||||||
| 96 | my @bills = $Merchant->bills( \%filter ); | ||||||||||||||
| 97 | |||||||||||||||
| 98 | Note that these methods marked have a dual interface, when called in list context | ||||||||||||||
| 99 | they will return the first 100 resource objects, when called in scalar context | ||||||||||||||
| 100 | they will return a L<Business::GoCardless::Paginator> object. | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =cut | ||||||||||||||
| 103 | |||||||||||||||
| 104 | 2 | ▶ | sub bills { shift->_list( 'bills',shift ) } | ||||||||||||
|
Subroutine
bills: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 105 | 1 | ▶ | sub pre_authorizations { shift->_list( 'pre_authorizations',shift )} | ||||||||||||
|
Subroutine
pre_authorizations: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 106 | 1 | ▶ | sub subscriptions { shift->_list( 'subscriptions',shift ) } | ||||||||||||
|
Subroutine
subscriptions: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 107 | 1 | ▶ | sub payouts { shift->_list( 'payouts',shift ) } | ||||||||||||
|
Subroutine
payouts: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 108 | 1 | ▶ | sub users { shift->_list( 'users',shift ) } | ||||||||||||
|
Subroutine
users: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 109 | |||||||||||||||
| 110 | 6 | ▶ | sub _list { | ||||||||||||
|
Subroutine
_list: called CC=7 SCAR=20.5
| |||||||||||||||
| 111 | 6 | my ( $self,$endpoint,$filters ) = @_; | |||||||||||||
| 112 | |||||||||||||||
| 113 | my $class = { | ||||||||||||||
| 114 | bills => 'Bill', | ||||||||||||||
| 115 | pre_authorizations => 'PreAuthorization', | ||||||||||||||
| 116 | subscriptions => 'Subscription', | ||||||||||||||
| 117 | payouts => 'Payout', | ||||||||||||||
| 118 | users => 'User', | ||||||||||||||
| 119 | 6 | }->{ $endpoint }; | |||||||||||||
| 120 | |||||||||||||||
| 121 | 6 | ▶ | $filters //= {}; | ||||||||||||
|
Condition50%1/2
$filters //= {}
MC/DC0%0/1
$filters //= {}
$filters
Truth table50%1/2
A
A= $filters
| |||||||||||||||
| 122 | 6 | ▶ | $filters->{per_page} ||= 100; | ||||||||||||
|
Condition50%1/2
$filters->{"per_page"} ||= 100
MC/DC0%0/1
$filters->{"per_page"} ||= 100
$filters->{"per_page"}
Truth table50%1/2
A
A= $filters->{"per_page"}
| |||||||||||||||
| 123 | 6 | ▶ | $filters->{page} ||= 1; | ||||||||||||
|
Condition50%1/2
$filters->{"page"} ||= 1
MC/DC0%0/1
$filters->{"page"} ||= 1
$filters->{"page"}
Truth table50%1/2
A
A= $filters->{"page"}
| |||||||||||||||
| 124 | |||||||||||||||
| 125 | 6 | my $uri = sprintf( $self->endpoint,$self->id ) . "/$endpoint"; | |||||||||||||
| 126 | |||||||||||||||
| 127 | 6 | ▶ | if ( keys( %{ $filters } ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 128 | 6 | $uri .= '?' . $self->client->normalize_params( $filters ); | |||||||||||||
| 129 | } | ||||||||||||||
| 130 | |||||||||||||||
| 131 | 6 | my ( $data,$links,$info ) = $self->client->api_get( $uri ); | |||||||||||||
| 132 | |||||||||||||||
| 133 | 6 | $class = "Business::GoCardless::$class"; | |||||||||||||
| 134 | 10 | my @objects = map { $class->new( client => $self->client,%{ $_ } ) } | |||||||||||||
| 135 | 6 | @{ $data }; | |||||||||||||
| 136 | |||||||||||||||
| 137 | 6 | ▶ | return wantarray ? ( @objects ) : Business::GoCardless::Paginator->new( | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 138 | class => $class, | ||||||||||||||
| 139 | client => $self->client, | ||||||||||||||
| 140 | links => $links, | ||||||||||||||
| 141 | info => $info ? JSON->new->decode( $info ) : {}, | ||||||||||||||
| 142 | objects => \@objects, | ||||||||||||||
| 143 | ); | ||||||||||||||
| 144 | } | ||||||||||||||
| 145 | |||||||||||||||
| 146 | =head1 AUTHOR | ||||||||||||||
| 147 | |||||||||||||||
| 148 | Lee Johnson - C<lee@payprop.com> | ||||||||||||||
| 149 | |||||||||||||||
| 150 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 151 | the same terms as Perl itself. If you would like to contribute documentation, | ||||||||||||||
| 152 | features, bug fixes, or anything else then please raise an issue / pull request: | ||||||||||||||
| 153 | |||||||||||||||
| 154 | https://github.com/payprop/business-gocardless | ||||||||||||||
| 155 | |||||||||||||||
| 156 | =cut | ||||||||||||||
| 157 | |||||||||||||||
| 158 | 55 | 1; | |||||||||||||
| 159 | |||||||||||||||
| 160 | # vim: ts=4:sw=4:et | ||||||||||||||