created webhook for listening to Stripe events
This commit is contained in:
parent
47f9e9d371
commit
e170c9223a
3 changed files with 18 additions and 9 deletions
|
@ -56,18 +56,15 @@ export async function POST(req){
|
|||
line_items: stripeLineItems,
|
||||
mode: 'payment',
|
||||
customer_email: userEmail,
|
||||
success_url: process.env.NEXTAUTH_URL + 'orders/' + orderDoc._id.toString() + '?clear-cart=1',
|
||||
success_url: process.env.NEXTAUTH_URL + 'cart?success=1',
|
||||
cancel_url: process.env.NEXTAUTH_URL + 'cart?canceled=1',
|
||||
metadata: {orderId: orderDoc._id.toString()},
|
||||
payment_intent_data: {
|
||||
metadata:{orderId:orderDoc._id.toString()},
|
||||
},
|
||||
shipping_options: [
|
||||
{
|
||||
shipping_rate_data: {
|
||||
display_name: 'Delivery fee',
|
||||
type: 'fixed_amount',
|
||||
fixed_amount: {amount: 500, currency: 'USD'},
|
||||
fixed_amount: {amount: 499, currency: 'USD'},
|
||||
},
|
||||
}
|
||||
],
|
||||
|
|
13
donutshop_ecommerce/src/app/api/webhook/route.js
Normal file
13
donutshop_ecommerce/src/app/api/webhook/route.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { Order } from "../models/Order"
|
||||
const stripe = require('stripe')(process.env.STRIPE_SK);
|
||||
|
||||
export async function POST(req){
|
||||
const sig = req.headers.get('stripe-signature');
|
||||
let event;
|
||||
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
|
@ -26,7 +26,6 @@ const CartPage = () => {
|
|||
}
|
||||
|
||||
|
||||
|
||||
function handleAddresschange(propName, value){
|
||||
setAddress(prevAddress => ({...prevAddress, [propName]:value}));
|
||||
}
|
||||
|
@ -87,7 +86,7 @@ const CartPage = () => {
|
|||
<div className='flex flex-col gap-1 mt-5 md:mt-10 text-xs sm:text-sm'>
|
||||
<div className='flex gap-10 justify-between font-semibold'>
|
||||
<p className='uppercase'>subtotal</p>
|
||||
<p className='ml-5 text-end'>${subtotal}</p>
|
||||
<p className='ml-5 text-end'>${subtotal.toFixed(2)}</p>
|
||||
</div>
|
||||
<div className='flex gap-10 justify-between font-semibold'>
|
||||
<p className='uppercase'>Delivery Fees</p>
|
||||
|
@ -95,7 +94,7 @@ const CartPage = () => {
|
|||
</div>
|
||||
<div className='flex gap-10 justify-between font-semibold'>
|
||||
<p className='uppercase'>Order total</p>
|
||||
<p className='ml-5 text-end'>${subtotal + 5}</p>
|
||||
<p className='ml-5 text-end'>${(subtotal + 4.99).toFixed(2)}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -106,7 +105,7 @@ const CartPage = () => {
|
|||
<p className='uppercase font-semibold mb-5 text-center'>Shipping Address</p>
|
||||
<form onSubmit={handleCheckout} className='border-t py-5'>
|
||||
<AddressInfo addressProps={address} setAddressProps={handleAddresschange}/>
|
||||
<button type='submit' className='w-full rounded-md bg-pink-500 text-white hover:opacity-80 duration-300 p-2 block'>Process to pay</button>
|
||||
<button type='submit' className='w-full rounded-md bg-pink-500 text-white hover:opacity-80 duration-300 p-2 block'>Checkout</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue