Initial commit

This commit is contained in:
Daan Geurts
2019-10-16 14:20:07 +02:00
commit 7f4b49d98d
28 changed files with 1340 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace Appvise\AppStoreNotifications\Model;
use Illuminate\Database\Eloquent\Model;
class AppleNotification extends Model
{
public $guarded = [];
public static function storeNotification(String $notificationType, NotificationPayload $notificationPayload): AppleNotification
{
return self::create([
'type' => $notificationType,
'payload' => serialize($notificationPayload),
]);
}
}
+193
View File
@@ -0,0 +1,193 @@
<?php
namespace Appvise\AppStoreNotifications\Model;
use Illuminate\Http\Request;
class NotificationPayload
{
private $environment;
private $notificationType;
private $password;
private $cancellationDate;
private $cancellationDatePst;
private $cancellationDateMs;
private $webOrderLineItemId;
private $latestReceipt;
private $latestReceiptInfo;
private $latestExpiredReceipt;
private $latestExpiredReceiptInfo;
private $autoRenewStatus;
private $autoRenewProductId;
private $autoRenewStatusChangeDate;
private $autoRenewStatusChangeDatePst;
private $autoRenewStatusChangeDateMs;
private $pendingRenewalInfo;
public function __construct()
{
}
static function createFromRequest(Request $request)
{
$instance = new self();
$instance->environment = $request->input('environment');
$instance->password = $request->input('password');
$instance->notificationType = $request->input('notification_type');
$instance->cancellationDate = $request->input('cancellation_date');
$instance->cancellationDatePst = $request->input('cancellation_date_pst');
$instance->cancellationDateMs = $request->input('cancellation_date_ms');
$instance->webOrderLineItemId = $request->input('web_order_line_item_id');
$instance->latestReceipt = $request->input('latest_receipt');
$instance->latestReceiptInfo = Receipt::createFromArray($request->input('latest_receipt_info'));
$instance->latestExpiredReceipt = $request->input('latest_expired_receipt');
$instance->latestExpiredReceiptInfo = Receipt::createFromArray($request->input('latest_expired_receipt_info'));
$instance->autoRenewStatus = $request->input('auto_renew_status');
$instance->autoRenewProductId = $request->input('auto_renew_product_id');
$instance->autoRenewStatusChangeDate = $request->input('auto_renew_status_change_date');
$instance->autoRenewStatusChangeDatePst = $request->input('auto_renew_status_change_date_pst');
$instance->autoRenewStatusChangeDateMs = $request->input('auto_renew_status_change_date_ms');
foreach ($request->input('pending_renewal_info') as $pendingRenewalInfo) {
$instance->pendingRenewalInfo[] = RenewalInfo::createFromRequest($pendingRenewalInfo);
}
return $instance;
}
/**
* Get the value of environment
*/
public function getEnvironment()
{
return $this->environment;
}
/**
* Get the value of notificationType
*/
public function getNotificationType()
{
return $this->notificationType;
}
/**
* Get the value of pendingRenewalInfo
*/
public function getPendingRenewalInfo()
{
return $this->pendingRenewalInfo;
}
/**
* Get the value of autoRenewStatusChangeDateMs
*/
public function getAutoRenewStatusChangeDateMs()
{
return $this->autoRenewStatusChangeDateMs;
}
/**
* Get the value of autoRenewStatusChangeDatePst
*/
public function getAutoRenewStatusChangeDatePst()
{
return $this->autoRenewStatusChangeDatePst;
}
/**
* Get the value of autoRenewStatusChangeDate
*/
public function getAutoRenewStatusChangeDate()
{
return $this->autoRenewStatusChangeDate;
}
/**
* Get the value of autoRenewProductId
*/
public function getAutoRenewProductId()
{
return $this->autoRenewProductId;
}
/**
* Get the value of autoRenewStatus
*/
public function getAutoRenewStatus()
{
return $this->autoRenewStatus;
}
/**
* Get the value of latestExpiredReceiptInfo
*/
public function getLatestExpiredReceiptInfo()
{
return $this->latestExpiredReceiptInfo;
}
/**
* Get the value of latestExpiredReceipt
*/
public function getLatestExpiredReceipt()
{
return $this->latestExpiredReceipt;
}
/**
* Get the value of latestReceiptInfo
*/
public function getLatestReceiptInfo()
{
return $this->latestReceiptInfo;
}
/**
* Get the value of latestReceipt
*/
public function getLatestReceipt()
{
return $this->latestReceipt;
}
/**
* Get the value of webOrderLineItemId
*/
public function getWebOrderLineItemId()
{
return $this->webOrderLineItemId;
}
/**
* Get the value of cancellationDateMs
*/
public function getCancellationDateMs()
{
return $this->cancellationDateMs;
}
/**
* Get the value of cancellationDatePst
*/
public function getCancellationDatePst()
{
return $this->cancellationDatePst;
}
/**
* Get the value of cancellationDate
*/
public function getCancellationDate()
{
return $this->cancellationDate;
}
/**
* Get the value of password
*/
public function getPassword()
{
return $this->password;
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace Appvise\AppStoreNotifications\Model;
use BenSampo\Enum\Enum;
class NotificationType extends Enum
{
const INITIAL_BUY = 'initial_buy';
const CANCEL = 'cancel';
const RENEWAL = 'renewal';
const INTERACTIVE_RENEWAL = 'interactive_renewal';
const DID_CHANGE_RENEWAL_PREF = 'did_change_renewal_pref';
const DID_CHANGE_RENEWAL_STATUS = 'did_change_renewal_status';
const DID_FAIL_TO_RENEW = 'did_fail_to_renew';
const DID_RECOVER = 'did_recover'; // replaces RENEWAL
const PRICE_INCREASE_CONSENT = 'price_increase_consent';
}
+301
View File
@@ -0,0 +1,301 @@
<?php
namespace Appvise\AppStoreNotifications\Model;
class Receipt
{
private $originalTransactionId;
private $webOrderLineItemId;
private $productId;
private $purchaseDateMs;
private $purchaseDate;
private $purchaseDatePst;
private $originalPurchaseDate;
private $originalPurchaseDateMs;
private $originalPurchaseDatePst;
private $cancellationReason;
private $cancellationDate;
private $cancellationDateMs;
private $cancellationDatePst;
private $expiresDate;
private $expiresDateMs;
private $expiresDateFormatted;
private $expiresDateFormattedPst;
private $quantity;
private $uniqueIdentifier;
private $uniqueVendorIdentifier;
private $isInIntroOfferPeriod;
private $isTrialPeriod;
private $itemId;
private $appItemId;
private $versionExternalIdentifier;
private $transactionId;
private $bvrs;
private $bid;
public function __construct()
{
}
static function createFromArray(array $receiptInfo)
{
$instance = new self();
$instance->originalTransactionId = $receiptInfo['original_transaction_id'] ?? null;
$instance->webOrderLineItemId = $receiptInfo['web_order_line_item_id'] ?? null;
$instance->productId = $receiptInfo['product_id'] ?? null;
$instance->purchaseDateMs = $receiptInfo['purchase_date_ms'] ?? null;
$instance->purchaseDate = $receiptInfo['purchase_date'] ?? null;
$instance->purchaseDatePst = $receiptInfo['purchase_date_pst'] ?? null;
$instance->originalPurchaseDate = $receiptInfo['original_purchase_date'] ?? null;
$instance->originalPurchaseDateMs = $receiptInfo['original_purchase_date_ms'] ?? null;
$instance->originalPurchaseDatePst = $receiptInfo['original_purchase_date_pst'] ?? null;
$instance->cancellationReason = $receiptInfo['cancellation_reason'] ?? null;
$instance->cancellationDate = $receiptInfo['cancellation_date'] ?? null;
$instance->cancellationDateMs = $receiptInfo['cancellation_date_ms'] ?? null;
$instance->cancellationDatePst = $receiptInfo['cancellation_date_pst'] ?? null;
$instance->expiresDate = $receiptInfo['expires_date'] ?? null;
$instance->expiresDateMs = $receiptInfo['expires_date_ms'] ?? null;
$instance->expiresDateFormatted = $receiptInfo['expires_date_formatted'] ?? null;
$instance->expiresDateFormattedPst = $receiptInfo['expires_date_formatted_pst'] ?? null;
$instance->quantity = $receiptInfo['quantity'] ?? null;
$instance->uniqueIdentifier = $receiptInfo['unique_identifier'] ?? null;
$instance->uniqueVendorIdentifier = $receiptInfo['unique_vendor_identifier'] ?? null;
$instance->isInIntroOfferPeriod = $receiptInfo['is_in_intro_offer_period'] ?? null;
$instance->isTrialPeriod = $receiptInfo['is_trial_period'] ?? null;
$instance->itemId = $receiptInfo['item_id'] ?? null;
$instance->appItemId = $receiptInfo['app_item_id'] ?? null;
$instance->versionExternalIdentifier = $receiptInfo['version_external_identifier'] ?? null;
$instance->transactionId = $receiptInfo['transaction_id'] ?? null;
$instance->bvrs = $receiptInfo['bvrs'] ?? null;
$instance->bid = $receiptInfo['bid'] ?? null;
return $instance;
}
/**
* Get the value of bid
*/
public function getBid()
{
return $this->bid;
}
/**
* Get the value of bvrs
*/
public function getBvrs()
{
return $this->bvrs;
}
/**
* Get the value of transactionId
*/
public function getTransactionId()
{
return $this->transactionId;
}
/**
* Get the value of versionExternalIdentifier
*/
public function getVersionExternalIdentifier()
{
return $this->versionExternalIdentifier;
}
/**
* Get the value of appItemId
*/
public function getAppItemId()
{
return $this->appItemId;
}
/**
* Get the value of itemId
*/
public function getItemId()
{
return $this->itemId;
}
/**
* Get the value of isTrialPeriod
*/
public function getIsTrialPeriod()
{
return $this->isTrialPeriod;
}
/**
* Get the value of isInIntroOfferPeriod
*/
public function getIsInIntroOfferPeriod()
{
return $this->isInIntroOfferPeriod;
}
/**
* Get the value of uniqueVendorIdentifier
*/
public function getUniqueVendorIdentifier()
{
return $this->uniqueVendorIdentifier;
}
/**
* Get the value of uniqueIdentifier
*/
public function getUniqueIdentifier()
{
return $this->uniqueIdentifier;
}
/**
* Get the value of quantity
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* Get the value of expiresDateFormattedPst
*/
public function getExpiresDateFormattedPst()
{
return $this->expiresDateFormattedPst;
}
/**
* Get the value of expiresDateFormatted
*/
public function getExpiresDateFormatted()
{
return $this->expiresDateFormatted;
}
/**
* Get the value of expiresDateMs
*/
public function getExpiresDateMs()
{
return $this->expiresDateMs;
}
/**
* Get the value of expiresDate
*/
public function getExpiresDate()
{
return $this->expiresDate;
}
/**
* Get the value of cancellationDatePst
*/
public function getCancellationDatePst()
{
return $this->cancellationDatePst;
}
/**
* Get the value of cancellationDateMs
*/
public function getCancellationDateMs()
{
return $this->cancellationDateMs;
}
/**
* Get the value of cancellationDate
*/
public function getCancellationDate()
{
return $this->cancellationDate;
}
/**
* Get the value of cancellationReason
*/
public function getCancellationReason()
{
return $this->cancellationReason;
}
/**
* Get the value of originalPurchaseDatePst
*/
public function getOriginalPurchaseDatePst()
{
return $this->originalPurchaseDatePst;
}
/**
* Get the value of originalPurchaseDateMs
*/
public function getOriginalPurchaseDateMs()
{
return $this->originalPurchaseDateMs;
}
/**
* Get the value of originalPurchaseDate
*/
public function getOriginalPurchaseDate()
{
return $this->originalPurchaseDate;
}
/**
* Get the value of purchaseDatePst
*/
public function getPurchaseDatePst()
{
return $this->purchaseDatePst;
}
/**
* Get the value of purchaseDate
*/
public function getPurchaseDate()
{
return $this->purchaseDate;
}
/**
* Get the value of purchaseDateMs
*/
public function getPurchaseDateMs()
{
return $this->purchaseDateMs;
}
/**
* Get the value of productId
*/
public function getProductId()
{
return $this->productId;
}
/**
* Get the value of webOrderLineItemId
*/
public function getWebOrderLineItemId()
{
return $this->webOrderLineItemId;
}
/**
* Get the value of originalTransactionId
*/
public function getOriginalTransactionId()
{
return $this->originalTransactionId;
}
}
+116
View File
@@ -0,0 +1,116 @@
<?php
namespace Appvise\AppStoreNotifications\Model;
class RenewalInfo
{
private $autoRenewProductId;
private $autoRenewStatus;
private $expirationIntent;
private $originalTransactionId;
private $isInBillingRetryPeriod;
private $productId;
private $priceConsentStatus;
private $gracePeriodExpiresDate;
private $gracePeriodExpiresDateMs;
private $gracePeriodExpiresDatePst;
public function __construct()
{
}
public static function createFromRequest(array $pendingRenewalInfo) {
$instance = new self();
$instance->autoRenewProductId = $pendingRenewalInfo['auto_renew_product_id'] ?? null;
$instance->autoRenewStatus = $pendingRenewalInfo['auto_renew_status'] ?? null;
$instance->expirationIntent = $pendingRenewalInfo['expiration_intent'] ?? null;
$instance->originalTransactionId = $pendingRenewalInfo['original_transaction_id'] ?? null;
$instance->isInBillingRetryPeriod = $pendingRenewalInfo['is_in_billing_retry_period'] ?? null;
$instance->productId = $pendingRenewalInfo['product_id'] ?? null;
$instance->priceConsentStatus = $pendingRenewalInfo['price_consent_status'] ?? null;
$instance->gracePeriodExpiresDate = $pendingRenewalInfo['grace_period_expires_date'] ?? null;
$instance->gracePeriodExpiresDatePst = $pendingRenewalInfo['grace_period_expires_date_pst'] ?? null;
return $instance;
}
/**
* Get the value of autoRenewProductId
*/
public function getAutoRenewProductId()
{
return $this->autoRenewProductId;
}
/**
* Get the value of autoRenewStatus
*/
public function getAutoRenewStatus()
{
return $this->autoRenewStatus;
}
/**
* Get the value of expirationIntent
*/
public function getExpirationIntent()
{
return $this->expirationIntent;
}
/**
* Get the value of originalTransactionId
*/
public function getOriginalTransactionId()
{
return $this->originalTransactionId;
}
/**
* Get the value of isInBillingRetryPeriod
*/
public function getIsInBillingRetryPeriod()
{
return $this->isInBillingRetryPeriod;
}
/**
* Get the value of productId
*/
public function getProductId()
{
return $this->productId;
}
/**
* Get the value of priceConsentStatus
*/
public function getPriceConsentStatus()
{
return $this->priceConsentStatus;
}
/**
* Get the value of gracePeriodExpiresDate
*/
public function getGracePeriodExpiresDate()
{
return $this->gracePeriodExpiresDate;
}
/**
* Get the value of gracePeriodExpiresDateMs
*/
public function getGracePeriodExpiresDateMs()
{
return $this->gracePeriodExpiresDateMs;
}
/**
* Get the value of gracePeriodExpiresDatePst
*/
public function getGracePeriodExpiresDatePst()
{
return $this->gracePeriodExpiresDatePst;
}
}