You've already forked AstralRinth
forked from didirus/AstralRinth
Support ctoken_ in PATCH subscription (#4578)
This commit is contained in:
committed by
GitHub
parent
4a9f0b8a0e
commit
8a30b7978d
@@ -711,6 +711,14 @@ pub async fn edit_subscription(
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let payment_request_type =
|
||||||
|
PaymentRequestType::from_stripe_id(payment_method)
|
||||||
|
.ok_or_else(|| {
|
||||||
|
ApiError::InvalidInput(
|
||||||
|
"Invalid payment method ID".to_owned(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
if req == PaymentRequirement::RequiresPayment {
|
if req == PaymentRequirement::RequiresPayment {
|
||||||
let results = create_or_update_payment_intent(
|
let results = create_or_update_payment_intent(
|
||||||
&pool,
|
&pool,
|
||||||
@@ -721,10 +729,7 @@ pub async fn edit_subscription(
|
|||||||
user: &user,
|
user: &user,
|
||||||
payment_intent: None,
|
payment_intent: None,
|
||||||
payment_session: PaymentSession::Interactive {
|
payment_session: PaymentSession::Interactive {
|
||||||
payment_request_type:
|
payment_request_type,
|
||||||
PaymentRequestType::PaymentMethod {
|
|
||||||
id: payment_method,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
attached_charge: AttachedCharge::Promotion {
|
attached_charge: AttachedCharge::Promotion {
|
||||||
product_id: new_product_price.product_id.into(),
|
product_id: new_product_price.product_id.into(),
|
||||||
@@ -1293,6 +1298,19 @@ pub enum PaymentRequestType {
|
|||||||
ConfirmationToken { token: String },
|
ConfirmationToken { token: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PaymentRequestType {
|
||||||
|
pub fn from_stripe_id(id: String) -> Option<Self> {
|
||||||
|
let prefix = id.split_at(id.split_once('_')?.0.len() + 1).0;
|
||||||
|
if stripe::PaymentMethodId::is_valid_prefix(prefix) {
|
||||||
|
Some(Self::PaymentMethod { id })
|
||||||
|
} else if prefix == "ctoken_" {
|
||||||
|
Some(Self::ConfirmationToken { token: id })
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(tag = "type", rename_all = "snake_case")]
|
#[serde(tag = "type", rename_all = "snake_case")]
|
||||||
pub enum ChargeRequestType {
|
pub enum ChargeRequestType {
|
||||||
|
|||||||
Reference in New Issue
Block a user