#我正在尝试建立一个电子商务,我想以条纹形式运送费率,但他们的文档很混乱,所以我正在使用
line_items.push({
price_data: {
currency: 'usd',
product_data: {
name: ( name.length > 100 ? name.substring(0,100) + '...' : name )
},
unit_amount: ((value,quantity,shipping)=> {
value =Number(value)
value +=(shipping/quantity);
value = value*100;
return value
})(value,quantity,shipping),
},
quantity: quantity
})
##期望以运费进行条纹结账
let data = await createStripeCheckOut({
line_items:line_items,
success_url :'/api/api_s/stripe-order-success',
cancel_url :'/api/api_s/stripe-order-cancel',
amount_shipping:totalshipping
})
export async function createStripeCheckOut({success_url,cancel_url,line_items ,amount_shipping}) {
try {
const session = await STRIPE.checkout.sessions.create({
cancel_url:BASE_URL+cancel_url,
success_url: BASE_URL +success_url,
line_items:line_items,
// [
// {
// price_data: {
// currency: 'usd',
// product_data: {
// name: 'Node.js and Express book'
// },
// unit_amount: 50 * 100
// },
// quantity: 1
// },
// {
// price_data: {
// currency: 'usd',
// product_data: {
// name: 'JavaScript T-Shirt'
// },
// unit_amount: 20 * 100
// },
// quantity: 2
// }
// ],
mode: 'payment',
/* shipping_options: [
{
shipping_rate_data: {
type: 'fixed_amount',
fixed_amount: {
amount: amount_shipping,//0
currency: 'usd',
},
display_name: 'Free shipping',
delivery_estimate: {
minimum: {
unit: 'business_day',
value: 5,
},
maximum: {
unit: 'business_day',
value: 7,
},
},
},
},
{
shipping_rate_data: {
type: 'fixed_amount',
fixed_amount: {
amount: amount_shipping,//0
currency: 'usd',
},
display_name: 'Next day air',
delivery_estimate: {
minimum: {
unit: 'business_day',
value: 1,
},
maximum: {
unit: 'business_day',
value: 1,
},
},
},
},
]*/
});
return session;
} catch (error) {
log(error)
return false
}
}
任何人都可以在这方面帮助我。请描述一下您使用条纹的经历
为了通过 Stripe Checkout 实施运费,您应该遵循此指南。
这是您的函数的更新版本:
export async function createStripeCheckOut({success_url, cancel_url, line_items, amount_shipping}) {
try {
const session = await STRIPE.checkout.sessions.create({
cancel_url: BASE_URL + cancel_url,
success_url: BASE_URL + success_url,
line_items: line_items,
mode: 'payment',
shipping_options: [
{
shipping_rate_data: {
type: 'fixed_amount',
fixed_amount: {
amount: amount_shipping,
currency: 'usd',
},
display_name: 'Standard shipping',
delivery_estimate: {
minimum: {
unit: 'business_day',
value: 5,
},
maximum: {
unit: 'business_day',
value: 7,
},
},
},
},
],
});
return session;
} catch (error) {
log(error);
return false;
}
}