Skip to content

Commit

Permalink
Merge branch 'develop' into dev/5101-add-e2e-test-non-admin-users-can…
Browse files Browse the repository at this point in the history
…-login-to-wp-admin
  • Loading branch information
allie500 authored Feb 18, 2025
2 parents 7ce4f9c + 1957d7a commit 2a4e507
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 6 deletions.
4 changes: 4 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@
background-image: url( '../images/payment-methods/grabpay.svg' );
}

.payment-method__brand--wechat_pay {
background-image: url( '../images/payment-methods/wechat-pay.svg' );
}

.wc_gateways tr[data-gateway_id='woocommerce_payments'] .payment-method__icon {
border: 1px solid #ddd;
border-radius: 2px;
Expand Down
4 changes: 4 additions & 0 deletions changelog/add-wechat-checkout-support
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add WeChat Pay support to checkout.
2 changes: 2 additions & 0 deletions client/checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
PAYMENT_METHOD_NAME_AFTERPAY,
PAYMENT_METHOD_NAME_KLARNA,
PAYMENT_METHOD_NAME_GRABPAY,
PAYMENT_METHOD_NAME_WECHAT_PAY,
} from '../constants.js';
import { getDeferredIntentCreationUPEFields } from './payment-elements';
import { handleWooPayEmailInput } from '../woopay/email-input-iframe';
Expand All @@ -65,6 +66,7 @@ const upeMethods = {
afterpay_clearpay: PAYMENT_METHOD_NAME_AFTERPAY,
klarna: PAYMENT_METHOD_NAME_KLARNA,
grabpay: PAYMENT_METHOD_NAME_GRABPAY,
wechat_pay: PAYMENT_METHOD_NAME_WECHAT_PAY,
};

const enabledPaymentMethodsConfig = getUPEConfig( 'paymentMethodsConfig' );
Expand Down
2 changes: 2 additions & 0 deletions client/checkout/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const PAYMENT_METHOD_NAME_AFTERPAY =
'woocommerce_payments_afterpay_clearpay';
export const PAYMENT_METHOD_NAME_KLARNA = 'woocommerce_payments_klarna';
export const PAYMENT_METHOD_NAME_GRABPAY = 'woocommerce_payments_grabpay';
export const PAYMENT_METHOD_NAME_WECHAT_PAY = 'woocommerce_payments_wechat_pay';
export const PAYMENT_METHOD_NAME_EXPRESS_CHECKOUT_ELEMENT =
'woocommerce_payments_express_checkout';
export const PAYMENT_METHOD_NAME_WOOPAY_EXPRESS_CHECKOUT =
Expand All @@ -36,6 +37,7 @@ export function getPaymentMethodsConstants() {
PAYMENT_METHOD_NAME_CARD,
PAYMENT_METHOD_NAME_KLARNA,
PAYMENT_METHOD_NAME_GRABPAY,
PAYMENT_METHOD_NAME_WECHAT_PAY,
];
}

Expand Down
1 change: 1 addition & 0 deletions client/components/payment-method-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const formatDetails = ( payment ) => {
case 'affirm':
case 'afterpay_clearpay':
case 'klarna':
case 'wechat_pay':
default:
return <Fragment />;
}
Expand Down
2 changes: 1 addition & 1 deletion client/components/payment-method-logos/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Bancontact from 'assets/images/payment-methods/bancontact.svg?asset';
import Eps from 'assets/images/payment-methods/eps.svg?asset';
import Becs from 'assets/images/payment-methods/becs.svg?asset';
import Przelewy24 from 'assets/images/payment-methods/przelewy24.svg?asset';
import WeChatPay from 'assets/images/payment-method-icons/wechat_pay.svg?asset';
import WeChatPay from 'assets/images/payment-method-icons/wechat-pay.svg?asset';
import './style.scss';

