Do not complete non-checkout button orders via webhooks

This commit is contained in:
Alex P 2023-07-17 10:39:06 +03:00
parent 40371cbf67
commit f811ea6a99
No known key found for this signature in database
GPG key ID: 54487A734A204D71
2 changed files with 15 additions and 0 deletions

View file

@ -211,6 +211,15 @@ class PurchaseUnit {
return $this->custom_id; return $this->custom_id;
} }
/**
* Sets the custom ID.
*
* @param string $custom_id The value to set.
*/
public function set_custom_id( string $custom_id ): void {
$this->custom_id = $custom_id;
}
/** /**
* Returns the invoice id. * Returns the invoice id.
* *

View file

@ -258,6 +258,12 @@ class CreateOrderEndpoint implements EndpointInterface {
} 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->handle_shipping_in_paypal );
// Do not allow completion by webhooks when started via non-checkout buttons,
// it is needed only for some APMs in checkout.
if ( in_array( $data['context'], array( 'product', 'cart', 'cart-block' ), true ) ) {
$this->purchase_unit->set_custom_id( '' );
}
// The cart does not have any info about payment method, so we must handle free trial here. // The cart does not have any info about payment method, so we must handle free trial here.
if ( ( if ( (
in_array( $payment_method, array( CreditCardGateway::ID, CardButtonGateway::ID ), true ) in_array( $payment_method, array( CreditCardGateway::ID, CardButtonGateway::ID ), true )