logo, gh workflow, locales

This commit is contained in:
Djkáťo 2024-03-18 18:52:05 +01:00
parent 28d8d7a0f9
commit d0d8a98a0b
12 changed files with 137 additions and 38 deletions

2
.env
View file

@ -23,3 +23,5 @@ SITEMAP_INDEX_HOSTNAME="https://example.com"
ACTIVE_GATEWAYS="cod,cash,transfer"
# only SK,EN available :). Determines what language the gateway names will be in storefront
LOCALE="SK"
# uses https://crates.io/crates/iso_currency
CURRENCIES="EUR"

View file

@ -1,8 +1,12 @@
## COMMON VARIABLES FOR ALL APPS
REQUIRED_SALEOR_VERSION="^3.13"
APP_API_BASE_URL="http://0.0.0.0:3000"
APL="Redis"
APL_URL="redis://localhost:6380/2"
APL_URL="redis://localhost:6379/1"
LOG_LEVEL="DEBUG"
## THESE VARIABLES ARE FOR SITEMAP-GENERATOR APP
SITEMAP_TARGET_FOLDER="./temp"
# Available fields can be found in ./sitemap-generator/src/queries/event_subjects_updated.rs: ProductUpdate
SITEMAP_PRODUCT_TEMPLATE="https://example.com/{product.category.slug}/{product.slug}"
# Available fields can be found in ./sitemap-generator/src/queries/event_subjects_updated.rs: CategoryUpdate
@ -13,3 +17,11 @@ SITEMAP_COLLECTION_TEMPLATE="https://example.com/collection/{collection.slug}"
SITEMAP_PAGES_TEMPLATE="https://example.com/{page.slug}"
# Without trailing "/"!
SITEMAP_INDEX_HOSTNAME="https://example.com"
## THESE VARIABLES ARE FOR SIMPLE-PAYMENT-GATEWAY APP
#To see all possible options, check simple-payment-gateway/src/app:GatewayTypes
ACTIVE_GATEWAYS="cod,cash,transfer"
# only SK,EN available :). Determines what language the gateway names will be in storefront
LOCALE="SK"
# uses https://crates.io/crates/iso_currency
CURRENCIES="EUR"

View file

@ -32,7 +32,7 @@ jobs:
--all-features
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
-D warnings
continue-on-error: true
continue-on-error: false
- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v1

48
Cargo.lock generated
View file

