Added customer's billing and shipping data to paypal checkout fields
This commit is contained in:
@@ -63,14 +63,14 @@ class WC_Aluxpay_Payment_Gateway extends WC_Payment_Gateway {
|
|||||||
'title' => __('Title', 'aluxpay-payment-gateway'),
|
'title' => __('Title', 'aluxpay-payment-gateway'),
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'description' => __('This controls the title which the user sees during checkout.', 'aluxpay-payment-gateway'),
|
'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,
|
'desc_tip' => true,
|
||||||
),
|
),
|
||||||
'description' => array(
|
'description' => array(
|
||||||
'title' => __('Description', 'aluxpay-payment-gateway'),
|
'title' => __('Description', 'aluxpay-payment-gateway'),
|
||||||
'type' => 'textarea',
|
'type' => 'textarea',
|
||||||
'description' => __('Payment method description that the customer will see on your checkout.', 'aluxpay-payment-gateway'),
|
'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,
|
'desc_tip' => true,
|
||||||
),
|
),
|
||||||
'payment_url' => array(
|
'payment_url' => array(
|
||||||
|
|||||||
@@ -76,7 +76,31 @@ router.post('/create-order', validateCreateOrder, async (req, res) => {
|
|||||||
currency: currency || 'USD',
|
currency: currency || 'USD',
|
||||||
description: description || `Order #${wc_order_id} from ${wcOrder?.order?.billing?.first_name || 'Test Customer'}`,
|
description: description || `Order #${wc_order_id} from ${wcOrder?.order?.billing?.first_name || 'Test Customer'}`,
|
||||||
items: items || [],
|
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
|
// Create PayPal order
|
||||||
@@ -262,14 +286,31 @@ router.get('/order-status/:wc_order_id', async (req, res) => {
|
|||||||
total: item.total,
|
total: item.total,
|
||||||
image: item.image?.src || null
|
image: item.image?.src || null
|
||||||
})),
|
})),
|
||||||
shipping: {
|
|
||||||
total: wcOrder.order.shipping_total,
|
|
||||||
method: wcOrder.order.shipping_lines[0]?.method_title
|
|
||||||
},
|
|
||||||
billing: {
|
billing: {
|
||||||
first_name: wcOrder.order.billing.first_name,
|
first_name: wcOrder.order.billing.first_name,
|
||||||
last_name: wcOrder.order.billing.last_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.prefer("return=representation");
|
||||||
request.requestBody({
|
request.requestBody({
|
||||||
intent: 'CAPTURE',
|
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: [{
|
purchase_units: [{
|
||||||
reference_id: orderData.reference_id,
|
reference_id: orderData.reference_id,
|
||||||
amount: {
|
amount: {
|
||||||
currency_code: orderData.currency || 'USD',
|
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',
|
description: orderData.description || 'Payment from WooCommerce',
|
||||||
custom_id: orderData.wc_order_id,
|
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: {
|
application_context: {
|
||||||
brand_name: orderData.brand_name || 'Your Store',
|
brand_name: orderData.brand_name || 'Fashion Store',
|
||||||
landing_page: 'BILLING',
|
landing_page: 'BILLING',
|
||||||
user_action: 'PAY_NOW',
|
user_action: 'PAY_NOW',
|
||||||
return_url: `${process.env.FRONTEND_URL}/success`,
|
return_url: `${process.env.FRONTEND_URL}/success`,
|
||||||
|
|||||||
@@ -34,13 +34,25 @@ const OrderSummary = ({ orderData, loading, order }) => {
|
|||||||
<DataList.ItemValue>{orderData.wc_order_id}</DataList.ItemValue>
|
<DataList.ItemValue>{orderData.wc_order_id}</DataList.ItemValue>
|
||||||
</DataList.Item>
|
</DataList.Item>
|
||||||
{ order.billing !== undefined && <>
|
{ order.billing !== undefined && <>
|
||||||
|
{/*<DataList.Item pt="4">*/}
|
||||||
|
{/* <DataList.ItemLabel>First Name</DataList.ItemLabel>*/}
|
||||||
|
{/* <DataList.ItemValue>{order.billing.first_name}</DataList.ItemValue>*/}
|
||||||
|
{/*</DataList.Item>*/}
|
||||||
|
{/*<DataList.Item pt="4">*/}
|
||||||
|
{/* <DataList.ItemLabel>Last Name</DataList.ItemLabel>*/}
|
||||||
|
{/* <DataList.ItemValue>{order.billing.last_name}</DataList.ItemValue>*/}
|
||||||
|
{/*</DataList.Item>*/}
|
||||||
<DataList.Item pt="4">
|
<DataList.Item pt="4">
|
||||||
<DataList.ItemLabel>First Name</DataList.ItemLabel>
|
<DataList.ItemLabel>Shipping details</DataList.ItemLabel>
|
||||||
<DataList.ItemValue>{order.billing.first_name}</DataList.ItemValue>
|
<DataList.ItemValue>
|
||||||
</DataList.Item>
|
{order.shipping.first_name} {order.shipping.last_name}<br />
|
||||||
<DataList.Item pt="4">
|
{order.shipping.address_1}
|
||||||
<DataList.ItemLabel>Last Name</DataList.ItemLabel>
|
{order.shipping.address_2 && `, ${order.shipping.address_2}`}
|
||||||
<DataList.ItemValue>{order.billing.last_name}</DataList.ItemValue>
|
{`, ${order.shipping.city}`}
|
||||||
|
{`, ${order.shipping.postcode}`}
|
||||||
|
{order.shipping.state && `, ${order.shipping.state}`}
|
||||||
|
{`, ${order.shipping.country}`}
|
||||||
|
</DataList.ItemValue>
|
||||||
</DataList.Item>
|
</DataList.Item>
|
||||||
<DataList.Item pt="4">
|
<DataList.Item pt="4">
|
||||||
<DataList.ItemLabel>E-mail</DataList.ItemLabel>
|
<DataList.ItemLabel>E-mail</DataList.ItemLabel>
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ const Payment = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Heading as="h1" fontSize="2xl" textAlign="center" mb="10">Secure Payment with PayPal</Heading>
|
<Heading as="h1" fontSize="2xl" textAlign="center" mb="10">Secure Payment with PayPal or Credit/Debit Card</Heading>
|
||||||
{order.length === 0 ?
|
{order.length === 0 ?
|
||||||
<Center>
|
<Center>
|
||||||
<EmptyState.Root>
|
<EmptyState.Root>
|
||||||
@@ -248,8 +248,7 @@ const Payment = () => {
|
|||||||
<Timeline.Title textStyle="sm">Estimated Delivery Date</Timeline.Title>
|
<Timeline.Title textStyle="sm">Estimated Delivery Date</Timeline.Title>
|
||||||
<Timeline.Description>{getDateAfterDays(10)}</Timeline.Description>
|
<Timeline.Description>{getDateAfterDays(10)}</Timeline.Description>
|
||||||
<Text textStyle="sm">
|
<Text textStyle="sm">
|
||||||
We will shipp your product via <strong>FedEx</strong> and it should
|
We will ship our products via <strong>FedEx</strong> or any other <strong>Express Courier</strong> and it should arrive within 7-10 business days.
|
||||||
arrive within 7-10 business days.
|
|
||||||
</Text>
|
</Text>
|
||||||
</Timeline.Content>
|
</Timeline.Content>
|
||||||
</Timeline.Item>
|
</Timeline.Item>
|
||||||
|
|||||||
Reference in New Issue
Block a user