Skip to content

Commit

Permalink
Merge branch 'develop' into update/6505-dispute-task-wc-home
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinksi authored Jun 21, 2023
2 parents 4b92383 + 1ff019d commit 23b58e9
Show file tree
Hide file tree
Showing 24 changed files with 155 additions and 40 deletions.
4 changes: 4 additions & 0 deletions changelog/dev-ts-refactor-download-button
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

minor refactor from js to tsx
4 changes: 4 additions & 0 deletions changelog/dev-ts-refactor-inline-notice
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

minor tsx refactor
4 changes: 4 additions & 0 deletions changelog/dev-ts-refactor-progress-bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

minor tsx refactor
4 changes: 4 additions & 0 deletions changelog/fix-5525-cant-enable-cc-payments
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Corrected bug where checkbox could not be enabled when credit card was disabled
4 changes: 4 additions & 0 deletions changelog/fix-6278-frt-meta-missing-on-manual-capture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fixed payment intents still getting confirmed on UPE when intent update fails
6 changes: 5 additions & 1 deletion client/checkout/classic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ jQuery( function ( $ ) {
.catch( function ( error ) {
paymentMethodGenerated = null;
$form.removeClass( 'processing' ).unblock();
showError( error.message );
if ( error.responseJSON && ! error.responseJSON.success ) {
showError( error.responseJSON.data.error.message );
} else if ( error.message ) {
showError( error.message );
}
} );
};

Expand Down
4 changes: 4 additions & 0 deletions client/checkout/classic/upe-split.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ jQuery( function ( $ ) {
);

if ( updateResponse.data ) {
if ( updateResponse.data.error ) {
throw updateResponse.data.error;
}

if ( api.handleDuplicatePayments( updateResponse.data ) ) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions client/checkout/classic/upe.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ jQuery( function ( $ ) {
);

if ( updateResponse.data ) {
if ( updateResponse.data.error ) {
throw updateResponse.data.error;
}

if ( api.handleDuplicatePayments( updateResponse.data ) ) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ import CloudDownloadIcon from 'gridicons/dist/cloud-download';
*/
import './style.scss';

const DownloadButton = ( { isDisabled, onClick } ) => (
interface DownloadButtonProps {
isDisabled: boolean;
onClick: ( event: any ) => void;
}

const DownloadButton: React.FunctionComponent< DownloadButtonProps > = ( {
isDisabled,
onClick,
} ) => (
<Button
className="woocommerce-table__download-button"
disabled={ isDisabled }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ import { render, fireEvent, getByRole } from '@testing-library/react';
/**
* Internal dependencies
*/
import DownloadButton from '../';
import DownloadButton from '..';
import React from 'react';

describe( 'DownloadButton', () => {
function renderDownloadButton(
isDisabled: boolean,
onClick: jest.Mock< any, any >
) {
return render(
<DownloadButton isDisabled={ isDisabled } onClick={ onClick } />
);
}
test( 'renders an active button', () => {
const onDownload = jest.fn();
const { container: button } = renderDownloadButton( false, onDownload );
Expand Down Expand Up @@ -41,10 +50,4 @@ describe( 'DownloadButton', () => {
expect( onDownload.mock.calls.length ).toBe( 0 );
expect( button ).toMatchSnapshot();
} );

function renderDownloadButton( isDisabled, onClick ) {
return render(
<DownloadButton isDisabled={ isDisabled } onClick={ onClick } />
);
}
} );
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import classNames from 'classnames';
*/
import './style.scss';

const InlineNotice = ( { className, ...restProps } ) => (
const InlineNotice: React.FunctionComponent< Notice.Props > = ( {
className,
...restProps
} ) => (
<Notice
className={ classNames( 'wcpay-inline-notice', className ) }
{ ...restProps }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
/** @format */
/**
* External dependencies
*/
import React from 'react';

/**
* Internal dependencies
*/
import './style.scss';

const ProgressBar = ( { progressLabel, totalLabel, progress } ) => {
interface ProgressBarProps {
progressLabel: string;
totalLabel: string;
progress: number;
}

const ProgressBar: React.FunctionComponent< ProgressBarProps > = ( {
progressLabel,
totalLabel,
progress,
} ) => {
const useInnerLabel = 0.5 < progress;
return (
<div className="progressbar">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* External dependencies
*/
import { render } from '@testing-library/react';
import React from 'react';

/**
* Internal dependencies
Expand Down
3 changes: 3 additions & 0 deletions client/payment-methods/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ const PaymentMethods = () => {
( methodId ) => methodsConfiguration[ methodId ]
);

const isCreditCardEnabled = enabledMethodIds.includes( 'card' );

const [ activationModalParams, handleActivationModalOpen ] = useState(
null
);
Expand Down Expand Up @@ -300,6 +302,7 @@ const PaymentMethods = () => {
}
locked={
PAYMENT_METHOD_IDS.CARD === id &&
isCreditCardEnabled &&
isUpeEnabled
}
Icon={ Icon }
Expand Down
32 changes: 19 additions & 13 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
exit; // Exit if accessed directly.
}

use WCPay\Constants\Fraud_Meta_Box_Type;
use WCPay\Constants\Order_Status;
use WCPay\Constants\Payment_Capture_Type;
use WCPay\Constants\Payment_Initiated_By;
use WCPay\Constants\Payment_Intent_Status;
use WCPay\Constants\Payment_Type;
use WCPay\Constants\Payment_Method;
use WCPay\Exceptions\{ Add_Payment_Method_Exception, Amount_Too_Small_Exception, Process_Payment_Exception, Intent_Authentication_Exception, API_Exception };
use WCPay\Core\Mode;
use WCPay\Core\Server\Request\Cancel_Intention;
use WCPay\Core\Server\Request\Capture_Intention;
use WCPay\Core\Server\Request\Create_And_Confirm_Intention;
Expand All @@ -35,7 +35,6 @@
use WCPay\Payment_Methods\Link_Payment_Method;
use WCPay\WooPay\WooPay_Order_Status_Sync;
use WCPay\WooPay\WooPay_Utilities;
use WCPay\WooPay_Tracker;
use WCPay\Session_Rate_Limiter;
use WCPay\Tracker;

Expand Down Expand Up @@ -798,17 +797,23 @@ public function process_payment( $order_id ) {

$error_details = esc_html( rtrim( $e->getMessage(), '.' ) );

if ( $e instanceof API_Exception && 'card_error' === $e->get_error_type() && 'incorrect_zip' === $e->get_error_code() ) {
/* translators: %1: the failed payment amount, %2: error message */
$error_message = __(
'A payment of %1$s <strong>failed</strong>. %2$s',
'woocommerce-payments'
);
if ( $e instanceof API_Exception && 'card_error' === $e->get_error_type() ) {
// If the payment failed with a 'card_error' API exception, initialize the fraud meta box
// type with ALLOW, because fraud checks are passed, and the payment returned a "card error".
$this->order_service->set_fraud_meta_box_type_for_order( $order, Fraud_Meta_Box_Type::ALLOW );

$error_details = __(
'We couldn’t verify the postal code in the billing address. If the issue persists, suggest the customer to reach out to the card issuing bank.',
'woocommerce-payments'
);
if ( 'incorrect_zip' === $e->get_error_code() ) {
/* translators: %1: the failed payment amount, %2: error message */
$error_message = __(
'A payment of %1$s <strong>failed</strong>. %2$s',
'woocommerce-payments'
);

$error_details = __(
'We couldn’t verify the postal code in the billing address. If the issue persists, suggest the customer to reach out to the card issuing bank.',
'woocommerce-payments'
);
}
}

$note = sprintf(
Expand Down Expand Up @@ -3117,7 +3122,8 @@ public function create_setup_intent_ajax() {
'error' => [
'message' => WC_Payments_Utils::get_filtered_error_message( $e ),
],
]
],
WC_Payments_Utils::get_filtered_error_status_code( $e ),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ public function validate_state() {
*/
public function ajax_create_order() {
if ( WC()->cart->is_empty() ) {
wp_send_json_error( __( 'Empty cart', 'woocommerce-payments' ) );
wp_send_json_error( __( 'Empty cart', 'woocommerce-payments' ), 400 );
}

if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
Expand Down
14 changes: 14 additions & 0 deletions includes/class-wc-payments-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,20 @@ public static function get_filtered_error_message( Exception $e ) {
return $error_message;
}

/**
* Returns the customer facing HTTP status codes for an exception.
*
* @param Exception $e Exception to get the HTTP status code for.
*
* @return int
*/
public static function get_filtered_error_status_code( Exception $e ) : int {
if ( $e instanceof API_Exception ) {
return $e->get_http_code() ?? 400;
}
return 400;
}

/**
* Saves the minimum amount required for transactions in a given currency.
*
Expand Down
17 changes: 16 additions & 1 deletion includes/fraud-prevention/class-buyer-fingerprinting-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,27 @@ public function hash_data_for_fraud_prevention( string $data ): string {
* @return array An array of hashed data for an order.
*/
public function get_hashed_data_for_customer( $fingerprint ): array {
global $wp;
$order_items_count = WC()->cart ? intval( WC()->cart->get_cart_contents_count() ) : null;
$order_id = null;
if ( isset( $wp->query_vars['order-pay'] ) ) {
$order_id = absint( $wp->query_vars['order-pay'] );
} elseif ( isset( $_POST['wcpay_order_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$order_id = absint( $_POST['wcpay_order_id'] ); // phpcs:ignore WordPress.Security.NonceVerification
}
if ( ! $order_items_count && 0 < $order_id ) {
$order = wc_get_order( $order_id );
if ( $order ) {
$order_items_count = $order->get_item_count();
}
}

return array_filter(
[
'fraud_prevention_data_shopper_ip_hash' => $this->hash_data_for_fraud_prevention( WC_Geolocation::get_ip_address() ),
'fraud_prevention_data_shopper_ua_hash' => $fingerprint,
'fraud_prevention_data_ip_country' => WC_Geolocation::geolocate_ip( '', true )['country'],
'fraud_prevention_data_cart_contents' => WC()->cart ? intval( WC()->cart->get_cart_contents_count() ) : null,
'fraud_prevention_data_cart_contents' => $order_items_count,
]
);
}
Expand Down
17 changes: 11 additions & 6 deletions includes/payment-methods/class-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ public function update_payment_intent_ajax() {
'error' => [
'message' => WC_Payments_Utils::get_filtered_error_message( $e ),
],
]
],
WC_Payments_Utils::get_filtered_error_status_code( $e ),
);
}
}
Expand Down Expand Up @@ -283,7 +284,8 @@ public function create_payment_intent_ajax() {
'error' => [
'message' => WC_Payments_Utils::get_filtered_error_message( $e ),
],
]
],
WC_Payments_Utils::get_filtered_error_status_code( $e ),
);
}
}
Expand Down Expand Up @@ -386,7 +388,8 @@ public function init_setup_intent_ajax() {
'error' => [
'message' => WC_Payments_Utils::get_filtered_error_message( $e ),
],
]
],
WC_Payments_Utils::get_filtered_error_status_code( $e ),
);
}
}
Expand Down Expand Up @@ -1018,7 +1021,8 @@ public function save_upe_appearance_ajax() {
'error' => [
'message' => WC_Payments_Utils::get_filtered_error_message( $e ),
],
]
],
WC_Payments_Utils::get_filtered_error_status_code( $e ),
);
}
}
Expand Down Expand Up @@ -1141,9 +1145,10 @@ public function log_payment_error_ajax() {
wp_send_json_error(
[
'error' => [
'message' => $e->getMessage(),
'message' => WC_Payments_Utils::get_filtered_error_message( $e ),
],
]
],
WC_Payments_Utils::get_filtered_error_status_code( $e ),
);
}
}
Expand Down
9 changes: 6 additions & 3 deletions includes/payment-methods/class-upe-split-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ public function update_payment_intent_ajax() {
'error' => [
'message' => WC_Payments_Utils::get_filtered_error_message( $e ),
],
]
],
WC_Payments_Utils::get_filtered_error_status_code( $e ),
);
}
}
Expand Down Expand Up @@ -255,7 +256,8 @@ public function create_payment_intent_ajax() {
'error' => [
'message' => WC_Payments_Utils::get_filtered_error_message( $e ),
],
]
],
WC_Payments_Utils::get_filtered_error_status_code( $e ),
);
}
}
Expand Down Expand Up @@ -301,7 +303,8 @@ public function init_setup_intent_ajax() {
'error' => [
'message' => WC_Payments_Utils::get_filtered_error_message( $e ),
],
]
],
WC_Payments_Utils::get_filtered_error_status_code( $e ),
);
}
}
Expand Down
Loading

0 comments on commit 23b58e9

Please sign in to comment.