mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 17:58:55 +00:00
pass tolt params to stripe checkout sessions
This commit is contained in:
1 parent
10803a40f8
commit
0a18d9f5a2
4 files changed
+23
-1
No files matched your search
@@ -3,3 +3,5 @@
|
||||
pub const METADATA_USER_TOKEN : &str = "user_token";
|
||||
pub const METADATA_USERNAME : &str = "username";
|
||||
pub const METADATA_EMAIL : &str = "email";
|
||||
|
||||
pub const METADATA_TOLT_REFERRAL: &str = "tolt_referral";
|
||||
+5
@@ -18,6 +18,10 @@ pub struct CreateCheckoutSessionRequest {
|
||||
/// The (non-Stripe) internal identifier for the product or subscription.
|
||||
/// This will be translated into a Stripe identifier.
|
||||
internal_plan_key: Option<String>,
|
||||
|
||||
/// Optional Tolt referral code
|
||||
/// See: https://help.tolt.io/en/articles/6843411-how-to-set-up-stripe-with-tolt
|
||||
maybe_tolt_referral: Option<String>,
|
||||
}
|
||||
|
||||
// =============== Success Response ===============
|
||||
@@ -51,6 +55,7 @@ pub async fn stripe_create_checkout_session_json_handler(
|
||||
url_redirector: &url_redirector,
|
||||
internal_product_to_stripe_lookup: internal_product_to_stripe_lookup.get_ref(),
|
||||
internal_user_lookup: internal_user_lookup.get_ref(),
|
||||
maybe_tolt_referral: request.maybe_tolt_referral.as_deref()
|
||||
}).await?;
|
||||
|
||||
// Best effort to delete Redis session cache
|
||||
|
||||
+5
@@ -17,6 +17,10 @@ use crate::stripe::traits::internal_user_lookup::InternalUserLookup;
|
||||
#[derive(Deserialize)]
|
||||
pub struct CreateCheckoutSessionRequest {
|
||||
product: Option<String>,
|
||||
|
||||
/// Optional Tolt referral code
|
||||
/// See: https://help.tolt.io/en/articles/6843411-how-to-set-up-stripe-with-tolt
|
||||
maybe_tolt_referral: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn stripe_create_checkout_session_redirect_handler(
|
||||
@@ -42,6 +46,7 @@ pub async fn stripe_create_checkout_session_redirect_handler(
|
||||
url_redirector: &url_redirector,
|
||||
internal_product_to_stripe_lookup: internal_product_to_stripe_lookup.get_ref(),
|
||||
internal_user_lookup: internal_user_lookup.get_ref(),
|
||||
maybe_tolt_referral: request.maybe_tolt_referral.as_deref()
|
||||
}).await?;
|
||||
|
||||
// Best effort to delete Redis session cache
|
||||
|
||||
+11
-1
@@ -8,7 +8,7 @@ use stripe::{CheckoutSession, CheckoutSessionMode, CreateCheckoutSession, Create
|
||||
use reusable_types::server_environment::ServerEnvironment;
|
||||
use url_config::third_party_url_redirector::ThirdPartyUrlRedirector;
|
||||
|
||||
use crate::stripe::helpers::common_metadata_keys::{METADATA_EMAIL, METADATA_USER_TOKEN, METADATA_USERNAME};
|
||||
use crate::stripe::helpers::common_metadata_keys::{METADATA_EMAIL, METADATA_TOLT_REFERRAL, METADATA_USER_TOKEN, METADATA_USERNAME};
|
||||
use crate::stripe::http_endpoints::checkout::create::stripe_create_checkout_session_error::CreateCheckoutSessionError;
|
||||
use crate::stripe::stripe_config::{FullUrlOrPath, StripeConfig};
|
||||
use crate::stripe::traits::internal_product_to_stripe_lookup::InternalProductToStripeLookup;
|
||||
@@ -23,6 +23,10 @@ pub struct CreateStripeCheckoutSessionArgs<'a> {
|
||||
pub url_redirector: &'a ThirdPartyUrlRedirector,
|
||||
pub internal_product_to_stripe_lookup: &'a dyn InternalProductToStripeLookup,
|
||||
pub internal_user_lookup: &'a dyn InternalUserLookup,
|
||||
|
||||
/// Optional Tolt referral code
|
||||
/// See: https://help.tolt.io/en/articles/6843411-how-to-set-up-stripe-with-tolt
|
||||
pub maybe_tolt_referral: Option<&'a str>,
|
||||
}
|
||||
|
||||
/// Create a checkout session and return the URL
|
||||
@@ -115,10 +119,15 @@ pub async fn stripe_create_checkout_session_shared(
|
||||
if let Some(username) = user_metadata.username.as_deref() {
|
||||
metadata.insert(METADATA_USERNAME.to_string(), username.to_string());
|
||||
}
|
||||
|
||||
if let Some(user_email) = user_metadata.user_email.as_deref() {
|
||||
metadata.insert(METADATA_EMAIL.to_string(), user_email.to_string());
|
||||
}
|
||||
|
||||
if let Some(tolt_referral) = args.maybe_tolt_referral.as_deref() {
|
||||
metadata.insert(METADATA_TOLT_REFERRAL.to_string(), tolt_referral.to_string());
|
||||
}
|
||||
|
||||
// NB: This metadata attaches to Stripe's Checkout Session object.
|
||||
// This does not attach to the subscription or payment intent, which have their own metadata
|
||||
// objects. (TODO: Confirm this.)
|
||||
@@ -260,6 +269,7 @@ mod tests {
|
||||
url_redirector: &url_redirector,
|
||||
internal_product_to_stripe_lookup: &internal_product_to_stripe_lookup_mock,
|
||||
internal_user_lookup: &internal_user_lookup_mock,
|
||||
maybe_tolt_referral: None,
|
||||
}).await;
|
||||
|
||||
// TODO: Sort of throwing my hands up over testing this.
|
||||
|
||||
Reference in new issue
Block a user