Merge branch 'trunk' of github.com:woocommerce/woocommerce-paypal-payments into PCP-4649-track-wizard-screen-views

This commit is contained in:
Daniel Dudzic 2025-06-06 13:33:56 +02:00
commit ea3e64bcb9
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
63 changed files with 1323 additions and 1335 deletions

View file

@ -0,0 +1,22 @@
<?php
/**
* The factories of the API client.
*
* @package WooCommerce\PayPalCommerce\ApiClient
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
return array(
'wcgateway.builder.experience-context' => static function ( ContainerInterface $container ): ExperienceContextBuilder {
return new ExperienceContextBuilder(
$container->get( 'wcgateway.settings' )
);
},
);

View file

@ -47,7 +47,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokenEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\WebhookEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Factory\AddressFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\AmountFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ApplicationContextFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\AuthorizationFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\CaptureFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExchangeRateFactory;
@ -74,7 +73,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderHelper;
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderTransient;
use WooCommerce\PayPalCommerce\ApiClient\Helper\PurchaseUnitSanitizer;
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\CustomerRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\OrderRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
@ -254,7 +252,6 @@ return array(
assert( $settings instanceof Settings );
$intent = $settings->has( 'intent' ) && strtoupper( (string) $settings->get( 'intent' ) ) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE';
$application_context_repository = $container->get( 'api.repository.application-context' );
$subscription_helper = $container->get( 'wc-subscriptions.helper' );
return new OrderEndpoint(
$container->get( 'api.host' ),
@ -263,7 +260,6 @@ return array(
$patch_collection_factory,
$intent,
$logger,
$application_context_repository,
$subscription_helper,
$container->get( 'wcgateway.is-fraudnet-enabled' ),
$container->get( 'wcgateway.fraudnet' ),
@ -315,11 +311,6 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' )
);
},
'api.repository.application-context' => static function( ContainerInterface $container ) : ApplicationContextRepository {
$settings = $container->get( 'wcgateway.settings' );
return new ApplicationContextRepository( $settings );
},
'api.repository.partner-referrals-data' => static function ( ContainerInterface $container ) : PartnerReferralsData {
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
@ -339,9 +330,6 @@ return array(
$container->get( 'api.endpoint.order' )
);
},
'api.factory.application-context' => static function ( ContainerInterface $container ) : ApplicationContextFactory {
return new ApplicationContextFactory();
},
'api.factory.payment-token' => static function ( ContainerInterface $container ) : PaymentTokenFactory {
return new PaymentTokenFactory();
},
@ -440,13 +428,9 @@ return array(
'api.factory.order' => static function ( ContainerInterface $container ): OrderFactory {
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
$payer_factory = $container->get( 'api.factory.payer' );
$application_context_repository = $container->get( 'api.repository.application-context' );
$application_context_factory = $container->get( 'api.factory.application-context' );
return new OrderFactory(
$purchase_unit_factory,
$payer_factory,
$application_context_repository,
$application_context_factory
$payer_factory
);
},
'api.factory.payments' => static function ( ContainerInterface $container ): PaymentsFactory {

View file

@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderTransient;
use WooCommerce\PayPalCommerce\ApiClient\Helper\PartnerAttribution;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\FactoryModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
@ -28,7 +29,7 @@ use Psr\Log\LoggerInterface;
/**
* Class ApiModule
*/
class ApiModule implements ServiceModule, ExtendingModule, ExecutableModule {
class ApiModule implements ServiceModule, FactoryModule, ExtendingModule, ExecutableModule {
use ModuleClassNameIdTrait;
/**
@ -38,6 +39,13 @@ class ApiModule implements ServiceModule, ExtendingModule, ExecutableModule {
return require __DIR__ . '/../services.php';
}
/**
* {@inheritDoc}
*/
public function factories(): array {
return require __DIR__ . '/../factories.php';
}
/**
* {@inheritDoc}
*/

View file

@ -11,22 +11,20 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
use stdClass;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\CaptureStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ExperienceContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PatchCollection;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PatchCollectionFactory;
use WooCommerce\PayPalCommerce\ApiClient\Helper\ErrorResponse;
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\WcGateway\FraudNet\FraudNet;
@ -88,13 +86,6 @@ class OrderEndpoint {
*/
private $logger;
/**
* The application context repository.
*
* @var ApplicationContextRepository
*/
private $application_context_repository;
/**
* True if FraudNet support is enabled in settings, otherwise false.
*
@ -119,17 +110,16 @@ class OrderEndpoint {
/**
* OrderEndpoint constructor.
*
* @param string $host The host.
* @param Bearer $bearer The bearer.
* @param OrderFactory $order_factory The order factory.
* @param PatchCollectionFactory $patch_collection_factory The patch collection factory.
* @param string $intent The intent.
* @param LoggerInterface $logger The logger.
* @param ApplicationContextRepository $application_context_repository The application context repository.
* @param SubscriptionHelper $subscription_helper The subscription helper.
* @param bool $is_fraudnet_enabled true if FraudNet support is enabled in settings, otherwise false.
* @param FraudNet $fraudnet The FraudNet entity.
* @param string $bn_code The BN Code.
* @param string $host The host.
* @param Bearer $bearer The bearer.
* @param OrderFactory $order_factory The order factory.
* @param PatchCollectionFactory $patch_collection_factory The patch collection factory.
* @param string $intent The intent.
* @param LoggerInterface $logger The logger.
* @param SubscriptionHelper $subscription_helper The subscription helper.
* @param bool $is_fraudnet_enabled true if FraudNet support is enabled in settings, otherwise false.
* @param FraudNet $fraudnet The FraudNet entity.
* @param string $bn_code The BN Code.
*/
public function __construct(
string $host,
@ -138,24 +128,22 @@ class OrderEndpoint {
PatchCollectionFactory $patch_collection_factory,
string $intent,
LoggerInterface $logger,
ApplicationContextRepository $application_context_repository,
SubscriptionHelper $subscription_helper,
bool $is_fraudnet_enabled,
FraudNet $fraudnet,
string $bn_code = ''
) {
$this->host = $host;
$this->bearer = $bearer;
$this->order_factory = $order_factory;
$this->patch_collection_factory = $patch_collection_factory;
$this->intent = $intent;
$this->logger = $logger;
$this->application_context_repository = $application_context_repository;
$this->bn_code = $bn_code;
$this->is_fraudnet_enabled = $is_fraudnet_enabled;
$this->subscription_helper = $subscription_helper;
$this->fraudnet = $fraudnet;
$this->host = $host;
$this->bearer = $bearer;
$this->order_factory = $order_factory;
$this->patch_collection_factory = $patch_collection_factory;
$this->intent = $intent;
$this->logger = $logger;
$this->bn_code = $bn_code;
$this->is_fraudnet_enabled = $is_fraudnet_enabled;
$this->subscription_helper = $subscription_helper;
$this->fraudnet = $fraudnet;
}
/**
@ -176,11 +164,8 @@ class OrderEndpoint {
* Creates an order.
*
* @param PurchaseUnit[] $items The purchase unit items for the order.
* @param string $shipping_preference One of ApplicationContext::SHIPPING_PREFERENCE_ values.
* @param string $shipping_preference One of ExperienceContext::SHIPPING_PREFERENCE_ values.
* @param Payer|null $payer The payer off the order.
* @param PaymentToken|null $payment_token The payment token.
* @param string $paypal_request_id The PayPal request id.
* @param string $user_action The user action.
* @param string $payment_method WC payment method.
* @param array $request_data Request data.
* @param PaymentSource|null $payment_source The payment source.
@ -192,21 +177,18 @@ class OrderEndpoint {
array $items,
string $shipping_preference,
Payer $payer = null,
PaymentToken $payment_token = null,
string $paypal_request_id = '',
string $user_action = ApplicationContext::USER_ACTION_CONTINUE,
string $payment_method = '',
array $request_data = array(),
PaymentSource $payment_source = null
): Order {
$bearer = $this->bearer->bearer();
$data = array(
'intent' => apply_filters( 'woocommerce_paypal_payments_order_intent', $this->intent ),
'purchase_units' => array_map(
'intent' => apply_filters( 'woocommerce_paypal_payments_order_intent', $this->intent ),
'purchase_units' => array_map(
static function ( PurchaseUnit $item ) use ( $shipping_preference ): array {
$data = $item->to_array();
if ( $shipping_preference !== ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE ) {
if ( $shipping_preference !== ExperienceContext::SHIPPING_PREFERENCE_GET_FROM_FILE ) {
// Shipping options are not allowed to be sent when not getting the address from PayPal.
unset( $data['shipping']['options'] );
}
@ -215,15 +197,10 @@ class OrderEndpoint {
},
$items
),
'application_context' => $this->application_context_repository
->current_context( $shipping_preference, $user_action )->to_array(),
);
if ( $payer && ! empty( $payer->email_address() ) ) {
$data['payer'] = $payer->to_array();
}
if ( $payment_token ) {
$data['payment_source']['token'] = $payment_token->to_array();
}
if ( $payment_source ) {
$data['payment_source'] = array(
$payment_source->name() => $payment_source->properties(),
@ -259,11 +236,8 @@ class OrderEndpoint {
$response = $this->request( $url, $args );
if ( is_wp_error( $response ) ) {
$error = new RuntimeException(
__( 'Could not create order.', 'woocommerce-paypal-payments' )
);
$this->logger->log(
'warning',
$error = new RuntimeException( 'Could not create order.' );
$this->logger->warning(
$error->getMessage(),
array(
'args' => $args,
@ -332,8 +306,7 @@ class OrderEndpoint {
$error = new RuntimeException(
__( 'Could not capture order.', 'woocommerce-paypal-payments' )
);
$this->logger->log(
'warning',
$this->logger->warning(
$error->getMessage(),
array(
'args' => $args,
@ -354,8 +327,7 @@ class OrderEndpoint {
if ( strpos( $response['body'], ErrorResponse::ORDER_ALREADY_CAPTURED ) !== false ) {
return $this->order( $order->id() );
}
$this->logger->log(
'warning',
$this->logger->warning(
sprintf(
'Failed to capture order. PayPal API response: %1$s',
$error->getMessage()
@ -409,8 +381,7 @@ class OrderEndpoint {
'woocommerce-paypal-payments'
)
);
$this->logger->log(
'warning',
$this->logger->warning(
$error->getMessage(),
array(
'args' => $args,
@ -429,8 +400,7 @@ class OrderEndpoint {
$json,
$status_code
);
$this->logger->log(
'warning',
$this->logger->warning(
sprintf(
'Failed to authorize order. PayPal API response: %1$s',
$error->getMessage()
@ -489,8 +459,7 @@ class OrderEndpoint {
__( 'Could not retrieve order.', 'woocommerce-paypal-payments' ),
404
);
$this->logger->log(
'warning',
$this->logger->warning(
$error->getMessage(),
array(
'args' => $args,
@ -505,8 +474,7 @@ class OrderEndpoint {
$json,
$status_code
);
$this->logger->log(
'warning',
$this->logger->warning(
$error->getMessage(),
array(
'args' => $args,

View file

@ -1,252 +0,0 @@
<?php
/**
* The application context object.
*
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
/**
* Class ApplicationContext
*/
class ApplicationContext {
const LANDING_PAGE_LOGIN = 'LOGIN';
const LANDING_PAGE_BILLING = 'BILLING';
const LANDING_PAGE_NO_PREFERENCE = 'NO_PREFERENCE';
const VALID_LANDING_PAGE_VALUES = array(
self::LANDING_PAGE_LOGIN,
self::LANDING_PAGE_BILLING,
self::LANDING_PAGE_NO_PREFERENCE,
);
const SHIPPING_PREFERENCE_GET_FROM_FILE = 'GET_FROM_FILE';
const SHIPPING_PREFERENCE_NO_SHIPPING = 'NO_SHIPPING';
const SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS = 'SET_PROVIDED_ADDRESS';
const VALID_SHIPPING_PREFERENCE_VALUES = array(
self::SHIPPING_PREFERENCE_GET_FROM_FILE,
self::SHIPPING_PREFERENCE_NO_SHIPPING,
self::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS,
);
const USER_ACTION_CONTINUE = 'CONTINUE';
const USER_ACTION_PAY_NOW = 'PAY_NOW';
const VALID_USER_ACTION_VALUES = array(
self::USER_ACTION_CONTINUE,
self::USER_ACTION_PAY_NOW,
);
const PAYMENT_METHOD_UNRESTRICTED = 'UNRESTRICTED';
const PAYMENT_METHOD_IMMEDIATE_PAYMENT_REQUIRED = 'IMMEDIATE_PAYMENT_REQUIRED';
/**
* The brand name.
*
* @var string
*/
private $brand_name;
/**
* The locale.
*
* @var string
*/
private $locale;
/**
* The landing page.
*
* @var string
*/
private $landing_page;
/**
* The shipping preference.
*
* @var string
*/
private $shipping_preference;
/**
* The user action.
*
* @var string
*/
private $user_action;
/**
* The return url.
*
* @var string
*/
private $return_url;
/**
* The cancel url.
*
* @var string
*/
private $cancel_url;
/**
* The payment method preference.
*
* @var string
*/
private $payment_method_preference;
/**
* ApplicationContext constructor.
*
* @param string $return_url The return URL.
* @param string $cancel_url The cancel URL.
* @param string $brand_name The brand name.
* @param string $locale The locale.
* @param string $landing_page The landing page.
* @param string $shipping_preference The shipping preference.
* @param string $user_action The user action.
* @param string $payment_method_preference The payment method preference.
*
* @throws RuntimeException When values are not valid.
*/
public function __construct(
string $return_url = '',
string $cancel_url = '',
string $brand_name = '',
string $locale = '',
string $landing_page = self::LANDING_PAGE_NO_PREFERENCE,
string $shipping_preference = self::SHIPPING_PREFERENCE_NO_SHIPPING,
string $user_action = self::USER_ACTION_CONTINUE,
string $payment_method_preference = self::PAYMENT_METHOD_IMMEDIATE_PAYMENT_REQUIRED
) {
if ( ! in_array( $landing_page, self::VALID_LANDING_PAGE_VALUES, true ) ) {
throw new RuntimeException( 'Landingpage not correct' );
}
if ( ! in_array( $shipping_preference, self::VALID_SHIPPING_PREFERENCE_VALUES, true ) ) {
throw new RuntimeException( 'Shipping preference not correct' );
}
if ( ! in_array( $user_action, self::VALID_USER_ACTION_VALUES, true ) ) {
throw new RuntimeException( 'User action preference not correct' );
}
$this->return_url = $return_url;
$this->cancel_url = $cancel_url;
$this->brand_name = $brand_name;
$this->locale = $locale;
$this->landing_page = $landing_page;
$this->shipping_preference = $shipping_preference;
$this->user_action = $user_action;
$this->payment_method_preference = $payment_method_preference;
}
/**
* Returns the brand name.
*
* @return string
*/
public function brand_name(): string {
return $this->brand_name;
}
/**
* Returns the locale.
*
* @return string
*/
public function locale(): string {
return $this->locale;
}
/**
* Returns the landing page.
*
* @return string
*/
public function landing_page(): string {
return $this->landing_page;
}
/**
* Returns the shipping preference.
*
* @return string
*/
public function shipping_preference(): string {
return $this->shipping_preference;
}
/**
* Returns the user action.
*
* @return string
*/
public function user_action(): string {
return $this->user_action;
}
/**
* Returns the return URL.
*
* @return string
*/
public function return_url(): string {
return $this->return_url;
}
/**
* Returns the cancel URL.
*
* @return string
*/
public function cancel_url(): string {
return $this->cancel_url;
}
/**
* Returns the payment method preference.
*/
public function payment_method_preference(): string {
return $this->payment_method_preference;
}
/**
* Returns the object as array.
*
* @return array
*/
public function to_array(): array {
$data = array();
if ( $this->user_action() ) {
$data['user_action'] = $this->user_action();
}
if ( $this->shipping_preference() ) {
$data['shipping_preference'] = $this->shipping_preference();
}
if ( $this->landing_page() ) {
$data['landing_page'] = $this->landing_page();
}
if ( $this->locale() ) {
$data['locale'] = $this->locale();
}
if ( $this->brand_name() ) {
$data['brand_name'] = $this->brand_name();
}
if ( $this->return_url() ) {
$data['return_url'] = $this->return_url();
}
if ( $this->cancel_url() ) {
$data['cancel_url'] = $this->cancel_url();
}
if ( $this->payment_method_preference ) {
$data['payment_method'] = array(
'payee_preferred' => $this->payment_method_preference,
);
}
return $data;
}
}

View file

@ -0,0 +1,244 @@
<?php
/**
* The experience_context object.
*
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use ReflectionClass;
/**
* Class ExperienceContext
*/
class ExperienceContext {
public const LANDING_PAGE_LOGIN = 'LOGIN';
public const LANDING_PAGE_GUEST_CHECKOUT = 'GUEST_CHECKOUT';
public const LANDING_PAGE_NO_PREFERENCE = 'NO_PREFERENCE';
public const SHIPPING_PREFERENCE_GET_FROM_FILE = 'GET_FROM_FILE';
public const SHIPPING_PREFERENCE_NO_SHIPPING = 'NO_SHIPPING';
public const SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS = 'SET_PROVIDED_ADDRESS';
public const USER_ACTION_CONTINUE = 'CONTINUE';
public const USER_ACTION_PAY_NOW = 'PAY_NOW';
public const PAYMENT_METHOD_UNRESTRICTED = 'UNRESTRICTED';
public const PAYMENT_METHOD_IMMEDIATE_PAYMENT_REQUIRED = 'IMMEDIATE_PAYMENT_REQUIRED';
/**
* The return url.
*/
private ?string $return_url = null;
/**
* The cancel url.
*/
private ?string $cancel_url = null;
/**
* The brand name.
*/
private ?string $brand_name = null;
/**
* The locale.
*/
private ?string $locale = null;
/**
* The landing page.
*/
private ?string $landing_page = null;
/**
* The shipping preference.
*/
private ?string $shipping_preference = null;
/**
* The user action.
*/
private ?string $user_action = null;
/**
* The payment method preference.
*/
private ?string $payment_method_preference = null;
/**
* Returns the return URL.
*/
public function return_url(): ?string {
return $this->return_url;
}
/**
* Sets the return URL.
*
* @param string|null $new_value The value to set.
*/
public function with_return_url( ?string $new_value ): ExperienceContext {
$obj = clone $this;
$obj->return_url = $new_value;
return $obj;
}
/**
* Returns the cancel URL.
*/
public function cancel_url(): ?string {
return $this->cancel_url;
}
/**
* Sets the cancel URL.
*
* @param string|null $new_value The value to set.
*/
public function with_cancel_url( ?string $new_value ): ExperienceContext {
$obj = clone $this;
$obj->cancel_url = $new_value;
return $obj;
}
/**
* Returns the brand name.
*
* @return string
*/
public function brand_name(): ?string {
return $this->brand_name;
}
/**
* Sets the brand name.
*
* @param string|null $new_value The value to set.
*/
public function with_brand_name( ?string $new_value ): ExperienceContext {
$obj = clone $this;
$obj->brand_name = $new_value;
return $obj;
}
/**
* Returns the locale.
*/
public function locale(): ?string {
return $this->locale;
}
/**
* Sets the locale.
*
* @param string|null $new_value The value to set.
*/
public function with_locale( ?string $new_value ): ExperienceContext {
$obj = clone $this;
$obj->locale = $new_value;
return $obj;
}
/**
* Returns the landing page.
*/
public function landing_page(): ?string {
return $this->landing_page;
}
/**
* Sets the landing page.
*
* @param string|null $new_value The value to set.
*/
public function with_landing_page( ?string $new_value ): ExperienceContext {
$obj = clone $this;
$obj->landing_page = $new_value;
return $obj;
}
/**
* Returns the shipping preference.
*/
public function shipping_preference(): ?string {
return $this->shipping_preference;
}
/**
* Sets the shipping preference.
*
* @param string|null $new_value The value to set.
*/
public function with_shipping_preference( ?string $new_value ): ExperienceContext {
$obj = clone $this;
$obj->shipping_preference = $new_value;
return $obj;
}
/**
* Returns the user action.
*/
public function user_action(): ?string {
return $this->user_action;
}
/**
* Sets the user action.
*
* @param string|null $new_value The value to set.
*/
public function with_user_action( ?string $new_value ): ExperienceContext {
$obj = clone $this;
$obj->user_action = $new_value;
return $obj;
}
/**
* Returns the payment method preference.
*/
public function payment_method_preference(): ?string {
return $this->payment_method_preference;
}
/**
* Sets the payment method preference.
*
* @param string|null $new_value The value to set.
*/
public function with_payment_method_preference( ?string $new_value ): ExperienceContext {
$obj = clone $this;
$obj->payment_method_preference = $new_value;
return $obj;
}
/**
* Returns the object as array.
*/
public function to_array(): array {
$data = array();
$class = new ReflectionClass( $this );
foreach ( $class->getProperties() as $prop ) {
$value = $this->{$prop->getName()};
if ( $value === null ) {
continue;
}
$data[ $prop->getName() ] = $value;
}
return $data;
}
}

View file

@ -64,13 +64,6 @@ class Order {
*/
private $update_time;
/**
* The application context.
*
* @var ApplicationContext|null
*/
private $application_context;
/**
* The payment source.
*
@ -83,21 +76,19 @@ class Order {
*
* @see https://developer.paypal.com/docs/api/orders/v2/#orders-create-response
*
* @param string $id The ID.
* @param PurchaseUnit[] $purchase_units The purchase units.
* @param OrderStatus $order_status The order status.
* @param ApplicationContext|null $application_context The application context.
* @param PaymentSource|null $payment_source The payment source.
* @param Payer|null $payer The payer.
* @param string $intent The intent.
* @param \DateTime|null $create_time The create time.
* @param \DateTime|null $update_time The update time.
* @param string $id The ID.
* @param PurchaseUnit[] $purchase_units The purchase units.
* @param OrderStatus $order_status The order status.
* @param PaymentSource|null $payment_source The payment source.
* @param Payer|null $payer The payer.
* @param string $intent The intent.
* @param \DateTime|null $create_time The create time.
* @param \DateTime|null $update_time The update time.
*/
public function __construct(
string $id,
array $purchase_units,
OrderStatus $order_status,
ApplicationContext $application_context = null,
PaymentSource $payment_source = null,
Payer $payer = null,
string $intent = 'CAPTURE',
@ -105,15 +96,14 @@ class Order {
\DateTime $update_time = null
) {
$this->id = $id;
$this->application_context = $application_context;
$this->payer = $payer;
$this->order_status = $order_status;
$this->intent = ( 'CAPTURE' === $intent ) ? 'CAPTURE' : 'AUTHORIZE';
$this->purchase_units = $purchase_units;
$this->create_time = $create_time;
$this->update_time = $update_time;
$this->payment_source = $payment_source;
$this->id = $id;
$this->payer = $payer;
$this->order_status = $order_status;
$this->intent = ( 'CAPTURE' === $intent ) ? 'CAPTURE' : 'AUTHORIZE';
$this->purchase_units = $purchase_units;
$this->create_time = $create_time;
$this->update_time = $update_time;
$this->payment_source = $payment_source;
}
/**
@ -179,16 +169,6 @@ class Order {
return $this->order_status;
}
/**
* Returns the application context.
*
* @return ApplicationContext|null
*/
public function application_context() {
return $this->application_context;
}
/**
* Returns the payment source.
*
@ -225,9 +205,6 @@ class Order {
if ( $this->update_time() ) {
$order['update_time'] = $this->update_time()->format( 'Y-m-d\TH:i:sO' );
}
if ( $this->application_context() ) {
$order['application_context'] = $this->application_context()->to_array();
}
return $order;
}

View file

@ -99,6 +99,16 @@ class PaymentToken {
);
}
/**
* Returns the PaymentSource object.
*/
public function to_payment_source(): PaymentSource {
return new PaymentSource(
'token',
(object) $this->to_array()
);
}
/**
* Returns a list of valid token types.
* Can be modified through the `woocommerce_paypal_payments_valid_payment_token_types` filter.

View file

@ -1,44 +0,0 @@
<?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
);
}
}

View file

@ -0,0 +1,193 @@
<?php
/**
* The ExperienceContext builder.
*
* @package WooCommerce\PayPalCommerce\ApiClient\Factory
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use WC_AJAX;
use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ExperienceContext;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
/**
* Class ExperienceContextBuilder
*/
class ExperienceContextBuilder {
/**
* The object being built.
*/
private ExperienceContext $experience_context;
/**
* The Settings.
*/
private ContainerInterface $settings;
/**
* ExperienceContextBuilder constructor.
*
* @param ContainerInterface $settings The settings.
*/
public function __construct( ContainerInterface $settings ) {
$this->experience_context = new ExperienceContext();
$this->settings = $settings;
}
/**
* Uses the default config for the PayPal buttons.
*
* @param string $shipping_preference One of the ExperienceContext::SHIPPING_PREFERENCE_* values.
* @param string $user_action One of the ExperienceContext::USER_ACTION_* values.
*/
public function with_default_paypal_config(
string $shipping_preference = ExperienceContext::SHIPPING_PREFERENCE_NO_SHIPPING,
string $user_action = ExperienceContext::USER_ACTION_CONTINUE
): ExperienceContextBuilder {
$builder = clone $this;
$builder = $builder
->with_current_locale()
->with_current_brand_name()
->with_current_landing_page()
->with_current_payment_method_preference()
->with_endpoint_return_urls();
$builder->experience_context = $builder->experience_context
->with_shipping_preference( $shipping_preference )
->with_user_action( $user_action );
return $builder;
}
/**
* Uses the ReturnUrlEndpoint return URL.
*/
public function with_endpoint_return_urls(): ExperienceContextBuilder {
$builder = clone $this;
$builder->experience_context = $builder->experience_context
->with_return_url( home_url( WC_AJAX::get_endpoint( ReturnUrlEndpoint::ENDPOINT ) ) )
->with_cancel_url( wc_get_checkout_url() );
return $builder;
}
/**
* Uses the WC order return URLs.
*
* @param WC_Order $wc_order The WC order.
*/
public function with_order_return_urls( WC_Order $wc_order ): ExperienceContextBuilder {
$builder = clone $this;
$url = $wc_order->get_checkout_order_received_url();
$builder->experience_context = $builder->experience_context
->with_return_url( $url )
->with_cancel_url( add_query_arg( 'cancelled', 'true', $url ) );
return $builder;
}
/**
* Uses the current brand name from the settings.
*/
public function with_current_brand_name(): ExperienceContextBuilder {
$builder = clone $this;
$brand_name = $this->settings->has( 'brand_name' ) ? (string) $this->settings->get( 'brand_name' ) : '';
if ( empty( $brand_name ) ) {
$brand_name = null;
}
$builder->experience_context = $builder->experience_context
->with_brand_name( $brand_name );
return $builder;
}
/**
* Uses the current user locale.
*/
public function with_current_locale(): ExperienceContextBuilder {
$builder = clone $this;
$builder->experience_context = $builder->experience_context
->with_locale( $this->locale_to_bcp47( get_user_locale() ) );
return $builder;
}
/**
* Uses the current landing page from the settings.
*/
public function with_current_landing_page(): ExperienceContextBuilder {
$builder = clone $this;
$landing_page = $this->settings->has( 'landing_page' ) ?
(string) $this->settings->get( 'landing_page' )
: ExperienceContext::LANDING_PAGE_NO_PREFERENCE;
if ( empty( $landing_page ) ) {
$landing_page = ExperienceContext::LANDING_PAGE_NO_PREFERENCE;
}
$builder->experience_context = $builder->experience_context
->with_landing_page( $landing_page );
return $builder;
}
/**
* Uses the payment method preference from the settings.
*/
public function with_current_payment_method_preference(): ExperienceContextBuilder {
$builder = clone $this;
$builder->experience_context = $builder->experience_context
->with_payment_method_preference(
$this->settings->has( 'payee_preferred' ) && $this->settings->get( 'payee_preferred' ) ?
ExperienceContext::PAYMENT_METHOD_IMMEDIATE_PAYMENT_REQUIRED
: ExperienceContext::PAYMENT_METHOD_UNRESTRICTED
);
return $builder;
}
/**
* Returns the ExperienceContext.
*/
public function build(): ExperienceContext {
return $this->experience_context;
}
/**
* Returns BCP-47 code supported by PayPal, for example de-DE-formal becomes de-DE.
*
* @param string $locale The locale, e.g. from get_user_locale.
*/
protected function locale_to_bcp47( string $locale ): string {
$locale = str_replace( '_', '-', $locale );
if ( preg_match( '/^[a-z]{2}(?:-[A-Z][a-z]{3})?(?:-(?:[A-Z]{2}))?$/', $locale ) ) {
return $locale;
}
$parts = explode( '-', $locale );
if ( count( $parts ) === 3 ) {
$ret = substr( $locale, 0, (int) strrpos( $locale, '-' ) );
if ( false !== $ret ) {
return $ret;
}
}
return 'en';
}
}

View file

@ -14,7 +14,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
/**
* Class OrderFactory
@ -35,39 +34,19 @@ class OrderFactory {
*/
private $payer_factory;
/**
* The ApplicationContext repository.
*
* @var ApplicationContextRepository
*/
private $application_context_repository;
/**
* The ApplicationContext factory.
*
* @var ApplicationContextFactory
*/
private $application_context_factory;
/**
* OrderFactory constructor.
*
* @param PurchaseUnitFactory $purchase_unit_factory The PurchaseUnit factory.
* @param PayerFactory $payer_factory The Payer factory.
* @param ApplicationContextRepository $application_context_repository The Application Context repository.
* @param ApplicationContextFactory $application_context_factory The Application Context factory.
* @param PurchaseUnitFactory $purchase_unit_factory The PurchaseUnit factory.
* @param PayerFactory $payer_factory The Payer factory.
*/
public function __construct(
PurchaseUnitFactory $purchase_unit_factory,
PayerFactory $payer_factory,
ApplicationContextRepository $application_context_repository,
ApplicationContextFactory $application_context_factory
PayerFactory $payer_factory
) {
$this->purchase_unit_factory = $purchase_unit_factory;
$this->payer_factory = $payer_factory;
$this->application_context_repository = $application_context_repository;
$this->application_context_factory = $application_context_factory;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->payer_factory = $payer_factory;
}
/**
@ -85,7 +64,6 @@ class OrderFactory {
$order->id(),
$purchase_units,
$order->status(),
$order->application_context(),
$order->payment_source(),
$order->payer(),
$order->intent(),
@ -131,18 +109,15 @@ class OrderFactory {
$order_data->purchase_units
);
$create_time = ( isset( $order_data->create_time ) ) ?
$create_time = ( isset( $order_data->create_time ) ) ?
\DateTime::createFromFormat( 'Y-m-d\TH:i:sO', $order_data->create_time )
: null;
$update_time = ( isset( $order_data->update_time ) ) ?
$update_time = ( isset( $order_data->update_time ) ) ?
\DateTime::createFromFormat( 'Y-m-d\TH:i:sO', $order_data->update_time )
: null;
$payer = ( isset( $order_data->payer ) ) ?
$payer = ( isset( $order_data->payer ) ) ?
$this->payer_factory->from_paypal_response( $order_data->payer )
: null;
$application_context = ( isset( $order_data->application_context ) ) ?
$this->application_context_factory->from_paypal_response( $order_data->application_context )
: null;
$payment_source = null;
if ( isset( $order_data->payment_source ) ) {
@ -165,7 +140,6 @@ class OrderFactory {
$order_data->id,
$purchase_units,
new OrderStatus( $order_data->status ),
$application_context,
$payment_source,
$payer,
$order_data->intent,

View file

@ -10,7 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use WC_Cart;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ExperienceContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
/**
@ -35,7 +35,7 @@ class ShippingPreferenceFactory {
): string {
$contains_physical_goods = $purchase_unit->contains_physical_goods();
if ( ! $contains_physical_goods ) {
return ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
return ExperienceContext::SHIPPING_PREFERENCE_NO_SHIPPING;
}
$has_shipping = null !== $purchase_unit->shipping();
@ -45,20 +45,20 @@ class ShippingPreferenceFactory {
if ( $shipping_address_is_fixed ) {
// Checkout + no address given? Probably something weird happened, like no form validation?
if ( ! $has_shipping ) {
return ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
return ExperienceContext::SHIPPING_PREFERENCE_NO_SHIPPING;
}
return ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS;
return ExperienceContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS;
}
if ( 'card' === $funding_source ) {
if ( ! $has_shipping ) {
return ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
return ExperienceContext::SHIPPING_PREFERENCE_NO_SHIPPING;
}
// Looks like GET_FROM_FILE does not work for the vaulted card button.
return ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS;
return ExperienceContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS;
}
return ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE;
return ExperienceContext::SHIPPING_PREFERENCE_GET_FROM_FILE;
}
}

View file

@ -1,91 +0,0 @@
<?php
/**
* Returns the current application context.
*
* @package WooCommerce\PayPalCommerce\ApiClient\Repository
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Repository;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
/**
* Class ApplicationContextRepository
*/
class ApplicationContextRepository {
/**
* The Settings.
*
* @var ContainerInterface
*/
private $settings;
/**
* ApplicationContextRepository constructor.
*
* @param ContainerInterface $settings The settings.
*/
public function __construct( ContainerInterface $settings ) {
$this->settings = $settings;
}
/**
* Returns the current application context.
*
* @param string $shipping_preferences The shipping preferences.
* @param string $user_action The user action.
*
* @return ApplicationContext
*/
public function current_context(
string $shipping_preferences = ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING,
string $user_action = ApplicationContext::USER_ACTION_CONTINUE
): ApplicationContext {
$brand_name = $this->settings->has( 'brand_name' ) ? $this->settings->get( 'brand_name' ) : '';
$locale = $this->valid_bcp47_code();
$landingpage = $this->settings->has( 'landing_page' ) ?
$this->settings->get( 'landing_page' ) : ApplicationContext::LANDING_PAGE_NO_PREFERENCE;
$payment_preference = $this->settings->has( 'payee_preferred' ) && $this->settings->get( 'payee_preferred' ) ?
ApplicationContext::PAYMENT_METHOD_IMMEDIATE_PAYMENT_REQUIRED : ApplicationContext::PAYMENT_METHOD_UNRESTRICTED;
$context = new ApplicationContext(
home_url( \WC_AJAX::get_endpoint( ReturnUrlEndpoint::ENDPOINT ) ),
(string) wc_get_checkout_url(),
(string) $brand_name,
$locale,
(string) $landingpage,
$shipping_preferences,
$user_action,
$payment_preference
);
return $context;
}
/**
* Returns a PayPal-supported BCP-47 code, for example de-DE-formal becomes de-DE.
*
* @return string
*/
protected function valid_bcp47_code() {
$locale = str_replace( '_', '-', get_user_locale() );
if ( preg_match( '/^[a-z]{2}(?:-[A-Z][a-z]{3})?(?:-(?:[A-Z]{2}))?$/', $locale ) ) {
return $locale;
}
$parts = explode( '-', $locale );
if ( count( $parts ) === 3 ) {
$ret = substr( $locale, 0, strrpos( $locale, '-' ) );
if ( false !== $ret ) {
return $ret;
}
}
return 'en';
}
}

View file

@ -90,16 +90,15 @@ class PartnerReferralsData {
);
if ( $in_acdc_country ) {
$products = array( 'PPCP', 'ADVANCED_VAULTING' );
$capabilities[] = 'PAYPAL_WALLET_VAULTING_ADVANCED';
}
$first_party_features[] = 'BILLING_AGREEMENT';
// Backwards compatibility. Keep those features in the #legacy-ui (null-value).
// Move this into the previous condition, once legacy code is removed.
if ( false !== $use_subscriptions ) {
$first_party_features[] = 'FUTURE_PAYMENT';
if ( $use_card_payments !== false ) {
$first_party_features[] = 'VAULT';
$first_party_features[] = 'FUTURE_PAYMENT';
}
$payload = array(

View file

@ -219,6 +219,11 @@ return array(
'SE', // Sweden
'US', // United States
'GB', // United Kingdom
'YT', // Mayotte
'RE', // Reunion
'GP', // Guadelope
'GF', // French Guiana
'MQ', // Martinique
)
// phpcs:enable Squiz.Commenting.InlineComment
);

View file

@ -14,7 +14,6 @@ use Exception;
use WC_Order;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
@ -307,9 +306,6 @@ class AxoGateway extends WC_Payment_Gateway {
array( $purchase_unit ),
$shipping_preference,
null,
null,
'',
ApplicationContext::USER_ACTION_CONTINUE,
'',
array(),
$payment_source

View file

@ -162,12 +162,16 @@ class SingleProductBootstrap {
},
]
.map( ( f ) => f() )
.sort((a, b) => {
if (parseInt(a.replace(/\D/g, '')) < parseInt(b.replace(/\D/g, '')) ) {
return 1;
}
return -1;
})
.filter( ( val ) => val !== null && val !== undefined )
.sort( ( a, b ) => {
if (
parseInt( a.replace( /\D/g, '' ) ) <
parseInt( b.replace( /\D/g, '' ) )
) {
return 1;
}
return -1;
} )
.find( ( val ) => val );
if ( typeof priceText === 'undefined' ) {

View file

@ -227,6 +227,7 @@ return array(
$request_data,
$purchase_unit_factory,
$container->get( 'api.factory.shipping-preference' ),
$container->get( 'wcgateway.builder.experience-context' ),
$order_endpoint,
$payer_factory,
$session_handler,
@ -347,7 +348,7 @@ return array(
$container->get( 'wcgateway.settings' ),
$container->get( 'wcgateway.all-funding-sources' ),
$container->get( 'wcgateway.configuration.card-configuration' ),
$container->get( 'settings.data.general' )->get_merchant_country()
$container->get( 'api.shop.country' )
);
},
'button.is-logged-in' => static function ( ContainerInterface $container ): bool {

View file

@ -15,13 +15,15 @@ use stdClass;
use Throwable;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Amount;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ExperienceContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
@ -66,6 +68,11 @@ class CreateOrderEndpoint implements EndpointInterface {
*/
private $shipping_preference_factory;
/**
* The ExperienceContextBuilder.
*/
private ExperienceContextBuilder $experience_context_builder;
/**
* The order endpoint.
*
@ -177,6 +184,7 @@ class CreateOrderEndpoint implements EndpointInterface {
* @param RequestData $request_data The RequestData object.
* @param PurchaseUnitFactory $purchase_unit_factory The PurchaseUnit factory.
* @param ShippingPreferenceFactory $shipping_preference_factory The shipping_preference factory.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
* @param OrderEndpoint $order_endpoint The OrderEndpoint object.
* @param PayerFactory $payer_factory The PayerFactory object.
* @param SessionHandler $session_handler The SessionHandler object.
@ -194,6 +202,7 @@ class CreateOrderEndpoint implements EndpointInterface {
RequestData $request_data,
PurchaseUnitFactory $purchase_unit_factory,
ShippingPreferenceFactory $shipping_preference_factory,
ExperienceContextBuilder $experience_context_builder,
OrderEndpoint $order_endpoint,
PayerFactory $payer_factory,
SessionHandler $session_handler,
@ -211,6 +220,7 @@ class CreateOrderEndpoint implements EndpointInterface {
$this->request_data = $request_data;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->shipping_preference_factory = $shipping_preference_factory;
$this->experience_context_builder = $experience_context_builder;
$this->api_endpoint = $order_endpoint;
$this->payer_factory = $payer_factory;
$this->session_handler = $session_handler;
@ -454,16 +464,16 @@ class CreateOrderEndpoint implements EndpointInterface {
);
$action = in_array( $this->parsed_request_data['context'], $this->pay_now_contexts, true ) ?
ApplicationContext::USER_ACTION_PAY_NOW : ApplicationContext::USER_ACTION_CONTINUE;
ExperienceContext::USER_ACTION_PAY_NOW : ExperienceContext::USER_ACTION_CONTINUE;
if ( 'card' === $funding_source ) {
if ( CardBillingMode::MINIMAL_INPUT === $this->card_billing_data_mode ) {
if ( ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS === $shipping_preference ) {
if ( ExperienceContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS === $shipping_preference ) {
if ( $payer ) {
$payer->set_address( null );
}
}
if ( ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING === $shipping_preference ) {
if ( ExperienceContext::SHIPPING_PREFERENCE_NO_SHIPPING === $shipping_preference ) {
if ( $payer ) {
$payer->set_name( null );
}
@ -475,16 +485,23 @@ class CreateOrderEndpoint implements EndpointInterface {
}
}
$payment_source = new PaymentSource(
'paypal',
(object) array(
'experience_context' => $this->experience_context_builder
->with_default_paypal_config( $shipping_preference, $action )
->build()->to_array(),
)
);
try {
return $this->api_endpoint->create(
array( $this->purchase_unit ),
$shipping_preference,
$payer,
null,
'',
$action,
$payment_method,
$data
$data,
$payment_source
);
} catch ( PayPalApiException $exception ) {
// Looks like currently there is no proper way to validate the shipping address for PayPal,
@ -505,7 +522,9 @@ class CreateOrderEndpoint implements EndpointInterface {
array( $this->purchase_unit ),
$shipping_preference,
$payer,
null
$payment_method,
$data,
$payment_source
);
}

View file

@ -74,6 +74,11 @@ return array(
'GB',
'US',
'NO',
'YT',
'RE',
'GP',
'GF',
'MQ'
)
);
},

View file

@ -9,7 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Compat\Settings;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ExperienceContext;
use WooCommerce\PayPalCommerce\ApiClient\Helper\PurchaseUnitSanitizer;
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
@ -94,7 +94,7 @@ class SettingsTabMapHelper {
* Retrieves the mapped value for the 'landing_page' from the new settings.
*
* @param array<string, scalar|array> $settings_model The new settings model data as an array.
* @return 'LOGIN'|'BILLING'|'NO_PREFERENCE'|null The mapped 'landing_page' setting value.
* @return 'LOGIN'|'GUEST_CHECKOUT'|'NO_PREFERENCE'|null The mapped 'landing_page' setting value.
*/
protected function mapped_landing_page_value( array $settings_model ): ?string {
$landing_page = $settings_model['landing_page'] ?? false;
@ -104,10 +104,10 @@ class SettingsTabMapHelper {
}
return $landing_page === 'login'
? ApplicationContext::LANDING_PAGE_LOGIN
? ExperienceContext::LANDING_PAGE_LOGIN
: ( $landing_page === 'guest_checkout'
? ApplicationContext::LANDING_PAGE_BILLING
: ApplicationContext::LANDING_PAGE_NO_PREFERENCE
? ExperienceContext::LANDING_PAGE_GUEST_CHECKOUT
: ExperienceContext::LANDING_PAGE_NO_PREFERENCE
);
}

View file

@ -132,6 +132,11 @@ return array(
'SE', // Sweden
'US', // United States
'GB', // United Kingdom
'YT', // Mayotte
'RE', // Reunion
'GP', // Guadelope
'GF', // French Guiana
'MQ', // Martinique
)
// phpcs:enable Squiz.Commenting.InlineComment
);

View file

@ -81,7 +81,8 @@ return array(
$container->get( 'api.endpoint.orders' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' )
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'wcgateway.builder.experience-context' )
);
},
'ppcp-local-apms.blik.wc-gateway' => static function ( ContainerInterface $container ): BlikGateway {
@ -89,7 +90,8 @@ return array(
$container->get( 'api.endpoint.orders' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' )
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'wcgateway.builder.experience-context' )
);
},
'ppcp-local-apms.eps.wc-gateway' => static function ( ContainerInterface $container ): EPSGateway {
@ -97,7 +99,8 @@ return array(
$container->get( 'api.endpoint.orders' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' )
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'wcgateway.builder.experience-context' )
);
},
'ppcp-local-apms.ideal.wc-gateway' => static function ( ContainerInterface $container ): IDealGateway {
@ -105,7 +108,8 @@ return array(
$container->get( 'api.endpoint.orders' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' )
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'wcgateway.builder.experience-context' )
);
},
'ppcp-local-apms.mybank.wc-gateway' => static function ( ContainerInterface $container ): MyBankGateway {
@ -113,7 +117,8 @@ return array(
$container->get( 'api.endpoint.orders' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' )
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'wcgateway.builder.experience-context' )
);
},
'ppcp-local-apms.p24.wc-gateway' => static function ( ContainerInterface $container ): P24Gateway {
@ -121,7 +126,8 @@ return array(
$container->get( 'api.endpoint.orders' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' )
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'wcgateway.builder.experience-context' )
);
},
'ppcp-local-apms.trustly.wc-gateway' => static function ( ContainerInterface $container ): TrustlyGateway {
@ -129,7 +135,8 @@ return array(
$container->get( 'api.endpoint.orders' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' )
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'wcgateway.builder.experience-context' )
);
},
'ppcp-local-apms.multibanco.wc-gateway' => static function ( ContainerInterface $container ): MultibancoGateway {
@ -137,7 +144,8 @@ return array(
$container->get( 'api.endpoint.orders' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' )
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'wcgateway.builder.experience-context' )
);
},
'ppcp-local-apms.bancontact.payment-method' => static function( ContainerInterface $container ): BancontactPaymentMethod {

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
@ -52,19 +53,26 @@ class BancontactGateway extends WC_Payment_Gateway {
*/
protected $transaction_url_provider;
/**
* The ExperienceContextBuilder.
*/
protected ExperienceContextBuilder $experience_context_builder;
/**
* BancontactGateway constructor.
*
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
*/
public function __construct(
Orders $orders_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider
TransactionUrlProvider $transaction_url_provider,
ExperienceContextBuilder $experience_context_builder
) {
$this->id = self::ID;
@ -86,10 +94,11 @@ class BancontactGateway extends WC_Payment_Gateway {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->experience_context_builder = $experience_context_builder;
}
/**
@ -139,8 +148,13 @@ class BancontactGateway extends WC_Payment_Gateway {
'intent' => 'CAPTURE',
'payment_source' => array(
'bancontact' => array(
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'experience_context' => $this->experience_context_builder
->with_order_return_urls( $wc_order )
->build()
->with_locale( 'en-BE' )
->to_array(),
),
),
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@ -155,11 +169,6 @@ class BancontactGateway extends WC_Payment_Gateway {
'invoice_id' => $purchase_unit->invoice_id(),
),
),
'application_context' => array(
'locale' => 'en-BE',
'return_url' => $this->get_return_url( $wc_order ),
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
),
);
try {

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
@ -52,19 +53,26 @@ class BlikGateway extends WC_Payment_Gateway {
*/
protected $transaction_url_provider;
/**
* The ExperienceContextBuilder.
*/
protected ExperienceContextBuilder $experience_context_builder;
/**
* BlikGateway constructor.
*
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
*/
public function __construct(
Orders $orders_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider
TransactionUrlProvider $transaction_url_provider,
ExperienceContextBuilder $experience_context_builder
) {
$this->id = self::ID;
@ -86,10 +94,11 @@ class BlikGateway extends WC_Payment_Gateway {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->experience_context_builder = $experience_context_builder;
}
/**
@ -139,9 +148,14 @@ class BlikGateway extends WC_Payment_Gateway {
'intent' => 'CAPTURE',
'payment_source' => array(
'blik' => array(
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'email' => $wc_order->get_billing_email(),
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'email' => $wc_order->get_billing_email(),
'experience_context' => $this->experience_context_builder
->with_order_return_urls( $wc_order )
->build()
->with_locale( 'en-PL' )
->to_array(),
),
),
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@ -156,11 +170,6 @@ class BlikGateway extends WC_Payment_Gateway {
'invoice_id' => $purchase_unit->invoice_id(),
),
),
'application_context' => array(
'locale' => 'en-PL',
'return_url' => $this->get_return_url( $wc_order ),
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
),
);
try {

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
@ -52,19 +53,26 @@ class EPSGateway extends WC_Payment_Gateway {
*/
protected $transaction_url_provider;
/**
* The ExperienceContextBuilder.
*/
protected ExperienceContextBuilder $experience_context_builder;
/**
* EPSGateway constructor.
*
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
*/
public function __construct(
Orders $orders_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider
TransactionUrlProvider $transaction_url_provider,
ExperienceContextBuilder $experience_context_builder
) {
$this->id = self::ID;
@ -86,10 +94,11 @@ class EPSGateway extends WC_Payment_Gateway {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->experience_context_builder = $experience_context_builder;
}
/**
@ -139,8 +148,13 @@ class EPSGateway extends WC_Payment_Gateway {
'intent' => 'CAPTURE',
'payment_source' => array(
'eps' => array(
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'experience_context' => $this->experience_context_builder
->with_order_return_urls( $wc_order )
->build()
->with_locale( 'en-AT' )
->to_array(),
),
),
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@ -155,11 +169,6 @@ class EPSGateway extends WC_Payment_Gateway {
'invoice_id' => $purchase_unit->invoice_id(),
),
),
'application_context' => array(
'locale' => 'en-AT',
'return_url' => $this->get_return_url( $wc_order ),
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
),
);
try {

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
@ -52,19 +53,26 @@ class IDealGateway extends WC_Payment_Gateway {
*/
protected $transaction_url_provider;
/**
* The ExperienceContextBuilder.
*/
protected ExperienceContextBuilder $experience_context_builder;
/**
* IDealGateway constructor.
*
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
*/
public function __construct(
Orders $orders_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider
TransactionUrlProvider $transaction_url_provider,
ExperienceContextBuilder $experience_context_builder
) {
$this->id = self::ID;
@ -86,10 +94,11 @@ class IDealGateway extends WC_Payment_Gateway {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->experience_context_builder = $experience_context_builder;
}
/**
@ -139,8 +148,11 @@ class IDealGateway extends WC_Payment_Gateway {
'intent' => 'CAPTURE',
'payment_source' => array(
'ideal' => array(
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'experience_context' => $this->experience_context_builder
->with_order_return_urls( $wc_order )
->build()->to_array(),
),
),
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@ -155,10 +167,6 @@ class IDealGateway extends WC_Payment_Gateway {
'invoice_id' => $purchase_unit->invoice_id(),
),
),
'application_context' => array(
'return_url' => $this->get_return_url( $wc_order ),
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
),
);
try {

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
@ -52,19 +53,26 @@ class MultibancoGateway extends WC_Payment_Gateway {
*/
protected $transaction_url_provider;
/**
* The ExperienceContextBuilder.
*/
protected ExperienceContextBuilder $experience_context_builder;
/**
* MultibancoGateway constructor.
*
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
*/
public function __construct(
Orders $orders_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider
TransactionUrlProvider $transaction_url_provider,
ExperienceContextBuilder $experience_context_builder
) {
$this->id = self::ID;
@ -86,10 +94,11 @@ class MultibancoGateway extends WC_Payment_Gateway {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->experience_context_builder = $experience_context_builder;
}
/**
@ -157,16 +166,16 @@ class MultibancoGateway extends WC_Payment_Gateway {
$request_body = array(
'payment_source' => array(
'multibanco' => array(
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'experience_context' => $this->experience_context_builder
->with_order_return_urls( $wc_order )
->build()
->with_locale( 'en-PT' )
->to_array(),
),
),
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
'application_context' => array(
'locale' => 'en-PT',
'return_url' => $this->get_return_url( $wc_order ),
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
),
);
$response = $this->orders_endpoint->confirm_payment_source( $request_body, $body->id );

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
@ -52,19 +53,26 @@ class MyBankGateway extends WC_Payment_Gateway {
*/
protected $transaction_url_provider;
/**
* The ExperienceContextBuilder.
*/
protected ExperienceContextBuilder $experience_context_builder;
/**
* MyBankGateway constructor.
*
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
*/
public function __construct(
Orders $orders_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider
TransactionUrlProvider $transaction_url_provider,
ExperienceContextBuilder $experience_context_builder
) {
$this->id = self::ID;
@ -86,10 +94,11 @@ class MyBankGateway extends WC_Payment_Gateway {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->experience_context_builder = $experience_context_builder;
}
/**
@ -139,8 +148,13 @@ class MyBankGateway extends WC_Payment_Gateway {
'intent' => 'CAPTURE',
'payment_source' => array(
'mybank' => array(
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'experience_context' => $this->experience_context_builder
->with_order_return_urls( $wc_order )
->build()
->with_locale( 'en-IT' )
->to_array(),
),
),
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@ -155,11 +169,6 @@ class MyBankGateway extends WC_Payment_Gateway {
'invoice_id' => $purchase_unit->invoice_id(),
),
),
'application_context' => array(
'locale' => 'en-IT',
'return_url' => $this->get_return_url( $wc_order ),
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
),
);
try {

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
@ -52,19 +53,26 @@ class P24Gateway extends WC_Payment_Gateway {
*/
protected $transaction_url_provider;
/**
* The ExperienceContextBuilder.
*/
protected ExperienceContextBuilder $experience_context_builder;
/**
* P24Gateway constructor.
*
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
*/
public function __construct(
Orders $orders_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider
TransactionUrlProvider $transaction_url_provider,
ExperienceContextBuilder $experience_context_builder
) {
$this->id = self::ID;
@ -86,10 +94,11 @@ class P24Gateway extends WC_Payment_Gateway {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->experience_context_builder = $experience_context_builder;
}
/**
@ -139,9 +148,14 @@ class P24Gateway extends WC_Payment_Gateway {
'intent' => 'CAPTURE',
'payment_source' => array(
'p24' => array(
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'email' => $wc_order->get_billing_email(),
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'email' => $wc_order->get_billing_email(),
'experience_context' => $this->experience_context_builder
->with_order_return_urls( $wc_order )
->build()
->with_locale( 'en-PL' )
->to_array(),
),
),
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@ -156,11 +170,6 @@ class P24Gateway extends WC_Payment_Gateway {
'invoice_id' => $purchase_unit->invoice_id(),
),
),
'application_context' => array(
'locale' => 'en-PL',
'return_url' => $this->get_return_url( $wc_order ),
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
),
);
try {

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
@ -52,19 +53,26 @@ class TrustlyGateway extends WC_Payment_Gateway {
*/
protected $transaction_url_provider;
/**
* The ExperienceContextBuilder.
*/
protected ExperienceContextBuilder $experience_context_builder;
/**
* TrustlyGateway constructor.
*
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param Orders $orders_endpoint PayPal Orders endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
*/
public function __construct(
Orders $orders_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider
TransactionUrlProvider $transaction_url_provider,
ExperienceContextBuilder $experience_context_builder
) {
$this->id = self::ID;
@ -86,10 +94,11 @@ class TrustlyGateway extends WC_Payment_Gateway {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->orders_endpoint = $orders_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->experience_context_builder = $experience_context_builder;
}
/**
@ -139,9 +148,13 @@ class TrustlyGateway extends WC_Payment_Gateway {
'intent' => 'CAPTURE',
'payment_source' => array(
'trustly' => array(
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'email' => $wc_order->get_billing_email(),
'country_code' => $wc_order->get_billing_country(),
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'email' => $wc_order->get_billing_email(),
'experience_context' => $this->experience_context_builder
->with_order_return_urls( $wc_order )
->with_current_locale()
->build()->to_array(),
),
),
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@ -156,11 +169,6 @@ class TrustlyGateway extends WC_Payment_Gateway {
'invoice_id' => $purchase_unit->invoice_id(),
),
),
'application_context' => array(
'locale' => $this->valid_bcp47_code(),
'return_url' => $this->get_return_url( $wc_order ),
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
),
);
try {
@ -228,27 +236,4 @@ class TrustlyGateway extends WC_Payment_Gateway {
return parent::get_transaction_url( $order );
}
/**
* Returns a PayPal-supported BCP-47 code, for example de-DE-formal becomes de-DE.
*
* @return string
*/
private function valid_bcp47_code() {
$locale = str_replace( '_', '-', get_user_locale() );
if ( preg_match( '/^[a-z]{2}(?:-[A-Z][a-z]{3})?(?:-(?:[A-Z]{2}))?$/', $locale ) ) {
return $locale;
}
$parts = explode( '-', $locale );
if ( count( $parts ) === 3 ) {
$ret = substr( $locale, 0, strrpos( $locale, '-' ) );
if ( false !== $ret ) {
return $ret;
}
}
return 'en';
}
}

View file

@ -681,7 +681,7 @@ class PayPalSubscriptionsModule implements ServiceModule, ExtendingModule, Execu
'<label for="ppcp_enable_subscription_product-' . esc_attr( (string) $product->get_id() ) . '" style="' . esc_attr( $style ) . '">',
'</label>'
);
$plan_id = isset( $subscription_plan['id'] ) ?? '';
$plan_id = $subscription_plan['id'] ?? '';
echo '<input type="checkbox" id="ppcp_enable_subscription_product-' . esc_attr( (string) $product->get_id() ) . '" data-subs-plan="' . esc_attr( (string) $plan_id ) . '" name="_ppcp_enable_subscription_product" value="yes" ' . checked( $enable_subscription_product, 'yes', false ) . '/>';
echo sprintf(
// translators: %1$s and %2$s are label open and close tags.

View file

@ -0,0 +1,25 @@
import { __ } from '@wordpress/i18n';
import { ControlToggleButton } from '../../../../../ReusableComponents/Controls';
import { SettingsHooks } from '../../../../../../data';
import SettingsBlock from '../../../../../ReusableComponents/SettingsBlock';
const StayUpdated = () => {
const { stayUpdated, setStayUpdated } = SettingsHooks.useSettings();
return (
<SettingsBlock className="ppcp--pay-now-experience">
<ControlToggleButton
label={ __( 'Stay Updated', 'woocommerce-paypal-payments' ) }
description={ __(
'Get the latest PayPal features and capabilities as they are released. When the extension is updated, new features, payment methods, styling options, and more will automatically update.',
'woocommerce-paypal-payments'
) }
onChange={ setStayUpdated }
value={ stayUpdated }
/>
</SettingsBlock>
);
};
export default StayUpdated;

View file

@ -5,6 +5,7 @@ import OrderIntent from './Blocks/OrderIntent';
import SavePaymentMethods from './Blocks/SavePaymentMethods';
import InvoicePrefix from './Blocks/InvoicePrefix';
import PayNowExperience from './Blocks/PayNowExperience';
import StayUpdated from './Blocks/StayUpdated';
const CommonSettings = ( { ownBradOnly } ) => (
<SettingsCard
@ -20,6 +21,7 @@ const CommonSettings = ( { ownBradOnly } ) => (
<OrderIntent />
<SavePaymentMethods ownBradOnly={ ownBradOnly } />
<PayNowExperience />
<StayUpdated />
</SettingsCard>
);

View file

@ -63,6 +63,7 @@ const useHooks = () => {
const [ payNowExperience, setPayNowExperience ] =
usePersistent( 'enablePayNow' );
const [ logging, setLogging ] = usePersistent( 'enableLogging' );
const [ stayUpdated, setStayUpdated ] = usePersistent( 'stayUpdated' );
const [ disabledCards, setDisabledCards ] =
usePersistent( 'disabledCards' );
@ -82,6 +83,8 @@ const useHooks = () => {
setPayNowExperience,
logging,
setLogging,
stayUpdated,
setStayUpdated,
subtotalAdjustment,
setSubtotalAdjustment,
brandName,
@ -126,6 +129,8 @@ export const useSettings = () => {
setPayNowExperience,
logging,
setLogging,
stayUpdated,
setStayUpdated,
subtotalAdjustment,
setSubtotalAdjustment,
brandName,
@ -155,6 +160,8 @@ export const useSettings = () => {
setPayNowExperience,
logging,
setLogging,
stayUpdated,
setStayUpdated,
subtotalAdjustment,
setSubtotalAdjustment,
brandName,

View file

@ -42,6 +42,7 @@ const defaultPersistent = Object.freeze( {
saveCardDetails: false, // Enable card vaulting
enablePayNow: false, // Enable Pay Now experience
enableLogging: false, // Enable debug logging
stayUpdated: false, // Enable to get the latest PayPal features
// String arrays.
disabledCards: [], // Disabled credit card types

View file

@ -82,6 +82,7 @@ class SettingsModel extends AbstractDataModel {
'save_card_details' => false,
'enable_pay_now' => false,
'enable_logging' => false,
'stay_updated' => true,
// Array of string values.
'disabled_cards' => array(),

View file

@ -86,6 +86,10 @@ class SettingsRestEndpoint extends RestEndpoint {
'js_name' => 'enableLogging',
'sanitize' => 'to_boolean',
),
'stay_updated' => array(
'js_name' => 'stayUpdated',
'sanitize' => 'to_boolean',
),
'disabled_cards' => array(
'js_name' => 'disabledCards',
),

View file

@ -167,7 +167,9 @@ class VaultedCreditCardHandler {
array( $purchase_unit ),
$shipping_preference,
$payer,
$selected_token
'',
array(),
$selected_token->to_payment_source()
);
$this->add_paypal_meta( $wc_order, $order, $this->environment );

View file

@ -13,7 +13,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ExperienceContext;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
@ -398,7 +398,6 @@ return array(
'ML',
'MH',
'MR',
'YT',
'FM',
'MN',
'ME',
@ -570,7 +569,8 @@ return array(
$order_helper,
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'api.factory.payer' ),
$container->get( 'api.factory.shipping-preference' )
$container->get( 'api.factory.shipping-preference' ),
$container->get( 'wcgateway.builder.experience-context' )
);
},
'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
@ -874,15 +874,15 @@ return array(
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => ApplicationContext::LANDING_PAGE_LOGIN,
'default' => ExperienceContext::LANDING_PAGE_LOGIN,
'desc_tip' => true,
'description' => __(
'Type of PayPal page to display.',
'woocommerce-paypal-payments'
),
'options' => array(
ApplicationContext::LANDING_PAGE_LOGIN => __( 'Login (PayPal account login)', 'woocommerce-paypal-payments' ),
ApplicationContext::LANDING_PAGE_BILLING => __( 'Billing (Non-PayPal account)', 'woocommerce-paypal-payments' ),
ExperienceContext::LANDING_PAGE_LOGIN => __( 'Login (PayPal account login)', 'woocommerce-paypal-payments' ),
ExperienceContext::LANDING_PAGE_GUEST_CHECKOUT => __( 'Billing (Non-PayPal account)', 'woocommerce-paypal-payments' ),
),
'screens' => array(
State::STATE_START,
@ -1405,7 +1405,7 @@ return array(
$container->get( 'wcgateway.settings' ),
$container->get( 'api.helpers.dccapplies' ),
$container->get( 'wcgateway.helper.dcc-product-status' ),
$container->get( 'settings.data.general' )
$container->get( 'api.shop.country' )
);
},
@ -1543,6 +1543,7 @@ return array(
$container->get( 'api.endpoint.order' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'api.factory.shipping-preference' ),
$container->get( 'wcgateway.builder.experience-context' ),
$container->get( 'wcgateway.url' ),
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'settings.environment' ),

View file

@ -13,8 +13,10 @@ use Psr\Log\LoggerInterface;
use WC_Order;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
@ -79,12 +81,18 @@ class OXXOGateway extends WC_Payment_Gateway {
*/
protected $logger;
/**
* The ExperienceContextBuilder.
*/
protected ExperienceContextBuilder $experience_context_builder;
/**
* OXXOGateway constructor.
*
* @param OrderEndpoint $order_endpoint The order endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
* @param ShippingPreferenceFactory $shipping_preference_factory The shipping preference factory.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
* @param string $module_url The URL to the module.
* @param TransactionUrlProvider $transaction_url_provider The transaction url provider.
* @param Environment $environment The environment.
@ -94,6 +102,7 @@ class OXXOGateway extends WC_Payment_Gateway {
OrderEndpoint $order_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
ShippingPreferenceFactory $shipping_preference_factory,
ExperienceContextBuilder $experience_context_builder,
string $module_url,
TransactionUrlProvider $transaction_url_provider,
Environment $environment,
@ -121,6 +130,7 @@ class OXXOGateway extends WC_Payment_Gateway {
$this->order_endpoint = $order_endpoint;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->shipping_preference_factory = $shipping_preference_factory;
$this->experience_context_builder = $experience_context_builder;
$this->module_url = $module_url;
$this->logger = $logger;
@ -176,17 +186,29 @@ class OXXOGateway extends WC_Payment_Gateway {
'checkout'
);
$order = $this->order_endpoint->create( array( $purchase_unit ), $shipping_preference );
$payment_source_data = array(
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'email' => $wc_order->get_billing_email(),
'country_code' => $wc_order->get_billing_country(),
'experience_context' => $this->experience_context_builder
->with_default_paypal_config( $shipping_preference )
->build()->to_array(),
);
$order = $this->order_endpoint->create(
array( $purchase_unit ),
$shipping_preference,
null,
'',
array(),
new PaymentSource(
'oxxo',
(object) $payment_source_data
)
);
$this->add_paypal_meta( $wc_order, $order, $this->environment );
$payment_source = array(
'oxxo' => array(
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
'email' => $wc_order->get_billing_email(),
'country_code' => $wc_order->get_billing_country(),
),
);
$payment_method = $this->order_endpoint->confirm_payment_source( $order->id(), $payment_source );
$payment_method = $this->order_endpoint->confirm_payment_source( $order->id(), array( 'oxxo' => $payment_source_data ) );
foreach ( $payment_method->links as $link ) {
if ( $link->rel === 'payer-action' ) {
$payer_action = $link->href;

View file

@ -71,11 +71,11 @@ class CardPaymentsConfiguration {
private DCCProductStatus $dcc_status;
/**
* General Settings
* Store country.
*
* @var GeneralSettings
* @var string
*/
private GeneralSettings $general_settings;
private string $store_country;
/**
* This classes lazily resolves settings on first access. This flag indicates
@ -142,20 +142,20 @@ class CardPaymentsConfiguration {
* @param Settings $settings Plugin settings instance.
* @param DccApplies $dcc_applies DCC eligibility helper.
* @param DCCProductStatus $dcc_status Manages the Seller status.
* @param GeneralSettings $general_settings General settings instance.
* @param string $store_country The shop's country code.
*/
public function __construct(
ConnectionState $connection_state,
Settings $settings,
DccApplies $dcc_applies,
DCCProductStatus $dcc_status,
GeneralSettings $general_settings
string $store_country
) {
$this->connection_state = $connection_state;
$this->settings = $settings;
$this->dcc_applies = $dcc_applies;
$this->dcc_status = $dcc_status;
$this->general_settings = $general_settings;
$this->store_country = $store_country;
$this->is_resolved = false;
}
@ -330,7 +330,7 @@ class CardPaymentsConfiguration {
* @return bool
*/
public function is_bcdc_enabled() : bool {
if ( 'MX' === $this->general_settings->get_merchant_country() ) {
if ( 'MX' === $this->store_country ) {
$bcdc_setting = get_option( 'woocommerce_ppcp-card-button-gateway_settings' );
return 'yes' === $bcdc_setting['enabled'];
}

View file

@ -13,11 +13,12 @@ use Exception;
use Psr\Log\LoggerInterface;
use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ExperienceContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
@ -144,6 +145,11 @@ class OrderProcessor {
*/
private $restore_order_data = array();
/**
* The ExperienceContextBuilder.
*/
private ExperienceContextBuilder $experience_context_builder;
/**
* OrderProcessor constructor.
*
@ -160,6 +166,7 @@ class OrderProcessor {
* @param PurchaseUnitFactory $purchase_unit_factory The PurchaseUnit factory.
* @param PayerFactory $payer_factory The payer factory.
* @param ShippingPreferenceFactory $shipping_preference_factory The shipping_preference factory.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
*/
public function __construct(
SessionHandler $session_handler,
@ -174,7 +181,8 @@ class OrderProcessor {
OrderHelper $order_helper,
PurchaseUnitFactory $purchase_unit_factory,
PayerFactory $payer_factory,
ShippingPreferenceFactory $shipping_preference_factory
ShippingPreferenceFactory $shipping_preference_factory,
ExperienceContextBuilder $experience_context_builder
) {
$this->session_handler = $session_handler;
@ -190,6 +198,7 @@ class OrderProcessor {
$this->purchase_unit_factory = $purchase_unit_factory;
$this->payer_factory = $payer_factory;
$this->shipping_preference_factory = $shipping_preference_factory;
$this->experience_context_builder = $experience_context_builder;
}
/**
@ -325,9 +334,16 @@ class OrderProcessor {
array( $pu ),
$shipping_preference,
$this->payer_factory->from_wc_order( $wc_order ),
null,
'',
ApplicationContext::USER_ACTION_PAY_NOW
array(),
new PaymentSource(
'paypal',
(object) array(
'experience_context' => $this->experience_context_builder
->with_default_paypal_config( $shipping_preference, ExperienceContext::USER_ACTION_PAY_NOW )
->build()->to_array(),
)
)
);
return $order;

View file

@ -539,6 +539,20 @@ return function ( ContainerInterface $container, array $fields ): array {
'requirements' => array(),
'gateway' => Settings::CONNECTION_TAB_ID,
),
'stay_updated' => array(
'title' => __( 'Stay Updated', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'desc_tip' => true,
'label' => __( 'Update to the latest features when available. ', 'woocommerce-paypal-payments' ),
'description' => __( 'Get the latest PayPal features and capabilities as they are released. When the extension is updated, new features, payment methods, styling options, and more will automatically update.', 'woocommerce-paypal-payments' ),
'default' => true,
'screens' => array(
State::STATE_START,
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => Settings::CONNECTION_TAB_ID,
),
'subtotal_mismatch_behavior' => array(
'title' => __( 'Subtotal mismatch behavior', 'woocommerce-paypal-payments' ),
'type' => 'select',

View file

@ -46,7 +46,8 @@ return array(
$container->get( 'wc-subscriptions.helpers.real-time-account-updater' ),
$container->get( 'wc-subscriptions.helper' ),
$container->get( 'api.endpoint.payment-tokens' ),
$container->get( 'vaulting.wc-payment-tokens' )
$container->get( 'vaulting.wc-payment-tokens' ),
$container->get( 'wcgateway.builder.experience-context' )
);
},
'wc-subscriptions.repository.payment-token' => static function ( ContainerInterface $container ): PaymentTokenRepository {

View file

@ -15,11 +15,11 @@ use WC_Payment_Tokens;
use WC_Subscription;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokensEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
@ -148,6 +148,11 @@ class RenewalHandler {
*/
private $wc_payment_tokens;
/**
* The ExperienceContextBuilder.
*/
private ExperienceContextBuilder $experience_context_builder;
/**
* RenewalHandler constructor.
*
@ -165,6 +170,7 @@ class RenewalHandler {
* @param SubscriptionHelper $subscription_helper Subscription helper.
* @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint.
* @param WooCommercePaymentTokens $wc_payment_tokens WooCommerce payments tokens factory.
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
*/
public function __construct(
LoggerInterface $logger,
@ -180,7 +186,8 @@ class RenewalHandler {
RealTimeAccountUpdaterHelper $real_time_account_updater_helper,
SubscriptionHelper $subscription_helper,
PaymentTokensEndpoint $payment_tokens_endpoint,
WooCommercePaymentTokens $wc_payment_tokens
WooCommercePaymentTokens $wc_payment_tokens,
ExperienceContextBuilder $experience_context_builder
) {
$this->logger = $logger;
@ -197,6 +204,7 @@ class RenewalHandler {
$this->subscription_helper = $subscription_helper;
$this->payment_tokens_endpoint = $payment_tokens_endpoint;
$this->wc_payment_tokens = $wc_payment_tokens;
$this->experience_context_builder = $experience_context_builder;
}
/**
@ -344,9 +352,6 @@ class RenewalHandler {
array( $purchase_unit ),
$shipping_preference,
$payer,
null,
'',
ApplicationContext::USER_ACTION_CONTINUE,
'',
array(),
$payment_source
@ -388,9 +393,6 @@ class RenewalHandler {
array( $purchase_unit ),
$shipping_preference,
$payer,
null,
'',
ApplicationContext::USER_ACTION_CONTINUE,
'',
array(),
$payment_source
@ -413,7 +415,9 @@ class RenewalHandler {
array( $purchase_unit ),
$shipping_preference,
$payer,
$token
'',
array(),
$token->to_payment_source()
);
$this->handle_paypal_order( $wc_order, $order );
@ -543,12 +547,15 @@ class RenewalHandler {
*/
private function card_payment_source( string $token, WC_Order $wc_order ): PaymentSource {
$properties = array(
'vault_id' => $token,
'stored_credential' => array(
'vault_id' => $token,
'stored_credential' => array(
'payment_initiator' => 'MERCHANT',
'payment_type' => 'RECURRING',
'usage' => 'SUBSEQUENT',
),
'experience_context' => $this->experience_context_builder
->with_endpoint_return_urls()
->build()->to_array(),
);
$subscriptions = wcs_get_subscriptions_for_renewal_order( $wc_order );