woocommerce-paypal-payments/modules/ppcp-api-client/src/Factory/ApplicationContextFactory.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2020-09-01 09:00:45 +03:00
<?php
/**
* The ApplicationContext factory.
*
2020-09-11 14:11:10 +03:00
* @package WooCommerce\PayPalCommerce\ApiClient\Factory
2020-09-01 09:00:45 +03:00
*/
declare(strict_types=1);
2020-09-11 14:11:10 +03:00
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
2020-09-01 09:00:45 +03:00
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
2020-09-01 09:00:45 +03:00
/**
* 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
);
}
}