Skip to content

Commit

Permalink
Add WeChat Pay to settings (#10319)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmoore authored Feb 7, 2025
1 parent fcea57b commit af5914b
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 1 deletion.
4 changes: 4 additions & 0 deletions assets/images/payment-method-icons/wechat_pay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/images/payment-methods/wechat_pay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions changelog/add-10102-wechat-pay-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add WeChat Pay settings.
1 change: 1 addition & 0 deletions client/additional-methods-setup/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const upeMethods = [
'jcb',
'klarna',
'grabpay',
'wechat_pay',
];

export const upeCapabilityStatuses = {
Expand Down
5 changes: 5 additions & 0 deletions client/components/payment-method-logos/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +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 './style.scss';

const PaymentMethods = [
Expand Down Expand Up @@ -115,6 +116,10 @@ const PaymentMethods = [
name: 'grabpay',
component: GrabPay,
},
{
name: 'wechat_pay',
component: WeChatPay,
},
];

export const WooPaymentsMethodsLogos: React.VFC< {
Expand Down
2 changes: 2 additions & 0 deletions client/constants/payment-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum PAYMENT_METHOD_IDS {
P24 = 'p24',
SEPA_DEBIT = 'sepa_debit',
SOFORT = 'sofort',
WECHAT_PAY = 'wechat_pay',
}

const accountCountry = window.wcpaySettings?.accountStatus?.country || 'US';
Expand Down Expand Up @@ -58,6 +59,7 @@ export const PAYMENT_METHOD_TITLES = {
unionpay: __( 'Union Pay', 'woocommerce-payments' ),
visa: __( 'Visa', 'woocommerce-payments' ),
wechat: __( 'WeChat', 'woocommerce-payments' ),
wechat_pay: __( 'WeChat Pay', 'woocommerce-payments' ),
};

export default PAYMENT_METHOD_IDS;
2 changes: 1 addition & 1 deletion client/data/transactions/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface Transaction {
| 'stripe_account'
| 'unionpay'
| 'visa'
| 'wechat';
| 'wechat_pay';
loan_id?: string;
metadata?: {
charge_type: 'card_reader_fee';
Expand Down
5 changes: 5 additions & 0 deletions client/payment-methods-icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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 './style.scss';

const iconComponent = (
Expand Down Expand Up @@ -155,6 +156,10 @@ export const GrabPayIcon = iconComponent(
GrabPayAsset,
__( 'GrabPay', 'woocommerce-payments' )
);
export const WeChatPayIcon = iconComponent(
WeChatPayAsset,
__( 'WeChat Pay', 'woocommerce-payments' )
);
export const WooIcon = iconComponent(
WooAsset,
__( 'WooPay', 'woocommerce-payments' ),
Expand Down
29 changes: 29 additions & 0 deletions client/payment-methods-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SepaIcon,
SofortIcon,
GrabPayIcon,
WeChatPayIcon,
} from 'wcpay/payment-methods-icons';

const accountCountry = window.wcpaySettings?.accountStatus?.country || 'US';
Expand Down Expand Up @@ -248,6 +249,34 @@ const PaymentMethodInformationObject: Record<
allows_pay_later: false,
accepts_only_domestic_payment: false,
},
wechat_pay: {
id: 'wechat_pay',
label: __( 'WeChat Pay', 'woocommerce-payments' ),
description: __(
'A digital wallet popular with customers from China.',
'woocommerce-payments'
),
icon: WeChatPayIcon,
currencies: [
'USD',
'CNY',
'AUD',
'CAD',
'EUR',
'GBP',
'HKD',
'JPY',
'SGD',
'DKK',
'NOK',
'SEK',
'CHF',
],
stripe_key: 'wechat_pay_payments',
allows_manual_capture: false,
allows_pay_later: false,
accepts_only_domestic_payment: false,
},
};

export default PaymentMethodInformationObject;
2 changes: 2 additions & 0 deletions includes/class-duplicates-detection-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use WCPay\Payment_Methods\P24_Payment_Method;
use WCPay\Payment_Methods\Sepa_Payment_Method;
use WCPay\Payment_Methods\Grabpay_Payment_Method;
use WCPay\Payment_Methods\Wechatpay_Payment_Method;

/**
* Class handling detection of payment methods enabled by multiple plugins simultaneously.
Expand Down Expand Up @@ -105,6 +106,7 @@ private function search_for_additional_payment_methods() {
'clearpay' => Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'klarna' => Klarna_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'grabpay' => Grabpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'wechatpay' => Wechatpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
];

foreach ( $this->get_enabled_gateways() as $gateway ) {
Expand Down
3 changes: 3 additions & 0 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
use WCPay\Payment_Methods\Sepa_Payment_Method;
use WCPay\Payment_Methods\UPE_Payment_Method;
use WCPay\Payment_Methods\Grabpay_Payment_Method;
use WCPay\Payment_Methods\Wechatpay_Payment_Method;

/**
* Gateway class for WooPayments
Expand Down Expand Up @@ -354,6 +355,7 @@ public function __construct(
'klarna' => 'klarna_payments',
'grabpay' => 'grabpay_payments',
'jcb' => 'jcb_payments',
'wechat_pay' => 'wechat_pay_payments',
];

// WooPay utilities.
Expand Down Expand Up @@ -4145,6 +4147,7 @@ public function get_upe_available_payment_methods() {
$available_methods[] = Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Klarna_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Grabpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Wechatpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;

$available_methods = array_values(
apply_filters(
Expand Down
3 changes: 3 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use WCPay\Payment_Methods\Sofort_Payment_Method;
use WCPay\Payment_Methods\Ideal_Payment_Method;
use WCPay\Payment_Methods\Eps_Payment_Method;
use WCPay\Payment_Methods\Wechatpay_Payment_Method;
use WCPay\Payment_Methods\UPE_Payment_Method;
use WCPay\WooPay_Tracker;
use WCPay\WooPay\WooPay_Utilities;
Expand Down Expand Up @@ -439,6 +440,7 @@ public static function init() {
include_once __DIR__ . '/payment-methods/class-afterpay-payment-method.php';
include_once __DIR__ . '/payment-methods/class-klarna-payment-method.php';
include_once __DIR__ . '/payment-methods/class-grabpay-payment-method.php';
include_once __DIR__ . '/payment-methods/class-wechatpay-payment-method.php';
include_once __DIR__ . '/express-checkout/class-wc-payments-express-checkout-button-helper.php';
include_once __DIR__ . '/class-wc-payment-token-wcpay-sepa.php';
include_once __DIR__ . '/class-wc-payments-status.php';
Expand Down Expand Up @@ -578,6 +580,7 @@ public static function init() {
Afterpay_Payment_Method::class,
Klarna_Payment_Method::class,
Grabpay_Payment_Method::class,
Wechatpay_Payment_Method::class,
];

$payment_methods = [];
Expand Down
1 change: 1 addition & 0 deletions includes/constants/class-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Payment_Method extends Base_Constant {
const AFTERPAY = 'afterpay_clearpay';
const KLARNA = 'klarna';
const GRABPAY = 'grabpay';
const WECHAT_PAY = 'wechat_pay';

const IPP_ALLOWED_PAYMENT_METHODS = [
self::CARD_PRESENT,
Expand Down
58 changes: 58 additions & 0 deletions includes/payment-methods/class-wechatpay-payment-method.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Class Wechatpay_Payment_Method
*
* @package WCPay\Payment_Methods
*/

namespace WCPay\Payment_Methods;

use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;

/**
* WeChatPay Payment Method class extending UPE base class
*/
class Wechatpay_Payment_Method extends UPE_Payment_Method {

const PAYMENT_METHOD_STRIPE_ID = 'wechat_pay';

/**
* Constructor for WeChatPay payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__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->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 ];
}

/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return __( 'WeChat Pay', 'woocommerce-payments' );
}

/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}

0 comments on commit af5914b

Please sign in to comment.