const PaymentMethods = [
Expand Down
1 change: 0 additions & 1 deletion client/constants/payment-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const PAYMENT_METHOD_TITLES = {
stripe_account: __( 'Stripe Account', 'woocommerce-payments' ),
unionpay: __( 'Union Pay', 'woocommerce-payments' ),
visa: __( 'Visa', 'woocommerce-payments' ),
wechat: __( 'WeChat', 'woocommerce-payments' ),
wechat_pay: __( 'WeChat Pay', 'woocommerce-payments' ),
};

Expand Down
2 changes: 2 additions & 0 deletions client/payment-details/payment-method/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import KlarnaDetails from './klarna';
import P24Details from './p24';
import SepaDetails from './sepa';
import SofortDetails from './sofort';
import WeChatPayDetails from './wechat-pay';

const detailsComponentMap = {
affirm: AffirmDetails,
Expand All @@ -40,6 +41,7 @@ const detailsComponentMap = {
p24: P24Details,
sepa_debit: SepaDetails,
sofort: SofortDetails,
wechat_pay: WeChatPayDetails,
};

const PaymentDetailsPaymentMethod = ( { charge = {}, isLoading } ) => {
Expand Down
98 changes: 98 additions & 0 deletions client/payment-details/payment-method/wechat-pay/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import React from 'react';

/**
* Internal dependencies.
*/
import Detail from '../detail';
import { PaymentMethodDetails } from 'wcpay/payment-details/types';
import { Charge } from 'wcpay/types/charges';

/**
* Extracts and formats payment method details from a charge.
*
* @param {Charge} charge The charge object.
* @return {PaymentMethodDetails} A flat hash of all necessary values.
*/
const formatPaymentMethodDetails = ( charge: Charge ): PaymentMethodDetails => {
const { billing_details: billingDetails, payment_method: id } = charge;
const { name, email, formatted_address: formattedAddress } = billingDetails;

return {
id,
name,
email,
formattedAddress,
};
};

/**
* Placeholders to display while loading.
*/
const paymentMethodPlaceholders: PaymentMethodDetails = {
id: 'id placeholder',
name: 'name placeholder',
email: 'email placeholder',
formattedAddress: 'address placeholder',
};

interface WeChatPayDetailsProps {
charge?: Charge;
isLoading: boolean;
}

const WeChatPayDetails: React.FC< WeChatPayDetailsProps > = ( {
charge,
isLoading,
} ) => {
const { id, name, email, formattedAddress } =
charge && charge.payment_method_details
? formatPaymentMethodDetails( charge )
: paymentMethodPlaceholders;

return (
<div className="payment-method-details">
<div className="payment-method-details__column">
<Detail
isLoading={ isLoading }
label={ __( 'ID', 'woocommerce-payments' ) }
>
{ !! id ? id : '–' }
</Detail>
</div>

<div className="payment-method-details__column">
<Detail
isLoading={ isLoading }
label={ __( 'Owner', 'woocommerce-payments' ) }
>
{ name || '–' }
</Detail>

<Detail
isLoading={ isLoading }
label={ __( 'Owner email', 'woocommerce-payments' ) }
>
{ email || '–' }
</Detail>

<Detail
isLoading={ isLoading }
label={ __( 'Address', 'woocommerce-payments' ) }
>
<span
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={ {
__html: formattedAddress || '–',
} }
/>
</Detail>
</div>
</div>
);
};

export default WeChatPayDetails;
2 changes: 1 addition & 1 deletion client/payment-methods-icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import CBAsset from 'assets/images/cards/cb.svg?asset';
import UnionPayAsset from 'assets/images/cards/unionpay.svg?asset';
import LinkAsset from 'assets/images/payment-methods/link.svg?asset';
import CreditCardAsset from 'assets/images/payment-methods/cc.svg?asset';
import WeChatPayAsset from 'assets/images/payment-methods/wechat_pay.svg?asset';
import WeChatPayAsset from 'assets/images/payment-methods/wechat-pay.svg?asset';
import './style.scss';

const iconComponent = (
Expand Down
106 changes: 103 additions & 3 deletions includes/payment-methods/class-wechatpay-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,48 @@ public function __construct( $token_service ) {
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = false;
$this->is_bnpl = false;
$this->icon_url = plugins_url( 'assets/images/payment-methods/wechat_pay.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::CHINESE_YUAN, Currency_Code::AUSTRALIAN_DOLLAR, Currency_Code::CANADIAN_DOLLAR, Currency_Code::EURO, Currency_Code::POUND_STERLING, Currency_Code::HONG_KONG_DOLLAR, Currency_Code::JAPANESE_YEN, Currency_Code::SINGAPORE_DOLLAR, Currency_Code::DANISH_KRONE, Currency_Code::NORWEGIAN_KRONE, Currency_Code::SWEDISH_KRONA, Currency_Code::SWISS_FRANC ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/wechat-pay.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [
Currency_Code::UNITED_STATES_DOLLAR,
Currency_Code::CHINESE_YUAN,
Currency_Code::AUSTRALIAN_DOLLAR,
Currency_Code::CANADIAN_DOLLAR,
Currency_Code::EURO,
Currency_Code::POUND_STERLING,
Currency_Code::HONG_KONG_DOLLAR,
Currency_Code::JAPANESE_YEN,
Currency_Code::SINGAPORE_DOLLAR,
Currency_Code::DANISH_KRONE,
Currency_Code::NORWEGIAN_KRONE,
Currency_Code::SWEDISH_KRONA,
Currency_Code::SWISS_FRANC,
];
$this->accept_only_domestic_payment = false;
$this->countries = [ Country_Code::UNITED_STATES, Country_Code::CHINA, Country_Code::AUSTRALIA, Country_Code::CANADA, Country_Code::AUSTRIA, Country_Code::BELGIUM, Country_Code::DENMARK, Country_Code::FINLAND, Country_Code::FRANCE, Country_Code::GERMANY, Country_Code::IRELAND, Country_Code::ITALY, Country_Code::LUXEMBOURG, Country_Code::NETHERLANDS, Country_Code::NORWAY, Country_Code::PORTUGAL, Country_Code::SPAIN, Country_Code::SWEDEN, Country_Code::SWITZERLAND, Country_Code::UNITED_KINGDOM, Country_Code::HONG_KONG, Country_Code::JAPAN, Country_Code::SINGAPORE ];
$this->countries = [
Country_Code::UNITED_STATES,
Country_Code::CHINA,
Country_Code::AUSTRALIA,
Country_Code::CANADA,
Country_Code::AUSTRIA,
Country_Code::BELGIUM,
Country_Code::DENMARK,
Country_Code::FINLAND,
Country_Code::FRANCE,
Country_Code::GERMANY,
Country_Code::IRELAND,
Country_Code::ITALY,
Country_Code::LUXEMBOURG,
Country_Code::NETHERLANDS,
Country_Code::NORWAY,
Country_Code::PORTUGAL,
Country_Code::SPAIN,
Country_Code::SWEDEN,
Country_Code::SWITZERLAND,
Country_Code::UNITED_KINGDOM,
Country_Code::HONG_KONG,
Country_Code::JAPAN,
Country_Code::SINGAPORE,
];
}

/**
Expand All @@ -55,4 +93,66 @@ public function get_title( ?string $account_country = null, $payment_details = f
public function get_testing_instructions( string $account_country ) {
return '';
}

/**
* Returns payment method supported currencies for the merchant's account.
*
* @return array
*/
public function get_currencies() {
$account = \WC_Payments::get_account_service()->get_cached_account_data();
$account_country = isset( $account['country'] ) ? strtoupper( $account['country'] ) : '';

// Map countries to their primary currencies.
switch ( $account_country ) {
case Country_Code::AUSTRALIA:
return [ Currency_Code::AUSTRALIAN_DOLLAR, Currency_Code::CHINESE_YUAN ];
case Country_Code::CANADA:
return [ Currency_Code::CANADIAN_DOLLAR, Currency_Code::CHINESE_YUAN ];
case Country_Code::CHINA:
return [ Currency_Code::CHINESE_YUAN ];
case Country_Code::DENMARK:
return [ Currency_Code::DANISH_KRONE, Currency_Code::EURO, Currency_Code::CHINESE_YUAN ];
case Country_Code::HONG_KONG:
return [ Currency_Code::HONG_KONG_DOLLAR, Currency_Code::CHINESE_YUAN ];
case Country_Code::JAPAN:
return [ Currency_Code::JAPANESE_YEN, Currency_Code::CHINESE_YUAN ];
case Country_Code::NORWAY:
return [ Currency_Code::NORWEGIAN_KRONE, Currency_Code::EURO, Currency_Code::CHINESE_YUAN ];
case Country_Code::SINGAPORE:
return [ Currency_Code::SINGAPORE_DOLLAR, Currency_Code::CHINESE_YUAN ];
case Country_Code::SWEDEN:
return [ Currency_Code::SWEDISH_KRONA, Currency_Code::EURO, Currency_Code::CHINESE_YUAN ];
case Country_Code::SWITZERLAND:
return [ Currency_Code::SWISS_FRANC, Currency_Code::EURO, Currency_Code::CHINESE_YUAN ];
case Country_Code::UNITED_KINGDOM:
return [ Currency_Code::POUND_STERLING, Currency_Code::CHINESE_YUAN ];
case Country_Code::UNITED_STATES:
return [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::CHINESE_YUAN ];
default:
// For all European countries in the supported list, return EUR and CNY.
if ( in_array(
$account_country,
[
Country_Code::AUSTRIA,
Country_Code::BELGIUM,
Country_Code::FINLAND,
Country_Code::FRANCE,
Country_Code::GERMANY,
Country_Code::IRELAND,
Country_Code::ITALY,
Country_Code::LUXEMBOURG,
Country_Code::NETHERLANDS,
Country_Code::PORTUGAL,
Country_Code::SPAIN,
],
true
) ) {
return [ Currency_Code::EURO, Currency_Code::CHINESE_YUAN ];
}

// Default to Chinese Yuan.
return [ Currency_Code::CHINESE_YUAN ];
}
}
}

0 comments on commit 2a4e507

Please sign in to comment.