Skip to content

Commit

Permalink
Added Unknown webhook payload.
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed May 30, 2018
1 parent fd9b840 commit 4d62131
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ServerRequest/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Academe\AuthorizeNet\ServerRequest\Payload\Payment;
use Academe\AuthorizeNet\ServerRequest\Payload\Subscription;
use Academe\AuthorizeNet\ServerRequest\Payload\CustomerProfile;
use Academe\AuthorizeNet\ServerRequest\Payload\Unknown;

class Notification extends AbstractModel
{
Expand Down Expand Up @@ -143,7 +144,8 @@ public function __construct($data)
$this->setPayload(new CustomerProfile($payload));
}
} else {
// TODO: fall back to some default payload.
// Fall back to a default payload.
$this->setPayload(new Unknown($payload));
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/ServerRequest/Payload/Unknown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Academe\AuthorizeNet\ServerRequest\Payload;

/**
* The "unknown" notification payload.
*/

use Academe\AuthorizeNet\ServerRequest\AbstractPayload;

class Unknown extends AbstractPayload
{
}
21 changes: 21 additions & 0 deletions tests/ServerRequest/NotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Academe\AuthorizeNet\ServerRequest\Payload\Fraud;
use Academe\AuthorizeNet\ServerRequest\Payload\Subscription;
use Academe\AuthorizeNet\ServerRequest\Payload\CustomerProfile;
use Academe\AuthorizeNet\ServerRequest\Payload\Unknown;

class NotificationTest extends TestCase
{
Expand Down Expand Up @@ -160,4 +161,24 @@ public function testCreateCustomerProfile()

$this->assertArraySubset($data, $notification->toData(true));
}

public function testUnknownEvent()
{
$data = json_decode('{
"notificationId": "5c3f7e00-1265-4e8e-abd0-a7d734163881",
"eventType": "net.authorize.foobar.stuff",
"eventDate": "2016-03-23T05:23:06.5430555Z",
"webhookId": "0b90f2e8-02ae-4d1d-b2e0-1bd167e60176",
"payload": {
"entityName": "foo",
"id": "bar"
}
}', true);

$notification = new Notification($data);

$this->assertInstanceOf(Unknown::class, $notification->payload);

$this->assertArraySubset($data, $notification->toData(true));
}
}

0 comments on commit 4d62131

Please sign in to comment.