lib/WebService/Braintree/_/WebhookNotification.pm

filter: Statementstmt 91.8% 45 / 49 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 75.0% 3 / 4 totaltotal 88.5% 62 / 70 CC 6 SCAR 8.3
CC
6
Cov
89%
BUILD
4.0
errors
2.3
message
2.3
CRAP 2.3
« lib/WebService/Braintree/_/Transaction/DisbursementDetail.pm ↑ Summary lib/WebService/Braintree/DocumentUploadGateway.pm »
1 # vim: sw=4 ts=4 ft=perl
2  
3 package WebService::Braintree::_::WebhookNotification;
4 22 $WebService::Braintree::_::WebhookNotification::VERSION = '1.7';
5 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 WebService::Braintree::_::WebhookNotification
11  
12 =head1 PURPOSE
13  
14 This class represents a webhook notification.
15  
16 This class will only be created as part of a L<response|WebService::Braintree::Result> or L<error response|WebService::Braintree::ErrorResult>.
17  
18 =cut
19  
20 22 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 22 ▶use MooX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 22 extends 'WebService::Braintree::_';
24  
25 22 ▶use WebService::Braintree::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
26 ErrorResult
27 HashInflator
28 AccountUpdaterDailyReport
29 ConnectedMerchantPayPalStatusChanged
30 ConnectedMerchantStatusTransitioned
31 Disbursement
32 Dispute
33 GrantedPaymentInstrumentUpdate
34 IdealPayment
35 MerchantAccount
36 Subscription
37 Transaction
38 22 );
39  
40 =head1 ATTRIBUTES
41  
42 =cut
43  
44 =head2 account_updater_daily_report()
45  
46 This returns the webhook notification's account-updater daily report.
47  
48 =cut
49  
50 22 has account_updater_daily_report => (
51 is => 'rw',
52 );
53  
54 =head2 api_error_response()
55  
56 This returns the webhook notification's API error response. This will be an object of type
57 L<WebService::Braintree::ErrorResult/>.
58  
59 C<< error_result() >> is an alias for this attribute.
60  
61 =cut
62  
63 22 has api_error_response => (
64 is => 'rw',
65 isa => ErrorResult,
66 coerce => 1,
67 alias => 'error_result',
68 );
69  
70 =head2 connected_merchant_paypal_status_changed()
71  
72 This returns the webhook notification's status change of the connected merchant. This will be an object of type
73 L<WebService::Braintree::_::ConnectedMerchantPayPalStatusChanged/>.
74  
75 =cut
76  
77 22 has connected_merchant_paypal_status_changed => (
78 is => 'rw',
79 isa => ConnectedMerchantPayPalStatusChanged,
80 coerce => 1,
81 );
82  
83 =head2 connected_merchant_status_transmitted()
84  
85 This returns the webhook notification's status transition of connected merchant. This will be an object of type
86 L<WebService::Braintree::_::ConnectedMerchantstatusTransitioned/>.
87  
88 =cut
89  
90 22 has connected_merchant_status_transitioned => (
91 is => 'rw',
92 isa => ConnectedMerchantStatusTransitioned,
93 coerce => 1,
94 );
95  
96 =head2 disbursement()
97  
98 This returns the webhook notification's disbursement. This will be an object of type
99 L<WebService::Braintree::_::Disbursement/>.
100  
101 =cut
102  
103 22 has disbursement => (
104 is => 'rw',
105 isa => Disbursement,
106 coerce => 1,
107 );
108  
109 =head2 dispute()
110  
111 This returns the webhook notification's dispute. This will be an object of type
112 L<WebService::Braintree::_::Dispute/>.
113  
114 =cut
115  
116 22 has dispute => (
117 is => 'rw',
118 isa => Dispute,
119 coerce => 1,
120 );
121  
122 =head2 granted_payment_instrument_type()
123  
124 This returns the webhook notification's granted payment instrument type. This will be an object of type
125 L<WebService::Braintree::_::GrantedPaymentInstrumentUpdate/>.
126  
127 =cut
128  
129 22 has granted_payment_instrument_update => (
130 is => 'rw',
131 isa => GrantedPaymentInstrumentUpdate,
132 coerce => 1,
133 );
134  
135 =head2 ideal_payment()
136  
137 This returns the webhook notification's Ideal payment. This will be an object of type
138 L<WebService::Braintree::_::IdealPayment/>.
139  
140 =cut
141  
142 22 has ideal_payment => (
143 is => 'rw',
144 isa => IdealPayment,
145 coerce => 1,
146 );
147  
148 =head2 kind()
149  
150 This returns the webhook notification's kind.
151  
152 =cut
153  
154 22 has kind => (
155 is => 'rw',
156 );
157  
158 =head2 merchant_account()
159  
160 This returns the webhook notification's merchant account. This will be an object of type
161 L<WebService::Braintree::_::MerchantAccount/>.
162  
163 =cut
164  
165 22 has merchant_account => (
166 is => 'rw',
167 isa => MerchantAccount,
168 coerce => 1,
169 );
170  
171 =head2 partner_merchant()
172  
173 This returns the webhook notification's partner merchant. This will be an object of type
174 L<Hash::Inflator/>.
175  
176 =cut
177  
178 22 has partner_merchant => (
179 is => 'rw',
180 isa => HashInflator,
181 coerce => 1,
182 );
183  
184 =head2 subscription()
185  
186 This returns the webhook notification's subscription. This will be an object of type
187 L<WebService::Braintree::_::Subscription/>.
188  
189 =cut
190  
191 22 has subscription => (
192 is => 'rw',
193 isa => Subscription,
194 coerce => 1,
195 );
196  
197 =head2 subject()
198  
199 This returns the webhook notification's subject.
200  
201 This is not meant for client usage.
202  
203 =cut
204  
205 22 has subject => (
206 is => 'rw',
207 );
208  
209 =head2 timestamp()
210  
211 This returns the webhook notification's timestamp.
212  
213 =cut
214  
215 22 has timestamp => (
216 is => 'rw',
217 );
218  
219 =head2 transaction()
220  
221 This returns the webhook notification's transaction. This will be an object of type
222 L<WebService::Braintree::_::Transaction/>.
223  
224 =cut
225  
226 22 has transaction => (
227 is => 'rw',
228 isa => Transaction,
229 coerce => 1,
230 );
231  
232 # WebhookNotification receives a single parameter called 'subject'.
233 # Everything we care about is on that. So, let the parent's BUILD set
234 # the subject(), then we assign the rest of the attributes from there.
235 #
236 # Note: This means the attributes need to be rw instead of ro.
237 12 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
238 12 my $self = shift;
239  
240 12 my $wrapper = $self->subject;
241 12 ▶ if (exists $wrapper->{api_error_response}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $wrapper->{"api_error_response"}) 1 11 12
242 1 $self->api_error_response($wrapper->{api_error_response});
243 1 $wrapper = $wrapper->{api_error_response};
244 }
245  
246 # Yes, this is a duplicate list of the attributes and could be
247 # retrieved with $self->meta->get_all_attributes(). But, we use
248 # Moo, not Moose, so there's no $self->meta.
249 12 foreach my $attr (qw(
250 account_updater_daily_report
251 api_error_response
252 connected_merchant_paypal_status_changed
253 connected_merchant_status_transitioned
254 disbursement
255 dispute
256 granted_payment_instrument_update
257 ideal_payment
258 kind
259 merchant_account
260 partner_merchant
261 subscription
262 subject
263 timestamp
264 transaction
265 )) {
266 180 ▶ next unless exists $wrapper->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $wrapper->{$attr} 168 12 180
267  
268 12 $self->$attr($wrapper->{$attr});
269 }
270 }
271  
272 =head1 METHODS
273  
274 =cut
275  
276 # TODO: Delegate merchant_account() to error_result() if it's set.
277  
278 =head2 errors
279  
280 This returns the errors if this object has errors.
281  
282 =cut
283  
284 1 ▶sub errors {
Subroutine errors: called CC=2 SCAR=8.1
Pod documented
285 1 my $self = shift;
286 1 ▶ return $self->error_result->errors if $self->error_result;
Branch: 1 branch
BranchTrueFalseTotal
if $self->error_result 1 0 1
287 0 return;
288 }
289  
290 =head2 message
291  
292 This returns the error's message if this object has errors.
293  
294 =cut
295  
296 1 ▶sub message {
Subroutine message: called CC=2 SCAR=8.1
Pod documented
297 1 my $self = shift;
298 1 ▶ return $self->error_result->message if $self->error_result;
Branch: 1 branch
BranchTrueFalseTotal
if $self->error_result 1 0 1
299 0 return;
300 }
301  
302 =head2 is_check
303  
304 This returns true if this is a check.
305  
306 =cut
307  
308 0 ▶sub is_check {
Subroutine is_check: not called CC=1 SCAR=6.9
Pod documented
309 0 my $self = shift;
310 0 return !!$self->subject->{check};
311 }
312  
313 22 __PACKAGE__->meta->make_immutable;
314  
315 22 1;
316 __END__
« lib/WebService/Braintree/_/Transaction/DisbursementDetail.pm ↑ Summary lib/WebService/Braintree/DocumentUploadGateway.pm »