支持官方直连支付、退款配置与套餐联动

This commit is contained in:
zhiqicloud
2026-05-20 00:21:56 +08:00
parent f5deed8709
commit 3a318a86b2
40 changed files with 4674 additions and 365 deletions
@@ -5,6 +5,8 @@ mod email_templates;
mod external_models;
mod normalize;
mod payloads;
mod payment_direct;
mod payment_gateway_config;
pub(crate) mod provider_pool;
mod request_utils;
mod system_config_values;
@@ -41,6 +43,18 @@ pub(crate) use self::payloads::{
InternalGatewayAuthContextRequest, InternalGatewayExecuteRequest,
InternalGatewayResolveRequest, InternalTunnelHeartbeatRequest, InternalTunnelNodeStatusRequest,
};
pub(crate) use self::payment_direct::{
close_direct_gateway_order, create_alipay_direct_checkout, create_stripe_direct_checkout,
create_wxpay_direct_checkout, direct_payment_client_ip, refund_direct_gateway_order,
verify_alipay_notify_callback, verify_wxpay_notify_callback, DirectGatewayRefundResult,
DirectPaymentCheckoutInput,
};
pub(crate) use self::payment_gateway_config::{
payment_gateway_allow_user_refund, payment_gateway_channels_config_json,
payment_gateway_channels_json, payment_gateway_config_json,
payment_gateway_provider_for_payment_method, payment_gateway_refund_enabled,
payment_gateway_secret_keys_json,
};
pub(crate) use self::request_utils::{
admin_proxy_local_requires_buffered_body, internal_proxy_local_requires_buffered_body,
json_string_list, local_proxy_route_requires_buffered_body,
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,85 @@
use serde_json::{json, Value};
const REFUND_ENABLED_KEY: &str = "refund_enabled";
const ALLOW_USER_REFUND_KEY: &str = "allow_user_refund";
fn json_bool(value: Option<&Value>) -> bool {
match value {
Some(Value::Bool(value)) => *value,
Some(Value::Number(value)) => value.as_u64().is_some_and(|value| value != 0),
Some(Value::String(value)) => matches!(
value.trim().to_ascii_lowercase().as_str(),
"1" | "true" | "yes" | "on"
),
_ => false,
}
}
pub(crate) fn payment_gateway_channels_json(value: &Value) -> Value {
value
.as_object()
.and_then(|object| object.get("channels"))
.cloned()
.unwrap_or_else(|| value.clone())
}
pub(crate) fn payment_gateway_config_json(value: &Value) -> Value {
value
.as_object()
.and_then(|object| object.get("config"))
.cloned()
.unwrap_or_else(|| json!({}))
}
pub(crate) fn payment_gateway_secret_keys_json(value: &Value) -> Value {
value
.as_object()
.and_then(|object| object.get("secret_keys"))
.cloned()
.unwrap_or_else(|| json!([]))
}
pub(crate) fn payment_gateway_refund_enabled(value: &Value) -> bool {
json_bool(
value
.as_object()
.and_then(|object| object.get(REFUND_ENABLED_KEY)),
)
}
pub(crate) fn payment_gateway_allow_user_refund(value: &Value) -> bool {
payment_gateway_refund_enabled(value)
&& json_bool(
value
.as_object()
.and_then(|object| object.get(ALLOW_USER_REFUND_KEY)),
)
}
pub(crate) fn payment_gateway_channels_config_json(
channels: Value,
config: Value,
secret_keys: Value,
refund_enabled: bool,
allow_user_refund: bool,
) -> Value {
json!({
"channels": channels,
"config": config,
"secret_keys": secret_keys,
"refund_enabled": refund_enabled,
"allow_user_refund": refund_enabled && allow_user_refund,
})
}
pub(crate) fn payment_gateway_provider_for_payment_method(
payment_method: &str,
) -> Option<&'static str> {
match payment_method.trim().to_ascii_lowercase().as_str() {
"epay" => Some("epay"),
"alipay" => Some("alipay"),
"wxpay" => Some("wxpay"),
"stripe" => Some("stripe"),
_ => None,
}
}
@@ -313,7 +313,11 @@ pub(crate) fn admin_proxy_local_requires_buffered_body(
| (Some("billing_manage"), http::Method::POST, Some("create_plan"))
| (Some("billing_manage"), http::Method::PUT, Some("update_plan"))
| (Some("billing_manage"), http::Method::PATCH, Some("set_plan_status"))
| (Some("payments_manage"), http::Method::PUT, Some("update_epay_gateway"))
| (
Some("payments_manage"),
http::Method::PUT,
Some("update_epay_gateway" | "update_payment_gateway"),
)
| (Some("payments_manage"), http::Method::POST, Some("credit_order"))
| (Some("payments_manage"), http::Method::POST, Some("create_redeem_code_batch"))
| (Some("payments_manage"), http::Method::POST, Some("delete_redeem_code_batch"))
@@ -483,7 +487,14 @@ pub(crate) fn public_support_local_requires_buffered_body(
| (
Some("payment_callback"),
http::Method::POST,
Some("callback" | "epay_notify" | "epay_return"),
Some(
"callback"
| "epay_notify"
| "epay_return"
| "alipay_notify"
| "wxpay_notify"
| "stripe_webhook",
),
)
)
})