Added customer's billing and shipping data to paypal checkout fields

This commit is contained in:
2025-10-06 21:41:22 +02:00
parent be64c0484e
commit 5df46cba7e
5 changed files with 116 additions and 20 deletions

View File

@@ -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`,