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)
{
$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();
}

10
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,
]
);
}
}

20
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;
}
}

1
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';

Loading…
Cancel
Save