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