Skip to content

Commit

Permalink
Merge branch 'develop' into update/remove-feature-flag-payment-overvi…
Browse files Browse the repository at this point in the history
…ew-widget
  • Loading branch information
Jinksi authored Jun 25, 2024
2 parents 72cbf17 + e85cc3b commit 09fa2e9
Show file tree
Hide file tree
Showing 34 changed files with 332 additions and 153 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*** WooPayments Changelog ***

= 7.8.1 - 2024-06-25 =
* Fix - Fix "Dispute not loaded" error that was affecting responding to disputes.

= 7.8.0 - 2024-06-19 =
* Add - Add a feedback survey modal upon deactivation.
* Add - Add new select component to be used for reporting filters, e.g. Payments overview currency select
Expand Down
4 changes: 4 additions & 0 deletions changelog/add-8951-support-style-settings-with-ece-buttons
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Support style settings for ECE buttons
4 changes: 4 additions & 0 deletions changelog/fix-token-retrieval-per-payment-method
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Retrieve saved tokens only relevant for the specific payment gateway.
4 changes: 4 additions & 0 deletions changelog/revert-8901-update-route-param-validation
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix "Dispute not loaded" error that was affecting responding to disputes.
5 changes: 5 additions & 0 deletions changelog/update-speedup-phpunit-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: These changes only affect PHPUnit tests.


Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { Elements } from '@stripe/react-stripe-js';
import { getExpressCheckoutButtonAppearance } from 'wcpay/express-checkout/utils';

/**
* Internal dependencies
Expand All @@ -16,6 +17,7 @@ const ExpressCheckoutContainer = ( props ) => {
paymentMethodCreation: 'manual',
amount: billing.cartTotal.value,
currency: billing.currency.code.toLowerCase(),
appearance: getExpressCheckoutButtonAppearance(),
};

return (
Expand Down
17 changes: 5 additions & 12 deletions client/express-checkout/blocks/hooks/use-express-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
*/
import { useCallback } from '@wordpress/element';
import { useStripe, useElements } from '@stripe/react-stripe-js';
import { normalizeLineItems } from 'wcpay/express-checkout/utils';
import {
getExpressCheckoutButtonStyleSettings,
normalizeLineItems,
} from 'wcpay/express-checkout/utils';
import { onConfirmHandler } from 'wcpay/express-checkout/event-handlers';

