| 1 | # vim: sw=4 ts=4 ft=perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | package # hide from pause | ||||||||||||||||||||
| 4 | WebService::Braintree::WebhookTestingGateway; | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 22 | ▶ | use 5.010_001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 22 | ▶ | use strictures 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 22 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 22 | ▶ | use MIME::Base64; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 22 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 22 | ▶ | use WebService::Braintree::Digest qw(hexdigest); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 22 | ▶ | use WebService::Braintree::WebhookNotification::Kind; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | # This does not use Role::MakeRequest which provides the gateway attribute. | ||||||||||||||||||||
| 18 | 22 | has 'gateway' => (is => 'ro'); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 15 | ▶ | sub sample_notification { | ||||||||||||||||||
|
Subroutine
sample_notification: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 21 | 15 | my ($self, $kind, $id) = @_; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 15 | my $sample_xml = $self->_sample_xml($kind, $id); | |||||||||||||||||||
| 24 | 15 | my $payload = encode_base64($sample_xml); | |||||||||||||||||||
| 25 | 15 | my $signature = $self->gateway->config->public_key . "|" . hexdigest($self->gateway->config->private_key, $payload); | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 15 | return ($signature, $payload); | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 15 | ▶ | sub _sample_xml { | ||||||||||||||||||
|
Subroutine
_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 15 | my ($self, $kind, $id) = @_; | |||||||||||||||||||
| 32 | 15 | my $subject_sample_xml = $self->_subject_sample_xml($kind, $id); | |||||||||||||||||||
| 33 | 15 | my $timestamp = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()); | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | return <<XML | ||||||||||||||||||||
| 36 | <notification> | ||||||||||||||||||||
| 37 | <timestamp type="datetime">$timestamp</timestamp> | ||||||||||||||||||||
| 38 | <kind>$kind</kind> | ||||||||||||||||||||
| 39 | <subject>$subject_sample_xml</subject> | ||||||||||||||||||||
| 40 | </notification> | ||||||||||||||||||||
| 41 | XML | ||||||||||||||||||||
| 42 | 15 | } | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 15 | ▶ | sub _subject_sample_xml { | ||||||||||||||||||
|
Subroutine
_subject_sample_xml: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 45 | 15 | my ($self, $kind, $id) = @_; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | my $dispatch = { | ||||||||||||||||||||
| 48 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::TransactionDisbursed => sub { _transaction_disbursed_sample_xml(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 49 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::DisbursementException => sub { _disbursement_exception_sample_xml(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 50 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::Disbursement => sub { _disbursement_sample_xml(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::SubMerchantAccountApproved => sub { _merchant_account_approved_sample_xml(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::SubMerchantAccountDeclined => sub { _merchant_account_declined_sample_xml(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::PartnerMerchantConnected => sub { _partner_merchant_connected_sample_xml(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::PartnerMerchantDisconnected => sub { _partner_merchant_disconnected_sample_xml(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 55 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::PartnerMerchantDeclined => sub { _partner_merchant_declined_sample_xml(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 56 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::DisputeOpened => sub { _dispute_opened_sample_xml(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::DisputeLost => sub { _dispute_lost_sample_xml(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 58 | 1 | ▶ | WebService::Braintree::WebhookNotification::Kind::DisputeWon => sub { _dispute_won_sample_xml(@_) } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 59 | 15 | }; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 15 | ▶ | my $templater = $dispatch->{$kind} || sub { _subscription_sample_xml(@_) }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$dispatch->{$kind} || sub {
_subscription_sample_xml(@_);
}
MC/DC0%0/2
$dispatch->{$kind} || sub {
_subscription_sample_xml(@_);
}
$dispatch->{$kind}
sub {
_subscription_sample_xml(@_);
}
Truth table66%2/3
A || B
A= $dispatch->{$kind}B= sub {
_subscription_sample_xml(@_);
}
| |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 15 | return $templater->($id); | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 1 | ▶ | sub _transaction_disbursed_sample_xml { | ||||||||||||||||||
|
Subroutine
_transaction_disbursed_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 67 | 1 | my $id = shift; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | return <<XML | ||||||||||||||||||||
| 70 | <transaction> | ||||||||||||||||||||
| 71 | <id>$id</id> | ||||||||||||||||||||
| 72 | <amount>100</amount> | ||||||||||||||||||||
| 73 | <disbursement-details> | ||||||||||||||||||||
| 74 | <disbursement-date type="date">2013-07-09</disbursement-date> | ||||||||||||||||||||
| 75 | </disbursement-details> | ||||||||||||||||||||
| 76 | </transaction> | ||||||||||||||||||||
| 77 | XML | ||||||||||||||||||||
| 78 | 1 | }; | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 1 | ▶ | sub _dispute_opened_sample_xml { | ||||||||||||||||||
|
Subroutine
_dispute_opened_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 81 | 1 | my $id = shift; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | return <<XML | ||||||||||||||||||||
| 84 | <dispute> | ||||||||||||||||||||
| 85 | <amount>250.00</amount> | ||||||||||||||||||||
| 86 | <currency-iso-code>USD</currency-iso-code> | ||||||||||||||||||||
| 87 | <received-date type="date">2014-03-01</received-date> | ||||||||||||||||||||
| 88 | <reply-by-date type="date">2014-03-21</reply-by-date> | ||||||||||||||||||||
| 89 | <status>open</status> | ||||||||||||||||||||
| 90 | <reason>fraud</reason> | ||||||||||||||||||||
| 91 | <id>$id</id> | ||||||||||||||||||||
| 92 | <transaction> | ||||||||||||||||||||
| 93 | <id>$id</id> | ||||||||||||||||||||
| 94 | <amount>250.00</amount> | ||||||||||||||||||||
| 95 | </transaction> | ||||||||||||||||||||
| 96 | </dispute> | ||||||||||||||||||||
| 97 | XML | ||||||||||||||||||||
| 98 | 1 | }; | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 1 | ▶ | sub _dispute_lost_sample_xml { | ||||||||||||||||||
|
Subroutine
_dispute_lost_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 101 | 1 | my $id = shift; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | return <<XML | ||||||||||||||||||||
| 104 | <dispute> | ||||||||||||||||||||
| 105 | <amount>250.00</amount> | ||||||||||||||||||||
| 106 | <currency-iso-code>USD</currency-iso-code> | ||||||||||||||||||||
| 107 | <received-date type="date">2014-03-01</received-date> | ||||||||||||||||||||
| 108 | <reply-by-date type="date">2014-03-21</reply-by-date> | ||||||||||||||||||||
| 109 | <status>lost</status> | ||||||||||||||||||||
| 110 | <reason>fraud</reason> | ||||||||||||||||||||
| 111 | <id>$id</id> | ||||||||||||||||||||
| 112 | <transaction> | ||||||||||||||||||||
| 113 | <id>$id</id> | ||||||||||||||||||||
| 114 | <amount>250.00</amount> | ||||||||||||||||||||
| 115 | </transaction> | ||||||||||||||||||||
| 116 | </dispute> | ||||||||||||||||||||
| 117 | XML | ||||||||||||||||||||
| 118 | 1 | }; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 1 | ▶ | sub _dispute_won_sample_xml { | ||||||||||||||||||
|
Subroutine
_dispute_won_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 121 | 1 | my $id = shift; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | return <<XML | ||||||||||||||||||||
| 124 | <dispute> | ||||||||||||||||||||
| 125 | <amount>250.00</amount> | ||||||||||||||||||||
| 126 | <currency-iso-code>USD</currency-iso-code> | ||||||||||||||||||||
| 127 | <received-date type="date">2014-03-01</received-date> | ||||||||||||||||||||
| 128 | <reply-by-date type="date">2014-03-21</reply-by-date> | ||||||||||||||||||||
| 129 | <status>won</status> | ||||||||||||||||||||
| 130 | <reason>fraud</reason> | ||||||||||||||||||||
| 131 | <id>$id</id> | ||||||||||||||||||||
| 132 | <transaction> | ||||||||||||||||||||
| 133 | <id>$id</id> | ||||||||||||||||||||
| 134 | <amount>250.00</amount> | ||||||||||||||||||||
| 135 | </transaction> | ||||||||||||||||||||
| 136 | </dispute> | ||||||||||||||||||||
| 137 | XML | ||||||||||||||||||||
| 138 | 1 | }; | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 1 | ▶ | sub _disbursement_exception_sample_xml { | ||||||||||||||||||
|
Subroutine
_disbursement_exception_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 141 | 1 | my $id = shift; | |||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | return <<XML | ||||||||||||||||||||
| 144 | <disbursement> | ||||||||||||||||||||
| 145 | <id>$id</id> | ||||||||||||||||||||
| 146 | <transaction-ids type="array"> | ||||||||||||||||||||
| 147 | <item>afv56j</item> | ||||||||||||||||||||
| 148 | <item>kj8hjk</item> | ||||||||||||||||||||
| 149 | </transaction-ids> | ||||||||||||||||||||
| 150 | <success type="boolean">false</success> | ||||||||||||||||||||
| 151 | <retry type="boolean">false</retry> | ||||||||||||||||||||
| 152 | <merchant-account> | ||||||||||||||||||||
| 153 | <id>merchant_account_token</id> | ||||||||||||||||||||
| 154 | <currency-iso-code>USD</currency-iso-code> | ||||||||||||||||||||
| 155 | <sub-merchant-account type="boolean">false</sub-merchant-account> | ||||||||||||||||||||
| 156 | <status>active</status> | ||||||||||||||||||||
| 157 | </merchant-account> | ||||||||||||||||||||
| 158 | <amount>100.00</amount> | ||||||||||||||||||||
| 159 | <disbursement-date type="date">2014-02-10</disbursement-date> | ||||||||||||||||||||
| 160 | <exception-message>bank_rejected</exception-message> | ||||||||||||||||||||
| 161 | <follow-up-action>update_funding_information</follow-up-action> | ||||||||||||||||||||
| 162 | </disbursement> | ||||||||||||||||||||
| 163 | XML | ||||||||||||||||||||
| 164 | 1 | }; | |||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | 1 | ▶ | sub _disbursement_sample_xml { | ||||||||||||||||||
|
Subroutine
_disbursement_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 167 | 1 | my $id = shift; | |||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | return <<XML | ||||||||||||||||||||
| 170 | <disbursement> | ||||||||||||||||||||
| 171 | <id>$id</id> | ||||||||||||||||||||
| 172 | <transaction-ids type="array"> | ||||||||||||||||||||
| 173 | <item>afv56j</item> | ||||||||||||||||||||
| 174 | <item>kj8hjk</item> | ||||||||||||||||||||
| 175 | </transaction-ids> | ||||||||||||||||||||
| 176 | <success type="boolean">true</success> | ||||||||||||||||||||
| 177 | <retry type="boolean">false</retry> | ||||||||||||||||||||
| 178 | <merchant-account> | ||||||||||||||||||||
| 179 | <id>merchant_account_token</id> | ||||||||||||||||||||
| 180 | <currency-iso-code>USD</currency-iso-code> | ||||||||||||||||||||
| 181 | <sub-merchant-account type="boolean">false</sub-merchant-account> | ||||||||||||||||||||
| 182 | <status>active</status> | ||||||||||||||||||||
| 183 | </merchant-account> | ||||||||||||||||||||
| 184 | <amount>100.00</amount> | ||||||||||||||||||||
| 185 | <disbursement-date type="date">2014-02-10</disbursement-date> | ||||||||||||||||||||
| 186 | <exception-message nil="true"/> | ||||||||||||||||||||
| 187 | <follow-up-action nil="true"/> | ||||||||||||||||||||
| 188 | </disbursement> | ||||||||||||||||||||
| 189 | XML | ||||||||||||||||||||
| 190 | 1 | }; | |||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | 1 | ▶ | sub _merchant_account_approved_sample_xml { | ||||||||||||||||||
|
Subroutine
_merchant_account_approved_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 193 | 1 | my $id = shift; | |||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | return <<XML | ||||||||||||||||||||
| 196 | <merchant_account> | ||||||||||||||||||||
| 197 | <id>$id</id> | ||||||||||||||||||||
| 198 | <master_merchant_account> | ||||||||||||||||||||
| 199 | <id>master_ma_for_$id</id> | ||||||||||||||||||||
| 200 | <status>active</status> | ||||||||||||||||||||
| 201 | </master_merchant_account> | ||||||||||||||||||||
| 202 | <status>active</status> | ||||||||||||||||||||
| 203 | </merchant_account> | ||||||||||||||||||||
| 204 | XML | ||||||||||||||||||||
| 205 | 1 | }; | |||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | 1 | ▶ | sub _merchant_account_declined_sample_xml { | ||||||||||||||||||
|
Subroutine
_merchant_account_declined_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 208 | 1 | my $id = shift; | |||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | return <<XML | ||||||||||||||||||||
| 211 | <api-error-response> | ||||||||||||||||||||
| 212 | <message>Credit score is too low</message> | ||||||||||||||||||||
| 213 | <errors> | ||||||||||||||||||||
| 214 | <errors type="array"/> | ||||||||||||||||||||
| 215 | <merchant-account> | ||||||||||||||||||||
| 216 | <errors type="array"> | ||||||||||||||||||||
| 217 | <error> | ||||||||||||||||||||
| 218 | <code>82621</code> | ||||||||||||||||||||
| 219 | <message>Credit score is too low</message> | ||||||||||||||||||||
| 220 | <attribute type="symbol">base</attribute> | ||||||||||||||||||||
| 221 | </error> | ||||||||||||||||||||
| 222 | </errors> | ||||||||||||||||||||
| 223 | </merchant-account> | ||||||||||||||||||||
| 224 | </errors> | ||||||||||||||||||||
| 225 | <merchant-account> | ||||||||||||||||||||
| 226 | <id>$id</id> | ||||||||||||||||||||
| 227 | <status>suspended</status> | ||||||||||||||||||||
| 228 | <master-merchant-account> | ||||||||||||||||||||
| 229 | <id>master_ma_for_$id</id> | ||||||||||||||||||||
| 230 | <status>suspended</status> | ||||||||||||||||||||
| 231 | </master-merchant-account> | ||||||||||||||||||||
| 232 | </merchant-account> | ||||||||||||||||||||
| 233 | </api-error-response> | ||||||||||||||||||||
| 234 | XML | ||||||||||||||||||||
| 235 | 1 | }; | |||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | 4 | ▶ | sub _subscription_sample_xml { | ||||||||||||||||||
|
Subroutine
_subscription_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 238 | 4 | my $id = shift; | |||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | return <<XML | ||||||||||||||||||||
| 241 | <subscription> | ||||||||||||||||||||
| 242 | <id>$id</id> | ||||||||||||||||||||
| 243 | <transactions type="array"> | ||||||||||||||||||||
| 244 | </transactions> | ||||||||||||||||||||
| 245 | <add_ons type="array"> | ||||||||||||||||||||
| 246 | </add_ons> | ||||||||||||||||||||
| 247 | <discounts type="array"> | ||||||||||||||||||||
| 248 | </discounts> | ||||||||||||||||||||
| 249 | </subscription> | ||||||||||||||||||||
| 250 | XML | ||||||||||||||||||||
| 251 | 4 | } | |||||||||||||||||||
| 252 | |||||||||||||||||||||
| 253 | 1 | ▶ | sub _partner_merchant_connected_sample_xml { | ||||||||||||||||||
|
Subroutine
_partner_merchant_connected_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 254 | return <<XML | ||||||||||||||||||||
| 255 | <partner-merchant> | ||||||||||||||||||||
| 256 | <merchant-public-id>public_id</merchant-public-id> | ||||||||||||||||||||
| 257 | <public-key>public_key</public-key> | ||||||||||||||||||||
| 258 | <private-key>private_key</private-key> | ||||||||||||||||||||
| 259 | <partner-merchant-id>abc123</partner-merchant-id> | ||||||||||||||||||||
| 260 | <client-side-encryption-key>cse_key</client-side-encryption-key> | ||||||||||||||||||||
| 261 | </partner-merchant> | ||||||||||||||||||||
| 262 | XML | ||||||||||||||||||||
| 263 | 1 | } | |||||||||||||||||||
| 264 | |||||||||||||||||||||
| 265 | 1 | ▶ | sub _partner_merchant_disconnected_sample_xml { | ||||||||||||||||||
|
Subroutine
_partner_merchant_disconnected_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 266 | return <<XML | ||||||||||||||||||||
| 267 | <partner-merchant> | ||||||||||||||||||||
| 268 | <partner-merchant-id>abc123</partner-merchant-id> | ||||||||||||||||||||
| 269 | </partner-merchant> | ||||||||||||||||||||
| 270 | XML | ||||||||||||||||||||
| 271 | 1 | } | |||||||||||||||||||
| 272 | |||||||||||||||||||||
| 273 | 1 | ▶ | sub _partner_merchant_declined_sample_xml { | ||||||||||||||||||
|
Subroutine
_partner_merchant_declined_sample_xml: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 274 | return <<XML | ||||||||||||||||||||
| 275 | <partner-merchant> | ||||||||||||||||||||
| 276 | <partner-merchant-id>abc123</partner-merchant-id> | ||||||||||||||||||||
| 277 | </partner-merchant> | ||||||||||||||||||||
| 278 | XML | ||||||||||||||||||||
| 279 | 1 | } | |||||||||||||||||||
| 280 | |||||||||||||||||||||
| 281 | 22 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 282 | |||||||||||||||||||||
| 283 | 22 | 1; | |||||||||||||||||||
| 284 | __END__ | ||||||||||||||||||||