mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-04 22:59:41 +00:00
Read order lines and invoices of app orders
Document the items (subscription, period, net amount, discount), invoice and metadata of orders read with the app's token, add AppOrders::invoicePdf() for the invoice PDF and the opt-in subscription.renewed event type with its period data.
This commit is contained in:
6 files changed
+188
-3
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace Anikeen\Id\Tests;
|
||||
|
||||
use Anikeen\Id\Exceptions\SignatureVerificationException;
|
||||
use Anikeen\Id\Webhooks\EventType;
|
||||
use Anikeen\Id\Webhooks\Webhook;
|
||||
|
||||
class WebhookTest extends TestCase
|
||||
@@ -53,4 +54,30 @@ class WebhookTest extends TestCase
|
||||
|
||||
Webhook::constructEvent($this->payload, null, $this->secret);
|
||||
}
|
||||
|
||||
public function test_a_renewal_carries_the_booked_period(): void
|
||||
{
|
||||
$this->payload = json_encode(['id' => '01JEVT', 'type' => EventType::SUBSCRIPTION_RENEWED, 'created' => time(), 'data' => [
|
||||
'object' => ['id' => '01JSUB', 'status' => 'active'],
|
||||
'period' => ['object' => 'subscription_period', 'subscription_id' => '01JSUB', 'period_start' => '2026-11-01T00:00:00+00:00', 'period_end' => '2026-12-01T00:00:00+00:00', 'periods' => 1, 'unit' => 'month', 'order_id' => '01JORD', 'order_item_id' => '01JITEM', 'items' => [], 'currency_iso' => 'EUR', 'net_amount' => 8],
|
||||
]]);
|
||||
|
||||
$event = Webhook::constructEvent($this->payload, $this->header(), $this->secret);
|
||||
|
||||
$this->assertSame('subscription.renewed', $event['type']);
|
||||
$this->assertSame('01JORD', $event['data']['period']['order_id']);
|
||||
$this->assertContains(EventType::SUBSCRIPTION_RENEWED, EventType::all());
|
||||
}
|
||||
|
||||
public function test_a_change_carries_the_previous_attributes(): void
|
||||
{
|
||||
$this->payload = json_encode(['id' => '01JEVT', 'type' => EventType::SUBSCRIPTION_UPDATED, 'created' => time(), 'data' => [
|
||||
'object' => ['id' => '01JSUB', 'price' => 14.99],
|
||||
'previous_attributes' => ['price' => 9.99],
|
||||
]]);
|
||||
|
||||
$event = Webhook::constructEvent($this->payload, $this->header(), $this->secret);
|
||||
|
||||
$this->assertSame(9.99, $event['data']['previous_attributes']['price']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user