mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Use shipping callback
This commit is contained in:
parent
b16ef8e333
commit
6691ee5a21
5 changed files with 44 additions and 12 deletions
|
@ -16,7 +16,8 @@ return array(
|
|||
|
||||
'wcgateway.builder.experience-context' => static function ( ContainerInterface $container ): ExperienceContextBuilder {
|
||||
return new ExperienceContextBuilder(
|
||||
$container->get( 'wcgateway.settings' )
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'wcgateway.shipping.callback.factory.url' )
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -11,9 +11,11 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
|||
|
||||
use WC_AJAX;
|
||||
use WC_Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\CallbackConfig;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\ExperienceContext;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Shipping\ShippingCallbackUrlFactory;
|
||||
|
||||
/**
|
||||
* Class ExperienceContextBuilder
|
||||
|
@ -30,15 +32,16 @@ class ExperienceContextBuilder {
|
|||
*/
|
||||
private ContainerInterface $settings;
|
||||
|
||||
/**
|
||||
* ExperienceContextBuilder constructor.
|
||||
*
|
||||
* @param ContainerInterface $settings The settings.
|
||||
*/
|
||||
public function __construct( ContainerInterface $settings ) {
|
||||
private ShippingCallbackUrlFactory $shipping_callback_url_factory;
|
||||
|
||||
public function __construct(
|
||||
ContainerInterface $settings,
|
||||
ShippingCallbackUrlFactory $shipping_callback_url_factory
|
||||
) {
|
||||
$this->experience_context = new ExperienceContext();
|
||||
|
||||
$this->settings = $settings;
|
||||
$this->settings = $settings;
|
||||
$this->shipping_callback_url_factory = $shipping_callback_url_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,6 +164,23 @@ class ExperienceContextBuilder {
|
|||
return $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the server-side shipping callback configuration.
|
||||
*/
|
||||
public function with_shipping_callback(): ExperienceContextBuilder {
|
||||
$builder = clone $this;
|
||||
|
||||
$builder->experience_context = $builder->experience_context
|
||||
->with_order_update_callback_config(
|
||||
new CallbackConfig(
|
||||
array( CallbackConfig::EVENT_SHIPPING_ADDRESS, CallbackConfig::EVENT_SHIPPING_OPTIONS ),
|
||||
$this->shipping_callback_url_factory->create()
|
||||
)
|
||||
);
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ExperienceContext.
|
||||
*/
|
||||
|
|
|
@ -352,6 +352,8 @@ export const PayPalComponent = ( {
|
|||
);
|
||||
|
||||
const getOnShippingOptionsChange = ( fundingSource ) => {
|
||||
return null;
|
||||
|
||||
if ( fundingSource === 'venmo' ) {
|
||||
return null;
|
||||
}
|
||||
|
@ -364,6 +366,8 @@ export const PayPalComponent = ( {
|
|||
};
|
||||
|
||||
const getOnShippingAddressChange = ( fundingSource ) => {
|
||||
return null;
|
||||
|
||||
if ( fundingSource === 'venmo' ) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -446,12 +446,15 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
$payment_source_key = $funding_source;
|
||||
}
|
||||
|
||||
$experience_context = $this->experience_context_builder->with_default_paypal_config( $shipping_preference, $action );
|
||||
if ( $shipping_preference === ExperienceContext::SHIPPING_PREFERENCE_GET_FROM_FILE ) {
|
||||
$experience_context = $experience_context->with_shipping_callback();
|
||||
}
|
||||
|
||||
$payment_source = new PaymentSource(
|
||||
$payment_source_key,
|
||||
(object) array(
|
||||
'experience_context' => $this->experience_context_builder
|
||||
->with_default_paypal_config( $shipping_preference, $action )
|
||||
->build()->to_array(),
|
||||
'experience_context' => $experience_context->build()->to_array(),
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
|
|||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Shipping\ShippingCallbackUrlFactory;
|
||||
use function Brain\Monkey\Functions\expect;
|
||||
use Mockery;
|
||||
|
||||
|
@ -15,6 +16,8 @@ class ExperienceContextBuilderTest extends TestCase
|
|||
{
|
||||
private $settings;
|
||||
|
||||
private $shipping_callback_url_factory;
|
||||
|
||||
private $sut;
|
||||
|
||||
public function setUp(): void
|
||||
|
@ -22,8 +25,9 @@ class ExperienceContextBuilderTest extends TestCase
|
|||
parent::setUp();
|
||||
|
||||
$this->settings = Mockery::mock(Settings::class);
|
||||
$this->shipping_callback_url_factory = Mockery::mock(ShippingCallbackUrlFactory::class);
|
||||
|
||||
$this->sut = new ExperienceContextBuilder($this->settings);
|
||||
$this->sut = new ExperienceContextBuilder($this->settings, $this->shipping_callback_url_factory);
|
||||
}
|
||||
|
||||
public function testOrderReturnUrls()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue