mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
PSR-4 is much more robust and predictable. But to do this, a source root dir must be specified for every module. This could be done in the root file, but this is not very modular. Instead, now every module declares its own source root by using the amazing Composer Merge Plugin. This approach allows each module to also declare its own dependencies. Together, these changes allow modules to be easily extractable to separate pacakges when the need arises, and in general improves modularity significantly.
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* The ApplicationContext factory.
|
|
*
|
|
* @package WooCommerce\PayPalCommerce\ApiClient\Factory
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
|
|
|
/**
|
|
* Class ApplicationContextFactory
|
|
*/
|
|
class ApplicationContextFactory {
|
|
|
|
/**
|
|
* Returns an Application Context based off a PayPal Response.
|
|
*
|
|
* @param \stdClass $data The JSON object.
|
|
*
|
|
* @return ApplicationContext
|
|
*/
|
|
public function from_paypal_response( \stdClass $data ): ApplicationContext {
|
|
return new ApplicationContext(
|
|
isset( $data->return_url ) ?
|
|
$data->return_url : '',
|
|
isset( $data->cancel_url ) ?
|
|
$data->cancel_url : '',
|
|
isset( $data->brand_name ) ?
|
|
$data->brand_name : '',
|
|
isset( $data->locale ) ?
|
|
$data->locale : '',
|
|
isset( $data->landing_page ) ?
|
|
$data->landing_page : ApplicationContext::LANDING_PAGE_NO_PREFERENCE,
|
|
isset( $data->shipping_preference ) ?
|
|
$data->shipping_preference : ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE,
|
|
isset( $data->user_action ) ?
|
|
$data->user_action : ApplicationContext::USER_ACTION_CONTINUE
|
|
);
|
|
}
|
|
}
|