GoCardless/Webhook/Event.pm

filter: Statementstmt 92.1% 70 / 76 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 86.2% 25 / 29 Podpod 84.6% 11 / 13 totaltotal 88.5% 108 / 122 CC 3 SCAR 2.9
CC
3
Cov
90%
resources
3.2
is_billing_request
2.0
is_instalment_schedule
2.0
CRAP 1.3
« GoCardless/Mandate.pm ↑ Summary GoCardless/CreditorBankAccount.pm »
1 package Business::GoCardless::Webhook::Event;
2  
3 =head1 NAME
4  
5 Business::GoCardless::Webhook::Event
6  
7 =head1 DESCRIPTION
8  
9 A class for gocardless webhook events, extends L<Business::GoCardless::Resource>.
10 For more details see the gocardless API documentation specific to webhooks:
11 https://developer.gocardless.com/api-reference/#appendix-webhooks
12  
13 =cut
14  
15 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 extends 'Business::GoCardless::Resource';
20 6 with 'Business::GoCardless::Utils';
21  
22 6 ▶use Business::GoCardless::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶use Business::GoCardless::Payment;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶use Business::GoCardless::Subscription;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶use Business::GoCardless::Mandate;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶use Business::GoCardless::Payout;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use Business::GoCardless::Refund;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 ▶use Business::GoCardless::Customer;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 6 ▶use Business::GoCardless::BillingRequest;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶use Business::GoCardless::Creditor;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 ▶use Business::GoCardless::InstalmentSchedule;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 6 ▶use Business::GoCardless::OutboundPayment;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 6 ▶use Business::GoCardless::SchemeIdentifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 ▶use Business::GoCardless::PaymentAccountTransaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 =head1 ATTRIBUTES
37  
38 id
39 created_at
40 action
41 resource_type
42 links
43 details
44 metadata
45 resource_metadata
46 customer_notifications
47 source
48  
49 This class is used for events in webhooks, and for events from the events API
50 endpoints (see L<Business::GoCardless::Pro/events>).
51  
52 =cut
53  
54 6 has [ qw/
55 id
56 created_at
57 action
58 resource_type
59 links
60 / ] => (
61 is => 'ro',
62 required => 1,
63 );
64  
65 6 has [ qw/
66 details
67 metadata
68 resource_metadata
69 customer_notifications
70 source
71 / ] => (
72 is => 'rw',
73 required => 0,
74 );
75  
76 =head2 resources
77  
78 Returns an array of resource objects (Payment, Subscription, etc) that are present
79 in the event allowing you to do things with them or update your own data:
80  
81 if ( $Event->is_payment ) {
82  
83 foreach my $Payment ( $Event->resources ) {
84  
85 if ( $Event->action eq 'paid_out' ) {
86 ...
87 }
88 }
89 }
90  
91 =cut
92  
93 10 ▶sub resources {
Subroutine resources: called CC=3 SCAR=11.5
Pod documented
94 10 my ( $self ) = @_;
95  
96 10 ▶ return if ! $self->resource_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->resource_type 0 10 10
97  
98 10 my $mapping = {
99 payments => 'payment',
100 payouts => 'payout',
101 subscriptions => 'subscription',
102 mandates => 'mandate',
103 refunds => 'refund',
104 customers => 'customer',
105 billing_requests => 'billing_request',
106 creditors => 'creditor',
107 instalment_schedules => 'instalment_schedule',
108 outbound_payments => 'outbound_payment',
109 scheme_identifiers => 'scheme_identifier',
110 payment_account_transactions => 'payment_account_transaction',
111 };
112  
113 10 my $resource = $mapping->{ $self->resource_type };
114  
115 10 ▶ $resource || Business::GoCardless::Exception->throw({
Branch: 1 branch
BranchTrueFalseTotal
$resource or "Business::GoCardless::Exception"->throw({"message", "Unknown resource_type (@{[$self->resource_type];}) in ->resources"}) 10 0 10
116 0 message => "Unknown resource_type (@{[$self->resource_type]}) in ->resources",
117 });
118  
119 10 my $class_suffix = ucfirst( $resource );
120 0 $class_suffix =~ s/_([A-z])/uc($1)/ge;
121 10 my $class = "Business::GoCardless::$class_suffix";
122  
123 return $class->new(
124 client => $self->client,
125 10 id => $self->links->{ $resource },
126 links => $self->links,
127 );
128 }
129  
130 =pod
131  
132 Shortcut methods to get the type of data in the event, and thus the type of
133 objects that will be returned by the call to ->resources
134  
135 =head2 is_payment
136  
137 True if the event is for payments
138  
139 =head2 is_subscription
140  
141 True if the event is for subscriptions
142  
143 =head2 is_payout
144  
145 True if the event is for payouts
146  
147 =head2 is_mandate
148  
149 True if the event is for mandates
150  
151 =head2 is_refund
152  
153 True if the event is for refunds
154  
155 =head2 is_customer
156  
157 True if the event is for customers
158  
159 =head2 is_billing_request
160  
161 True if the event is for billing requests
162  
163 =head2 is_instalment_schedule
164  
165 True if the event is for instalment schedules
166  
167 =head2 is_creditor
168  
169 True if the event is for creditors
170  
171 =head2 is_outbound_payment
172  
173 True if the event is for outbound payments
174  
175 =cut
176  
177 2 ▶sub is_payment { return shift->resource_type eq 'payments' }
Subroutine is_payment: called CC=1 SCAR=0.0
Pod documented
178 1 ▶sub is_subscription { return shift->resource_type eq 'subscriptions' }
Subroutine is_subscription: called CC=1 SCAR=0.0
Pod documented
179 1 ▶sub is_payout { return shift->resource_type eq 'payouts' }
Subroutine is_payout: called CC=1 SCAR=0.0
Pod documented
180 2 ▶sub is_mandate { return shift->resource_type eq 'mandates' }
Subroutine is_mandate: called CC=1 SCAR=0.0
Pod documented
181 1 ▶sub is_refund { return shift->resource_type eq 'refunds' }
Subroutine is_refund: called CC=1 SCAR=0.0
Pod documented
182 2 ▶sub is_customer { return shift->resource_type eq 'customers' }
Subroutine is_customer: called CC=1 SCAR=0.0
Pod documented
183  
184 0 ▶sub is_billing_request { return shift->resource_type eq 'billing_requests' }
Subroutine is_billing_request: not called CC=1 SCAR=6.9
Pod documented
185 0 ▶sub is_instalment_schedule { return shift->resource_type eq 'instalment_schedules' }
Subroutine is_instalment_schedule: not called CC=1 SCAR=6.9
Pod documented
186 0 ▶sub is_creditor { return shift->resource_type eq 'creditors' }
Subroutine is_creditor: not called CC=1 SCAR=6.9
Pod documented
187 0 ▶sub is_outbound_payment { return shift->resource_type eq 'outbound_payments' }
Subroutine is_outbound_payment: not called CC=1 SCAR=6.9
Pod documented
188  
189 # BACK COMPATIBILITY
190 1 ▶sub is_pre_authorization { return shift->is_mandate }
Subroutine is_pre_authorization: called CC=1 SCAR=0.0
Pod undocumented
191 1 ▶sub is_bill { return shift->is_payment }
Subroutine is_bill: called CC=1 SCAR=0.0
Pod undocumented
192  
193 6 1;
194  
195 # vim: ts=4:sw=4:et
« GoCardless/Mandate.pm ↑ Summary GoCardless/CreditorBankAccount.pm »