diff options
| author | Jonathan <jonathan@mullvad.net> | 2023-10-03 18:06:55 +0200 |
|---|---|---|
| committer | Jonathan <jonathan@mullvad.net> | 2023-10-16 18:34:07 +0200 |
| commit | 9204e1c66e710d22ebf7b55ab6ec045cc53bdad9 (patch) | |
| tree | 83745d24e9e09a81f6b9cb7884f04ba05a39e371 /mullvad-api/src | |
| parent | d32b6f81ceb8c383588678e8fbabe613fbac4142 (diff) | |
| download | mullvadvpn-9204e1c66e710d22ebf7b55ab6ec045cc53bdad9.tar.xz mullvadvpn-9204e1c66e710d22ebf7b55ab6ec045cc53bdad9.zip | |
Add piping for google play payment API requests
This commit adds all of the basic piping in order to let Android use the
JNI interface in order to make requests to our API pertaining to google
play payment initialization and status.
Diffstat (limited to 'mullvad-api/src')
| -rw-r--r-- | mullvad-api/src/lib.rs | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs index 37faf5c40c..647b5cf071 100644 --- a/mullvad-api/src/lib.rs +++ b/mullvad-api/src/lib.rs @@ -6,7 +6,7 @@ use futures::channel::mpsc; use futures::Stream; use hyper::Method; use mullvad_types::{ - account::{AccountToken, VoucherSubmission}, + account::{AccountToken, PlayPurchase, PlayPurchasePaymentToken, VoucherSubmission}, version::AppVersion, }; use proxy::ApiConnectionMode; @@ -63,6 +63,7 @@ pub const API_IP_CACHE_FILENAME: &str = "api-ip-address.txt"; const ACCOUNTS_URL_PREFIX: &str = "accounts/v1"; const APP_URL_PREFIX: &str = "app/v1"; +const GOOGLE_PAYMENTS_URL_PREFIX: &str = "payments/google-play/v1"; pub static API: LazyManual<ApiEndpoint> = LazyManual::new(ApiEndpoint::from_env_vars); @@ -457,6 +458,62 @@ impl AccountsProxy { } } + pub fn init_play_purchase( + &mut self, + account_token: AccountToken, + ) -> impl Future<Output = Result<PlayPurchasePaymentToken, rest::Error>> { + #[derive(serde::Deserialize)] + struct PlayPurchaseInitResponse { + obfuscated_id: String, + } + + let service = self.handle.service.clone(); + let factory = self.handle.factory.clone(); + let access_proxy = self.handle.token_store.clone(); + + async move { + let response = rest::send_json_request( + &factory, + service, + &format!("{GOOGLE_PAYMENTS_URL_PREFIX}/init"), + Method::POST, + &(), + Some((access_proxy, account_token)), + &[StatusCode::OK], + ) + .await; + + let PlayPurchaseInitResponse { obfuscated_id } = + rest::deserialize_body(response?).await?; + + Ok(obfuscated_id) + } + } + + pub fn verify_play_purchase( + &mut self, + account_token: AccountToken, + play_purchase: PlayPurchase, + ) -> impl Future<Output = Result<(), rest::Error>> { + let service = self.handle.service.clone(); + let factory = self.handle.factory.clone(); + let access_proxy = self.handle.token_store.clone(); + + async move { + rest::send_json_request( + &factory, + service, + &format!("{GOOGLE_PAYMENTS_URL_PREFIX}/acknowledge"), + Method::POST, + &play_purchase, + Some((access_proxy, account_token)), + &[StatusCode::ACCEPTED], + ) + .await?; + Ok(()) + } + } + pub fn get_www_auth_token( &self, account: AccountToken, |
