mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Add CallbackConfig
This commit is contained in:
parent
2c27bc416d
commit
a397d7d9fa
3 changed files with 80 additions and 1 deletions
44
modules/ppcp-api-client/src/Entity/CallbackConfig.php
Normal file
44
modules/ppcp-api-client/src/Entity/CallbackConfig.php
Normal 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,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue