Add CallbackConfig

This commit is contained in:
Alex P. 2025-06-06 09:09:06 +03:00
parent 2c27bc416d
commit a397d7d9fa
No known key found for this signature in database
GPG key ID: 54487A734A204D71
3 changed files with 80 additions and 1 deletions

View file

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
/**
* The config for experience_context.order_update_callback_config.
*/
class CallbackConfig {
public const EVENT_SHIPPING_ADDRESS = 'SHIPPING_ADDRESS';
public const EVENT_SHIPPING_OPTIONS = 'SHIPPING_OPTIONS';
/**
* The events.
*
* @var string[]
*/
private array $events;
/**
* The URL that will be called when the events occur.
*/
private string $url;
/**
* @param string[] $events The events.
* @param string $url The URL that will be called when the events occur.
*/
public function __construct( array $events, string $url ) {
$this->events = $events;
$this->url = $url;
}
/**
* Returns the object as array.
*/
public function to_array(): array {
return array(
'callback_events' => $this->events,
'callback_url' => $this->url,
);
}
}

View file

@ -70,6 +70,11 @@ class ExperienceContext {
*/
private ?string $payment_method_preference = null;
/**
* The callback config.
*/
private ?CallbackConfig $order_update_callback_config = null;
/**
* Returns the return URL.
*/
@ -224,6 +229,25 @@ class ExperienceContext {
return $obj;
}
/**
* Returns the callback config.
*/
public function order_update_callback_config(): ?CallbackConfig {
return $this->order_update_callback_config;
}
/**
* Sets the callback config.
*
* @param CallbackConfig|null $new_value The value to set.
*/
public function with_order_update_callback_config( ?CallbackConfig $new_value ): ExperienceContext {
$obj = clone $this;
$obj->order_update_callback_config = $new_value;
return $obj;
}
/**
* Returns the object as array.
*/
@ -236,6 +260,9 @@ class ExperienceContext {
if ( $value === null ) {
continue;
}
if ( is_object( $value ) && method_exists( $value, 'to_array' ) ) {
$value = $value->to_array();
}
$data[ $prop->getName() ] = $value;
}