From d5dea7cd1f846db28baedf43cd48ef238fc117d7 Mon Sep 17 00:00:00 2001 From: Daan Geurts Date: Wed, 30 Oct 2019 15:13:20 +0100 Subject: [PATCH] Fixes --- src/WebhooksController.php | 10 +++++----- src/model/AppleNotification.php | 10 ++++++---- src/model/Receipt.php | 20 ++++++++++++++++++++ tests/IntegrationTest.php | 1 + 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/WebhooksController.php b/src/WebhooksController.php index 85b8bd0..f6be999 100644 --- a/src/WebhooksController.php +++ b/src/WebhooksController.php @@ -13,11 +13,11 @@ class WebhooksController public function __invoke(Request $request) { $jobConfigKey = NotificationType::{$request->input('notification_type')}(); - $payload = NotificationPayload::createFromRequest($request); + $this->determineValidRequest($request->input('password')); - $this->determineValidRequest($payload); + AppleNotification::storeNotification($jobConfigKey, $request->input()); - AppleNotification::storeNotification($jobConfigKey, $payload); + $payload = NotificationPayload::createFromRequest($request); $jobClass = config("appstore-server-notifications.jobs.{$jobConfigKey}", null); @@ -31,9 +31,9 @@ class WebhooksController return response()->json(); } - private function determineValidRequest(NotificationPayload $notificationPayload): bool + private function determineValidRequest(string $password): bool { - if ($notificationPayload->getPassword() !== config('appstore-server-notifications.shared_secret')) { + if ($password !== config('appstore-server-notifications.shared_secret')) { throw WebhookFailed::nonValidRequest(); } diff --git a/src/model/AppleNotification.php b/src/model/AppleNotification.php index a57cd3e..f935534 100644 --- a/src/model/AppleNotification.php +++ b/src/model/AppleNotification.php @@ -8,11 +8,13 @@ class AppleNotification extends Model { public $guarded = []; - public static function storeNotification(string $notificationType, NotificationPayload $notificationPayload) + public static function storeNotification(string $notificationType, array $notificationPayload) { - return self::create([ + return self::create( + [ 'type' => $notificationType, - 'payload' => serialize($notificationPayload), - ]); + 'payload' => $notificationPayload, + ] + ); } } diff --git a/src/model/Receipt.php b/src/model/Receipt.php index bc94191..6e2a987 100644 --- a/src/model/Receipt.php +++ b/src/model/Receipt.php @@ -14,6 +14,7 @@ class Receipt private $originalPurchaseDateMs; private $originalPurchaseDatePst; private $cancellationReason; + private $promotionalOfferId; private $cancellationDate; private $cancellationDateMs; private $cancellationDatePst; @@ -26,6 +27,7 @@ class Receipt private $uniqueVendorIdentifier; private $isInIntroOfferPeriod; private $isTrialPeriod; + private $isUpgraded; private $itemId; private $appItemId; private $versionExternalIdentifier; @@ -42,6 +44,7 @@ class Receipt $instance = new self(); $instance->originalTransactionId = $receiptInfo['original_transaction_id'] ?? null; $instance->webOrderLineItemId = $receiptInfo['web_order_line_item_id'] ?? null; + $instance->promotionalOfferId = $receiptInfo['promotional_offer_id'] ?? null; $instance->productId = $receiptInfo['product_id'] ?? null; $instance->purchaseDateMs = $receiptInfo['purchase_date_ms'] ?? null; $instance->purchaseDate = $receiptInfo['purchase_date'] ?? null; @@ -62,6 +65,7 @@ class Receipt $instance->uniqueVendorIdentifier = $receiptInfo['unique_vendor_identifier'] ?? null; $instance->isInIntroOfferPeriod = $receiptInfo['is_in_intro_offer_period'] ?? null; $instance->isTrialPeriod = $receiptInfo['is_trial_period'] ?? null; + $instance->isUpgraded = $receiptInfo['is_upgraded'] ?? null; $instance->itemId = $receiptInfo['item_id'] ?? null; $instance->appItemId = $receiptInfo['app_item_id'] ?? null; $instance->versionExternalIdentifier = $receiptInfo['version_external_identifier'] ?? null; @@ -295,4 +299,20 @@ class Receipt { return $this->originalTransactionId; } + + /** + * Get the value of isUpgraded + */ + public function getIsUpgraded() + { + return $this->isUpgraded; + } + + /** + * Get the value of promotionalOfferId + */ + public function getPromotionalOfferId() + { + return $this->promotionalOfferId; + } } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 10be14d..0274c42 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -29,6 +29,7 @@ class IntegrationTest extends TestCase /** @test */ public function it_can_handle_a_valid_request() { + $this->withExceptionHandling(); $payload = include_once __DIR__.'/__fixtures__/request.php'; $payload['password'] = 'VALID_APPLE_PASSWORD';