Check for venmo and vaulting before creating wc order

This commit is contained in:
Narek Zakarian 2024-05-17 00:25:05 +04:00
parent 1561272657
commit 2ad6df385c
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7

View file

@ -246,6 +246,7 @@ class CreateOrderEndpoint implements EndpointInterface {
$this->parsed_request_data = $data; $this->parsed_request_data = $data;
$payment_method = $data['payment_method'] ?? ''; $payment_method = $data['payment_method'] ?? '';
$funding_source = $data['funding_source'] ?? ''; $funding_source = $data['funding_source'] ?? '';
$payment_source = $data['payment_source'] ?? '';
$wc_order = null; $wc_order = null;
if ( 'pay-now' === $data['context'] ) { if ( 'pay-now' === $data['context'] ) {
$wc_order = wc_get_order( (int) $data['order_id'] ); $wc_order = wc_get_order( (int) $data['order_id'] );
@ -261,7 +262,7 @@ class CreateOrderEndpoint implements EndpointInterface {
} }
$this->purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order ); $this->purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
} else { } else {
$this->purchase_unit = $this->purchase_unit_factory->from_wc_cart( null, $this->handle_shipping_in_paypal ); $this->purchase_unit = $this->purchase_unit_factory->from_wc_cart( null, $this->should_handle_shipping_in_paypal( $payment_source ) );
// Do not allow completion by webhooks when started via non-checkout buttons, // Do not allow completion by webhooks when started via non-checkout buttons,
// it is needed only for some APMs in checkout. // it is needed only for some APMs in checkout.
@ -610,4 +611,20 @@ class CreateOrderEndpoint implements EndpointInterface {
'custom_id' => $order->purchase_units()[0]->custom_id(), 'custom_id' => $order->purchase_units()[0]->custom_id(),
); );
} }
/**
* Checks if the shipping should be handled in PayPal popup.
*
* @param string $payment_source The payment source.
* @return bool true if the shipping should be handled in PayPal popup, otherwise false.
*/
protected function should_handle_shipping_in_paypal( string $payment_source ): bool {
$is_vaulting_enabled = $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' );
if ( ! $this->handle_shipping_in_paypal ) {
return false;
}
return ! $is_vaulting_enabled || $payment_source !== 'venmo';
}
} }