-
Notifications
You must be signed in to change notification settings - Fork 72
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
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bb39bd4
fix: wechat pay payment method title on payment processing
frosso 83ba4b6
rename
frosso d47ff00
Merge branch 'develop' into fix/payment-method-title-for-wechat-pay
frosso ae9d26b
Merge branch 'develop' into fix/payment-method-title-for-wechat-pay
frosso 1200847
WIP
frosso 6842c3f
WIP
frosso 404deac
WIP
frosso 3224ba4
WIP
frosso 08e6f4e
WIP
frosso f528aa5
WIP
frosso e4d0093
WIP
frosso a8bd2ed
WIP
frosso 3577c11
WIP
frosso 4550845
WIP
frosso a90c175
WIP
frosso 8320788
WIP
frosso 574d65c
copilot suggestion
frosso 1e2d57b
Merge branch 'develop' into fix/payment-method-title-for-wechat-pay
frosso 4903bf6
Merge branch 'develop' into fix/payment-method-title-for-wechat-pay
frosso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
/** | ||
|
@@ -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 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 ), | ||
|
@@ -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(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.