Skip to content

Commit

Permalink
Merge branch 'develop' into dev/auto-generate-changelog-and-readme-en…
Browse files Browse the repository at this point in the history
…tries2
  • Loading branch information
wjrosa authored Oct 25, 2024
2 parents 5f22a77 + ba01a9b commit 6c84a36
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 13 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Fix - Prevent marking orders on-hold with order note "Process order to take payment" when the payment has failed.
* Fix - Fix payment methods count on settings page.
* Tweak - Add error logging in ECE critical Ajax requests.
* Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the block cart and block checkout pages.
* Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the product, cart, checkout and pay for order pages.

= 8.8.0 - 2024-10-17 =
* Fix - Update URL and path constants to support use of symlinked plugin.
Expand Down
6 changes: 5 additions & 1 deletion client/blocks/express-checkout/express-checkout-container.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React from 'react';
import { Elements } from '@stripe/react-stripe-js';
import ExpressCheckoutComponent from './express-checkout-component';
import { getPaymentMethodTypesForExpressMethod } from 'wcstripe/express-checkout/utils';

export const ExpressCheckoutContainer = ( props ) => {
const { stripe, billing } = props;
const { stripe, billing, expressPaymentMethod } = props;
const options = {
mode: 'payment',
paymentMethodCreation: 'manual',
amount: billing.cartTotal.value,
currency: billing.currency.code.toLowerCase(),
paymentMethodTypes: getPaymentMethodTypesForExpressMethod(
expressPaymentMethod
),
};

return (
Expand Down
33 changes: 32 additions & 1 deletion client/blocks/express-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PAYMENT_METHOD_EXPRESS_CHECKOUT_ELEMENT } from './constants';
import { ExpressCheckoutContainer } from './express-checkout-container';
import ApplePayPreview from './apple-pay-preview';
import GooglePayPreview from './google-pay-preview';
import StripeLinkPreview from './stripe-link-preview';
import { loadStripe } from 'wcstripe/blocks/load-stripe';
import { getBlocksConfiguration } from 'wcstripe/blocks/utils';
import { checkPaymentMethodIsAvailable } from 'wcstripe/express-checkout/utils/check-payment-method-availability';
Expand Down Expand Up @@ -66,4 +67,34 @@ const expressCheckoutElementsApplePay = ( api ) => ( {
},
} );

export { expressCheckoutElementsGooglePay, expressCheckoutElementsApplePay };
const expressCheckoutElementsStripeLink = ( api ) => ( {
name: PAYMENT_METHOD_EXPRESS_CHECKOUT_ELEMENT + '_link',
content: (
<ExpressCheckoutContainer
api={ api }
stripe={ stripePromise }
expressPaymentMethod="link"
/>
),
edit: <StripeLinkPreview />,
canMakePayment: ( { cart } ) => {
// eslint-disable-next-line camelcase
if ( typeof wc_stripe_express_checkout_params === 'undefined' ) {
return false;
}

return new Promise( ( resolve ) => {
checkPaymentMethodIsAvailable( 'link', api, cart, resolve );
} );
},
paymentMethodId: PAYMENT_METHOD_EXPRESS_CHECKOUT_ELEMENT,
supports: {
features: getBlocksConfiguration()?.supports ?? [],
},
} );

export {
expressCheckoutElementsGooglePay,
expressCheckoutElementsApplePay,
expressCheckoutElementsStripeLink,
};
9 changes: 9 additions & 0 deletions client/blocks/express-checkout/stripe-link-preview/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions client/blocks/express-checkout/stripe-link-preview/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable max-len */
import icon from './icon.svg';
import './style.scss';

const useStripeLinkPreview = () => (
<div className="stripe-link-preview">
<img src={ icon } alt="" />
</div>
);

