8000 fix: wechat pay payment method title on payment processing by frosso · Pull Request #10806 · Automattic/woocommerce-payments · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: wechat pay payment method title on payment processing #10806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/fix-payment-method-title-for-wechat-pay
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

fix: set the correct payment method title when processing the payment with wechat pay, multibanco, and others
2 changes: 0 additions & 2 deletions includes/class-duplicates-detection-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;
use WCPay\PaymentMethods\Configs\Registry\PaymentMethodDefinitionRegistry;

/**
Expand Down Expand Up @@ -111,7 +110,6 @@ 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,
];

// Get all payment method definitions.
Expand Down
51 changes: 28 additions & 23 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
use WCPay\Payment_Methods\UPE_Payment_Method;
use WCPay\Payment_Methods\Multibanco_Payment_Method;
use WCPay\Payment_Methods\Grabpay_Payment_Method;
use WCPay\Payment_Methods\Wechatpay_Payment_Method;
use WCPay\PaymentMethods\Configs\Registry\PaymentMethodDefinitionRegistry;

/**
Expand Down Expand Up @@ -1777,6 +1776,34 @@ public function process_payment_for_order( $cart, $payment_information, $schedul

$this->maybe_add_customer_notification_note( $order, $processing );

// ensuring the payment method title is set before any early return paths to avoid incomplete order data.
if ( empty( $_POST['payment_request_type'] ) && empty( $_POST['express_payment_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
// Extract payment method details for setting the payment method title.
if ( $payment_needed ) {
Copy link
Contributor Author
@frosso frosso May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this logic from below - this is one of the main fixes.

$charge = $intent ? $intent->get_charge() : null;
$payment_method_details = $charge ? $charge->get_payment_method_details() : [];
// For payment intents, get payment method type from the intent itself, fallback to charge details.
$payment_method_type = $intent ? $intent->get_payment_method_type() : null;
if ( ! $payment_method_type && $payment_method_details ) {
$payment_method_type = $payment_method_details['type'] ?? null;
}

if ( 'card' === $payment_method_type && isset( $payment_method_details['card']['last4'] ) ) {
$order->add_meta_data( 'last4', $payment_method_details['card']['last4'], true );
if ( isset( $payment_method_details['card']['brand'] ) ) {
$order->add_meta_data( '_card_brand', $payment_method_details['card']['brand'], true );
}
$order->save_meta_data();
}
} else {
$payment_method_details = false;
$token = $payment_information->is_using_saved_payment_method() ? $payment_information->get_payment_token() : null;
$payment_method_type = $token ? $this->get_payment_method_type_for_setup_intent( $intent, $token ) : null;
}

$this->set_payment_method_title_for_order( $order, $payment_method_type, $payment_method_details );
}

if ( isset( $status ) && Intent_Status::REQUIRES_ACTION === $status && $this->is_changing_payment_method_for_subscription() ) {
// Because we're filtering woocommerce_subscriptions_update_payment_via_pay_shortcode, we need to manually set this delayed update all flag here.
if ( isset( $_POST['update_all_subscriptions_payment_method'] ) && wc_clean( wp_unslash( $_POST['update_all_subscriptions_payment_method'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
Expand All @@ -1797,27 +1824,6 @@ public function process_payment_for_order( $cart, $payment_information, $schedul
$cart->empty_cart();
}

if ( $payment_needed ) {
$charge = $intent ? $intent->get_charge() : null;
$payment_method_details = $charge ? $charge->get_payment_method_details() : [];
$payment_method_type = $payment_method_details ? $payment_method_details['type'] : null;

if ( 'card' === $payment_method_type && isset( $payment_method_details['card']['last4'] ) ) {
$order->add_meta_data( 'last4', $payment_method_details['card']['last4'], true );
if ( isset( $payment_method_details['card']['brand'] ) ) {
$order->add_meta_data( '_card_brand', $payment_method_details['card']['brand'], true );
}
$order->save_meta_data();
}
} else {
$payment_method_details = false;
$payment_method_type = $this->get_payment_method_type_for_setup_intent( $intent, $token );
}

if ( empty( $_POST['payment_request_type'] ) && empty( $_POST['express_payment_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->set_payment_method_title_for_order( $order, $payment_method_type, $payment_method_details );
}

return [
'result' => 'success',
'redirect' => $this->get_return_url( $order ),
Expand Down Expand Up @@ -4106,7 +4112,6 @@ public function get_upe_available_payment_methods() {
$available_methods[] = Klarna_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Multibanco_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Grabpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Wechatpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;

// This gets all the registered payment method definitions. As new payment methods are converted from the legacy style, they need to be removed from the list above.
$payment_method_definitions = PaymentMethodDefinitionRegistry::instance()->get_all_payment_method_definitions();
Expand Down
3 changes: 0 additions & 3 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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\Payment_Methods\Multibanco_Payment_Method;
use WCPay\WooPay_Tracker;
Expand Down Expand Up @@ -443,7 +442,6 @@ public static function init() {
include_once __DIR__ . '/payment-methods/class-klarna-payment-method.php';
include_once __DIR__ . '/payment-methods/class-multibanco-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__ . '/inline-script-payloads/class-woo-payments-payment-methods-config.php';
include_once __DIR__ . '/express-checkout/class-wc-payments-express-checkout-button-helper.php';
include_once __DIR__ . '/class-wc-payment-token-wcpay-sepa.php';
Expand Down Expand Up @@ -591,7 +589,6 @@ public static function init() {
Klarna_Payment_Method::class,
Multibanco_Payment_Method::class,
Grabpay_Payment_Method::class,
Wechatpay_Payment_Method::class,
];

$payment_methods = [];
Expand Down
Loading
0