Merge branch 'trunk' into PCP-305-enable-save-card-for-guest-users

This commit is contained in:
dinamiko 2021-11-04 11:01:33 +01:00
commit 78fe636e65
8 changed files with 20 additions and 35 deletions

View file

@ -17,49 +17,49 @@ class AmountBreakdown {
/** /**
* The item total. * The item total.
* *
* @var Money * @var Money|null
*/ */
private $item_total; private $item_total;
/** /**
* The shipping. * The shipping.
* *
* @var Money * @var Money|null
*/ */
private $shipping; private $shipping;
/** /**
* The tax total. * The tax total.
* *
* @var Money * @var Money|null
*/ */
private $tax_total; private $tax_total;
/** /**
* The handling. * The handling.
* *
* @var Money * @var Money|null
*/ */
private $handling; private $handling;
/** /**
* The insurance. * The insurance.
* *
* @var Money * @var Money|null
*/ */
private $insurance; private $insurance;
/** /**
* The shipping discount. * The shipping discount.
* *
* @var Money * @var Money|null
*/ */
private $shipping_discount; private $shipping_discount;
/** /**
* The discount. * The discount.
* *
* @var Money * @var Money|null
*/ */
private $discount; private $discount;
@ -75,13 +75,13 @@ class AmountBreakdown {
* @param Money|null $discount The discount. * @param Money|null $discount The discount.
*/ */
public function __construct( public function __construct(
Money $item_total = null, ?Money $item_total = null,
Money $shipping = null, ?Money $shipping = null,
Money $tax_total = null, ?Money $tax_total = null,
Money $handling = null, ?Money $handling = null,
Money $insurance = null, ?Money $insurance = null,
Money $shipping_discount = null, ?Money $shipping_discount = null,
Money $discount = null ?Money $discount = null
) { ) {
$this->item_total = $item_total; $this->item_total = $item_total;

View file

@ -52,14 +52,12 @@ class PatchCollectionFactory {
array_filter( array_filter(
$from, $from,
static function ( PurchaseUnit $unit ) use ( $purchase_unit_to ): bool { static function ( PurchaseUnit $unit ) use ( $purchase_unit_to ): bool {
//phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
// Loose comparison needed to compare two objects. // Loose comparison needed to compare two objects.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
return $unit == $purchase_unit_to; return $unit == $purchase_unit_to;
//phpcs:enable WordPress.PHP.StrictComparisons.LooseComparison
} }
) )
); );
$needs_update = true;
if ( ! $needs_update ) { if ( ! $needs_update ) {
continue; continue;
} }

View file

@ -728,7 +728,7 @@ class SmartButton implements SmartButtonInterface {
private function payerData() { private function payerData() {
$customer = WC()->customer; $customer = WC()->customer;
if ( ! is_user_logged_in() || ! is_a( $customer, \WC_Customer::class ) ) { if ( ! is_user_logged_in() || ! ( $customer instanceof \WC_Customer ) ) {
return null; return null;
} }
return $this->payer_factory->from_customer( $customer )->to_array(); return $this->payer_factory->from_customer( $customer )->to_array();
@ -757,7 +757,7 @@ class SmartButton implements SmartButtonInterface {
if ( if (
$this->environment->current_environment_is( Environment::SANDBOX ) $this->environment->current_environment_is( Environment::SANDBOX )
&& defined( 'WP_DEBUG' ) && \WP_DEBUG && is_user_logged_in() && defined( 'WP_DEBUG' ) && \WP_DEBUG && is_user_logged_in()
&& WC()->customer && WC()->customer->get_billing_country() && WC()->customer instanceof \WC_Customer && WC()->customer->get_billing_country()
&& 2 === strlen( WC()->customer->get_billing_country() ) && 2 === strlen( WC()->customer->get_billing_country() )
) { ) {
$params['buyer-country'] = WC()->customer->get_billing_country(); $params['buyer-country'] = WC()->customer->get_billing_country();

View file

@ -121,7 +121,7 @@ class ApproveOrderEndpoint implements EndpointInterface {
* Handles the request. * Handles the request.
* *
* @return bool * @return bool
* @throws RuntimeException When no order was found. * @throws RuntimeException When order not found or handling failed.
*/ */
public function handle_request(): bool { public function handle_request(): bool {
try { try {
@ -133,15 +133,6 @@ class ApproveOrderEndpoint implements EndpointInterface {
} }
$order = $this->api_endpoint->order( $data['order_id'] ); $order = $this->api_endpoint->order( $data['order_id'] );
if ( ! $order ) {
throw new RuntimeException(
sprintf(
// translators: %s is the id of the order.
__( 'Order %s not found.', 'woocommerce-paypal-payments' ),
$data['order_id']
)
);
}
if ( $order->payment_source() && $order->payment_source()->card() ) { if ( $order->payment_source() && $order->payment_source()->card() ) {
if ( $this->settings->has( 'disable_cards' ) ) { if ( $this->settings->has( 'disable_cards' ) ) {

View file

@ -284,7 +284,7 @@ class CreateOrderEndpoint implements EndpointInterface {
* @throws RuntimeException If create order request fails. * @throws RuntimeException If create order request fails.
*/ */
private function create_paypal_order( \WC_Order $wc_order = null ): Order { private function create_paypal_order( \WC_Order $wc_order = null ): Order {
$needs_shipping = WC()->cart && WC()->cart->needs_shipping(); $needs_shipping = WC()->cart instanceof \WC_Cart && WC()->cart->needs_shipping();
$shipping_address_is_fix = $needs_shipping && 'checkout' === $this->parsed_request_data['context']; $shipping_address_is_fix = $needs_shipping && 'checkout' === $this->parsed_request_data['context'];
return $this->api_endpoint->create( return $this->api_endpoint->create(

View file

@ -112,7 +112,7 @@ class SubscriptionModule implements ModuleInterface {
* @return void * @return void
*/ */
protected function renew( $order, $container ) { protected function renew( $order, $container ) {
if ( ! is_a( $order, \WC_Order::class ) ) { if ( ! ( $order instanceof \WC_Order ) ) {
return; return;
} }

View file

@ -114,7 +114,6 @@ class CheckoutPayPalAddressPreset {
array_key_exists( $field_id, $payer_phone_map ) array_key_exists( $field_id, $payer_phone_map )
&& $payer && $payer
&& $payer->phone() && $payer->phone()
&& $payer->phone()->phone()
) { ) {
return $payer->phone()->phone()->{$payer_phone_map[ $field_id ]}() ? $payer->phone()->phone()->{$payer_phone_map[ $field_id ]}() : null; return $payer->phone()->phone()->{$payer_phone_map[ $field_id ]}() ? $payer->phone()->phone()->{$payer_phone_map[ $field_id ]}() : null;
} }

View file

@ -61,9 +61,6 @@ class ReturnUrlEndpoint {
$token = sanitize_text_field( wp_unslash( $_GET['token'] ) ); $token = sanitize_text_field( wp_unslash( $_GET['token'] ) );
// phpcs:enable WordPress.Security.NonceVerification.Recommended // phpcs:enable WordPress.Security.NonceVerification.Recommended
$order = $this->order_endpoint->order( $token ); $order = $this->order_endpoint->order( $token );
if ( ! $order ) {
exit();
}
$wc_order_id = $this->sanitize_custom_id( $order->purchase_units()[0]->custom_id() ); $wc_order_id = $this->sanitize_custom_id( $order->purchase_units()[0]->custom_id() );
if ( ! $wc_order_id ) { if ( ! $wc_order_id ) {