export default useStripeLinkPreview;
12 changes: 12 additions & 0 deletions client/blocks/express-checkout/stripe-link-preview/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.stripe-link-preview {
display: flex;
justify-content: center;
align-items: center;
background-color: #00d66f;
border-radius: 5px;
height: 40px;
&:hover {
cursor: pointer;
filter: opacity(0.7);
}
}
2 changes: 2 additions & 0 deletions client/blocks/upe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import paymentRequestPaymentMethod from 'wcstripe/blocks/payment-request';
import {
expressCheckoutElementsGooglePay,
expressCheckoutElementsApplePay,
expressCheckoutElementsStripeLink,
} from 'wcstripe/blocks/express-checkout';
import WCStripeAPI from 'wcstripe/api';
import { getBlocksConfiguration } from 'wcstripe/blocks/utils';
Expand Down Expand Up @@ -97,6 +98,7 @@ if ( getBlocksConfiguration()?.isECEEnabled ) {
// Register Express Checkout Element.
registerExpressPaymentMethod( expressCheckoutElementsGooglePay( api ) );
registerExpressPaymentMethod( expressCheckoutElementsApplePay( api ) );
registerExpressPaymentMethod( expressCheckoutElementsStripeLink( api ) );
} else {
// Register Stripe Payment Request.
registerExpressPaymentMethod( paymentRequestPaymentMethod );
Expand Down
6 changes: 5 additions & 1 deletion client/entrypoints/express-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,11 @@ jQuery( function ( $ ) {
};

// We don't need to initialize ECE on the checkout page now because it will be initialized by updated_checkout event.
if ( ! getExpressCheckoutData( 'is_checkout_page' ) ) {
if (
getExpressCheckoutData( 'is_product_page' ) ||
getExpressCheckoutData( 'is_pay_for_order' ) ||
getExpressCheckoutData( 'is_cart_page' )
) {
wcStripeECE.init();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ReactDOM from 'react-dom';
import { ExpressCheckoutElement, Elements } from '@stripe/react-stripe-js';
import { memoize } from 'lodash';
import { getPaymentMethodTypesForExpressMethod } from 'wcstripe/express-checkout/utils';

export const checkPaymentMethodIsAvailable = memoize(
( paymentMethod, api, cart, resolve ) => {
Expand All @@ -22,6 +23,9 @@ export const checkPaymentMethodIsAvailable = memoize(
paymentMethodCreation: 'manual',
amount: Number( cart.cartTotals.total_price ),
currency: cart.cartTotals.currency_code.toLowerCase(),
paymentMethodTypes: getPaymentMethodTypesForExpressMethod(
paymentMethod
),
} }
>
<ExpressCheckoutElement
Expand All @@ -37,7 +41,7 @@ export const checkPaymentMethodIsAvailable = memoize(
paymentMethod === 'googlePay'
? 'always'
: 'never',
link: 'never',
link: paymentMethod === 'link' ? 'auto' : 'never',
paypal: 'never',
},
} }
Expand Down
52 changes: 46 additions & 6 deletions client/express-checkout/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global wc_stripe_express_checkout_params */

import { getPaymentMethodTypes } from 'wcstripe/stripe-utils';
import { isLinkEnabled, getPaymentMethodTypes } from 'wcstripe/stripe-utils';
import { getBlocksConfiguration } from 'wcstripe/blocks/utils';

export * from './normalize';

Expand Down Expand Up @@ -262,7 +262,47 @@ const getRequiredFieldDataFromShortcodeCheckoutForm = ( data ) => {
* @param {string} paymentMethodType Payment method type Stripe ID.
* @return {Array} Array of payment method types to use with intent, for Express Checkout.
*/
export const getExpressPaymentMethodTypes = ( paymentMethodType = null ) =>
getPaymentMethodTypes( paymentMethodType ).filter( ( type ) =>
[ 'link', 'paypal', 'amazon_pay', 'card' ].includes( type )
);
export const getExpressPaymentMethodTypes = ( paymentMethodType = null ) => {
const expressPaymentMethodTypes = getPaymentMethodTypes(
paymentMethodType
).filter( ( type ) => [ 'paypal', 'amazon_pay', 'card' ].includes( type ) );

if ( isLinkEnabled() ) {
expressPaymentMethodTypes.push( 'link' );
}

return expressPaymentMethodTypes;
};

/**
* Fetches the payment method types required to process a payment for an Express method.
*
* @see https://docs.stripe.com/elements/express-checkout-element/accept-a-payment#enable-payment-methods - lists the method types
* supported and which ones are required by each Express Checkout method.
*
* @param {*} paymentMethodType The express payment method type. eg 'link', 'googlePay', or 'applePay'.
* @return {Array} Array of payment method types necessary to process a payment for an Express method.
*/
export const getPaymentMethodTypesForExpressMethod = ( paymentMethodType ) => {
const paymentMethodsConfig = getBlocksConfiguration()?.paymentMethodsConfig;
const paymentMethodTypes = [];

if ( ! paymentMethodsConfig ) {
return paymentMethodTypes;
}

// All express payment methods require 'card' payments. Add it if it's enabled.
if ( paymentMethodsConfig?.card !== undefined ) {
paymentMethodTypes.push( 'card' );
}

// Add 'link' payment method type if enabled and requested.
if (
paymentMethodType === 'link' &&
isLinkEnabled( paymentMethodsConfig )
) {
paymentMethodTypes.push( 'link' );
}

return paymentMethodTypes;
};
2 changes: 2 additions & 0 deletions client/stripe-utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ export { getStripeServerData, getErrorMessageForTypeAndCode };
* @return {boolean} True, if enabled; false otherwise.
*/
export const isLinkEnabled = ( paymentMethodsConfig ) => {
paymentMethodsConfig =
paymentMethodsConfig || getStripeServerData()?.paymentMethodsConfig;
return (
paymentMethodsConfig?.link !== undefined &&
paymentMethodsConfig?.card !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public function javascript_params() {
'is_product_page' => $this->express_checkout_helper->is_product(),
'is_checkout_page' => $this->express_checkout_helper->is_checkout(),
'product' => $this->express_checkout_helper->get_product_data(),
'is_cart_page' => is_cart(),
];
}

Expand Down
14 changes: 11 additions & 3 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -1620,9 +1620,17 @@ public function set_payment_method_title_for_order( $order, $payment_method_type
if ( ! isset( $this->payment_methods[ $payment_method_type ] ) ) {
return;
}
$payment_method = $this->payment_methods[ $payment_method_type ];
$payment_method_title = $payment_method->get_title( $stripe_payment_method );
$payment_method_id = $payment_method instanceof WC_Stripe_UPE_Payment_Method_CC ? $this->id : $payment_method->id;

$payment_method = $this->payment_methods[ $payment_method_type ];
$payment_method_id = $payment_method instanceof WC_Stripe_UPE_Payment_Method_CC ? $this->id : $payment_method->id;
$is_stripe_link = isset( $stripe_payment_method->type ) && WC_Stripe_Payment_Methods::LINK === $stripe_payment_method->type;

// Stripe Link uses the main gateway to process payments, however Link payments should use the title of the Link payment method.
if ( $is_stripe_link && isset( $this->payment_methods[ WC_Stripe_Payment_Methods::LINK ] ) ) {
$payment_method_title = $this->payment_methods[ WC_Stripe_Payment_Methods::LINK ]->get_title( $stripe_payment_method );
} else {
$payment_method_title = $payment_method->get_title( $stripe_payment_method );
}

$order->set_payment_method( $payment_method_id );
$order->set_payment_method_title( $payment_method_title );
Expand Down
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Fix - Prevent marking orders on-hold with order note "Process order to take payment" when the payment has failed.
* Fix - Fix payment methods count on settings page.
* Tweak - Add error logging in ECE critical Ajax requests.
* Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the block cart and block checkout pages.
* Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the product, cart, checkout and pay for order pages.

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 comments on commit 6c84a36

Please sign in to comment.