From 5df46cba7ef91fe67a27bbbbfa486c40da48fd20 Mon Sep 17 00:00:00 2001 From: matej Date: Mon, 6 Oct 2025 21:41:22 +0200 Subject: [PATCH] Added customer's billing and shipping data to paypal checkout fields --- .../class-aluxpay-payment-gateway.php | 4 +- backend/routes/payment.js | 53 ++++++++++++++++--- backend/services/paypal.js | 50 +++++++++++++++-- frontend/src/components/OrderSummary.jsx | 24 ++++++--- frontend/src/pages/Payment.jsx | 5 +- 5 files changed, 116 insertions(+), 20 deletions(-) diff --git a/aluxpay-payment-gateway/includes/class-aluxpay-payment-gateway.php b/aluxpay-payment-gateway/includes/class-aluxpay-payment-gateway.php index 81fa70b..b9f4124 100644 --- a/aluxpay-payment-gateway/includes/class-aluxpay-payment-gateway.php +++ b/aluxpay-payment-gateway/includes/class-aluxpay-payment-gateway.php @@ -63,14 +63,14 @@ class WC_Aluxpay_Payment_Gateway extends WC_Payment_Gateway { 'title' => __('Title', 'aluxpay-payment-gateway'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'aluxpay-payment-gateway'), - 'default' => __('PayPal Payment', 'aluxpay-payment-gateway'), + 'default' => __(' PayPal or Credit/Debit Card Payment ', 'aluxpay-payment-gateway'), 'desc_tip' => true, ), 'description' => array( 'title' => __('Description', 'aluxpay-payment-gateway'), 'type' => 'textarea', 'description' => __('Payment method description that the customer will see on your checkout.', 'aluxpay-payment-gateway'), - 'default' => __('You will be redirected to complete payment securely with PayPal.', 'aluxpay-payment-gateway'), + 'default' => __('You will be redirected to complete payment securely with PayPal or Credit Card.', 'aluxpay-payment-gateway'), 'desc_tip' => true, ), 'payment_url' => array( diff --git a/backend/routes/payment.js b/backend/routes/payment.js index 8e30b5a..7eb8e4c 100644 --- a/backend/routes/payment.js +++ b/backend/routes/payment.js @@ -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 } }); diff --git a/backend/services/paypal.js b/backend/services/paypal.js index b25e931..593496b 100644 --- a/backend/services/paypal.js +++ b/backend/services/paypal.js @@ -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`, diff --git a/frontend/src/components/OrderSummary.jsx b/frontend/src/components/OrderSummary.jsx index 111055f..b1ebf26 100644 --- a/frontend/src/components/OrderSummary.jsx +++ b/frontend/src/components/OrderSummary.jsx @@ -34,13 +34,25 @@ const OrderSummary = ({ orderData, loading, order }) => { {orderData.wc_order_id} { order.billing !== undefined && <> + {/**/} + {/* First Name*/} + {/* {order.billing.first_name}*/} + {/**/} + {/**/} + {/* Last Name*/} + {/* {order.billing.last_name}*/} + {/**/} - First Name - {order.billing.first_name} - - - Last Name - {order.billing.last_name} + Shipping details + + {order.shipping.first_name} {order.shipping.last_name}
+ {order.shipping.address_1} + {order.shipping.address_2 && `, ${order.shipping.address_2}`} + {`, ${order.shipping.city}`} + {`, ${order.shipping.postcode}`} + {order.shipping.state && `, ${order.shipping.state}`} + {`, ${order.shipping.country}`} +
E-mail diff --git a/frontend/src/pages/Payment.jsx b/frontend/src/pages/Payment.jsx index 19a0c27..e475864 100644 --- a/frontend/src/pages/Payment.jsx +++ b/frontend/src/pages/Payment.jsx @@ -170,7 +170,7 @@ const Payment = () => { return (
- Secure Payment with PayPal + Secure Payment with PayPal or Credit/Debit Card {order.length === 0 ?
@@ -248,8 +248,7 @@ const Payment = () => { Estimated Delivery Date {getDateAfterDays(10)} - We will shipp your product via FedEx and it should - arrive within 7-10 business days. + We will ship our products via FedEx or any other Express Courier and it should arrive within 7-10 business days.