| 1 | package Business::GoCardless::BillingRequest; | ||||||||||||
| 2 | |||||||||||||
| 3 | =head1 NAME | ||||||||||||
| 4 | |||||||||||||
| 5 | Business::GoCardless::BillingRequest | ||||||||||||
| 6 | |||||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||||
| 8 | |||||||||||||
| 9 | A class for a gocardless billing request, extends L<Business::GoCardless::Resource> | ||||||||||||
| 10 | |||||||||||||
| 11 | Billing Requests are the recommended way to collect payments and/or set up | ||||||||||||
| 12 | mandates, replacing Redirect Flows. See | ||||||||||||
| 13 | L<https://developer.gocardless.com/api-reference/#billing-requests-billing-requests> | ||||||||||||
| 14 | |||||||||||||
| 15 | =cut | ||||||||||||
| 16 | |||||||||||||
| 17 | 7 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 7 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | 7 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 7 | extends 'Business::GoCardless::Resource'; | |||||||||||
| 22 | |||||||||||||
| 23 | 7 | ▶ | use Business::GoCardless::BillingRequestFlow; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 7 | ▶ | use Business::GoCardless::Institution; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | |||||||||||||
| 26 | =head1 ATTRIBUTES | ||||||||||||
| 27 | |||||||||||||
| 28 | actions | ||||||||||||
| 29 | auto_fulfil | ||||||||||||
| 30 | created_at | ||||||||||||
| 31 | creditor_address | ||||||||||||
| 32 | creditor_identifier | ||||||||||||
| 33 | creditor_name | ||||||||||||
| 34 | creditor_scheme_identifier | ||||||||||||
| 35 | experimentation | ||||||||||||
| 36 | fallback_enabled | ||||||||||||
| 37 | fallback_occurred | ||||||||||||
| 38 | id | ||||||||||||
| 39 | instalment_schedule_request | ||||||||||||
| 40 | links | ||||||||||||
| 41 | mandate_request | ||||||||||||
| 42 | metadata | ||||||||||||
| 43 | payment_context_code | ||||||||||||
| 44 | payment_purpose_code | ||||||||||||
| 45 | payment_request | ||||||||||||
| 46 | purpose_code | ||||||||||||
| 47 | resources | ||||||||||||
| 48 | sign_flow_url | ||||||||||||
| 49 | status | ||||||||||||
| 50 | subscription_request | ||||||||||||
| 51 | |||||||||||||
| 52 | =cut | ||||||||||||
| 53 | |||||||||||||
| 54 | 7 | has [ qw/ | |||||||||||
| 55 | actions | ||||||||||||
| 56 | auto_fulfil | ||||||||||||
| 57 | created_at | ||||||||||||
| 58 | creditor_address | ||||||||||||
| 59 | creditor_identifier | ||||||||||||
| 60 | creditor_name | ||||||||||||
| 61 | creditor_scheme_identifier | ||||||||||||
| 62 | experimentation | ||||||||||||
| 63 | fallback_enabled | ||||||||||||
| 64 | fallback_occurred | ||||||||||||
| 65 | id | ||||||||||||
| 66 | instalment_schedule_request | ||||||||||||
| 67 | links | ||||||||||||
| 68 | mandate_request | ||||||||||||
| 69 | metadata | ||||||||||||
| 70 | payment_context_code | ||||||||||||
| 71 | payment_purpose_code | ||||||||||||
| 72 | payment_request | ||||||||||||
| 73 | purpose_code | ||||||||||||
| 74 | resources | ||||||||||||
| 75 | sign_flow_url | ||||||||||||
| 76 | status | ||||||||||||
| 77 | subscription_request | ||||||||||||
| 78 | / ] => ( | ||||||||||||
| 79 | is => 'rw', | ||||||||||||
| 80 | ); | ||||||||||||
| 81 | |||||||||||||
| 82 | =head1 Operations on a billing request | ||||||||||||
| 83 | |||||||||||||
| 84 | =head2 collect_customer_details | ||||||||||||
| 85 | |||||||||||||
| 86 | Collect the customer details (if not already known), takes C<customer> and | ||||||||||||
| 87 | C<customer_billing_detail> hashrefs: | ||||||||||||
| 88 | |||||||||||||
| 89 | $BillingRequest->collect_customer_details( | ||||||||||||
| 90 | customer => { | ||||||||||||
| 91 | email => 'lee@example.com', | ||||||||||||
| 92 | given_name => 'Lee', | ||||||||||||
| 93 | family_name => 'Johnson', | ||||||||||||
| 94 | }, | ||||||||||||
| 95 | customer_billing_detail => { | ||||||||||||
| 96 | address_line1 => '1 Test Street', | ||||||||||||
| 97 | city => 'London', | ||||||||||||
| 98 | postal_code => 'E1 1AA', | ||||||||||||
| 99 | country_code => 'GB', | ||||||||||||
| 100 | }, | ||||||||||||
| 101 | ); | ||||||||||||
| 102 | |||||||||||||
| 103 | =head2 collect_bank_account | ||||||||||||
| 104 | |||||||||||||
| 105 | Collect the customer's bank account details: | ||||||||||||
| 106 | |||||||||||||
| 107 | $BillingRequest->collect_bank_account( | ||||||||||||
| 108 | account_holder_name => 'Lee Johnson', | ||||||||||||
| 109 | account_number => '55779911', | ||||||||||||
| 110 | branch_code => '200000', | ||||||||||||
| 111 | country_code => 'GB', | ||||||||||||
| 112 | ); | ||||||||||||
| 113 | |||||||||||||
| 114 | =head2 confirm_payer_details | ||||||||||||
| 115 | |||||||||||||
| 116 | Confirm the payer details have been collected (required for mandate requests): | ||||||||||||
| 117 | |||||||||||||
| 118 | $BillingRequest->confirm_payer_details; | ||||||||||||
| 119 | |||||||||||||
| 120 | =head2 fulfil | ||||||||||||
| 121 | |||||||||||||
| 122 | Fulfil the billing request once it is C<ready_to_fulfil>, creating the payment | ||||||||||||
| 123 | and/or mandate: | ||||||||||||
| 124 | |||||||||||||
| 125 | $BillingRequest->fulfil; | ||||||||||||
| 126 | |||||||||||||
| 127 | =head2 cancel | ||||||||||||
| 128 | |||||||||||||
| 129 | Cancel the billing request, causing any billing request flows to expire: | ||||||||||||
| 130 | |||||||||||||
| 131 | $BillingRequest->cancel; | ||||||||||||
| 132 | |||||||||||||
| 133 | =head2 notify | ||||||||||||
| 134 | |||||||||||||
| 135 | Notify the customer about the billing request: | ||||||||||||
| 136 | |||||||||||||
| 137 | $BillingRequest->notify( notification_type => 'email' ); | ||||||||||||
| 138 | |||||||||||||
| 139 | =head2 fallback | ||||||||||||
| 140 | |||||||||||||
| 141 | Trigger a fallback from Pay by Bank to direct debit (when C<fallback_enabled>): | ||||||||||||
| 142 | |||||||||||||
| 143 | $BillingRequest->fallback; | ||||||||||||
| 144 | |||||||||||||
| 145 | =head2 choose_currency | ||||||||||||
| 146 | |||||||||||||
| 147 | Choose the currency of the billing request (when it supports multiple): | ||||||||||||
| 148 | |||||||||||||
| 149 | $BillingRequest->choose_currency( currency => 'EUR' ); | ||||||||||||
| 150 | |||||||||||||
| 151 | =head2 select_institution | ||||||||||||
| 152 | |||||||||||||
| 153 | Select the customer's bank (for Pay by Bank): | ||||||||||||
| 154 | |||||||||||||
| 155 | $BillingRequest->select_institution( | ||||||||||||
| 156 | institution => 'monzo', | ||||||||||||
| 157 | country_code => 'GB', | ||||||||||||
| 158 | ); | ||||||||||||
| 159 | |||||||||||||
| 160 | =cut | ||||||||||||
| 161 | |||||||||||||
| 162 | 2 | ▶ | sub collect_customer_details { shift->_action( 'collect_customer_details',@_ ); } | ||||||||||
|
Subroutine
collect_customer_details: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 163 | 2 | ▶ | sub collect_bank_account { shift->_action( 'collect_bank_account',@_ ); } | ||||||||||
|
Subroutine
collect_bank_account: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 164 | 2 | ▶ | sub confirm_payer_details { shift->_action( 'confirm_payer_details',@_ ); } | ||||||||||
|
Subroutine
confirm_payer_details: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 165 | 2 | ▶ | sub fulfil { shift->_action( 'fulfil',@_ ); } | ||||||||||
|
Subroutine
fulfil: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 166 | 2 | ▶ | sub cancel { shift->_action( 'cancel',@_ ); } | ||||||||||
|
Subroutine
cancel: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 167 | 2 | ▶ | sub notify { shift->_action( 'notify',@_ ); } | ||||||||||
|
Subroutine
notify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 168 | 2 | ▶ | sub fallback { shift->_action( 'fallback',@_ ); } | ||||||||||
|
Subroutine
fallback: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 169 | 2 | ▶ | sub choose_currency { shift->_action( 'choose_currency',@_ ); } | ||||||||||
|
Subroutine
choose_currency: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 170 | 2 | ▶ | sub select_institution { shift->_action( 'select_institution',@_ ); } | ||||||||||
|
Subroutine
select_institution: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 171 | |||||||||||||
| 172 | =head1 Status checks on a billing request | ||||||||||||
| 173 | |||||||||||||
| 174 | pending | ||||||||||||
| 175 | ready_to_fulfil | ||||||||||||
| 176 | fulfilling | ||||||||||||
| 177 | fulfilled | ||||||||||||
| 178 | cancelled | ||||||||||||
| 179 | |||||||||||||
| 180 | if ( $BillingRequest->pending ) { | ||||||||||||
| 181 | ... | ||||||||||||
| 182 | } | ||||||||||||
| 183 | |||||||||||||
| 184 | =cut | ||||||||||||
| 185 | |||||||||||||
| 186 | 6 | ▶ | sub pending { return ( shift->status // '' ) eq 'pending' } | ||||||||||
|
Subroutine
pending: called CC=2 SCAR=6.9
Pod
undocumented
Condition100%2/2
(shift())->status // ""
MC/DC100%1/1
(shift())->status // ""
(shift())->status
Truth table100%2/2
A
A= (shift())->status
| |||||||||||||
| 187 | 5 | ▶ | sub ready_to_fulfil { return ( shift->status // '' ) eq 'ready_to_fulfil' } | ||||||||||
|
Subroutine
ready_to_fulfil: called CC=2 SCAR=7.6
Pod
undocumented
Condition50%1/2
(shift())->status // ""
MC/DC0%0/1
(shift())->status // ""
(shift())->status
Truth table50%1/2
A
A= (shift())->status
| |||||||||||||
| 188 | 5 | ▶ | sub fulfilling { return ( shift->status // '' ) eq 'fulfilling' } | ||||||||||
|
Subroutine
fulfilling: called CC=2 SCAR=7.6
Pod
undocumented
Condition50%1/2
(shift())->status // ""
MC/DC0%0/1
(shift())->status // ""
(shift())->status
Truth table50%1/2
A
A= (shift())->status
| |||||||||||||
| 189 | 5 | ▶ | sub fulfilled { return ( shift->status // '' ) eq 'fulfilled' } | ||||||||||
|
Subroutine
fulfilled: called CC=2 SCAR=7.6
Pod
undocumented
Condition50%1/2
(shift())->status // ""
MC/DC0%0/1
(shift())->status // ""
(shift())->status
Truth table50%1/2
A
A= (shift())->status
| |||||||||||||
| 190 | 5 | ▶ | sub cancelled { return ( shift->status // '' ) eq 'cancelled' } | ||||||||||
|
Subroutine
cancelled: called CC=2 SCAR=7.6
Pod
undocumented
Condition50%1/2
(shift())->status // ""
MC/DC0%0/1
(shift())->status // ""
(shift())->status
Truth table50%1/2
A
A= (shift())->status
| |||||||||||||
| 191 | |||||||||||||
| 192 | =head1 Flows and institutions | ||||||||||||
| 193 | |||||||||||||
| 194 | =head2 create_flow | ||||||||||||
| 195 | |||||||||||||
| 196 | Create a L<Business::GoCardless::BillingRequestFlow> for the billing request, | ||||||||||||
| 197 | which provides the C<authorisation_url> to send the customer to: | ||||||||||||
| 198 | |||||||||||||
| 199 | my $Flow = $BillingRequest->create_flow( | ||||||||||||
| 200 | redirect_uri => 'https://example.com/complete', | ||||||||||||
| 201 | exit_uri => 'https://example.com/exit', | ||||||||||||
| 202 | ); | ||||||||||||
| 203 | |||||||||||||
| 204 | my $url = $Flow->authorisation_url; | ||||||||||||
| 205 | |||||||||||||
| 206 | =head2 institutions | ||||||||||||
| 207 | |||||||||||||
| 208 | Get a list of L<Business::GoCardless::Institution> objects for the billing | ||||||||||||
| 209 | request, for use with L</select_institution>: | ||||||||||||
| 210 | |||||||||||||
| 211 | my @institutions = $BillingRequest->institutions( country_code => 'GB' ); | ||||||||||||
| 212 | |||||||||||||
| 213 | =head1 Links | ||||||||||||
| 214 | |||||||||||||
| 215 | Shortcut methods to get the IDs of the resources created by the billing request: | ||||||||||||
| 216 | |||||||||||||
| 217 | customer_id | ||||||||||||
| 218 | mandate_id | ||||||||||||
| 219 | payment_id | ||||||||||||
| 220 | subscription_id | ||||||||||||
| 221 | instalment_schedule_id | ||||||||||||
| 222 | |||||||||||||
| 223 | =cut | ||||||||||||
| 224 | |||||||||||||
| 225 | 2 | ▶ | sub create_flow { | ||||||||||
|
Subroutine
create_flow: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 226 | 2 | my ( $self,%params ) = @_; | |||||||||||
| 227 | |||||||||||||
| 228 | my $data = $self->client->api_post( | ||||||||||||
| 229 | '/billing_request_flows', | ||||||||||||
| 230 | { billing_request_flows => { | ||||||||||||
| 231 | %params, | ||||||||||||
| 232 | links => { | ||||||||||||
| 233 | 2 | ▶ | %{ $params{links} // {} }, | ||||||||||
|
Condition100%2/2
$params{"links"} // {}
MC/DC100%1/1
$params{"links"} // {}
$params{"links"}
Truth table100%2/2
A
A= $params{"links"}
| |||||||||||||
| 234 | billing_request => $self->id, | ||||||||||||
| 235 | }, | ||||||||||||
| 236 | } }, | ||||||||||||
| 237 | ); | ||||||||||||
| 238 | |||||||||||||
| 239 | return Business::GoCardless::BillingRequestFlow->new( | ||||||||||||
| 240 | client => $self->client, | ||||||||||||
| 241 | 2 | %{ $data->{billing_request_flows} }, | |||||||||||
| 242 | ); | ||||||||||||
| 243 | } | ||||||||||||
| 244 | |||||||||||||
| 245 | 3 | ▶ | sub institutions { | ||||||||||
|
Subroutine
institutions: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 246 | 3 | my ( $self,%filters ) = @_; | |||||||||||
| 247 | |||||||||||||
| 248 | 3 | my $uri = sprintf( $self->endpoint,$self->id ) . '/institutions'; | |||||||||||
| 249 | 3 | ▶ | $uri .= '?' . $self->client->normalize_params( \%filters ) if keys %filters; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 250 | |||||||||||||
| 251 | 3 | my $data = $self->client->api_get( $uri ); | |||||||||||
| 252 | |||||||||||||
| 253 | return map { | ||||||||||||
| 254 | 3 | Business::GoCardless::Institution->new( client => $self->client,%{ $_ } ) | |||||||||||
| 255 | 3 | ▶ | } @{ $data->{institutions} // [] }; | ||||||||||
|
Condition50%1/2
$data->{"institutions"} // []
MC/DC0%0/1
$data->{"institutions"} // []
$data->{"institutions"}
Truth table50%1/2
A
A= $data->{"institutions"}
| |||||||||||||
| 256 | } | ||||||||||||
| 257 | |||||||||||||
| 258 | 3 | ▶ | sub customer_id { return shift->_link( 'customer' ) } | ||||||||||
|
Subroutine
customer_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 259 | 2 | ▶ | sub mandate_id { return shift->_link( 'mandate_request_mandate' ) } | ||||||||||
|
Subroutine
mandate_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 260 | 2 | ▶ | sub payment_id { return shift->_link( 'payment_request_payment' ) } | ||||||||||
|
Subroutine
payment_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 261 | 2 | ▶ | sub subscription_id { return shift->_link( 'subscription_request_subscription' ) } | ||||||||||
|
Subroutine
subscription_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 262 | 2 | ▶ | sub instalment_schedule_id { return shift->_link( 'instalment_schedule_request_instalment_schedule' ) } | ||||||||||
|
Subroutine
instalment_schedule_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 263 | |||||||||||||
| 264 | 11 | ▶ | sub _link { | ||||||||||
|
Subroutine
_link: called CC=2 SCAR=6.9
| |||||||||||||
| 265 | 11 | my ( $self,$link ) = @_; | |||||||||||
| 266 | 11 | ▶ | return ( $self->links // {} )->{$link}; | ||||||||||
|
Condition100%2/2
$self->links // {}
MC/DC100%1/1
$self->links // {}
$self->links
Truth table100%2/2
A
A= $self->links
| |||||||||||||
| 267 | } | ||||||||||||
| 268 | |||||||||||||
| 269 | =head1 AUTHOR | ||||||||||||
| 270 | |||||||||||||
| 271 | Lee Johnson - C<lee@payprop.com> | ||||||||||||
| 272 | |||||||||||||
| 273 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||
| 274 | the same terms as Perl itself. If you would like to contribute documentation, | ||||||||||||
| 275 | features, bug fixes, or anything else then please raise an issue / pull request: | ||||||||||||
| 276 | |||||||||||||
| 277 | https://github.com/payprop/business-gocardless | ||||||||||||
| 278 | |||||||||||||
| 279 | =cut | ||||||||||||
| 280 | |||||||||||||
| 281 | 7 | 1; | |||||||||||
| 282 | |||||||||||||
| 283 | # vim: ts=4:sw=4:et | ||||||||||||