#[doc(hidden)]
pub mod bindings {
wit_bindgen::generate!({
path: "wit/order-completed/v1",
world: "order-completed-guest",
generate_all,
additional_derives: [serde::Serialize, serde::Deserialize],
pub_export_macro: true,
export_macro_name: "export_order_completed",
default_bindings_module: "makeshop_extensions::order_completed::bindings",
});
}
pub use bindings::exports::makeshop::order_completed::handler::{Guest, Input, OrderCompletedData};
pub use bindings::makeshop::event_types::types::{DeliveryContext, DeliveryFailure, DeliveryResult, EventMetadata};
pub use bindings::makeshop::order_snapshot::types::{
AppliedCoupon,
Buyer,
Order,
OrderedProduct,
OrderedProductVariation,
ProductKind,
Receiver,
};
pub use bindings::makeshop::runtime_types::common::{GuestError, ShopMetafieldEntry};
pub use crate::host::{connector, debug, error, execution, info, uuid, warn};
pub mod mail {
pub use super::bindings::makeshop::mail::buyer::{BuyerMail, MailBodyFormat, MailError, MailErrorCode};
impl BuyerMail {
pub fn text(operation_key: impl Into<String>, subject: impl Into<String>, body: impl Into<String>) -> Self {
Self {
operation_key: operation_key.into(),
subject: subject.into(),
format: MailBodyFormat::Text,
body: body.into(),
}
}
pub fn html(operation_key: impl Into<String>, subject: impl Into<String>, body: impl Into<String>) -> Self {
Self {
operation_key: operation_key.into(),
subject: subject.into(),
format: MailBodyFormat::Html,
body: body.into(),
}
}
}
pub fn send_to_buyer(mail: &BuyerMail) -> Result<(), MailError> {
#[cfg(target_arch = "wasm32")]
{
super::bindings::makeshop::mail::buyer::send_to_buyer(mail)
}
#[cfg(not(target_arch = "wasm32"))]
{
crate::testing::dispatch_buyer_mail(mail.clone())
}
}
}
pub fn ok() -> Result<DeliveryResult, GuestError> {
Ok(DeliveryResult::Ok)
}
pub fn retry(failure: DeliveryFailure) -> Result<DeliveryResult, GuestError> {
Ok(DeliveryResult::Retry(failure))
}
pub fn dead_letter(failure: DeliveryFailure) -> Result<DeliveryResult, GuestError> {
Ok(DeliveryResult::DeadLetter(failure))
}
#[cfg(not(target_arch = "wasm32"))]
pub mod fixture {
use super::{Buyer, DeliveryContext, EventMetadata, Input, Order, OrderCompletedData, OrderedProduct, Receiver};
pub fn input() -> Input {
Input {
context: DeliveryContext {
shop_id: "shop-1".to_string(),
subscription_id: "sub-1".to_string(),
delivery_id: "delivery-1".to_string(),
delivery_attempt: 1,
},
event: EventMetadata {
event_id: "event-1".to_string(),
event_type: "order_completed".to_string(),
event_schema_version: 1,
source: "makeshop".to_string(),
subject: "shop-1".to_string(),
occurred_at: "2026-08-06T00:00:00+09:00".to_string(),
published_at: "2026-08-06T00:00:01+09:00".to_string(),
sequence_number: Some(1),
correlation_id: Some("018f0000-0000-7000-8000-000000000001".to_string()),
causation_id: None,
replay_id: None,
},
shop_metafields: Vec::new(),
data: OrderCompletedData {
order: order(),
applied_coupon: None,
},
}
}
pub fn order() -> Order {
Order {
display_order_number: "20260806-000001".to_string(),
member_id: Some("member-1".to_string()),
buyer: Buyer {
name: "試験 太郎".to_string(),
name_kana: "シケン タロウ".to_string(),
zip_code: "1500001".to_string(),
prefecture: "東京都".to_string(),
address1: "渋谷区1-1-1".to_string(),
address2: None,
tel: "0300000000".to_string(),
email: "taro@example.com".to_string(),
company_name: None,
company_name_kana: None,
department_name: None,
mail_magazine_allowed: Some(true),
},
receivers: vec![Receiver {
name: "試験 花子".to_string(),
name_kana: "シケン ハナコ".to_string(),
zip_code: "1500002".to_string(),
prefecture: "東京都".to_string(),
address1: "渋谷区2-2-2".to_string(),
address2: None,
tel: "0300000001".to_string(),
company_name: None,
company_name_kana: None,
department_name: None,
}],
shop_point_discount: 0,
total_price: 1000,
payment_method_code: "credit".to_string(),
products: vec![OrderedProduct {
name: "テスト商品".to_string(),
system_code: "000000000001".to_string(),
custom_code: None,
jan_code: None,
kind: None,
variation: None,
quantity: 1,
}],
}
}
}