Added customer's billing and shipping data to paypal checkout fields
This commit is contained in:
@@ -76,7 +76,31 @@ router.post('/create-order', validateCreateOrder, async (req, res) => {
|
||||
currency: currency || 'USD',
|
||||
description: description || `Order #${wc_order_id} from ${wcOrder?.order?.billing?.first_name || 'Test Customer'}`,
|
||||
items: items || [],
|
||||
brand_name: 'Your Store Name' // Customize this
|
||||
brand_name: 'Fashion Store', // Customize this
|
||||
|
||||
// ADD CUSTOMER DETAILS FROM WOOCOMMERCE:
|
||||
payer: wcOrder ? {
|
||||
email: wcOrder.order.billing.email,
|
||||
first_name: wcOrder.order.billing.first_name,
|
||||
last_name: wcOrder.order.billing.last_name,
|
||||
phone: wcOrder.order.billing.phone
|
||||
} : null,
|
||||
|
||||
shipping: wcOrder ? {
|
||||
first_name: wcOrder.order.shipping.first_name,
|
||||
last_name: wcOrder.order.shipping.last_name,
|
||||
address_1: wcOrder.order.shipping.address_1,
|
||||
address_2: wcOrder.order.shipping.address_2,
|
||||
city: wcOrder.order.shipping.city,
|
||||
state: wcOrder.order.shipping.state,
|
||||
postcode: wcOrder.order.shipping.postcode,
|
||||
country: wcOrder.order.shipping.country
|
||||
} : null,
|
||||
|
||||
// Optional: Add breakdown
|
||||
items_total: wcOrder ? wcOrder.order.total : total,
|
||||
shipping_total: wcOrder ? wcOrder.order.shipping_total : '0.00',
|
||||
tax_total: wcOrder ? wcOrder.order.total_tax : '0.00'
|
||||
};
|
||||
|
||||
// Create PayPal order
|
||||
@@ -262,14 +286,31 @@ router.get('/order-status/:wc_order_id', async (req, res) => {
|
||||
total: item.total,
|
||||
image: item.image?.src || null
|
||||
})),
|
||||
shipping: {
|
||||
total: wcOrder.order.shipping_total,
|
||||
method: wcOrder.order.shipping_lines[0]?.method_title
|
||||
},
|
||||
billing: {
|
||||
first_name: wcOrder.order.billing.first_name,
|
||||
last_name: wcOrder.order.billing.last_name,
|
||||
email: wcOrder.order.billing.email
|
||||
company: wcOrder.order.billing.company,
|
||||
address_1: wcOrder.order.billing.address_1,
|
||||
address_2: wcOrder.order.billing.address_2,
|
||||
city: wcOrder.order.billing.city,
|
||||
state: wcOrder.order.billing.state,
|
||||
postcode: wcOrder.order.billing.postcode,
|
||||
country: wcOrder.order.billing.country,
|
||||
email: wcOrder.order.billing.email,
|
||||
phone: wcOrder.order.billing.phone
|
||||
},
|
||||
shipping: {
|
||||
total: wcOrder.order.shipping_total,
|
||||
method: wcOrder.order.shipping_lines[0]?.method_title,
|
||||
first_name: wcOrder.order.shipping.first_name,
|
||||
last_name: wcOrder.order.shipping.last_name,
|
||||
company: wcOrder.order.shipping.company,
|
||||
address_1: wcOrder.order.shipping.address_1,
|
||||
address_2: wcOrder.order.shipping.address_2,
|
||||
city: wcOrder.order.shipping.city,
|
||||
state: wcOrder.order.shipping.state,
|
||||
postcode: wcOrder.order.shipping.postcode,
|
||||
country: wcOrder.order.shipping.country
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -27,18 +27,62 @@ async function createOrder(orderData) {
|
||||
request.prefer("return=representation");
|
||||
request.requestBody({
|
||||
intent: 'CAPTURE',
|
||||
|
||||
// ADD PAYER INFORMATION
|
||||
payer: orderData.payer ? {
|
||||
email_address: orderData.payer.email,
|
||||
name: {
|
||||
given_name: orderData.payer.first_name,
|
||||
surname: orderData.payer.last_name
|
||||
},
|
||||
phone: orderData.payer.phone ? {
|
||||
phone_type: "MOBILE",
|
||||
phone_number: {
|
||||
national_number: orderData.payer.phone
|
||||
}
|
||||
} : undefined,
|
||||
} : undefined,
|
||||
|
||||
purchase_units: [{
|
||||
reference_id: orderData.reference_id,
|
||||
amount: {
|
||||
currency_code: orderData.currency || 'USD',
|
||||
value: orderData.total
|
||||
value: orderData.total,
|
||||
breakdown: {
|
||||
item_total: {
|
||||
currency_code: orderData.currency || 'USD',
|
||||
value: orderData.items_total || orderData.total
|
||||
},
|
||||
shipping: orderData.shipping.total ? {
|
||||
currency_code: orderData.currency_code || 'USD',
|
||||
value: orderData.shipping.total
|
||||
} : undefined,
|
||||
tax_total: orderData.tax_total ? {
|
||||
currency_code: orderData.currency || 'USD',
|
||||
value: orderData.tax_total
|
||||
} : undefined,
|
||||
}
|
||||
},
|
||||
description: orderData.description || 'Payment from WooCommerce',
|
||||
custom_id: orderData.wc_order_id,
|
||||
items: orderData.items || []
|
||||
items: orderData.items || [],
|
||||
// ADD SHIPPING INFORMATION
|
||||
shipping: orderData.shipping ? {
|
||||
name: {
|
||||
full_name: `${orderData.shipping.first_name} ${orderData.shipping.last_name}`
|
||||
},
|
||||
address: {
|
||||
address_line_1: orderData.shipping.address_1,
|
||||
address_line_2: orderData.shipping.address_2 || undefined,
|
||||
admin_area_2: orderData.shipping.city,
|
||||
admin_area_1: orderData.shipping.state,
|
||||
postal_code: orderData.shipping.postcode,
|
||||
country_code: orderData.shipping.country
|
||||
}
|
||||
} : undefined
|
||||
}],
|
||||
application_context: {
|
||||
brand_name: orderData.brand_name || 'Your Store',
|
||||
brand_name: orderData.brand_name || 'Fashion Store',
|
||||
landing_page: 'BILLING',
|
||||
user_action: 'PAY_NOW',
|
||||
return_url: `${process.env.FRONTEND_URL}/success`,
|
||||
|
||||
Reference in New Issue
Block a user