Fixes
This commit is contained in:
parent
3444ad06ba
commit
d5dea7cd1f
@ -13,12 +13,12 @@ class WebhooksController
|
|||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
$jobConfigKey = NotificationType::{$request->input('notification_type')}();
|
$jobConfigKey = NotificationType::{$request->input('notification_type')}();
|
||||||
|
$this->determineValidRequest($request->input('password'));
|
||||||
|
|
||||||
|
AppleNotification::storeNotification($jobConfigKey, $request->input());
|
||||||
|
|
||||||
$payload = NotificationPayload::createFromRequest($request);
|
$payload = NotificationPayload::createFromRequest($request);
|
||||||
|
|
||||||
$this->determineValidRequest($payload);
|
|
||||||
|
|
||||||
AppleNotification::storeNotification($jobConfigKey, $payload);
|
|
||||||
|
|
||||||
$jobClass = config("appstore-server-notifications.jobs.{$jobConfigKey}", null);
|
$jobClass = config("appstore-server-notifications.jobs.{$jobConfigKey}", null);
|
||||||
|
|
||||||
if (is_null($jobClass)) {
|
if (is_null($jobClass)) {
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user