mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
refactor
This commit is contained in:
1 parent
d10cb54c62
commit
cba6f25a17
16 files changed
+17
-26
No files matched your search
+1
-7
@@ -2,7 +2,7 @@ use crate::configs::credits_packs::stripe_artcraft_credits_pack_info::StripeArtc
|
||||
use tokens::tokens::users::UserToken;
|
||||
use tokens::tokens::wallets::WalletToken;
|
||||
|
||||
pub enum BillingAction {
|
||||
pub enum ArtcraftBillingAction {
|
||||
/// An ignorable event.
|
||||
IgnorableEvent,
|
||||
|
||||
@@ -29,9 +29,3 @@ pub struct WalletCreditsPurchaseEvent {
|
||||
pub quantity: u64,
|
||||
}
|
||||
|
||||
#[derive(Copy,Clone,Debug)]
|
||||
pub enum IgnoreableEventType {
|
||||
Other,
|
||||
PaymentIntentFailed,
|
||||
PaymentIntentForSubscription,
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,4 @@
|
||||
pub (crate) mod subscriptions;
|
||||
pub (crate) mod credits_pack;
|
||||
pub (crate) mod transactionally_fulfill_artcraft_billing_action;
|
||||
pub (crate) mod artcraft_billing_action;
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+5
-5
@@ -1,21 +1,21 @@
|
||||
use crate::endpoints::webhook::common::artcraft_billing_action::BillingAction;
|
||||
use crate::fulfillment::credits_pack::complete_credits_pack_purchase::complete_credits_pack_purchase;
|
||||
use crate::billing_action_fulfillment::artcraft_billing_action::ArtcraftBillingAction;
|
||||
use crate::billing_action_fulfillment::credits_pack::complete_credits_pack_purchase::complete_credits_pack_purchase;
|
||||
use anyhow::anyhow;
|
||||
use errors::AnyhowResult;
|
||||
use log::{info, warn};
|
||||
use sqlx::Transaction;
|
||||
|
||||
pub async fn transactionally_fulfill_artcraft_billing_action(
|
||||
event: &BillingAction,
|
||||
event: &ArtcraftBillingAction,
|
||||
transaction: &mut Transaction<'_, sqlx::MySql>,
|
||||
) -> AnyhowResult<()> {
|
||||
|
||||
match event {
|
||||
BillingAction::IgnorableEvent => {
|
||||
ArtcraftBillingAction::IgnorableEvent => {
|
||||
warn!("Received ignorable billing action; nothing to fulfill.");
|
||||
return Ok(())
|
||||
}
|
||||
BillingAction::WalletCreditsPurchase(purchase) => {
|
||||
ArtcraftBillingAction::WalletCreditsPurchase(purchase) => {
|
||||
info!("Completing credits pack purchase for user: {} ... ", purchase.owner_user_token.as_str());
|
||||
complete_credits_pack_purchase(
|
||||
&purchase.owner_user_token,
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
use crate::endpoints::webhook::common::artcraft_billing_action::BillingAction;
|
||||
use crate::billing_action_fulfillment::artcraft_billing_action::ArtcraftBillingAction;
|
||||
use crate::endpoints::webhook::common::webhook_event_log_summary::WebhookEventLogSummary;
|
||||
|
||||
pub struct EnrichedWebhookEvent {
|
||||
/// Higher-level events that we care about handling.
|
||||
/// Not all webhook requests have them.
|
||||
pub maybe_billing_action: Option<BillingAction>,
|
||||
pub maybe_billing_action: Option<ArtcraftBillingAction>,
|
||||
|
||||
/// Details of what we'll write to the webhook event logs.
|
||||
/// In addition to important events, this includes some no-op events,
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
pub mod webhook_event_log_summary;
|
||||
pub mod enriched_webhook_event;
|
||||
pub mod artcraft_billing_action;
|
||||
pub mod enriched_webhook_event;
|
||||
+1
-1
@@ -1,10 +1,10 @@
|
||||
use actix_web::web::{Bytes, Data, Json};
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
|
||||
use crate::billing_action_fulfillment::transactionally_fulfill_artcraft_billing_action::transactionally_fulfill_artcraft_billing_action;
|
||||
use crate::endpoints::webhook::common::enriched_webhook_event::EnrichedWebhookEvent;
|
||||
use crate::endpoints::webhook::stripe_artcraft_webhook_error::StripeArtcraftWebhookError;
|
||||
use crate::endpoints::webhook::webhook_event_enrichment::handle_webhook_event_enrichment::handle_webhook_event_enrichment;
|
||||
use crate::fulfillment::transactionally_fulfill_artcraft_billing_event::transactionally_fulfill_artcraft_billing_action;
|
||||
use crate::utils::artcraft_stripe_config::ArtcraftStripeConfigWithClient;
|
||||
use crate::utils::verify_stripe_webhook_ip_address::verify_stripe_webhook_ip_address;
|
||||
use chrono::NaiveDateTime;
|
||||
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
use crate::endpoints::webhook::common::artcraft_billing_action::BillingAction::IgnorableEvent;
|
||||
use crate::endpoints::webhook::common::artcraft_billing_action::{BillingAction, IgnoreableEventType};
|
||||
use crate::endpoints::webhook::common::enriched_webhook_event::EnrichedWebhookEvent;
|
||||
use crate::endpoints::webhook::common::webhook_event_log_summary::WebhookEventLogSummary;
|
||||
use crate::endpoints::webhook::stripe_artcraft_webhook_error::StripeArtcraftWebhookError;
|
||||
|
||||
+2
-3
@@ -1,12 +1,11 @@
|
||||
use crate::billing_action_fulfillment::artcraft_billing_action::{ArtcraftBillingAction, WalletCreditsPurchaseEvent};
|
||||
use crate::configs::get_artcraft_product_by_stripe_id_and_env::get_artcraft_product_by_stripe_id_and_env;
|
||||
use crate::configs::stripe_artcraft_generic_product_info::StripeArtcraftGenericProductInfo;
|
||||
use crate::configs::subscriptions::stripe_artcraft_subscription_info::StripeArtcraftSubscriptionInfo;
|
||||
use crate::endpoints::webhook::common::artcraft_billing_action::{BillingAction, IgnoreableEventType, WalletCreditsPurchaseEvent};
|
||||
use crate::endpoints::webhook::common::enriched_webhook_event::EnrichedWebhookEvent;
|
||||
use crate::endpoints::webhook::common::webhook_event_log_summary::WebhookEventLogSummary;
|
||||
use crate::endpoints::webhook::stripe_artcraft_webhook_error::StripeArtcraftWebhookError;
|
||||
use crate::endpoints::webhook::webhook_event_enrichment::stripe_artcraft_webhook_summary::StripeArtcraftWebhookSummary;
|
||||
use crate::fulfillment::credits_pack::complete_credits_pack_purchase::complete_credits_pack_purchase;
|
||||
use crate::requests::lookup_purchase_from_payment_intent_success::lookup_purchase_from_payment_intent_success;
|
||||
use crate::utils::expand_ids::expand_customer_id::expand_customer_id;
|
||||
use crate::utils::metadata::get_metadata_user_token::get_metadata_user_token;
|
||||
@@ -113,7 +112,7 @@ pub async fn payment_intent_succeeded_extractor(
|
||||
};
|
||||
|
||||
Ok(EnrichedWebhookEvent {
|
||||
maybe_billing_action: Some(BillingAction::WalletCreditsPurchase(WalletCreditsPurchaseEvent {
|
||||
maybe_billing_action: Some(ArtcraftBillingAction::WalletCreditsPurchase(WalletCreditsPurchaseEvent {
|
||||
owner_user_token: user_token,
|
||||
maybe_wallet_token: None, // TODO: Use the checkout session to set this !
|
||||
pack: credits_pack.clone(),
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
pub (crate) mod subscriptions;
|
||||
pub (crate) mod credits_pack;
|
||||
pub (crate) mod transactionally_fulfill_artcraft_billing_event;
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod billing_action_fulfillment;
|
||||
pub mod configs;
|
||||
pub mod endpoints;
|
||||
pub mod fulfillment;
|
||||
pub mod requests;
|
||||
pub mod utils;
|
||||
Reference in new issue
Block a user