mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Fix psalm
This commit is contained in:
parent
8a5e823801
commit
eb7e921d44
2 changed files with 16 additions and 8 deletions
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\WcSubscriptions\Endpoint;
|
||||
|
||||
use Exception;
|
||||
use WC_Order;
|
||||
use WC_Payment_Tokens;
|
||||
use WooCommerce\PayPalCommerce\Button\Endpoint\EndpointInterface;
|
||||
use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData;
|
||||
|
@ -57,16 +58,21 @@ class SubscriptionChangePaymentMethod implements EndpointInterface {
|
|||
$data = $this->request_data->read_request( $this->nonce() );
|
||||
|
||||
$subscription = wcs_get_subscription( $data['subscription_id'] );
|
||||
$subscription->set_payment_method( $data['payment_method'] );
|
||||
if ( $subscription instanceof WC_Order ) {
|
||||
$subscription->set_payment_method( $data['payment_method'] );
|
||||
|
||||
$wc_payment_token = WC_Payment_Tokens::get( $data['wc_payment_token_id'] );
|
||||
if ( $wc_payment_token ) {
|
||||
$subscription->add_payment_token( $wc_payment_token );
|
||||
$subscription->save();
|
||||
$wc_payment_token = WC_Payment_Tokens::get( $data['wc_payment_token_id'] );
|
||||
if ( $wc_payment_token ) {
|
||||
$subscription->add_payment_token( $wc_payment_token );
|
||||
$subscription->save();
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
return true;
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
return true;
|
||||
wp_send_json_error();
|
||||
return false;
|
||||
} catch ( Exception $exception ) {
|
||||
wp_send_json_error();
|
||||
return false;
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcSubscriptions;
|
|||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WC_Order;
|
||||
use WC_Payment_Token_CC;
|
||||
use WC_Payment_Tokens;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
||||
|
@ -309,13 +310,14 @@ class WcSubscriptionsModule implements ModuleInterface {
|
|||
esc_html__( 'Select a saved Credit Card payment', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
foreach ( $tokens as $token ) {
|
||||
if ( $token instanceof WC_Payment_Token_CC ) {
|
||||
$output .= sprintf(
|
||||
'<option value="%1$s">%2$s ...%3$s</option>',
|
||||
$token->get_id(),
|
||||
$token->get_card_type(),
|
||||
$token->get_last4()
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
$output .= '</select></p>';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue