Skip to main content

egs_api/api/
commerce.rs

1use crate::api::error::EpicAPIError;
2use crate::api::types::billing_account::BillingAccount;
3use crate::api::types::price::PriceResponse;
4use crate::api::types::quick_purchase::QuickPurchaseResponse;
5use crate::api::EpicAPI;
6
7impl EpicAPI {
8    /// Fetch offer prices from the price engine.
9    pub async fn offer_prices(
10        &self,
11        namespace: &str,
12        offer_ids: &[String],
13        country: &str,
14    ) -> Result<PriceResponse, EpicAPIError> {
15        let url = "https://priceengine-public-service-ecomprod01.ol.epicgames.com/priceengine/api/shared/offers/price";
16        let body = serde_json::json!({
17            "namespace": namespace,
18            "offers": offer_ids,
19            "country": country,
20        });
21        self.authorized_post_json(&url, &body).await
22    }
23
24    /// Execute a quick purchase (typically for free game claims).
25    pub async fn quick_purchase(
26        &self,
27        namespace: &str,
28        offer_id: &str,
29    ) -> Result<QuickPurchaseResponse, EpicAPIError> {
30        let url = match &self.user_data.account_id {
31            Some(id) => format!(
32                "https://orderprocessor-public-service-ecomprod01.ol.epicgames.com/orderprocessor/api/shared/accounts/{}/orders/quickPurchase",
33                id
34            ),
35            None => return Err(EpicAPIError::InvalidCredentials),
36        };
37        let body = serde_json::json!({
38            "salesChannel": "Launcher-purchase-client",
39            "entitlementSource": "Launcher-purchase-client",
40            "returnSplitPaymentItems": false,
41            "lineOffers": [{
42                "offerId": offer_id,
43                "quantity": 1,
44                "namespace": namespace,
45            }],
46        });
47        self.authorized_post_json(&url, &body).await
48    }
49
50    /// Fetch the default billing account for the logged-in user.
51    pub async fn billing_account(&self) -> Result<BillingAccount, EpicAPIError> {
52        let url = match &self.user_data.account_id {
53            Some(id) => format!(
54                "https://launcher-public-service-prod06.ol.epicgames.com/launcher/api/public/payment/accounts/{}/billingaccounts/default",
55                id
56            ),
57            None => return Err(EpicAPIError::InvalidCredentials),
58        };
59        self.authorized_get_json(&url).await
60    }
61}