mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Merge branch 'trunk' of github.com:woocommerce/woocommerce-paypal-payments into PCP-375-order-of-woocommerce-checkout-ac
This commit is contained in:
commit
02519b7f35
10 changed files with 89 additions and 127 deletions
|
@ -17,49 +17,49 @@ class AmountBreakdown {
|
|||
/**
|
||||
* The item total.
|
||||
*
|
||||
* @var Money
|
||||
* @var Money|null
|
||||
*/
|
||||
private $item_total;
|
||||
|
||||
/**
|
||||
* The shipping.
|
||||
*
|
||||
* @var Money
|
||||
* @var Money|null
|
||||
*/
|
||||
private $shipping;
|
||||
|
||||
/**
|
||||
* The tax total.
|
||||
*
|
||||
* @var Money
|
||||
* @var Money|null
|
||||
*/
|
||||
private $tax_total;
|
||||
|
||||
/**
|
||||
* The handling.
|
||||
*
|
||||
* @var Money
|
||||
* @var Money|null
|
||||
*/
|
||||
private $handling;
|
||||
|
||||
/**
|
||||
* The insurance.
|
||||
*
|
||||
* @var Money
|
||||
* @var Money|null
|
||||
*/
|
||||
private $insurance;
|
||||
|
||||
/**
|
||||
* The shipping discount.
|
||||
*
|
||||
* @var Money
|
||||
* @var Money|null
|
||||
*/
|
||||
private $shipping_discount;
|
||||
|
||||
/**
|
||||
* The discount.
|
||||
*
|
||||
* @var Money
|
||||
* @var Money|null
|
||||
*/
|
||||
private $discount;
|
||||
|
||||
|
@ -75,13 +75,13 @@ class AmountBreakdown {
|
|||
* @param Money|null $discount The discount.
|
||||
*/
|
||||
public function __construct(
|
||||
Money $item_total = null,
|
||||
Money $shipping = null,
|
||||
Money $tax_total = null,
|
||||
Money $handling = null,
|
||||
Money $insurance = null,
|
||||
Money $shipping_discount = null,
|
||||
Money $discount = null
|
||||
?Money $item_total = null,
|
||||
?Money $shipping = null,
|
||||
?Money $tax_total = null,
|
||||
?Money $handling = null,
|
||||
?Money $insurance = null,
|
||||
?Money $shipping_discount = null,
|
||||
?Money $discount = null
|
||||
) {
|
||||
|
||||
$this->item_total = $item_total;
|
||||
|
|
|
@ -303,55 +303,79 @@ class PurchaseUnit {
|
|||
* @return bool
|
||||
*/
|
||||
private function ditch_items_when_mismatch( Amount $amount, Item ...$items ): bool {
|
||||
$fee_items_total = ( $amount->breakdown() && $amount->breakdown()->item_total() ) ?
|
||||
$amount->breakdown()->item_total()->value() : null;
|
||||
$fee_tax_total = ( $amount->breakdown() && $amount->breakdown()->tax_total() ) ?
|
||||
$amount->breakdown()->tax_total()->value() : null;
|
||||
|
||||
foreach ( $items as $item ) {
|
||||
if ( null !== $fee_items_total ) {
|
||||
$fee_items_total -= $item->unit_amount()->value() * $item->quantity();
|
||||
}
|
||||
if ( null !== $fee_tax_total ) {
|
||||
$fee_tax_total -= $item->tax()->value() * $item->quantity();
|
||||
}
|
||||
}
|
||||
|
||||
$fee_items_total = round( (float) $fee_items_total, 2 );
|
||||
$fee_tax_total = round( (float) $fee_tax_total, 2 );
|
||||
|
||||
if ( 0.0 !== $fee_items_total || 0.0 !== $fee_tax_total ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$breakdown = $this->amount()->breakdown();
|
||||
$breakdown = $amount->breakdown();
|
||||
if ( ! $breakdown ) {
|
||||
return false;
|
||||
}
|
||||
$amount_total = 0;
|
||||
if ( $breakdown->shipping() ) {
|
||||
$amount_total += $breakdown->shipping()->value();
|
||||
}
|
||||
if ( $breakdown->item_total() ) {
|
||||
$amount_total += $breakdown->item_total()->value();
|
||||
}
|
||||
if ( $breakdown->discount() ) {
|
||||
$amount_total -= $breakdown->discount()->value();
|
||||
}
|
||||
if ( $breakdown->tax_total() ) {
|
||||
$amount_total += $breakdown->tax_total()->value();
|
||||
}
|
||||
if ( $breakdown->shipping_discount() ) {
|
||||
$amount_total -= $breakdown->shipping_discount()->value();
|
||||
}
|
||||
if ( $breakdown->handling() ) {
|
||||
$amount_total += $breakdown->handling()->value();
|
||||
}
|
||||
if ( $breakdown->insurance() ) {
|
||||
$amount_total += $breakdown->insurance()->value();
|
||||
|
||||
$item_total = $breakdown->item_total();
|
||||
if ( $item_total ) {
|
||||
$remaining_item_total = array_reduce(
|
||||
$items,
|
||||
function ( float $total, Item $item ): float {
|
||||
return $total - $item->unit_amount()->value() * (float) $item->quantity();
|
||||
},
|
||||
$item_total->value()
|
||||
);
|
||||
|
||||
$remaining_item_total = round( $remaining_item_total, 2 );
|
||||
|
||||
if ( 0.0 !== $remaining_item_total ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$amount_value = $this->amount()->value();
|
||||
$tax_total = $breakdown->tax_total();
|
||||
if ( $tax_total ) {
|
||||
$remaining_tax_total = array_reduce(
|
||||
$items,
|
||||
function ( float $total, Item $item ): float {
|
||||
$tax = $item->tax();
|
||||
if ( $tax ) {
|
||||
$total -= $tax->value() * (float) $item->quantity();
|
||||
}
|
||||
return $total;
|
||||
},
|
||||
$tax_total->value()
|
||||
);
|
||||
|
||||
$remaining_tax_total = round( $remaining_tax_total, 2 );
|
||||
|
||||
if ( 0.0 !== $remaining_tax_total ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$shipping = $breakdown->shipping();
|
||||
$discount = $breakdown->discount();
|
||||
$shipping_discount = $breakdown->shipping_discount();
|
||||
$handling = $breakdown->handling();
|
||||
$insurance = $breakdown->insurance();
|
||||
|
||||
$amount_total = 0.0;
|
||||
if ( $shipping ) {
|
||||
$amount_total += $shipping->value();
|
||||
}
|
||||
if ( $item_total ) {
|
||||
$amount_total += $item_total->value();
|
||||
}
|
||||
if ( $discount ) {
|
||||
$amount_total -= $discount->value();
|
||||
}
|
||||
if ( $tax_total ) {
|
||||
$amount_total += $tax_total->value();
|
||||
}
|
||||
if ( $shipping_discount ) {
|
||||
$amount_total -= $shipping_discount->value();
|
||||
}
|
||||
if ( $handling ) {
|
||||
$amount_total += $handling->value();
|
||||
}
|
||||
if ( $insurance ) {
|
||||
$amount_total += $insurance->value();
|
||||
}
|
||||
|
||||
$amount_value = $amount->value();
|
||||
$needs_to_ditch = (string) $amount_total !== (string) $amount_value;
|
||||
return $needs_to_ditch;
|
||||
}
|
||||
|
|
|
@ -52,14 +52,12 @@ class PatchCollectionFactory {
|
|||
array_filter(
|
||||
$from,
|
||||
static function ( PurchaseUnit $unit ) use ( $purchase_unit_to ): bool {
|
||||
//phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
|
||||
// Loose comparison needed to compare two objects.
|
||||
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
||||
return $unit == $purchase_unit_to;
|
||||
//phpcs:enable WordPress.PHP.StrictComparisons.LooseComparison
|
||||
}
|
||||
)
|
||||
);
|
||||
$needs_update = true;
|
||||
if ( ! $needs_update ) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -728,7 +728,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
private function payerData() {
|
||||
|
||||
$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 $this->payer_factory->from_customer( $customer )->to_array();
|
||||
|
@ -757,7 +757,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
if (
|
||||
$this->environment->current_environment_is( Environment::SANDBOX )
|
||||
&& 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() )
|
||||
) {
|
||||
$params['buyer-country'] = WC()->customer->get_billing_country();
|
||||
|
|
|
@ -121,7 +121,7 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
* Handles the request.
|
||||
*
|
||||
* @return bool
|
||||
* @throws RuntimeException When no order was found.
|
||||
* @throws RuntimeException When order not found or handling failed.
|
||||
*/
|
||||
public function handle_request(): bool {
|
||||
try {
|
||||
|
@ -133,15 +133,6 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
}
|
||||
|
||||
$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 ( $this->settings->has( 'disable_cards' ) ) {
|
||||
|
|
|
@ -296,7 +296,7 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
* @throws RuntimeException If create order request fails.
|
||||
*/
|
||||
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'];
|
||||
|
||||
return $this->api_endpoint->create(
|
||||
|
|
|
@ -112,7 +112,7 @@ class SubscriptionModule implements ModuleInterface {
|
|||
* @return void
|
||||
*/
|
||||
protected function renew( $order, $container ) {
|
||||
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||
if ( ! ( $order instanceof \WC_Order ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,6 @@ class CheckoutPayPalAddressPreset {
|
|||
array_key_exists( $field_id, $payer_phone_map )
|
||||
&& $payer
|
||||
&& $payer->phone()
|
||||
&& $payer->phone()->phone()
|
||||
) {
|
||||
return $payer->phone()->phone()->{$payer_phone_map[ $field_id ]}() ? $payer->phone()->phone()->{$payer_phone_map[ $field_id ]}() : null;
|
||||
}
|
||||
|
|
|
@ -61,9 +61,6 @@ class ReturnUrlEndpoint {
|
|||
$token = sanitize_text_field( wp_unslash( $_GET['token'] ) );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
$order = $this->order_endpoint->order( $token );
|
||||
if ( ! $order ) {
|
||||
exit();
|
||||
}
|
||||
|
||||
$wc_order_id = $this->sanitize_custom_id( $order->purchase_units()[0]->custom_id() );
|
||||
if ( ! $wc_order_id ) {
|
||||
|
|
|
@ -159,35 +159,10 @@
|
|||
</PossiblyNullReference>
|
||||
</file>
|
||||
<file src="modules/ppcp-api-client/src/Entity/PurchaseUnit.php">
|
||||
<InvalidOperand occurrences="9">
|
||||
<code>$amount_total += $breakdown->handling()->value()</code>
|
||||
<code>$amount_total += $breakdown->insurance()->value()</code>
|
||||
<code>$amount_total += $breakdown->item_total()->value()</code>
|
||||
<code>$amount_total += $breakdown->shipping()->value()</code>
|
||||
<code>$amount_total += $breakdown->tax_total()->value()</code>
|
||||
<code>$amount_total -= $breakdown->discount()->value()</code>
|
||||
<code>$amount_total -= $breakdown->shipping_discount()->value()</code>
|
||||
<code>$item->tax()->value() * $item->quantity()</code>
|
||||
<code>$item->unit_amount()->value() * $item->quantity()</code>
|
||||
</InvalidOperand>
|
||||
<PossiblyNullReference occurrences="17">
|
||||
<code>item_total</code>
|
||||
<code>item_total</code>
|
||||
<code>tax_total</code>
|
||||
<code>tax_total</code>
|
||||
<PossiblyNullReference occurrences="3">
|
||||
<code>to_array</code>
|
||||
<code>to_array</code>
|
||||
<code>to_array</code>
|
||||
<code>value</code>
|
||||
<code>value</code>
|
||||
<code>value</code>
|
||||
<code>value</code>
|
||||
<code>value</code>
|
||||
<code>value</code>
|
||||
<code>value</code>
|
||||
<code>value</code>
|
||||
<code>value</code>
|
||||
<code>value</code>
|
||||
</PossiblyNullReference>
|
||||
</file>
|
||||
<file src="modules/ppcp-api-client/src/Entity/Refund.php">
|
||||
|
@ -768,9 +743,6 @@
|
|||
</PropertyNotSetInConstructor>
|
||||
</file>
|
||||
<file src="modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php">
|
||||
<MissingReturnType occurrences="1">
|
||||
<code>set_order_transaction_id</code>
|
||||
</MissingReturnType>
|
||||
<PossiblyNullReference occurrences="1">
|
||||
<code>card</code>
|
||||
</PossiblyNullReference>
|
||||
|
@ -928,25 +900,6 @@
|
|||
<code>$request['resource']['purchase_units']</code>
|
||||
</PossiblyNullArrayAccess>
|
||||
</file>
|
||||
<file src="modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php">
|
||||
<InvalidReturnStatement occurrences="4">
|
||||
<code>rest_ensure_response( $response )</code>
|
||||
<code>rest_ensure_response( $response )</code>
|
||||
<code>rest_ensure_response( $response )</code>
|
||||
<code>rest_ensure_response( $response )</code>
|
||||
</InvalidReturnStatement>
|
||||
<InvalidReturnType occurrences="1">
|
||||
<code>\WP_REST_Response</code>
|
||||
</InvalidReturnType>
|
||||
<PossiblyNullArgument occurrences="3">
|
||||
<code>$request['resource']['custom_id']</code>
|
||||
<code>isset( $request['id'] ) ? $request['id'] : ''</code>
|
||||
<code>isset( $request['id'] ) ? $request['id'] : ''</code>
|
||||
</PossiblyNullArgument>
|
||||
<PossiblyNullArrayAccess occurrences="1">
|
||||
<code>$request['resource']['custom_id']</code>
|
||||
</PossiblyNullArrayAccess>
|
||||
</file>
|
||||
<file src="modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php">
|
||||
<InvalidReturnStatement occurrences="4">
|
||||
<code>rest_ensure_response( $response )</code>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue