Skip to content

Commit e3c04c3

Browse files
committed
feat: Implement primitives
1 parent 7178d57 commit e3c04c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1567
-3
lines changed

.gitignore

+90-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,87 @@
1+
.idea/**/workspace.xml
2+
.idea/**/tasks.xml
3+
.idea/**/usage.statistics.xml
4+
.idea/**/dictionaries
5+
.idea/**/shelf
6+
7+
# AWS User-specific
8+
.idea/**/aws.xml
9+
10+
# Generated files
11+
.idea/**/contentModel.xml
12+
13+
# Sensitive or high-churn files
14+
.idea/**/dataSources/
15+
.idea/**/dataSources.ids
16+
.idea/**/dataSources.local.xml
17+
.idea/**/sqlDataSources.xml
18+
.idea/**/dynamic.xml
19+
.idea/**/uiDesigner.xml
20+
.idea/**/dbnavigator.xml
21+
22+
# Gradle
23+
.idea/**/gradle.xml
24+
.idea/**/libraries
25+
26+
# Gradle and Maven with auto-import
27+
# When using Gradle or Maven with auto-import, you should exclude module files,
28+
# since they will be recreated, and may cause churn. Uncomment if using
29+
# auto-import.
30+
# .idea/artifacts
31+
# .idea/compiler.xml
32+
# .idea/jarRepositories.xml
33+
# .idea/modules.xml
34+
# .idea/*.iml
35+
# .idea/modules
36+
# *.iml
37+
# *.ipr
38+
39+
# CMake
40+
cmake-build-*/
41+
42+
# Mongo Explorer plugin
43+
.idea/**/mongoSettings.xml
44+
45+
# File-based project format
46+
*.iws
47+
48+
# IntelliJ
49+
out/
50+
51+
# mpeltonen/sbt-idea plugin
52+
.idea_modules/
53+
54+
# JIRA plugin
55+
atlassian-ide-plugin.xml
56+
57+
# Cursive Clojure plugin
58+
.idea/replstate.xml
59+
60+
# SonarLint plugin
61+
.idea/sonarlint/
62+
63+
# Crashlytics plugin (for Android Studio and IntelliJ)
64+
com_crashlytics_export_strings.xml
65+
crashlytics.properties
66+
crashlytics-build.properties
67+
fabric.properties
68+
69+
# Editor-based Rest Client
70+
.idea/httpRequests
71+
72+
# Android studio 3.1+ serialized cache file
73+
.idea/caches/build_file_checksums.ser
74+
75+
### CLion+all Patch ###
76+
# Ignore everything but code style settings and run configurations
77+
# that are supposed to be shared within teams.
78+
79+
.idea/*
80+
81+
!.idea/codeStyles
82+
!.idea/runConfigurations
83+
84+
### Rust ###
185
# Generated by Cargo
286
# will have compiled files and executables
387
debug/
@@ -6,9 +90,12 @@ target/
690
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
791
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
892
Cargo.lock
9-
93+
api/Cargo.lock
94+
core/Cargo.lock
95+
sdk/bindings/Cargo.lock
96+
sdk/example/Cargo.lock
97+
sdk/lib/Cargo.lock
1098
# These are backup files generated by rustfmt
1199
**/*.rs.bk
12100

13-
# MSVC Windows builds of rustc generate these, which store debugging information
14-
*.pdb
101+
.env

Cargo.toml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "app-store-server-library"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license-file = "LICENSE"
6+
authors = ["tkhp", "namecare"]
7+
repository = "https://github.com/namecare/app-store-server-library-rust"
8+
homepage = "https://github.com/namecare/app-store-server-library-rust"
9+
10+
[dependencies]
11+
12+
# Serialization
13+
serde = { version = "1.0.176", features = ["derive"] }
14+
serde_json = { version = "1.0.104" }
15+
uuid = { version = "1.4.0", features = ["serde", "v4"] }
16+
chrono = { version = "0.4.26", features = ["serde"] }

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod primitives;
2+

src/primitives/account_tenure.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Debug, Deserialize, Serialize, Hash, PartialEq, Eq)]
4+
pub enum AccountTenure {
5+
Undeclared = 0,
6+
ZeroToThreeDays = 1,
7+
ThreeDaysToTenDays = 2,
8+
TenDaysToThirtyDays = 3,
9+
ThirtyDaysToNinetyDays = 4,
10+
NinetyDaysToOneHundredEightyDays = 5,
11+
OneHundredEightyDaysToThreeHundredSixtyFiveDays = 6,
12+
GreaterThanThreeHundredSixtyFiveDays = 7,
13+
}

src/primitives/app_transaction.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use chrono::{DateTime, Utc};
2+
use serde::{Deserialize, Serialize};
3+
use uuid::Uuid;
4+
use crate::primitives::environment::Environment;
5+
6+
#[derive(Debug, Deserialize, Serialize, Hash)]
7+
pub struct AppTransaction {
8+
/// The server environment that signs the app transaction.
9+
/// [environment](https://developer.apple.com/documentation/storekit/apptransaction/3963901-environment)
10+
pub receipt_type: Option<Environment>,
11+
12+
/// The unique identifier the App Store uses to identify the app.
13+
/// [appId](https://developer.apple.com/documentation/storekit/apptransaction/3954436-appid)
14+
pub app_apple_id: Option<i64>,
15+
16+
/// The bundle identifier that the app transaction applies to.
17+
/// [bundle_id](https://developer.apple.com/documentation/storekit/apptransaction/3954439-bundleid)
18+
pub bundle_id: Option<String>,
19+
20+
/// The app version that the app transaction applies to.
21+
/// [appVersion](https://developer.apple.com/documentation/storekit/apptransaction/3954437-appversion)
22+
pub application_version: Option<String>,
23+
24+
/// The version external identifier of the app.
25+
/// [appVersionID](https://developer.apple.com/documentation/storekit/apptransaction/3954438-appversionid)
26+
pub version_external_identifier: Option<i64>,
27+
28+
/// The date that the App Store signed the JWS app transaction.
29+
/// [signedDate](https://developer.apple.com/documentation/storekit/apptransaction/3954449-signeddate)
30+
pub receipt_creation_date: Option<DateTime<Utc>>,
31+
32+
/// The date the user originally purchased the app from the App Store.
33+
/// [originalPurchaseDate](https://developer.apple.com/documentation/storekit/apptransaction/3954448-originalpurchasedate)
34+
pub original_purchase_date: Option<DateTime<Utc>>,
35+
36+
/// The app version that the user originally purchased from the App Store.
37+
/// [originalAppVersion](https://developer.apple.com/documentation/storekit/apptransaction/3954447-originalappversion)
38+
pub original_application_version: Option<String>,
39+
40+
/// The Base64 device verification value to use to verify whether the app transaction belongs to the device.
41+
/// [deviceVerification](https://developer.apple.com/documentation/storekit/apptransaction/3954441-deviceverification)
42+
pub device_verification: Option<String>,
43+
44+
/// The UUID used to compute the device verification value.
45+
/// [deviceVerificationNonce](https://developer.apple.com/documentation/storekit/apptransaction/3954442-deviceverificationnonce)
46+
pub device_verification_nonce: Option<Uuid>,
47+
48+
/// The date the customer placed an order for the app before it’s available in the App Store.
49+
/// [preorderDate](https://developer.apple.com/documentation/storekit/apptransaction/4013175-preorderdate)
50+
pub preorder_date: Option<DateTime<Utc>>,
51+
52+
/// The date that the App Store signed the JWS app transaction.
53+
/// [signedDate](https://developer.apple.com/documentation/storekit/apptransaction/3954449-signeddate)
54+
pub signed_date: Option<DateTime<Utc>>,
55+
}

