Skip to content

Commit

Permalink
Merge branch 'develop' into add/6363-add-documentation-for-reporting-api
Browse files Browse the repository at this point in the history
  • Loading branch information
zmaglica authored Oct 26, 2023
2 parents 888bdca + ea53700 commit 589e05b
Show file tree
Hide file tree
Showing 17 changed files with 252 additions and 56 deletions.
4 changes: 4 additions & 0 deletions changelog/dev-fix-po-notice-not-appearing
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Update to properly show tooltip on Payments > Settings page when account is in PO state.
4 changes: 4 additions & 0 deletions changelog/fix-6950-fix-imp-mobile-tooltip
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fixed tooltip alignment for mobile view in payment settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix Afterpay checkout error when shipping information is missing
4 changes: 4 additions & 0 deletions changelog/fix-express-checkout-wrapper-float
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Clear floats for payment request button wrapper.
5 changes: 5 additions & 0 deletions changelog/rpp-authentication-state-meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Storing the metadata, that was forgotten in 7471


1 change: 1 addition & 0 deletions client/checkout/express-checkout-buttons.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.wcpay-payment-request-wrapper {
margin-top: 1em;
width: 100%;
clear: both;

&:first-child {
margin-top: 0;
Expand Down
22 changes: 16 additions & 6 deletions client/components/payment-methods-list/payment-method.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,29 @@ const PaymentMethod = ( {
isPoEnabled,
isPoComplete,
}: PaymentMethodProps ): React.ReactElement => {
// We want to show a tooltip if PO is enabled and not yet complete. (We make an exception to not show this for card payments).
const isPoInProgress =
isPoEnabled &&
! isPoComplete &&
status !== upeCapabilityStatuses.ACTIVE;

// APMs are disabled if they are inactive or if Progressive Onboarding is enabled and not yet complete.
const disabled =
upeCapabilityStatuses.INACTIVE === status ||
( id !== 'card' && isPoEnabled && ! isPoComplete );
upeCapabilityStatuses.INACTIVE === status || isPoInProgress;
const {
accountFees,
}: { accountFees: Record< string, FeeStructure > } = useContext(
WCPaySettingsContext
);
const [ isManualCaptureEnabled ] = useManualCapture();

const needsAttention = [
const needsMoreInformation = [
upeCapabilityStatuses.INACTIVE,
upeCapabilityStatuses.PENDING_APPROVAL,
upeCapabilityStatuses.PENDING_VERIFICATION,
].includes( status );

const needsAttention = needsMoreInformation || isPoInProgress;
const shouldDisplayNotice = id === 'sofort';

const needsOverlay =
Expand Down Expand Up @@ -190,9 +196,13 @@ const PaymentMethod = ( {
'woocommerce-payments'
) }
/* eslint-disable-next-line max-len */
href={ getDocumentationUrlForDisabledPaymentMethod(
paymentMethodId
) }
href={
isPoInProgress
? 'https://woocommerce.com/document/woopayments/startup-guide/gradual-signup/#additional-payment-methods'
: getDocumentationUrlForDisabledPaymentMethod(
paymentMethodId
)
}
/>
),
},
Expand Down
15 changes: 0 additions & 15 deletions client/components/tooltip/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@
padding: 10px;
text-align: center;

&::after {
content: ' ';
position: absolute;

// assuming all the tooltips are displayed at the top of the wrapped element.
// no need to complicate things since that's the only use case at the moment.
bottom: 0;
left: 50%;
transform: translate( -50%, 22px );
border: solid 15px transparent;
border-top-color: $gray-900;
// Ensure the tooltip arrow does not obscure the mouse target element.
pointer-events: none;
}

a {
color: var( --wp-admin-theme-color, $gutenberg-blue );
}
Expand Down
11 changes: 10 additions & 1 deletion client/components/tooltip/tooltip-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,18 @@ const TooltipBase: React.FC< TooltipBaseProps > = ( {
wrappedElement.offsetWidth / 2 + wrappedElementRect.left;
const tooltipWidth = tooltipElement.offsetWidth;
let tooltipLeft = elementMiddle - tooltipWidth / 2;
const tooltipRight =
window.innerWidth -
( wrappedElementRect.left + tooltipElement.offsetWidth );

if ( tooltipLeft < 0 ) {
tooltipLeft = 10;
// create a gap with the left edge if the element is out of view port
tooltipLeft = 45;
} else if ( tooltipRight < 0 ) {
// create a gap with the right edge if the element is out of view port
tooltipLeft = tooltipLeft - 85;
}

tooltipElement.style.left = `${ tooltipLeft }px`;

// make it visible only after all the calculations are done.
Expand Down
32 changes: 2 additions & 30 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2890,34 +2890,6 @@ public function cancel_authorization( $order ) {
];
}

/**
* Create the shipping data array to send to Stripe when making a purchase.
*
* @param WC_Order $order The order that is being paid for.
* @return array The shipping data to send to Stripe.
*/
public function get_shipping_data_from_order( WC_Order $order ): array {
return [
'name' => implode(
' ',
array_filter(
[
$order->get_shipping_first_name(),
$order->get_shipping_last_name(),
]
)
),
'address' => [
'line1' => $order->get_shipping_address_1(),
'line2' => $order->get_shipping_address_2(),
'postal_code' => $order->get_shipping_postcode(),
'city' => $order->get_shipping_city(),
'state' => $order->get_shipping_state(),
'country' => $order->get_shipping_country(),
],
];
}

/**
* Create the level 3 data array to send to Stripe when making a purchase.
*
Expand Down Expand Up @@ -3736,11 +3708,11 @@ private function upe_needs_redirection( $payment_methods ) {
*
* @param Create_And_Confirm_Intention $request The request object for creating and confirming intention.
* @param Payment_Information $payment_information The payment information object.
* @param mixed $order The order object or data.
* @param WC_Order $order The order object.
*
* @return void
*/
protected function modify_create_intent_parameters_when_processing_payment( Create_And_Confirm_Intention $request, Payment_Information $payment_information, $order ) {
protected function modify_create_intent_parameters_when_processing_payment( Create_And_Confirm_Intention $request, Payment_Information $payment_information, WC_Order $order ) {
// Do nothing.
}
}
56 changes: 56 additions & 0 deletions includes/class-wc-payments-order-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,62 @@ public function attach_intent_info_to_order( $order, $intent_id, $intent_status,
$order->save();
}

/**
* Create the shipping data array to send to Stripe when making a purchase.
*
* @param WC_Order $order The order that is being paid for.
* @return array The shipping data to send to Stripe.
*/
public function get_shipping_data_from_order( WC_Order $order ): array {
return [
'name' => implode(
' ',
array_filter(
[
$order->get_shipping_first_name(),
$order->get_shipping_last_name(),
]
)
),
'address' => [
'line1' => $order->get_shipping_address_1(),
'line2' => $order->get_shipping_address_2(),
'postal_code' => $order->get_shipping_postcode(),
'city' => $order->get_shipping_city(),
'state' => $order->get_shipping_state(),
'country' => $order->get_shipping_country(),
],
];
}

/**
* Create the billing data array to send to Stripe when making a purchase, based on order's billing data.
*
* @param WC_Order $order The order that is being paid for.
* @return array The shipping data to send to Stripe.
*/
public function get_billing_data_from_order( WC_Order $order ): array {
return [
'name' => implode(
' ',
array_filter(
[
$order->get_billing_first_name(),
$order->get_billing_last_name(),
]
)
),
'address' => [
'line1' => $order->get_billing_address_1(),
'line2' => $order->get_billing_address_2(),
'postal_code' => $order->get_billing_postcode(),
'city' => $order->get_billing_city(),
'state' => $order->get_billing_state(),
'country' => $order->get_billing_country(),
],
];
}

/**
* Updates an order to cancelled status, while adding a note with a link to the transaction.
*
Expand Down
17 changes: 17 additions & 0 deletions includes/exceptions/class-invalid-address-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Class Invalid_Address_Exception
*
* @package WooCommerce\Payments
*/

namespace WCPay\Exceptions;

use Exception;

defined( 'ABSPATH' ) || exit;

/**
* Exception for throwing errors when address is invalid.
*/
class Invalid_Address_Exception extends Exception {}
41 changes: 38 additions & 3 deletions includes/payment-methods/class-upe-split-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
namespace WCPay\Payment_Methods;

use Exception;
use WC_Order;
use WC_Payments_API_Setup_Intention;
use WC_Payments_Features;
use WCPay\Core\Server\Request\Get_Setup_Intention;
use WCPay\Exceptions\Add_Payment_Method_Exception;
use WCPay\Exceptions\Invalid_Address_Exception;
use WCPay\Exceptions\Process_Payment_Exception;
use WCPay\Logger;
use WCPay\Session_Rate_Limiter;
Expand Down Expand Up @@ -548,6 +550,39 @@ public function get_stripe_id() {
return $this->stripe_id;
}

/**
* Handles the shipping requirement for Afterpay payments.
*
* This method extracts the shipping and billing data from the order and sets the appropriate
* shipping data for the Afterpay payment request. If neither shipping nor billing data is valid
* for shipping, an exception is thrown.
*
* @param WC_Order $order The order object containing shipping and billing information.
* @param Create_And_Confirm_Intention $request The Afterpay payment request object to set shipping data on.
*
* @throws Invalid_Address_Exception If neither shipping nor billing address is valid for Afterpay payments.
* @return void
*/
private function handle_afterpay_shipping_requirement( WC_Order $order, Create_And_Confirm_Intention $request ): void {
$check_if_usable = function( array $address ): bool {
return $address['country'] && $address['state'] && $address['city'] && $address['postal_code'] && $address['line1'];
};

$shipping_data = $this->order_service->get_shipping_data_from_order( $order );
if ( $check_if_usable( $shipping_data['address'] ) ) {
$request->set_shipping( $shipping_data );
return;
}

$billing_data = $this->order_service->get_billing_data_from_order( $order );
if ( $check_if_usable( $billing_data['address'] ) ) {
$request->set_shipping( $billing_data );
return;
}

throw new Invalid_Address_Exception( __( 'A valid shipping address is required for Afterpay payments.', 'woocommerce-payments' ) );
}


/**
* Modifies the create intent parameters when processing a payment.
Expand All @@ -556,13 +591,13 @@ public function get_stripe_id() {
*
* @param Create_And_Confirm_Intention $request The request object for creating and confirming intention.
* @param Payment_Information $payment_information The payment information object.
* @param mixed $order The order object or data.
* @param WC_Order $order The order object.
*
* @return void
*/
protected function modify_create_intent_parameters_when_processing_payment( Create_And_Confirm_Intention $request, Payment_Information $payment_information, $order ) {
protected function modify_create_intent_parameters_when_processing_payment( Create_And_Confirm_Intention $request, Payment_Information $payment_information, WC_Order $order ): void {
if ( Payment_Method::AFTERPAY === $this->get_selected_stripe_payment_type_id() ) {
$request->set_shipping( $this->get_shipping_data_from_order( $order ) );
$this->handle_afterpay_shipping_requirement( $order, $request );
}
}
}
1 change: 1 addition & 0 deletions src/Internal/Payment/State/InitialState.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function start_processing( PaymentRequest $request ) {

// Intent requires authorization (3DS check).
if ( Intent_Status::REQUIRES_ACTION === $intent->get_status() ) {
$this->order_service->update_order_from_intent_that_requires_action( $context->get_order_id(), $intent, $context );
return $this->create_state( AuthenticationRequiredState::class );
}

Expand Down
28 changes: 28 additions & 0 deletions src/Internal/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,34 @@ public function update_order_from_successful_intent(
}
}

/**
* Updates the order with the necessary details whenever an intent requires action.
*
* @param int $order_id ID of the order.
* @param WC_Payments_API_Abstract_Intention $intent Remote object. To be abstracted soon.
* @param PaymentContext $context Context for the payment.
* @throws Order_Not_Found_Exception
*/
public function update_order_from_intent_that_requires_action(
int $order_id,
WC_Payments_API_Abstract_Intention $intent,
PaymentContext $context
) {
$order = $this->get_order( $order_id );

$this->legacy_service->attach_intent_info_to_order(
$order,
$intent->get_id(),
$intent->get_status(),
$context->get_payment_method()->get_id(),
$context->get_customer_id(),
'',
$context->get_currency()
);

$this->legacy_service->update_order_status_from_intent( $order, $intent );
}

/**
* Given the charge data, checks if there was an exchange and adds it to the given order as metadata
*
Expand Down
Loading

0 comments on commit 589e05b

Please sign in to comment.