logo, gh workflow, locales
This commit is contained in:
parent
28d8d7a0f9
commit
d0d8a98a0b
12 changed files with 137 additions and 38 deletions
2
.env
2
.env
|
@ -23,3 +23,5 @@ SITEMAP_INDEX_HOSTNAME="https://example.com"
|
||||||
ACTIVE_GATEWAYS="cod,cash,transfer"
|
ACTIVE_GATEWAYS="cod,cash,transfer"
|
||||||
# only SK,EN available :). Determines what language the gateway names will be in storefront
|
# only SK,EN available :). Determines what language the gateway names will be in storefront
|
||||||
LOCALE="SK"
|
LOCALE="SK"
|
||||||
|
# uses https://crates.io/crates/iso_currency
|
||||||
|
CURRENCIES="EUR"
|
||||||
|
|
14
.env.example
14
.env.example
|
@ -1,8 +1,12 @@
|
||||||
|
## COMMON VARIABLES FOR ALL APPS
|
||||||
REQUIRED_SALEOR_VERSION="^3.13"
|
REQUIRED_SALEOR_VERSION="^3.13"
|
||||||
APP_API_BASE_URL="http://0.0.0.0:3000"
|
APP_API_BASE_URL="http://0.0.0.0:3000"
|
||||||
APL="Redis"
|
APL="Redis"
|
||||||
APL_URL="redis://localhost:6380/2"
|
APL_URL="redis://localhost:6379/1"
|
||||||
LOG_LEVEL="DEBUG"
|
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
|
# 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}"
|
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
|
# 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}"
|
SITEMAP_PAGES_TEMPLATE="https://example.com/{page.slug}"
|
||||||
# Without trailing "/"!
|
# Without trailing "/"!
|
||||||
SITEMAP_INDEX_HOSTNAME="https://example.com"
|
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"
|
||||||
|
|
2
.github/workflows/rust-clippy.yml
vendored
2
.github/workflows/rust-clippy.yml
vendored
|
@ -32,7 +32,7 @@ jobs:
|
||||||
--all-features
|
--all-features
|
||||||
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
|
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
|
||||||
-D warnings
|
-D warnings
|
||||||
continue-on-error: true
|
continue-on-error: false
|
||||||
|
|
||||||
- name: Upload analysis results to GitHub
|
- name: Upload analysis results to GitHub
|
||||||
uses: github/codeql-action/upload-sarif@v1
|
uses: github/codeql-action/upload-sarif@v1
|
||||||
|
|
48
Cargo.lock
generated
48
Cargo.lock
generated
|
@ -1704,6 +1704,26 @@ dependencies = [
|
||||||
"waker-fn",
|
"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]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
|
@ -2696,14 +2716,15 @@ dependencies = [
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"envy",
|
"envy",
|
||||||
"http 1.0.0",
|
"http 1.0.0",
|
||||||
|
"iso_currency",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
"redis",
|
"redis",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rust_decimal",
|
"rust_decimal",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"strum",
|
"strum 0.26.2",
|
||||||
"strum_macros",
|
"strum_macros 0.26.1",
|
||||||
"tower",
|
"tower",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
@ -2950,6 +2971,7 @@ dependencies = [
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"enum-iterator",
|
"enum-iterator",
|
||||||
"envy",
|
"envy",
|
||||||
|
"iso_currency",
|
||||||
"redis",
|
"redis",
|
||||||
"rust_decimal",
|
"rust_decimal",
|
||||||
"saleor-app-sdk",
|
"saleor-app-sdk",
|
||||||
|
@ -3149,12 +3171,34 @@ version = "0.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
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]]
|
[[package]]
|
||||||
name = "strum"
|
name = "strum"
|
||||||
version = "0.26.2"
|
version = "0.26.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29"
|
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]]
|
[[package]]
|
||||||
name = "strum_macros"
|
name = "strum_macros"
|
||||||
version = "0.26.1"
|
version = "0.26.1"
|
||||||
|
|
|
@ -25,3 +25,4 @@ tower = { version = "0.4.13", features = ["util"] }
|
||||||
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
||||||
cynic-codegen = "3.4.3"
|
cynic-codegen = "3.4.3"
|
||||||
rust_decimal = { version = "1.34.3", features = ["serde-float"] }
|
rust_decimal = { version = "1.34.3", features = ["serde-float"] }
|
||||||
|
iso_currency = { version = "0.4.4", features = ["with-serde", "iterator"] }
|
||||||
|
|
|
@ -27,6 +27,7 @@ envy.workspace = true
|
||||||
dotenvy.workspace = true
|
dotenvy.workspace = true
|
||||||
tower = { workspace = true }
|
tower = { workspace = true }
|
||||||
rust_decimal = { workspace = true, features = ["serde-float"] }
|
rust_decimal = { workspace = true, features = ["serde-float"] }
|
||||||
|
iso_currency = { workspace = true, features = ["with-serde", "iterator"] }
|
||||||
reqwest = { version = "0.11.24", features = ["json"] }
|
reqwest = { version = "0.11.24", features = ["json"] }
|
||||||
jsonwebtoken = "9.2.0"
|
jsonwebtoken = "9.2.0"
|
||||||
async-trait = "0.1.77"
|
async-trait = "0.1.77"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use strum_macros::EnumString;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize, EnumString)]
|
||||||
pub enum LocaleCode {
|
pub enum LocaleCode {
|
||||||
Ar,
|
Ar,
|
||||||
Az,
|
Az,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use iso_currency::Currency;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
@ -234,3 +235,23 @@ pub struct ListStoredPaymentMethodsResponse<T: Serialize, C: Serialize> {
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub data: Option<T>,
|
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>);
|
||||||
|
|
|
@ -34,6 +34,7 @@ surf.workspace = true
|
||||||
cynic = { workspace = true, features = ["http-surf"] }
|
cynic = { workspace = true, features = ["http-surf"] }
|
||||||
cynic-codegen.workspace = true
|
cynic-codegen.workspace = true
|
||||||
rust_decimal = { workspace = true, features = ["serde-float"] }
|
rust_decimal = { workspace = true, features = ["serde-float"] }
|
||||||
|
iso_currency = { workspace = true, features = ["with-serde", "iterator"] }
|
||||||
const_format = "0.2.32"
|
const_format = "0.2.32"
|
||||||
enum-iterator = "2.0.0"
|
enum-iterator = "2.0.0"
|
||||||
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 14 KiB |
|
@ -3,11 +3,15 @@ use axum::{
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
};
|
};
|
||||||
use enum_iterator::{all, Sequence};
|
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::level_filters::LevelFilter;
|
||||||
use tracing_subscriber::EnvFilter;
|
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;
|
use serde::Serialize;
|
||||||
// Make our own error that wraps `anyhow::Error`.
|
// Make our own error that wraps `anyhow::Error`.
|
||||||
pub struct AppError(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"
|
//eg: "accreditation,cod,other,transfer"
|
||||||
let env_types = std::env::var("ACTIVE_GATEWAYS")?;
|
let env_types = std::env::var("ACTIVE_GATEWAYS")?;
|
||||||
let locale = std::env::var("LOCALE")?;
|
let locale = std::env::var("LOCALE")?;
|
||||||
let locale = match locale.as_str() {
|
let locale = LocaleCode::from_str(&locale)?;
|
||||||
"SK" => LocaleCode::Sk,
|
let currencies = std::env::var("CURRENCIES")?;
|
||||||
"EN" => LocaleCode::En,
|
let currencies = currencies.split(",").collect::<Vec<_>>();
|
||||||
l => unimplemented!("Locale {l} not implemented"),
|
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 str_types: Vec<_> = env_types.split(',').collect();
|
||||||
let gateway_types = str_types
|
let gateway_types = str_types
|
||||||
|
@ -95,9 +102,10 @@ pub fn get_active_gateways_from_env() -> anyhow::Result<Vec<ActiveGateway>> {
|
||||||
})
|
})
|
||||||
.map(|g| ActiveGateway {
|
.map(|g| ActiveGateway {
|
||||||
gateway_type: g.clone(),
|
gateway_type: g.clone(),
|
||||||
currencies: vec!["EUR".to_owned()],
|
gateway: PaymentGateway {
|
||||||
|
currencies: currencies.clone(),
|
||||||
id: format!("{:?}", &g).to_lowercase(),
|
id: format!("{:?}", &g).to_lowercase(),
|
||||||
config: [],
|
config: vec![],
|
||||||
name: match (g, &locale) {
|
name: match (g, &locale) {
|
||||||
(GatewayType::COD, LocaleCode::Sk) => "Dobierka".to_owned(),
|
(GatewayType::COD, LocaleCode::Sk) => "Dobierka".to_owned(),
|
||||||
(GatewayType::Cash, LocaleCode::Sk) => "Hotovosť".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(),
|
(GatewayType::Other, LocaleCode::En) => "Other".to_owned(),
|
||||||
(g, l) => unimplemented!("Gateway {:?} in locale {:?} not implemented", g, l),
|
(g, l) => unimplemented!("Gateway {:?} in locale {:?} not implemented", g, l),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
@ -122,9 +131,5 @@ pub fn get_active_gateways_from_env() -> anyhow::Result<Vec<ActiveGateway>> {
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct ActiveGateway {
|
pub struct ActiveGateway {
|
||||||
pub gateway_type: GatewayType,
|
pub gateway_type: GatewayType,
|
||||||
pub id: String,
|
pub gateway: PaymentGateway,
|
||||||
pub name: String,
|
|
||||||
pub currencies: Vec<String>,
|
|
||||||
//don't need this one yet
|
|
||||||
pub config: [(); 0],
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,11 @@ use saleor_app_sdk::{
|
||||||
webhooks::{
|
webhooks::{
|
||||||
sync_response::{
|
sync_response::{
|
||||||
CancelationRequestedResult, ChargeRequestedResult,
|
CancelationRequestedResult, ChargeRequestedResult,
|
||||||
PaymentGatewayInitializeSessionResponse, RefundRequestedResult,
|
PaymentGatewayInitializeSessionResponse, PaymentListGatewaysResponse,
|
||||||
TransactionCancelationRequestedResponse, TransactionChargeRequestedResponse,
|
RefundRequestedResult, TransactionCancelationRequestedResponse,
|
||||||
TransactionInitializeSessionResponse, TransactionProcessSessionResponse,
|
TransactionChargeRequestedResponse, TransactionInitializeSessionResponse,
|
||||||
TransactionRefundRequestedResponse, TransactionSessionResult,
|
TransactionProcessSessionResponse, TransactionRefundRequestedResponse,
|
||||||
|
TransactionSessionResult,
|
||||||
},
|
},
|
||||||
utils::{get_webhook_event_type, EitherWebhookType},
|
utils::{get_webhook_event_type, EitherWebhookType},
|
||||||
SyncWebhookEventType,
|
SyncWebhookEventType,
|
||||||
|
@ -52,6 +53,16 @@ pub async fn webhooks(
|
||||||
let event_type = get_webhook_event_type(&headers)?;
|
let event_type = get_webhook_event_type(&headers)?;
|
||||||
let res: Json<Value> = match event_type {
|
let res: Json<Value> = match event_type {
|
||||||
EitherWebhookType::Sync(a) => match a {
|
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 => {
|
SyncWebhookEventType::TransactionCancelationRequested => {
|
||||||
let data = serde_json::from_str::<TransactionCancelationRequested2>(&body)?;
|
let data = serde_json::from_str::<TransactionCancelationRequested2>(&body)?;
|
||||||
Json::from(serde_json::to_value(
|
Json::from(serde_json::to_value(
|
||||||
|
|
Loading…
Reference in a new issue