export const useExpressCheckout = ( {
Expand All @@ -19,17 +22,7 @@ export const useExpressCheckout = ( {
const stripe = useStripe();
const elements = useElements();

const buttonOptions = {
paymentMethods: {
applePay: 'always',
googlePay: 'always',
link: 'auto',
},
buttonType: {
googlePay: wcpayExpressCheckoutParams.button.type,
applePay: wcpayExpressCheckoutParams.button.type,
},
};
const buttonOptions = getExpressCheckoutButtonStyleSettings();

const onCancel = () => {
onClose();
Expand Down
18 changes: 11 additions & 7 deletions client/express-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { __ } from '@wordpress/i18n';
*/
import WCPayAPI from '../checkout/api';
import '../checkout/express-checkout-buttons.scss';
import { getExpressCheckoutData, normalizeLineItems } from './utils/index';
import {
getExpressCheckoutButtonAppearance,
getExpressCheckoutButtonStyleSettings,
getExpressCheckoutData,
normalizeLineItems,
} from './utils/index';
import {
onConfirmHandler,
shippingAddressChangeHandler,
Expand Down Expand Up @@ -232,14 +237,13 @@ jQuery( ( $ ) => {
amount: options?.total,
currency: options?.currency,
paymentMethodCreation: 'manual',
appearance: getExpressCheckoutButtonAppearance(),
} );

const eceButton = wcpayECE.createButton( elements, {
buttonType: {
googlePay: getExpressCheckoutData( 'button' ).type,
applePay: getExpressCheckoutData( 'button' ).type,
},
} );
const eceButton = wcpayECE.createButton(
elements,
getExpressCheckoutButtonStyleSettings()
);

wcpayECE.showButton( eceButton );

Expand Down
81 changes: 79 additions & 2 deletions client/express-checkout/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ declare global {
}
}

export const getExpressCheckoutData = (
key: keyof WCPayExpressCheckoutParams
export const getExpressCheckoutData = <
K extends keyof WCPayExpressCheckoutParams
>(
key: K
) => {
if ( window.wcpayExpressCheckoutParams ) {
return window.wcpayExpressCheckoutParams?.[ key ];
Expand All @@ -108,3 +110,78 @@ export const getErrorMessageFromNotice = ( notice: string ) => {
div.innerHTML = notice.trim();
return div.firstChild ? div.firstChild.textContent : '';
};

/**
* Returns the appearance settings for the Express Checkout buttons.
* Currently only configures border radius for the buttons.
*/
export const getExpressCheckoutButtonAppearance = () => {
return {
// variables: { borderRadius: '99999px' },
};
};

/**
* Returns the style settings for the Express Checkout buttons.
*/
export const getExpressCheckoutButtonStyleSettings = () => {
const buttonSettings = getExpressCheckoutData( 'button' );

const mapWooPaymentsThemeToButtonTheme = (
buttonType: string,
theme: string
) => {
switch ( theme ) {
case 'dark':
return 'black';
case 'light':
return 'white';
case 'light-outline':
if ( buttonType === 'googlePay' ) {
return 'white';
}

return 'white-outline';
default:
return 'black';
}
};

const googlePayType =
buttonSettings?.type === 'default'
? 'plain'
: buttonSettings?.type ?? 'buy';

const applePayType =
buttonSettings?.type === 'default'
? 'plain'
: buttonSettings?.type ?? 'plain';

return {
paymentMethods: {
applePay: 'always',
googlePay: 'always',
link: 'auto',
},
layout: { overflow: 'never' },
buttonTheme: {
googlePay: mapWooPaymentsThemeToButtonTheme(
'googlePay',
buttonSettings?.theme ?? 'black'
),
applePay: mapWooPaymentsThemeToButtonTheme(
'applePay',
buttonSettings?.theme ?? 'black'
),
},
buttonType: {
googlePay: googlePayType,
applePay: applePayType,
},
// Allowed height must be 40px to 55px.
buttonHeight: Math.min(
Math.max( parseInt( buttonSettings?.height ?? '48', 10 ), 40 ),
55
),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function register_routes() {
);
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<payment_intent_id>(ch|pi|py)_[A-Za-z0-9]+)',
'/' . $this->rest_base . '/(?P<payment_intent_id>\w+)',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_authorization' ],
Expand Down
4 changes: 2 additions & 2 deletions includes/admin/class-wc-rest-payments-charges-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class WC_REST_Payments_Charges_Controller extends WC_Payments_REST_Controller {
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<charge_id>ch_[A-Za-z0-9]+)',
'/' . $this->rest_base . '/(?P<charge_id>\w+)',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_charge' ],
Expand All @@ -37,7 +37,7 @@ public function register_routes() {
);
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/order/(?P<order_id>[A-Za-z0-9_\-]+)',
'/' . $this->rest_base . '/order/(?P<order_id>\w+)',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'generate_charge_from_order' ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<customer_id>[A-Za-z0-9_\-]+)/payment_methods',
'/' . $this->rest_base . '/(?P<customer_id>\w+)/payment_methods',
[
[
'methods' => WP_REST_Server::READABLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function register_routes() {
);
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<deposit_id>[A-Za-z0-9_\-]+)',
'/' . $this->rest_base . '/(?P<deposit_id>\w+)',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_deposit' ],
Expand Down
6 changes: 3 additions & 3 deletions includes/admin/class-wc-rest-payments-disputes-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function register_routes() {
);
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<dispute_id>(dp|dispute)_[A-Za-z0-9]+)',
'/' . $this->rest_base . '/(?P<dispute_id>\w+)',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_dispute' ],
Expand All @@ -63,7 +63,7 @@ public function register_routes() {
);
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<dispute_id>(dp|dispute)_[A-Za-z0-9]+)',
'/' . $this->rest_base . '/(?P<dispute_id>\w+)',
[
'methods' => WP_REST_Server::CREATABLE,
'callback' => [ $this, 'update_dispute' ],
Expand All @@ -72,7 +72,7 @@ public function register_routes() {
);
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<dispute_id>(dp|dispute)_[A-Za-z0-9]+)/close',
'/' . $this->rest_base . '/(?P<dispute_id>\w+)/close',
[
'methods' => WP_REST_Server::CREATABLE,
'callback' => [ $this, 'close_dispute' ],
Expand Down
6 changes: 3 additions & 3 deletions includes/admin/class-wc-rest-payments-files-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function register_routes() {

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<file_id>[A-Za-z0-9_\-]+)/details',
'/' . $this->rest_base . '/(?P<file_id>\w+)/details',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_file_detail' ],
Expand All @@ -45,7 +45,7 @@ public function register_routes() {

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<file_id>[A-Za-z0-9_\-]+)/content',
'/' . $this->rest_base . '/(?P<file_id>\w+)/content',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_file_content' ],
Expand All @@ -55,7 +55,7 @@ public function register_routes() {

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<file_id>[A-Za-z0-9_\-]+)',
'/' . $this->rest_base . '/(?P<file_id>\w+)',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_file' ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WC_REST_Payments_Fraud_Outcomes_Controller extends WC_Payments_REST_Contro
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<id>[A-Za-z0-9_\-]+)/latest',
'/' . $this->rest_base . '/(?P<id>\w+)/latest',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_latest_fraud_outcome' ],
Expand Down
8 changes: 4 additions & 4 deletions includes/admin/class-wc-rest-payments-orders-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct( WC_Payments_API_Client $api_client, WC_Payment_Gate
public function register_routes() {
register_rest_route(
$this->namespace,
$this->rest_base . '/(?P<order_id>[A-Za-z0-9_\-]+)/capture_terminal_payment',
$this->rest_base . '/(?P<order_id>\w+)/capture_terminal_payment',
[
'methods' => WP_REST_Server::CREATABLE,
'callback' => [ $this, 'capture_terminal_payment' ],
Expand All @@ -82,7 +82,7 @@ public function register_routes() {
);
register_rest_route(
$this->namespace,
$this->rest_base . '/(?P<order_id>[A-Za-z0-9_\-]+)/capture_authorization',
$this->rest_base . '/(?P<order_id>\w+)/capture_authorization',
[
'methods' => WP_REST_Server::CREATABLE,
'callback' => [ $this, 'capture_authorization' ],
Expand All @@ -96,7 +96,7 @@ public function register_routes() {
);
register_rest_route(
$this->namespace,
$this->rest_base . '/(?P<order_id>[A-Za-z0-9_\-]+)/cancel_authorization',
$this->rest_base . '/(?P<order_id>\w+)/cancel_authorization',
[
'methods' => WP_REST_Server::CREATABLE,
'callback' => [ $this, 'cancel_authorization' ],
Expand All @@ -110,7 +110,7 @@ public function register_routes() {
);
register_rest_route(
$this->namespace,
$this->rest_base . '/(?P<order_id>[A-Za-z0-9_\-]+)/create_terminal_intent',
$this->rest_base . '/(?P<order_id>\w+)/create_terminal_intent',
[
'methods' => WP_REST_Server::CREATABLE,
'callback' => [ $this, 'create_terminal_intent' ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class WC_REST_Payments_Payment_Intents_Controller extends WC_Payments_REST_Contr
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<payment_intent_id>(ch|pi|py)_[A-Za-z0-9]+)',
'/' . $this->rest_base . '/(?P<payment_intent_id>\w+)',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_payment_intent' ],
Expand Down
4 changes: 2 additions & 2 deletions includes/admin/class-wc-rest-payments-reader-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function register_routes() {

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/charges/(?P<transaction_id>[A-Za-z0-9_\-]+)',
'/' . $this->rest_base . '/charges/(?P<transaction_id>\w+)',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_summary' ],
Expand All @@ -132,7 +132,7 @@ public function register_routes() {
);
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/receipts/(?P<payment_intent_id>(ch|pi|py)_[A-Za-z0-9]+)',
'/' . $this->rest_base . '/receipts/(?P<payment_intent_id>\w+)',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'generate_print_receipt' ],
Expand Down
Loading

0 comments on commit 09fa2e9

Please sign in to comment.