@ -1704,6 +1704,26 @@ dependencies = [
"waker-fn",
]
[[package]]
name = "iso_country"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20633e788d3948ea7336861fdb09ec247f5dae4267e8f0743fa97de26c28624d"
dependencies = [
"lazy_static",
]
[[package]]
name = "iso_currency"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33f07181be95c82347a07cf4caf43d2acd8a7e8d08ef1db75e10ed5a9aec3c1b"
dependencies = [
"iso_country",
"serde",
"strum 0.25.0",
]
[[package]]
name = "itertools"
version = "0.12.1"
@ -2696,14 +2716,15 @@ dependencies = [
"dotenvy",
"envy",
"http 1.0.0",
"iso_currency",
"jsonwebtoken",
"redis",
"reqwest",
"rust_decimal",
"serde",
"serde_json",
"strum",
"strum_macros",
"strum 0.26.2",
"strum_macros 0.26.1",
"tower",
"tracing",
"tracing-subscriber",
@ -2950,6 +2971,7 @@ dependencies = [
"dotenvy",
"enum-iterator",
"envy",
"iso_currency",
"redis",
"rust_decimal",
"saleor-app-sdk",
@ -3149,12 +3171,34 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "strum"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125"
dependencies = [
"strum_macros 0.25.3",
]
[[package]]
name = "strum"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29"
[[package]]
name = "strum_macros"
version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0"
dependencies = [
"heck",
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.48",
]
[[package]]
name = "strum_macros"
version = "0.26.1"

View file

@ -25,3 +25,4 @@ tower = { version = "0.4.13", features = ["util"] }
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
cynic-codegen = "3.4.3"
rust_decimal = { version = "1.34.3", features = ["serde-float"] }
iso_currency = { version = "0.4.4", features = ["with-serde", "iterator"] }

View file

@ -27,6 +27,7 @@ envy.workspace = true
dotenvy.workspace = true
tower = { workspace = true }
rust_decimal = { workspace = true, features = ["serde-float"] }
iso_currency = { workspace = true, features = ["with-serde", "iterator"] }
reqwest = { version = "0.11.24", features = ["json"] }
jsonwebtoken = "9.2.0"
async-trait = "0.1.77"

View file

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use strum_macros::EnumString;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, EnumString)]
pub enum LocaleCode {
Ar,
Az,

View file

@ -1,3 +1,4 @@
use iso_currency::Currency;
use rust_decimal::Decimal;
use serde::Serialize;
@ -234,3 +235,23 @@ pub struct ListStoredPaymentMethodsResponse<T: Serialize, C: Serialize> {
pub name: Option<String>,
pub data: Option<T>,
}
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PaymentGateway {
pub id: String,
pub name: String,
pub currencies: Vec<Currency>,
pub config: Vec<ConfigMap>,
}
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ConfigMap {
field: String,
value: serde_json::Value,
}
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PaymentListGatewaysResponse(pub Vec<PaymentGateway>);

View file

@ -34,6 +34,7 @@ surf.workspace = true
cynic = { workspace = true, features = ["http-surf"] }
cynic-codegen.workspace = true
rust_decimal = { workspace = true, features = ["serde-float"] }
iso_currency = { workspace = true, features = ["with-serde", "iterator"] }
const_format = "0.2.32"
enum-iterator = "2.0.0"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -3,11 +3,15 @@ use axum::{
response::{IntoResponse, Response},
};
use enum_iterator::{all, Sequence};
use std::sync::Arc;
use iso_currency::Currency;
use std::{str::FromStr, sync::Arc};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::EnvFilter;
use saleor_app_sdk::{config::Config, locales::LocaleCode, manifest::AppManifest, SaleorApp};
use saleor_app_sdk::{
config::Config, locales::LocaleCode, manifest::AppManifest,
webhooks::sync_response::PaymentGateway, SaleorApp,
};
use serde::Serialize;
// Make our own error that wraps `anyhow::Error`.
pub struct AppError(anyhow::Error);
@ -79,11 +83,14 @@ pub fn get_active_gateways_from_env() -> anyhow::Result<Vec<ActiveGateway>> {
//eg: "accreditation,cod,other,transfer"
let env_types = std::env::var("ACTIVE_GATEWAYS")?;
let locale = std::env::var("LOCALE")?;
let locale = match locale.as_str() {
"SK" => LocaleCode::Sk,
"EN" => LocaleCode::En,
l => unimplemented!("Locale {l} not implemented"),
};
let locale = LocaleCode::from_str(&locale)?;
let currencies = std::env::var("CURRENCIES")?;
let currencies = currencies.split(",").collect::<Vec<_>>();
let currencies = currencies
.iter()
.map(|c| Currency::from_str(*c))
.collect::<Result<Vec<_>, _>>()
.map_err(|e| anyhow::anyhow!(format!("{:?}", e)))?;
let str_types: Vec<_> = env_types.split(',').collect();
let gateway_types = str_types
@ -95,9 +102,10 @@ pub fn get_active_gateways_from_env() -> anyhow::Result<Vec<ActiveGateway>> {
})
.map(|g| ActiveGateway {
gateway_type: g.clone(),
currencies: vec!["EUR".to_owned()],
gateway: PaymentGateway {
currencies: currencies.clone(),
id: format!("{:?}", &g).to_lowercase(),
config: [],
config: vec![],
name: match (g, &locale) {
(GatewayType::COD, LocaleCode::Sk) => "Dobierka".to_owned(),
(GatewayType::Cash, LocaleCode::Sk) => "Hotovosť".to_owned(),
@ -113,6 +121,7 @@ pub fn get_active_gateways_from_env() -> anyhow::Result<Vec<ActiveGateway>> {
(GatewayType::Other, LocaleCode::En) => "Other".to_owned(),
(g, l) => unimplemented!("Gateway {:?} in locale {:?} not implemented", g, l),
},
},
})
.collect::<Vec<_>>();
@ -122,9 +131,5 @@ pub fn get_active_gateways_from_env() -> anyhow::Result<Vec<ActiveGateway>> {
#[derive(Debug, Clone, Serialize)]
pub struct ActiveGateway {
pub gateway_type: GatewayType,
pub id: String,
pub name: String,
pub currencies: Vec<String>,
//don't need this one yet
pub config: [(); 0],
pub gateway: PaymentGateway,
}

View file

@ -7,10 +7,11 @@ use saleor_app_sdk::{
webhooks::{
sync_response::{
CancelationRequestedResult, ChargeRequestedResult,
PaymentGatewayInitializeSessionResponse, RefundRequestedResult,
TransactionCancelationRequestedResponse, TransactionChargeRequestedResponse,
TransactionInitializeSessionResponse, TransactionProcessSessionResponse,
TransactionRefundRequestedResponse, TransactionSessionResult,
PaymentGatewayInitializeSessionResponse, PaymentListGatewaysResponse,
RefundRequestedResult, TransactionCancelationRequestedResponse,
TransactionChargeRequestedResponse, TransactionInitializeSessionResponse,
TransactionProcessSessionResponse, TransactionRefundRequestedResponse,
TransactionSessionResult,
},
utils::{get_webhook_event_type, EitherWebhookType},
SyncWebhookEventType,
@ -52,6 +53,16 @@ pub async fn webhooks(
let event_type = get_webhook_event_type(&headers)?;
let res: Json<Value> = match event_type {
EitherWebhookType::Sync(a) => match a {
SyncWebhookEventType::PaymentListGateways => {
let gateways = state
.active_gateways
.iter()
.cloned()
.map(|g| g.gateway)
.collect::<Vec<_>>();
Json::from(serde_json::to_value(PaymentListGatewaysResponse(gateways))?)
}
SyncWebhookEventType::TransactionCancelationRequested => {
let data = serde_json::from_str::<TransactionCancelationRequested2>(&body)?;
Json::from(serde_json::to_value(