src/primitives/auto_renew_status.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Debug, Deserialize, Serialize, Hash, PartialEq, Eq)]
4+
pub enum AutoRenewStatus {
5+
Off = 0,
6+
On = 1,
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use serde::{Deserialize, Serialize};
2+
use crate::primitives::send_attempt_item::SendAttemptItem;
3+
4+
/// A response that contains the contents of the test notification sent by the App Store server and the result from your server.
5+
///
6+
/// [CheckTestNotificationResponse](https://developer.apple.com/documentation/appstoreserverapi/checktestnotificationresponse)
7+
#[derive(Debug, Deserialize, Serialize, Hash)]
8+
pub struct CheckTestNotificationResponse {
9+
/// A cryptographically signed payload, in JSON Web Signature (JWS) format, containing the response body for a version 2 notification.
10+
///
11+
/// [signedPayload](https://developer.apple.com/documentation/appstoreservernotifications/signedpayload)
12+
#[serde(rename = "signedPayload")]
13+
pub signed_payload: Option<String>,
14+
15+
/// An array of information the App Store server records for its attempts to send the TEST notification to your server. The array may contain a maximum of six sendAttemptItem objects.
16+
///
17+
/// [sendAttemptItem](https://developer.apple.com/documentation/appstoreserverapi/sendattemptitem)
18+
#[serde(rename = "sendAttemptItem")]
19+
pub send_attempts: Option<Vec<SendAttemptItem>>,
20+
}

src/primitives/consumption_request.rs

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use serde::{Deserialize, Serialize};
2+
use uuid::Uuid;
3+
use crate::primitives::account_tenure::AccountTenure;
4+
use crate::primitives::consumption_status::ConsumptionStatus;
5+
use crate::primitives::delivery_status::DeliveryStatus;
6+
use crate::primitives::lifetime_dollars_purchased::LifetimeDollarsPurchased;
7+
use crate::primitives::lifetime_dollars_refunded::LifetimeDollarsRefunded;
8+
use crate::primitives::platform::Platform;
9+
use crate::primitives::play_time::PlayTime;
10+
use crate::primitives::user_status::UserStatus;
11+
12+
/// The request body containing consumption information.
13+
///
14+
/// [ConsumptionRequest](https://developer.apple.com/documentation/appstoreserverapi/consumptionrequest)
15+
#[derive(Debug, Deserialize, Serialize, Hash)]
16+
pub struct ConsumptionRequest {
17+
/// A Boolean value that indicates whether the customer consented to provide consumption data to the App Store.
18+
///
19+
/// [customerConsented](https://developer.apple.com/documentation/appstoreserverapi/customerconsented)
20+
#[serde(rename = "customerConsented")]
21+
pub customer_consented: Option<bool>,
22+
23+
/// A value that indicates the extent to which the customer consumed the in-app purchase.
24+
///
25+
/// [consumptionStatus](https://developer.apple.com/documentation/appstoreserverapi/consumptionstatus)
26+
#[serde(rename = "consumptionStatus")]
27+
pub consumption_status: Option<ConsumptionStatus>,
28+
29+
/// A value that indicates the platform on which the customer consumed the in-app purchase.
30+
///
31+
/// [platform](https://developer.apple.com/documentation/appstoreserverapi/platform)
32+
pub platform: Option<Platform>,
33+
34+
/// A Boolean value that indicates whether you provided, prior to its purchase, a free sample or trial of the content, or information about its functionality.
35+
///
36+
/// [sampleContentProvided](https://developer.apple.com/documentation/appstoreserverapi/samplecontentprovided)
37+
#[serde(rename = "sampleContentProvided")]
38+
pub sample_content_provided: Option<bool>,
39+
40+
/// A value that indicates whether the app successfully delivered an in-app purchase that works properly.
41+
///
42+
/// [deliveryStatus](https://developer.apple.com/documentation/appstoreserverapi/deliverystatus)
43+
#[serde(rename = "deliveryStatus")]
44+
pub delivery_status: Option<DeliveryStatus>,
45+
46+
/// The UUID that an app optionally generates to map a customer’s in-app purchase with its resulting App Store transaction.
47+
///
48+
/// [appAccountToken](https://developer.apple.com/documentation/appstoreserverapi/appaccounttoken)
49+
#[serde(rename = "appAccountToken")]
50+
pub app_account_token: Option<Uuid>,
51+
52+
/// The age of the customer’s account.
53+
///
54+
/// [accountTenure](https://developer.apple.com/documentation/appstoreserverapi/accounttenure)
55+
#[serde(rename = "accountTenure")]
56+
pub account_tenure: Option<AccountTenure>,
57+
58+
/// A value that indicates the amount of time that the customer used the app.
59+
///
60+
/// [playTime](https://developer.apple.com/documentation/appstoreserverapi/playtime)
61+
#[serde(rename = "playTime")]
62+
pub play_time: Option<PlayTime>,
63+
64+
/// A value that indicates the total amount, in USD, of refunds the customer has received, in your app, across all platforms.
65+
///
66+
/// [lifetimeDollarsRefunded](https://developer.apple.com/documentation/appstoreserverapi/lifetimedollarsrefunded)
67+
#[serde(rename = "lifetimeDollarsRefunded")]
68+
pub lifetime_dollars_refunded: Option<LifetimeDollarsRefunded>,
69+
70+
/// A value that indicates the total amount, in USD, of in-app purchases the customer has made in your app, across all platforms.
71+
///
72+
/// [lifetimeDollarsPurchased](https://developer.apple.com/documentation/appstoreserverapi/lifetimedollarspurchased)
73+
#[serde(rename = "lifetimeDollarsPurchased")]
74+
pub lifetime_dollars_purchased: Option<LifetimeDollarsPurchased>,
75+
76+
/// The status of the customer’s account.
77+
///
78+
/// [userStatus](https://developer.apple.com/documentation/appstoreserverapi/userstatus)
79+
#[serde(rename = "userStatus")]
80+
pub user_status: Option<UserStatus>,
81+
}

src/primitives/consumption_status.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// A value that indicates the extent to which the customer consumed the in-app purchase.
4+
///
5+
/// [consumptionStatus](https://developer.apple.com/documentation/appstoreserverapi/consumptionstatus)
6+
#[derive(Debug, Deserialize, Serialize, Hash, PartialEq, Eq)]
7+
pub enum ConsumptionStatus {
8+
Undeclared = 0,
9+
NotConsumed = 1,
10+
PartiallyConsumed = 2,
11+
FullyConsumed = 3,
12+
}

src/primitives/data.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use serde::{Deserialize, Serialize};
2+
use crate::primitives::environment::Environment;
3+
4+
/// The app metadata and the signed renewal and transaction information.
5+
///
6+
/// [data](https://developer.apple.com/documentation/appstoreservernotifications/data)
7+
#[derive(Debug, Deserialize, Serialize, Hash)]
8+
pub struct Data {
9+
/// The server environment that the notification applies to, either sandbox or production.
10+
///
11+
/// [environment](https://developer.apple.com/documentation/appstoreservernotifications/environment)
12+
pub environment: Option<Environment>,
13+
14+
/// The unique identifier of an app in the App Store.
15+
///
16+
/// [app_apple_id](https://developer.apple.com/documentation/appstoreservernotifications/appappleid)
17+
pub app_apple_id: Option<i64>,
18+
19+
/// The bundle identifier of an app.
20+
///
21+
/// [bundle_id](https://developer.apple.com/documentation/appstoreserverapi/bundleid)
22+
pub bundle_id: Option<String>,
23+
24+
/// The version of the build that identifies an iteration of the bundle.
25+
///
26+
/// [bundleVersion](https://developer.apple.com/documentation/appstoreservernotifications/bundleversion)
27+
pub bundle_version: Option<String>,
28+
29+
/// Transaction information signed by the App Store, in JSON Web Signature (JWS) format.
30+
///
31+
/// [JWSTransaction](https://developer.apple.com/documentation/appstoreserverapi/jwstransaction)
32+
pub signed_transaction_info: Option<String>,
33+
34+
/// Subscription renewal information, signed by the App Store, in JSON Web Signature (JWS) format.
35+
///
36+
/// [JWSRenewalInfo](https://developer.apple.com/documentation/appstoreserverapi/jwsrenewalinfo)
37+
pub signed_renewal_info: Option<String>,
38+
}

src/primitives/delivery_status.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// A value that indicates whether the app successfully delivered an in-app purchase that works properly.
4+
///
5+
/// [deliveryStatus](https://developer.apple.com/documentation/appstoreserverapi/deliverystatus)
6+
#[derive(Debug, Deserialize, Serialize, Hash, PartialEq, Eq)]
7+
pub enum DeliveryStatus {
8+
DeliveredAndWorkingProperly = 0,
9+
DidNotDeliverDueToQualityIssue = 1,
10+
DeliveredWrongItem = 2,
11+
DidNotDeliverDueToServerOutage = 3,
12+
DidNotDeliverDueToIngameCurrencyChange = 4,
13+
DidNotDeliverForOtherReason = 5,
14+
}

src/primitives/environment.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Debug, Deserialize, Serialize, Hash, PartialEq, Eq)]
4+
pub enum Environment {
5+
#[serde(rename = "Sandbox")]
6+
Sandbox,
7+
#[serde(rename = "Production")]
8+
Production,
9+
}

src/primitives/error_payload.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Debug, Deserialize, Serialize, Hash)]
4+
pub struct ErrorPayload {
5+
pub error_code: Option<i64>,
6+
pub error_message: Option<String>,
7+
}

0 commit comments

Comments
 (0)