Browse Source

Fixes

proxy_request
Daan Geurts 5 years ago
parent
commit
d5dea7cd1f
  1. 10
      src/WebhooksController.php
  2. 10
      src/model/AppleNotification.php
  3. 20
      src/model/Receipt.php
  4. 1
      tests/IntegrationTest.php

10
src/WebhooksController.php

@ -13,11 +13,11 @@ class WebhooksController
public function __invoke(Request $request) public function __invoke(Request $request)
{ {
$jobConfigKey = NotificationType::{$request->input('notification_type')}(); $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); $jobClass = config("appstore-server-notifications.jobs.{$jobConfigKey}", null);
@ -31,9 +31,9 @@ class WebhooksController
return response()->json(); 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(); throw WebhookFailed::nonValidRequest();
} }

10
src/model/AppleNotification.php

@ -8,11 +8,13 @@ class AppleNotification extends Model
{ {
public $guarded = []; 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, 'type' => $notificationType,
'payload' => serialize($notificationPayload), 'payload' => $notificationPayload,
]); ]
);
} }
} }

20
src/model/Receipt.php

@ -14,6 +14,7 @@ class Receipt
private $originalPurchaseDateMs; private $originalPurchaseDateMs;
private $originalPurchaseDatePst; private $originalPurchaseDatePst;
private $cancellationReason; private $cancellationReason;
private $promotionalOfferId;
private $cancellationDate; private $cancellationDate;
private $cancellationDateMs; private $cancellationDateMs;
private $cancellationDatePst; private $cancellationDatePst;
@ -26,6 +27,7 @@ class Receipt
private $uniqueVendorIdentifier; private $uniqueVendorIdentifier;
private $isInIntroOfferPeriod; private $isInIntroOfferPeriod;
private $isTrialPeriod; private $isTrialPeriod;
private $isUpgraded;
private $itemId; private $itemId;
private $appItemId; private $appItemId;
private $versionExternalIdentifier; private $versionExternalIdentifier;
@ -42,6 +44,7 @@ class Receipt
$instance = new self(); $instance = new self();
$instance->originalTransactionId = $receiptInfo['original_transaction_id'] ?? null; $instance->originalTransactionId = $receiptInfo['original_transaction_id'] ?? null;
$instance->webOrderLineItemId = $receiptInfo['web_order_line_item_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->productId = $receiptInfo['product_id'] ?? null;
$instance->purchaseDateMs = $receiptInfo['purchase_date_ms'] ?? null; $instance->purchaseDateMs = $receiptInfo['purchase_date_ms'] ?? null;
$instance->purchaseDate = $receiptInfo['purchase_date'] ?? null; $instance->purchaseDate = $receiptInfo['purchase_date'] ?? null;
@ -62,6 +65,7 @@ class Receipt
$instance->uniqueVendorIdentifier = $receiptInfo['unique_vendor_identifier'] ?? null; $instance->uniqueVendorIdentifier = $receiptInfo['unique_vendor_identifier'] ?? null;
$instance->isInIntroOfferPeriod = $receiptInfo['is_in_intro_offer_period'] ?? null; $instance->isInIntroOfferPeriod = $receiptInfo['is_in_intro_offer_period'] ?? null;
$instance->isTrialPeriod = $receiptInfo['is_trial_period'] ?? null; $instance->isTrialPeriod = $receiptInfo['is_trial_period'] ?? null;
$instance->isUpgraded = $receiptInfo['is_upgraded'] ?? null;
$instance->itemId = $receiptInfo['item_id'] ?? null; $instance->itemId = $receiptInfo['item_id'] ?? null;
$instance->appItemId = $receiptInfo['app_item_id'] ?? null; $instance->appItemId = $receiptInfo['app_item_id'] ?? null;
$instance->versionExternalIdentifier = $receiptInfo['version_external_identifier'] ?? null; $instance->versionExternalIdentifier = $receiptInfo['version_external_identifier'] ?? null;
@ -295,4 +299,20 @@ class Receipt
{ {
return $this->originalTransactionId; 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;
}
} }

1
tests/IntegrationTest.php

@ -29,6 +29,7 @@ class IntegrationTest extends TestCase
/** @test */ /** @test */
public function it_can_handle_a_valid_request() public function it_can_handle_a_valid_request()
{ {
$this->withExceptionHandling();
$payload = include_once __DIR__.'/__fixtures__/request.php'; $payload = include_once __DIR__.'/__fixtures__/request.php';
$payload['password'] = 'VALID_APPLE_PASSWORD'; $payload['password'] = 'VALID_APPLE_PASSWORD';

Loading…
Cancel
Save