| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::Braintree::WebhookNotification; | 
| 2 |  |  |  |  |  |  | $WebService::Braintree::WebhookNotification::VERSION = '0.93'; | 
| 3 |  |  |  |  |  |  | =head1 NAME | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | WebService::Braintree::WebhookNotification | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 PURPOSE | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | This class parses and verifies webhook notifications. | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 NOTES | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Unlike all other classes, this class does B<NOT> interact with a REST API. | 
| 14 |  |  |  |  |  |  | Instead, this takes data you provide it and either parses it into a usable | 
| 15 |  |  |  |  |  |  | object or provides a verification of it. | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =cut | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 1 |  |  | 1 |  | 316 | use WebService::Braintree::WebhookNotification::Kind; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 1 |  |  | 1 |  | 5 | use Moose; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 22 |  |  |  |  |  |  | extends 'WebService::Braintree::ResultObject'; | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =head1 CLASS METHODS | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =head2 parse() | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | This takes a signature and a payload and returns a parsing of the notification | 
| 29 |  |  |  |  |  |  | within that payload. The payload is validated against the signature before | 
| 30 |  |  |  |  |  |  | parsing. | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | The return is an object of this class. | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =cut | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub parse { | 
| 37 | 0 |  |  | 0 | 1 |  | my ($class, $signature, $payload) = @_; | 
| 38 | 0 |  |  |  |  |  | $class->gateway->webhook_notification->parse($signature, $payload); | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | =head2 verify() | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | This takes a challenge and returns a proper response. | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | =cut | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub verify { | 
| 48 | 0 |  |  | 0 | 1 |  | my ($class, $challenge) = @_; | 
| 49 | 0 |  |  |  |  |  | $class->gateway->webhook_notification->verify($challenge); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub gateway { | 
| 53 | 0 |  |  | 0 | 0 |  | return WebService::Braintree->configuration->gateway; | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head1 OBJECT METHODS | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | In addition to the methods provided by the keys returned from Braintree, this | 
| 59 |  |  |  |  |  |  | class provides the following methods: | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head2 subscription() | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | This returns the subscription associated with this notification (if any). This | 
| 64 |  |  |  |  |  |  | will be an object of type L<WebService::Braintree::Subscription/>. | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =cut | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | has subscription => (is => 'rw'); | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =head2 merchant_account() | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | This returns the merchant account associated with this notification (if any). | 
| 73 |  |  |  |  |  |  | This will be an object of type L<WebService::Braintree::MerchantAccount/>. | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =cut | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | has merchant_account => (is => 'rw'); | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =head2 disbursement() | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | This returns the disbursement associated with this notification (if any). This | 
| 82 |  |  |  |  |  |  | will be an object of type L<WebService::Braintree::Disbursement/>. | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | =cut | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | has disbursement => (is => 'rw'); | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =head2 transaction() | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | This returns the stransaction associated with this notification (if any). This | 
| 91 |  |  |  |  |  |  | will be an object of type L<WebService::Braintree::Transaction/>. | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =cut | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | has transaction => (is => 'rw'); | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =head2 partner_merchant() | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | This returns the partner merchant associated with this notification (if any). | 
| 100 |  |  |  |  |  |  | This will be an object of type L<WebService::Braintree::PartnerMerchant/>. | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =cut | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | has partner_merchant => (is => 'rw'); | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =head2 dispute() | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | This returns the dispute associated with this notification (if any). This | 
| 109 |  |  |  |  |  |  | will be an object of type L<WebService::Braintree::Dispute/>. | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =cut | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | has dispute => (is => 'rw'); | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head2 errors() | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | This returns the errors associated with this notification (if any). This | 
| 118 |  |  |  |  |  |  | will be an object of type L<WebService::Braintree::ValidationErrorCollection/>. | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =cut | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | has errors => (is => 'rw'); | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | =head2 message() | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | This returns the message associated with this notification (if any). This will | 
| 127 |  |  |  |  |  |  | be a string. | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =cut | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | has message => (is => 'rw'); | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | sub BUILD { | 
| 135 | 0 |  |  | 0 | 0 |  | my ($self, $attributes) = @_; | 
| 136 |  |  |  |  |  |  |  | 
| 137 | 0 |  |  |  |  |  | my $wrapper_node = $attributes->{subject}; | 
| 138 |  |  |  |  |  |  |  | 
| 139 | 0 | 0 |  |  |  |  | if (ref($wrapper_node->{api_error_response}) eq 'HASH') { | 
| 140 | 0 |  |  |  |  |  | $wrapper_node = $wrapper_node->{api_error_response}; | 
| 141 |  |  |  |  |  |  | } | 
| 142 |  |  |  |  |  |  |  | 
| 143 | 0 | 0 |  |  |  |  | if (ref($wrapper_node->{subscription}) eq 'HASH') { | 
| 144 |  |  |  |  |  |  |  | 
| 145 | 0 |  |  |  |  |  | $self->subscription(WebService::Braintree::Subscription->new($wrapper_node->{subscription})); | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  |  | 
| 148 | 0 | 0 |  |  |  |  | if (ref($wrapper_node->{merchant_account}) eq 'HASH') { | 
| 149 |  |  |  |  |  |  |  | 
| 150 | 0 |  |  |  |  |  | $self->merchant_account(WebService::Braintree::MerchantAccount->new($wrapper_node->{merchant_account})); | 
| 151 |  |  |  |  |  |  | } | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 0 | 0 |  |  |  |  | if (ref($wrapper_node->{disbursement}) eq 'HASH') { | 
| 154 |  |  |  |  |  |  |  | 
| 155 | 0 |  |  |  |  |  | $self->disbursement(WebService::Braintree::Disbursement->new($wrapper_node->{disbursement})); | 
| 156 |  |  |  |  |  |  | } | 
| 157 |  |  |  |  |  |  |  | 
| 158 | 0 | 0 |  |  |  |  | if (ref($wrapper_node->{transaction}) eq 'HASH') { | 
| 159 |  |  |  |  |  |  |  | 
| 160 | 0 |  |  |  |  |  | $self->transaction(WebService::Braintree::Transaction->new($wrapper_node->{transaction})); | 
| 161 |  |  |  |  |  |  | } | 
| 162 |  |  |  |  |  |  |  | 
| 163 | 0 | 0 |  |  |  |  | if (ref($wrapper_node->{partner_merchant}) eq 'HASH') { | 
| 164 |  |  |  |  |  |  |  | 
| 165 | 0 |  |  |  |  |  | $self->partner_merchant(WebService::Braintree::PartnerMerchant->new($wrapper_node->{partner_merchant})); | 
| 166 |  |  |  |  |  |  | } | 
| 167 |  |  |  |  |  |  |  | 
| 168 | 0 | 0 |  |  |  |  | if (ref($wrapper_node->{dispute}) eq 'HASH') { | 
| 169 |  |  |  |  |  |  |  | 
| 170 | 0 |  |  |  |  |  | $self->dispute(WebService::Braintree::Dispute->new($wrapper_node->{dispute})); | 
| 171 |  |  |  |  |  |  | } | 
| 172 |  |  |  |  |  |  |  | 
| 173 | 0 | 0 |  |  |  |  | if (ref($wrapper_node->{errors}) eq 'HASH') { | 
| 174 | 0 |  |  |  |  |  | $self->errors(WebService::Braintree::ValidationErrorCollection->new($wrapper_node->{errors})); | 
| 175 | 0 |  |  |  |  |  | $self->message($wrapper_node->{message}); | 
| 176 |  |  |  |  |  |  | } | 
| 177 |  |  |  |  |  |  |  | 
| 178 | 0 |  |  |  |  |  | delete($attributes->{subject}); | 
| 179 | 0 |  |  |  |  |  | $self->set_attributes_from_hash($self, $attributes); | 
| 180 |  |  |  |  |  |  | } | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | __PACKAGE__->meta->make_immutable; | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  | 1; | 
| 185 |  |  |  |  |  |  | __END__ | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | =head1 TODO | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | =over 4 | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | =item Need to document the keys and values that are returned | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | =item Need to document the required and optional input parameters | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | =item Need to document the possible errors/exceptions | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | =back | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | =cut |