Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
CRAP | |
75.00% |
3 / 4 |
| AttributeType | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
3.14 | |
75.00% |
3 / 4 |
| getJsonFieldName | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getHumanFieldDescription | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Proton\IosReceiptParser\Attribute; |
| 4 | |
| 5 | /** |
| 6 | * @internal |
| 7 | */ |
| 8 | final class AttributeType |
| 9 | { |
| 10 | // Receipt |
| 11 | public const RECEIPT_APP_ITEM_ID = 0; |
| 12 | public const RECEIPT_BUNDLE_ID = 2; |
| 13 | public const RECEIPT_APP_VERSION = 3; |
| 14 | public const RECEIPT_OPAQUE = 4; |
| 15 | public const RECEIPT_SHA1 = 5; |
| 16 | public const RECEIPT_CREATION_DATE = 12; |
| 17 | public const RECEIPT_CREATION_DATE_MS = 12 * 1000; |
| 18 | public const RECEIPT_IN_APP = 17; |
| 19 | public const RECEIPT_ORIGINAL_APP_VERSION = 19; |
| 20 | public const RECEIPT_EXPIRATION_DATE = 21; |
| 21 | public const RECEIPT_EXPIRATION_DATE_MS = 21 * 1000; |
| 22 | |
| 23 | // InApp |
| 24 | public const IN_APP_QUANTITY = 1701; |
| 25 | public const IN_APP_PRODUCT_IDENTIFIER = 1702; |
| 26 | public const IN_APP_TRANSACTION_IDENTIFIER = 1703; |
| 27 | public const IN_APP_PURCHASE_DATE = 1704; |
| 28 | public const IN_APP_PURCHASE_DATE_MS = 1704 * 1000; |
| 29 | public const IN_APP_ORIGINAL_TRANSACTION_IDENTIFIER = 1705; |
| 30 | public const IN_APP_ORIGINAL_PURCHASE_DATE = 1706; |
| 31 | public const IN_APP_ORIGINAL_PURCHASE_DATE_MS = 1706 * 1000; |
| 32 | public const IN_APP_SUBSCRIPTION_EXPIRATION_DATE = 1708; |
| 33 | public const IN_APP_SUBSCRIPTION_EXPIRATION_DATE_MS = 1708 * 1000; |
| 34 | public const IN_APP_WEB_ORDER_LINE_ITEM_ID = 1711; |
| 35 | public const IN_APP_CANCELLATION_DATE = 1712; |
| 36 | public const IN_APP_CANCELLATION_DATE_MS = 1712 * 1000; |
| 37 | public const IN_APP_SUBSCRIPTION_INTRODUCTORY_PRICE_PERIOD = 1719; |
| 38 | |
| 39 | private const JSON_FIELD_NAMES = [ |
| 40 | self::RECEIPT_APP_ITEM_ID => 'app_item_id', |
| 41 | self::RECEIPT_BUNDLE_ID => 'bundle_id', |
| 42 | self::RECEIPT_APP_VERSION => 'application_version', |
| 43 | self::RECEIPT_CREATION_DATE => 'receipt_creation_date', |
| 44 | self::RECEIPT_CREATION_DATE_MS => 'receipt_creation_date_ms', |
| 45 | self::RECEIPT_IN_APP => 'in_app', |
| 46 | self::RECEIPT_ORIGINAL_APP_VERSION => 'original_application_version', |
| 47 | self::RECEIPT_EXPIRATION_DATE => 'receipt_expiration_date', |
| 48 | self::RECEIPT_EXPIRATION_DATE_MS => 'receipt_expiration_date_ms', |
| 49 | |
| 50 | self::IN_APP_QUANTITY => 'quantity', |
| 51 | self::IN_APP_PRODUCT_IDENTIFIER => 'product_id', |
| 52 | self::IN_APP_TRANSACTION_IDENTIFIER => 'transaction_id', |
| 53 | self::IN_APP_PURCHASE_DATE => 'purchase_date', |
| 54 | self::IN_APP_PURCHASE_DATE_MS => 'purchase_date_ms', |
| 55 | self::IN_APP_ORIGINAL_TRANSACTION_IDENTIFIER => 'original_transaction_id', |
| 56 | self::IN_APP_ORIGINAL_PURCHASE_DATE => 'original_purchase_date', |
| 57 | self::IN_APP_ORIGINAL_PURCHASE_DATE_MS => 'original_purchase_date_ms', |
| 58 | self::IN_APP_SUBSCRIPTION_EXPIRATION_DATE => 'expires_date', |
| 59 | self::IN_APP_SUBSCRIPTION_EXPIRATION_DATE_MS => 'expires_date_ms', |
| 60 | self::IN_APP_WEB_ORDER_LINE_ITEM_ID => 'web_order_line_item_id', |
| 61 | self::IN_APP_CANCELLATION_DATE => 'cancellation_date', |
| 62 | self::IN_APP_CANCELLATION_DATE_MS => 'cancellation_date_ms', |
| 63 | self::IN_APP_SUBSCRIPTION_INTRODUCTORY_PRICE_PERIOD => 'is_in_intro_offer_period', |
| 64 | ]; |
| 65 | |
| 66 | private const HUMAN_FIELD_DESCRIPTIONS = [ |
| 67 | self::RECEIPT_APP_ITEM_ID => 'A string that the App Store uses to uniquely identify the application that created the transaction.', |
| 68 | self::RECEIPT_BUNDLE_ID => 'The app\'s bundle identifier', |
| 69 | self::RECEIPT_APP_VERSION => 'The app\'s version number', |
| 70 | self::RECEIPT_OPAQUE => 'An opaque value used, with other data, to compute the SHA-1 hash during validation', |
| 71 | self::RECEIPT_SHA1 => 'A SHA-1 hash, used to validate the receipt', |
| 72 | self::RECEIPT_CREATION_DATE => 'The date when the app receipt was created', |
| 73 | self::RECEIPT_IN_APP => 'The receipt for an in-app purchase', |
| 74 | self::RECEIPT_ORIGINAL_APP_VERSION => 'The version of the app that was originally purchased', |
| 75 | self::RECEIPT_EXPIRATION_DATE => 'The date that the app receipt expires', |
| 76 | |
| 77 | self::IN_APP_QUANTITY => 'The number of items purchased', |
| 78 | self::IN_APP_PRODUCT_IDENTIFIER => 'The product identifier of the item that was purchased', |
| 79 | self::IN_APP_TRANSACTION_IDENTIFIER => 'The transaction identifier of the item that was purchased', |
| 80 | self::IN_APP_PURCHASE_DATE => 'The date and time that the item was purchased', |
| 81 | self::IN_APP_ORIGINAL_TRANSACTION_IDENTIFIER => 'For a transaction that restores a previous transaction, the transaction identifier of the original transaction. Otherwise, identical to the transaction identifier', |
| 82 | self::IN_APP_ORIGINAL_PURCHASE_DATE => 'For a transaction that restores a previous transaction, the date of the original transaction', |
| 83 | self::IN_APP_SUBSCRIPTION_EXPIRATION_DATE => 'The expiration date for the subscription, expressed as the number of milliseconds since January 1, 1970, 00:00:00 GMT', |
| 84 | self::IN_APP_WEB_ORDER_LINE_ITEM_ID => 'The primary key for identifying subscription purchases', |
| 85 | self::IN_APP_CANCELLATION_DATE => 'For a transaction that was canceled by Apple customer support, the time and date of the cancellation. For an auto-renewable subscription plan that was upgraded, the time and date of the upgrade transaction', |
| 86 | self::IN_APP_SUBSCRIPTION_INTRODUCTORY_PRICE_PERIOD => 'For an auto-renewable subscription, whether or not it is in the introductory price period', |
| 87 | ]; |
| 88 | |
| 89 | public static function getJsonFieldName(int $type): ?string |
| 90 | { |
| 91 | return self::JSON_FIELD_NAMES[$type] ?? null; |
| 92 | } |
| 93 | |
| 94 | public static function getHumanFieldDescription(int $type): string |
| 95 | { |
| 96 | if (($description = self::HUMAN_FIELD_DESCRIPTIONS[$type] ?? null) !== null) { |
| 97 | return $description; |
| 98 | } |
| 99 | |
| 100 | throw new \Exception("Unknown attribute type: {$type}"); |
| 101 | } |
| 102 | } |