app_store_server_library/primitives/app_transaction.rs
1use crate::primitives::environment::Environment;
2use crate::primitives::purchase_platform::PurchasePlatform;
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use serde_with::formats::Flexible;
6use serde_with::TimestampMilliSeconds;
7use uuid::Uuid;
8
9/// Information that represents the customer’s purchase of the app, cryptographically signed by the App Store.
10///
11/// [AppTransaction](https://developer.apple.com/documentation/storekit/apptransaction)
12#[serde_with::serde_as]
13#[derive(Debug, Clone, Deserialize, Serialize, Hash)]
14pub struct AppTransaction {
15 /// The server environment that signs the app transaction.
16 /// [environment](https://developer.apple.com/documentation/storekit/apptransaction/3963901-environment)
17 #[serde(rename = "receiptType")]
18 pub receipt_type: Option<Environment>,
19
20 /// The unique identifier the App Store uses to identify the app.
21 /// [appId](https://developer.apple.com/documentation/storekit/apptransaction/3954436-appid)
22 #[serde(rename = "appAppleId")]
23 pub app_apple_id: Option<i64>,
24
25 /// The bundle identifier that the app transaction applies to.
26 /// [bundle_id](https://developer.apple.com/documentation/storekit/apptransaction/3954439-bundleid)
27 #[serde(rename = "bundleId")]
28 pub bundle_id: Option<String>,
29
30 /// The app version that the app transaction applies to.
31 /// [appVersion](https://developer.apple.com/documentation/storekit/apptransaction/3954437-appversion)
32 #[serde(rename = "applicationVersion")]
33 pub application_version: Option<String>,
34
35 /// The version external identifier of the app.
36 /// [appVersionID](https://developer.apple.com/documentation/storekit/apptransaction/3954438-appversionid)
37 #[serde(rename = "versionExternalIdentifier")]
38 pub version_external_identifier: Option<i64>,
39
40 /// The date that the App Store signed the JWS app transaction.
41 /// [signedDate](https://developer.apple.com/documentation/storekit/apptransaction/3954449-signeddate)
42 #[serde(rename = "receiptCreationDate")]
43 #[serde_as(as = "Option<TimestampMilliSeconds<String, Flexible>>")]
44 pub receipt_creation_date: Option<DateTime<Utc>>,
45
46 /// The date the user originally purchased the app from the App Store.
47 /// [originalPurchaseDate](https://developer.apple.com/documentation/storekit/apptransaction/3954448-originalpurchasedate)
48 #[serde(rename = "originalPurchaseDate")]
49 #[serde_as(as = "Option<TimestampMilliSeconds<String, Flexible>>")]
50 pub original_purchase_date: Option<DateTime<Utc>>,
51
52 /// The app version that the user originally purchased from the App Store.
53 /// [originalAppVersion](https://developer.apple.com/documentation/storekit/apptransaction/3954447-originalappversion)
54 #[serde(rename = "originalApplicationVersion")]
55 pub original_application_version: Option<String>,
56
57 /// The Base64 device verification value to use to verify whether the app transaction belongs to the device.
58 /// [deviceVerification](https://developer.apple.com/documentation/storekit/apptransaction/3954441-deviceverification)
59 #[serde(rename = "deviceVerification")]
60 pub device_verification: Option<String>,
61
62 /// The UUID used to compute the device verification value.
63 /// [deviceVerificationNonce](https://developer.apple.com/documentation/storekit/apptransaction/3954442-deviceverificationnonce)
64 #[serde(rename = "deviceVerificationNonce")]
65 pub device_verification_nonce: Option<Uuid>,
66
67 /// The date the customer placed an order for the app before it’s available in the App Store.
68 /// [preorderDate](https://developer.apple.com/documentation/storekit/apptransaction/4013175-preorderdate)
69 #[serde(rename = "preorderDate")]
70 #[serde_as(as = "Option<TimestampMilliSeconds<String, Flexible>>")]
71 pub preorder_date: Option<DateTime<Utc>>,
72
73 /// The unique identifier of the app download transaction.
74 ///
75 /// [appTransactionId](https://developer.apple.com/documentation/storekit/apptransaction/apptransactionid)
76 #[serde(rename = "appTransactionId")]
77 pub app_transaction_id: Option<String>,
78
79 /// The platform on which the customer originally purchased the app.
80 ///
81 /// [original_platform](https://developer.apple.com/documentation/storekit/apptransaction/originalplatform)
82 #[serde(rename = "originalPlatform")]
83 pub original_platform: Option<PurchasePlatform>,
84}
85
86impl AppTransaction {
87 /// The date that the App Store signed the JWS app transaction.
88 /// [signedDate](https://developer.apple.com/documentation/storekit/apptransaction/3954449-signeddate)
89 pub fn signed_date(&self) -> Option<DateTime<Utc>> {
90 self.receipt_creation_date
91 }
92}