diff --git a/modules/ppcp-api-client/src/Entity/PurchaseUnit.php b/modules/ppcp-api-client/src/Entity/PurchaseUnit.php index ad138cc75..f2c64c73a 100644 --- a/modules/ppcp-api-client/src/Entity/PurchaseUnit.php +++ b/modules/ppcp-api-client/src/Entity/PurchaseUnit.php @@ -211,6 +211,15 @@ class PurchaseUnit { 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. * diff --git a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php index 686b87dd8..39a848433 100644 --- a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php +++ b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php @@ -258,6 +258,12 @@ class CreateOrderEndpoint implements EndpointInterface { } else { $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. if ( ( in_array( $payment_method, array( CreditCardGateway::ID, CardButtonGateway::ID ), true )