Simplify token parameter

This commit is contained in:
Alex P. 2025-05-29 09:48:35 +03:00
parent 7ea562c697
commit a61ae8b6eb
No known key found for this signature in database
GPG key ID: 54487A734A204D71
7 changed files with 20 additions and 23 deletions

View file

@ -19,7 +19,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PatchCollection;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
@ -178,8 +177,6 @@ class OrderEndpoint {
* @param PurchaseUnit[] $items The purchase unit items for the order.
* @param string $shipping_preference One of ApplicationContext::SHIPPING_PREFERENCE_ values.
* @param Payer|null $payer The payer off the order.
* @param PaymentToken|null $payment_token The payment token.
* @param string $paypal_request_id The PayPal request id.
* @param string $user_action The user action.
* @param string $payment_method WC payment method.
* @param array $request_data Request data.
@ -192,8 +189,6 @@ class OrderEndpoint {
array $items,
string $shipping_preference,
Payer $payer = null,
PaymentToken $payment_token = null,
string $paypal_request_id = '',
string $user_action = ApplicationContext::USER_ACTION_CONTINUE,
string $payment_method = '',
array $request_data = array(),
@ -221,9 +216,6 @@ class OrderEndpoint {
if ( $payer && ! empty( $payer->email_address() ) ) {
$data['payer'] = $payer->to_array();
}
if ( $payment_token ) {
$data['payment_source']['token'] = $payment_token->to_array();
}
if ( $payment_source ) {
$data['payment_source'] = array(
$payment_source->name() => $payment_source->properties(),

View file

@ -99,6 +99,16 @@ class PaymentToken {
);
}
/**
* Returns the PaymentSource object.
*/
public function to_payment_source(): PaymentSource {
return new PaymentSource(
'token',
(object) $this->to_array()
);
}
/**
* Returns a list of valid token types.
* Can be modified through the `woocommerce_paypal_payments_valid_payment_token_types` filter.