What's the process for including delivery charges in Stripe transactions?

I am facing an issue with Stripe where I am unable to incorporate delivery fees into my transactions. How can I successfully integrate this feature?


let line_items = [];
for (let productId of uniqIds) {
  const quantity = productsIds.filter(id => id === productId).length;
  const product = products.find(p => p._id.toString() === productId);
  line_items.push({
    quantity,
    price_data: {
      currency: 'EUR',
      product_data: {name:product.name},
      unit_amount: product.price * 100,
    },
  });

const session = await stripe.checkout.sessions.create({
  line_items: line_items,
  mode: 'payment',
  customer_email: email,
  success_url: `${req.headers.origin}/?success=true`,
  cancel_url: `${req.headers.origin}/?canceled=true`,
  metadata: {orderId:order._id.toString()},
});

I attempted to include "product.price*100+5" as the total amount including delivery costs, but encountered difficulties due to it being the price per unit.

Answer №1

When utilizing Checkout to gather payment from your customers, Stripe gives you the ability to establish a fixed shipping charge within the Checkout Session creation process.

You have the option of setting up a Shipping Rate separately and including it when generating the Checkout Session by following this link. Alternatively, you can create the Shipping Rate directly within the Checkout Session call by specifying the shipping_rate_data.

This feature allows you to include a set shipping fee in addition to the cost of the line items generated in your loop.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide: Displaying components within a Vue2 string

Within my Vue2 component, I am working with a string that looks something like this: <template> <div><h1>Hello World</h1> <div v-html="testString"></div> </div> </template> <script> exp ...

Accordion content in motion

After creating an accordion, I wanted to enhance the user experience by adding a transition effect whenever they click on the accordion header. Even though I included height: auto and transition in the accordion container, it did not seem to have any impa ...

Redux saga will halt all other effects if one fails during execution

Having some trouble with yield all in saga effect, I've included a snippet of my code below function* fetchData(item) { try { const data = yield call(request, url); yield put(fetchDataSuccess(data)); } catch (error) { yield put(fetchDa ...

State calculation occurs too tardily

I'm working on creating a simple like button that changes color based on whether it's liked or not. I've tried to calculate this beforehand using React.useEffect, but it seems to be calculating afterwards instead... The hearts are initially ...

React JS alterations in circular word cloud

I have a unique project with a dynamic word cloud feature displaying random words. My goal is to customize the code so that the word cloud can showcase specific words from a list of my selection, like: let WordList = ['Apple', 'Banana' ...

Activate the scroll accordion to automatically expand when the page loads

Incorporated within my FAQ page is an accordion feature. My desired functionality includes allowing the user to click on a link such as localhost:3000/faq#why-choose-us, which should prompt the page to smoothly scroll to the accordion element marked with t ...

Add information to the Database seamlessly without the need to refresh the page using PHP in combination with JQuery

Check out my code below: <form action='insert.php' method='post' id='myform'> <input type='hidden' name='tmdb_id'/> <button id='insert'>Insert</button> <p i ...

What is the best way to conceal a header on a single page within a Next.js application?

Currently working on a Next.js application, I've developed a <Header /> component and integrated it into the _app.tsx file. However, I'm looking to have it displayed on all pages except for one. Is there a way to achieve this? ...

Error message: Unable to access .exe file through HTML link

We have a need to include an HTML link on our intranet site that, when clicked, will open an .exe file that is already installed on all user machines. I attempted the following code: <a href = "C:\Program Files\Cisco Systems\VPN&bsol ...

What is the best way to store textarea information into a session using the jQuery AJAX post method in Codeigniter?

I am having trouble saving the text from a textarea to the Controller session using jQuery AJAX post method in Codeigniter Smarty. I am unable to save the data to the session. Can someone please provide me with guidance and a detailed example of how to ach ...

Vue's getComponentName method now properly returns a function instead of returning 'undefined'

After tirelessly working on upgrading my project from Vue 2.6 to 2.7, I've managed to resolve most of the issues. However, there is a persistent problem with certain files that have cased props, triggering Vue to generate an error message known as a & ...

Exploring the world of Next.js API routing

In my work with Next.js 13.4, I am attempting to pass the id of a product using query parameters in this format - http://localhost:3000/api/abc/abc/update/89?id=2 Here is the code snippet I have written: export async function PUT(req,res){ console.log(r ...

The issue with the value of the textarea in Selenium automated tests using

I have a webpage with Javascript where I've implemented a textarea using the following code: var textarea = $("<textarea>"); textarea.change(() => { console.log(textarea.val()); }); When I update the value in the textarea and then chang ...

Dealing with soon-to-expire access tokens from a partner API

Just starting out with Next.js and facing a common challenge without knowing where to begin. Here's the scenario: I am working with a partner who has an API that requires Bearer authentication. The Bearer token is obtained by calling an endpoint (/au ...

Using PHP to send JSONP callback responses

Is it possible to achieve "two-way" communication using JSONP and PHP? For example: jQuery / JSONP $.ajax({ url: 'http://server/po.php', cache : false, dataType: 'jsonp', timeout: 30000, type: 'GET', ...

Mastering the Igr Data grid with Next JS: A comprehensive guide

Hello everyone, I'm diving into Next.js for the first time and attempting to integrate the igr data grid into my application. However, I keep encountering an error when trying to use the igr data grid in React: "ReferenceError: HTMLElement is not defi ...

Transform the appearance of several elements using querySelectorAll

When targeting class names in an HTML page with a checkbox using querySelectorAll, keep in mind that getElementByID only works with the first element. QuerySelectorAll displays a nodeList which might require some corrections - how can this be achieved? le ...

What is the best way to trigger a javascript modal to open automatically after a specific duration

Let's take an instance where my modal has the ID #modal1. It usually appears through a button-based action. ...

What is the process of directing to another HTML page within the same Express controller script?

I am looking to switch the initial page (login page) to a second page (admin dashboard) from within the same controller in Express after a specific action has been taken. Here is the relevant code snippet from my controller file nimda.js: function handle ...

Setting the maximum width for a JavaScript pop-up box

Below is the html code that creates a link reading "sacola de compras" <div> <script type="text/javascript" src="https://app.ecwid.com/script.js?4549118"></script> <script type="text/javascript"> xMinicart("style=","layout=Mini") ...