mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Merge branch 'trunk' into PCP-1745-real-time-account-updater-rtau
This commit is contained in:
commit
821e425944
39 changed files with 3845 additions and 246 deletions
|
@ -626,6 +626,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'AT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'BE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -914,6 +938,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -1310,11 +1358,28 @@ return array(
|
|||
'USD',
|
||||
),
|
||||
'NO' => array(
|
||||
'EUR',
|
||||
'USD',
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -1335,6 +1400,11 @@ return array(
|
|||
'visa' => array(),
|
||||
'amex' => array( 'AUD' ),
|
||||
),
|
||||
'AT' => array(
|
||||
'mastercard' => array(),
|
||||
'visa' => array(),
|
||||
'amex' => array(),
|
||||
),
|
||||
'BE' => array(
|
||||
'mastercard' => array(),
|
||||
'visa' => array(),
|
||||
|
@ -1400,6 +1470,11 @@ return array(
|
|||
'visa' => array(),
|
||||
'amex' => array( 'HUF' ),
|
||||
),
|
||||
'IE' => array(
|
||||
'mastercard' => array(),
|
||||
'visa' => array(),
|
||||
'amex' => array(),
|
||||
),
|
||||
'IT' => array(
|
||||
'mastercard' => array(),
|
||||
'visa' => array(),
|
||||
|
@ -1417,6 +1492,11 @@ return array(
|
|||
'amex' => array( 'CAD' ),
|
||||
'jcb' => array( 'CAD' ),
|
||||
),
|
||||
'LI' => array(
|
||||
'mastercard' => array(),
|
||||
'visa' => array(),
|
||||
'amex' => array(),
|
||||
),
|
||||
'LT' => array(
|
||||
'mastercard' => array(),
|
||||
'visa' => array(),
|
||||
|
@ -1450,7 +1530,7 @@ return array(
|
|||
'NO' => array(
|
||||
'mastercard' => array(),
|
||||
'visa' => array(),
|
||||
'amex' => array( 'NOK' ),
|
||||
'amex' => array(),
|
||||
),
|
||||
'PL' => array(
|
||||
'mastercard' => array(),
|
||||
|
|
|
@ -21,19 +21,37 @@ class SellerStatus {
|
|||
*/
|
||||
private $products;
|
||||
|
||||
/**
|
||||
* The capabilities.
|
||||
*
|
||||
* @var SellerStatusCapability[]
|
||||
*/
|
||||
private $capabilities;
|
||||
|
||||
/**
|
||||
* SellerStatus constructor.
|
||||
*
|
||||
* @param SellerStatusProduct[] $products The products.
|
||||
* @param SellerStatusProduct[] $products The products.
|
||||
* @param SellerStatusCapability[] $capabilities The capabilities.
|
||||
*
|
||||
* @psalm-suppress RedundantConditionGivenDocblockType
|
||||
*/
|
||||
public function __construct( array $products ) {
|
||||
public function __construct( array $products, array $capabilities ) {
|
||||
foreach ( $products as $key => $product ) {
|
||||
if ( is_a( $product, SellerStatusProduct::class ) ) {
|
||||
continue;
|
||||
}
|
||||
unset( $products[ $key ] );
|
||||
}
|
||||
$this->products = $products;
|
||||
foreach ( $capabilities as $key => $capability ) {
|
||||
if ( is_a( $capability, SellerStatusCapability::class ) ) {
|
||||
continue;
|
||||
}
|
||||
unset( $capabilities[ $key ] );
|
||||
}
|
||||
|
||||
$this->products = $products;
|
||||
$this->capabilities = $capabilities;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,6 +63,15 @@ class SellerStatus {
|
|||
return $this->products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the capabilities.
|
||||
*
|
||||
* @return SellerStatusCapability[]
|
||||
*/
|
||||
public function capabilities() : array {
|
||||
return $this->capabilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enitity as array.
|
||||
*
|
||||
|
@ -58,8 +85,16 @@ class SellerStatus {
|
|||
$this->products()
|
||||
);
|
||||
|
||||
$capabilities = array_map(
|
||||
function( SellerStatusCapability $capability ) : array {
|
||||
return $capability->to_array();
|
||||
},
|
||||
$this->capabilities()
|
||||
);
|
||||
|
||||
return array(
|
||||
'products' => $products,
|
||||
'products' => $products,
|
||||
'capabilities' => $capabilities,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* The capabilities of a seller status.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
||||
*/
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
||||
|
||||
/**
|
||||
* Class SellerStatusCapability
|
||||
*/
|
||||
class SellerStatusCapability {
|
||||
|
||||
const STATUS_ACTIVE = 'ACTIVE';
|
||||
|
||||
/**
|
||||
* The name of the product.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* The status of the capability.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* SellerStatusCapability constructor.
|
||||
*
|
||||
* @param string $name The name of the product.
|
||||
* @param string $status The status of the capability.
|
||||
*/
|
||||
public function __construct(
|
||||
string $name,
|
||||
string $status
|
||||
) {
|
||||
$this->name = $name;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the product.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name() : string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status for this capability.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function status() : string {
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity as array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function to_array() : array {
|
||||
return array(
|
||||
'name' => $this->name(),
|
||||
'status' => $this->status(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -66,7 +66,7 @@ class ItemFactory {
|
|||
$quantity,
|
||||
$this->prepare_description( $product->get_description() ),
|
||||
null,
|
||||
$product->get_sku(),
|
||||
$this->prepare_sku( $product->get_sku() ),
|
||||
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
||||
$product->get_permalink(),
|
||||
$image[0] ?? '',
|
||||
|
@ -143,7 +143,7 @@ class ItemFactory {
|
|||
$quantity,
|
||||
$product instanceof WC_Product ? $this->prepare_description( $product->get_description() ) : '',
|
||||
null,
|
||||
$product instanceof WC_Product ? $product->get_sku() : '',
|
||||
$product instanceof WC_Product ? $this->prepare_sku( $product->get_sku() ) : '',
|
||||
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
||||
$product instanceof WC_Product ? $product->get_permalink() : '',
|
||||
$image[0] ?? ''
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
|||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusCapability;
|
||||
|
||||
/**
|
||||
* Class SellerStatusFactory
|
||||
|
@ -37,6 +38,17 @@ class SellerStatusFactory {
|
|||
isset( $json->products ) ? (array) $json->products : array()
|
||||
);
|
||||
|
||||
return new SellerStatus( $products );
|
||||
$capabilities = array_map(
|
||||
function( $json ) : SellerStatusCapability {
|
||||
$capability = new SellerStatusCapability(
|
||||
isset( $json->name ) ? (string) $json->name : '',
|
||||
isset( $json->status ) ? (string) $json->status : ''
|
||||
);
|
||||
return $capability;
|
||||
},
|
||||
isset( $json->capabilities ) ? (array) $json->capabilities : array()
|
||||
);
|
||||
|
||||
return new SellerStatus( $products, $capabilities );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,4 +21,14 @@ trait ItemTrait {
|
|||
$description = strip_shortcodes( wp_strip_all_tags( $description ) );
|
||||
return substr( $description, 0, 127 ) ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the sku for sending to PayPal.
|
||||
*
|
||||
* @param string $sku Item sku.
|
||||
* @return string
|
||||
*/
|
||||
protected function prepare_sku( string $sku ): string {
|
||||
return substr( wp_strip_all_tags( $sku ), 0, 127 ) ?: '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ use WooCommerce\PayPalCommerce\Applepay\Assets\BlocksPaymentMethod;
|
|||
use WooCommerce\PayPalCommerce\Applepay\Assets\PropertiesDictionary;
|
||||
use WooCommerce\PayPalCommerce\Applepay\Helper\ApmApplies;
|
||||
use WooCommerce\PayPalCommerce\Applepay\Helper\AvailabilityNotice;
|
||||
use WooCommerce\PayPalCommerce\Common\Pattern\SingletonDecorator;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
@ -72,14 +73,16 @@ return array(
|
|||
return $settings->has( 'applepay_validated' ) ? $settings->get( 'applepay_validated' ) === true : false;
|
||||
},
|
||||
|
||||
'applepay.apple-product-status' => static function( ContainerInterface $container ): AppleProductStatus {
|
||||
return new AppleProductStatus(
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'api.endpoint.partners' ),
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'api.helper.failure-registry' )
|
||||
);
|
||||
},
|
||||
'applepay.apple-product-status' => SingletonDecorator::make(
|
||||
static function( ContainerInterface $container ): AppleProductStatus {
|
||||
return new AppleProductStatus(
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'api.endpoint.partners' ),
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'api.helper.failure-registry' )
|
||||
);
|
||||
}
|
||||
),
|
||||
'applepay.available' => static function ( ContainerInterface $container ): bool {
|
||||
if ( apply_filters( 'woocommerce_paypal_payments_applepay_validate_product_status', true ) ) {
|
||||
$status = $container->get( 'applepay.apple-product-status' );
|
||||
|
@ -195,6 +198,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'AT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'BE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -483,6 +510,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -531,6 +582,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LI' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -603,6 +678,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'NO' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'NL' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Applepay\Assets;
|
|||
|
||||
use Throwable;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusCapability;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\FailureRegistry;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
@ -100,6 +101,11 @@ class AppleProductStatus {
|
|||
return false;
|
||||
}
|
||||
|
||||
$status_override = apply_filters( 'woocommerce_paypal_payments_apple_pay_product_status', null );
|
||||
if ( null !== $status_override ) {
|
||||
return $status_override;
|
||||
}
|
||||
|
||||
// If status was already checked on this request return the same result.
|
||||
if ( null !== $this->current_status ) {
|
||||
return $this->current_status;
|
||||
|
@ -128,21 +134,32 @@ class AppleProductStatus {
|
|||
}
|
||||
|
||||
// Check the seller status for the intended capability.
|
||||
$has_capability = false;
|
||||
foreach ( $seller_status->products() as $product ) {
|
||||
if ( $product->name() !== 'PAYMENT_METHODS' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( in_array( self::CAPABILITY_NAME, $product->capabilities(), true ) ) {
|
||||
// Capability found, persist status and return true.
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_ENABLED );
|
||||
$this->settings->persist();
|
||||
|
||||
$this->current_status = true;
|
||||
return $this->current_status;
|
||||
$has_capability = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $seller_status->capabilities() as $capability ) {
|
||||
if ( $capability->name() === self::CAPABILITY_NAME && $capability->status() === SellerStatusCapability::STATUS_ACTIVE ) {
|
||||
$has_capability = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $has_capability ) {
|
||||
// Capability found, persist status and return true.
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_ENABLED );
|
||||
$this->settings->persist();
|
||||
|
||||
$this->current_status = true;
|
||||
return $this->current_status;
|
||||
}
|
||||
|
||||
// Capability not found, persist status and return false.
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_DISABLED );
|
||||
$this->settings->persist();
|
||||
|
|
|
@ -422,6 +422,7 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
*
|
||||
* @throws RuntimeException If create order request fails.
|
||||
* @throws PayPalApiException If create order request fails.
|
||||
*
|
||||
* phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
|
||||
*/
|
||||
private function create_paypal_order( \WC_Order $wc_order = null, string $payment_method = '', array $data = array() ): Order {
|
||||
|
|
|
@ -78,7 +78,7 @@ class ThreeDSecure {
|
|||
if ( $authentication_result ) {
|
||||
$result = $this->card_authentication_result_factory->from_paypal_response( $authentication_result );
|
||||
|
||||
$this->logger->info( '3DS authentication result: ' . wc_print_r( $result->to_array(), true ) );
|
||||
$this->logger->info( '3DS Authentication Result: ' . wc_print_r( $result->to_array(), true ) );
|
||||
|
||||
if ( $result->liability_shift() === AuthResult::LIABILITY_SHIFT_POSSIBLE ) {
|
||||
return self::PROCCEED;
|
||||
|
|
|
@ -54,6 +54,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'AT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'BE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -342,6 +366,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -390,6 +438,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LI' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -686,6 +758,30 @@ return array(
|
|||
'JPY',
|
||||
'USD',
|
||||
),
|
||||
'NO' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -114,6 +114,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'AT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'BE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -402,6 +426,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -450,6 +498,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LI' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -522,6 +594,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'NO' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'NL' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Googlepay\Helper;
|
|||
|
||||
use Throwable;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusCapability;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\FailureRegistry;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
@ -100,6 +101,11 @@ class ApmProductStatus {
|
|||
return false;
|
||||
}
|
||||
|
||||
$status_override = apply_filters( 'woocommerce_paypal_payments_google_pay_product_status', null );
|
||||
if ( null !== $status_override ) {
|
||||
return $status_override;
|
||||
}
|
||||
|
||||
// If status was already checked on this request return the same result.
|
||||
if ( null !== $this->current_status ) {
|
||||
return $this->current_status;
|
||||
|
@ -128,21 +134,32 @@ class ApmProductStatus {
|
|||
}
|
||||
|
||||
// Check the seller status for the intended capability.
|
||||
$has_capability = false;
|
||||
foreach ( $seller_status->products() as $product ) {
|
||||
if ( $product->name() !== 'PAYMENT_METHODS' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( in_array( self::CAPABILITY_NAME, $product->capabilities(), true ) ) {
|
||||
// Capability found, persist status and return true.
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_ENABLED );
|
||||
$this->settings->persist();
|
||||
|
||||
$this->current_status = true;
|
||||
return $this->current_status;
|
||||
$has_capability = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $seller_status->capabilities() as $capability ) {
|
||||
if ( $capability->name() === self::CAPABILITY_NAME && $capability->status() === SellerStatusCapability::STATUS_ACTIVE ) {
|
||||
$has_capability = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $has_capability ) {
|
||||
// Capability found, persist status and return true.
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_ENABLED );
|
||||
$this->settings->persist();
|
||||
|
||||
$this->current_status = true;
|
||||
return $this->current_status;
|
||||
}
|
||||
|
||||
// Capability not found, persist status and return false.
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_DISABLED );
|
||||
$this->settings->persist();
|
||||
|
|
|
@ -359,6 +359,20 @@ document.addEventListener(
|
|||
);
|
||||
}
|
||||
|
||||
const referenceTransactionsCheck = () => {
|
||||
if (
|
||||
typeof PayPalCommerceGatewaySettings !== 'undefined'
|
||||
&& PayPalCommerceGatewaySettings.reference_transaction_enabled !== '1'
|
||||
) {
|
||||
document.getElementById('ppcp-vault_enabled')?.setAttribute('disabled', 'disabled');
|
||||
|
||||
const description = document.getElementById('field-vault_enabled')?.getElementsByClassName('description')[0];
|
||||
if (description) {
|
||||
description.innerHTML = PayPalCommerceGatewaySettings.vaulting_must_enable_advanced_wallet_message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(() => {
|
||||
removeDisabledCardIcons('select[name="ppcp[disable_cards][]"]', 'select[name="ppcp[card_icons][]"]');
|
||||
|
||||
|
@ -408,6 +422,8 @@ document.addEventListener(
|
|||
);
|
||||
|
||||
togglePayLaterMessageFields();
|
||||
|
||||
referenceTransactionsCheck()
|
||||
})();
|
||||
}
|
||||
)
|
||||
|
|
|
@ -14,6 +14,7 @@ use WC_Order_Item_Product;
|
|||
use WC_Product;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\ItemTrait;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\OrderTrackingModule;
|
||||
|
||||
/**
|
||||
|
@ -21,6 +22,8 @@ use WooCommerce\PayPalCommerce\OrderTracking\OrderTrackingModule;
|
|||
*/
|
||||
class Shipment implements ShipmentInterface {
|
||||
|
||||
use ItemTrait;
|
||||
|
||||
/**
|
||||
* The WC order ID.
|
||||
*
|
||||
|
@ -171,7 +174,7 @@ class Shipment implements ShipmentInterface {
|
|||
$quantity,
|
||||
$this->prepare_description( $product->get_description() ),
|
||||
null,
|
||||
$product->get_sku(),
|
||||
$this->prepare_sku( $product->get_sku() ),
|
||||
$product->is_virtual() ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
||||
$product->get_permalink(),
|
||||
$image[0] ?? ''
|
||||
|
@ -239,17 +242,6 @@ class Shipment implements ShipmentInterface {
|
|||
return $shipment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanups the description and prepares it for sending to PayPal.
|
||||
*
|
||||
* @param string $description Item description.
|
||||
* @return string
|
||||
*/
|
||||
protected function prepare_description( string $description ): string {
|
||||
$description = strip_shortcodes( wp_strip_all_tags( $description ) );
|
||||
return substr( $description, 0, 127 ) ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the shipment line items info.
|
||||
*
|
||||
|
|
14
modules/ppcp-paylater-configurator/.babelrc
Normal file
14
modules/ppcp-paylater-configurator/.babelrc
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"useBuiltIns": "usage",
|
||||
"corejs": "3.25.0"
|
||||
}
|
||||
],
|
||||
[
|
||||
"@babel/preset-react"
|
||||
]
|
||||
]
|
||||
}
|
3
modules/ppcp-paylater-configurator/.gitignore
vendored
Normal file
3
modules/ppcp-paylater-configurator/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
node_modules
|
||||
assets/js
|
||||
assets/css
|
17
modules/ppcp-paylater-configurator/composer.json
Normal file
17
modules/ppcp-paylater-configurator/composer.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "woocommerce/ppcp-paylater-configurator",
|
||||
"type": "dhii-mod",
|
||||
"description": "Pay Later Messaging configurator module for PPCP",
|
||||
"license": "GPL-2.0",
|
||||
"require": {
|
||||
"php": "^7.2 | ^8.0",
|
||||
"dhii/module-interface": "^0.3.0-alpha1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"WooCommerce\\PayPalCommerce\\PayLaterConfigurator\\": "src"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
74
modules/ppcp-paylater-configurator/extensions.php
Normal file
74
modules/ppcp-paylater-configurator/extensions.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/**
|
||||
* The Pay Later configurator module extensions.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\PayLaterConfigurator
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\PayLaterConfigurator;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'wcgateway.settings.fields' => function ( ContainerInterface $container, array $fields ): array {
|
||||
$old_fields = array(
|
||||
'pay_later_messaging_locations',
|
||||
'pay_later_enable_styling_per_messaging_location',
|
||||
'pay_later_general_message_layout',
|
||||
'pay_later_general_message_logo',
|
||||
'pay_later_general_message_position',
|
||||
'pay_later_general_message_color',
|
||||
'pay_later_general_message_flex_color',
|
||||
'pay_later_general_message_flex_ratio',
|
||||
'pay_later_general_message_preview',
|
||||
'pay_later_product_messaging_heading',
|
||||
'pay_later_product_message_layout',
|
||||
'pay_later_product_message_logo',
|
||||
'pay_later_product_message_position',
|
||||
'pay_later_product_message_color',
|
||||
'pay_later_product_message_flex_color',
|
||||
'pay_later_product_message_flex_ratio',
|
||||
'pay_later_product_message_preview',
|
||||
'pay_later_cart_messaging_heading',
|
||||
'pay_later_cart_message_layout',
|
||||
'pay_later_cart_message_logo',
|
||||
'pay_later_cart_message_position',
|
||||
'pay_later_cart_message_color',
|
||||
'pay_later_cart_message_flex_color',
|
||||
'pay_later_cart_message_flex_ratio',
|
||||
'pay_later_cart_message_preview',
|
||||
'pay_later_checkout_messaging_heading',
|
||||
'pay_later_checkout_message_layout',
|
||||
'pay_later_checkout_message_logo',
|
||||
'pay_later_checkout_message_position',
|
||||
'pay_later_checkout_message_color',
|
||||
'pay_later_checkout_message_flex_color',
|
||||
'pay_later_checkout_message_flex_ratio',
|
||||
'pay_later_checkout_message_preview',
|
||||
'pay_later_shop_messaging_heading',
|
||||
'pay_later_shop_message_layout',
|
||||
'pay_later_shop_message_logo',
|
||||
'pay_later_shop_message_position',
|
||||
'pay_later_shop_message_color',
|
||||
'pay_later_shop_message_flex_color',
|
||||
'pay_later_shop_message_flex_ratio',
|
||||
'pay_later_shop_message_preview',
|
||||
'pay_later_home_messaging_heading',
|
||||
'pay_later_home_message_layout',
|
||||
'pay_later_home_message_logo',
|
||||
'pay_later_home_message_position',
|
||||
'pay_later_home_message_color',
|
||||
'pay_later_home_message_flex_color',
|
||||
'pay_later_home_message_flex_ratio',
|
||||
'pay_later_home_message_preview',
|
||||
'pay_later_messaging_enabled',
|
||||
);
|
||||
foreach ( $old_fields as $old_field ) {
|
||||
unset( $fields[ $old_field ] );
|
||||
}
|
||||
|
||||
return $fields;
|
||||
},
|
||||
);
|
16
modules/ppcp-paylater-configurator/module.php
Normal file
16
modules/ppcp-paylater-configurator/module.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* The Pay Later configurator module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\PayLaterConfigurator
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\PayLaterConfigurator;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||
|
||||
return static function (): ModuleInterface {
|
||||
return new PayLaterConfiguratorModule();
|
||||
};
|
33
modules/ppcp-paylater-configurator/package.json
Normal file
33
modules/ppcp-paylater-configurator/package.json
Normal file
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "ppcp-paylater-configurator",
|
||||
"version": "1.0.0",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"browserslist": [
|
||||
"> 0.5%",
|
||||
"Safari >= 8",
|
||||
"Chrome >= 41",
|
||||
"Firefox >= 43",
|
||||
"Edge >= 14"
|
||||
],
|
||||
"dependencies": {
|
||||
"core-js": "^3.25.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.19",
|
||||
"@babel/preset-env": "^7.19",
|
||||
"@babel/preset-react": "^7.18.6",
|
||||
"@woocommerce/dependency-extraction-webpack-plugin": "^2.2.0",
|
||||
"babel-loader": "^8.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"file-loader": "^6.2.0",
|
||||
"sass": "^1.42.1",
|
||||
"sass-loader": "^12.1.0",
|
||||
"webpack": "^5.76",
|
||||
"webpack-cli": "^4.10"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
|
||||
"watch": "cross-env BABEL_ENV=default NODE_ENV=production webpack --watch",
|
||||
"dev": "cross-env BABEL_ENV=default webpack --watch"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#messaging-configurator {
|
||||
& > div {
|
||||
justify-content: left;
|
||||
margin: 0;
|
||||
|
||||
& > div {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
.ppcp-paylater-configurator-publishButton {
|
||||
display:none;
|
||||
}
|
||||
.ppcp-paylater-configurator-header {
|
||||
font-size: 1.3em;
|
||||
color: #1d2327;
|
||||
margin: 1em 0;
|
||||
font-weight: 600;
|
||||
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
|
||||
line-height: 1.3;
|
||||
}
|
||||
#configurator-eligibleContainer div:has(.ppcp-paylater-configurator-header#configurator-headerText) {
|
||||
display: none;
|
||||
}
|
||||
.ppcp-paylater-configurator-subheader {
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
color: #3c434a;
|
||||
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
document.addEventListener( 'DOMContentLoaded', () => {
|
||||
const form = document.querySelector('#mainform');
|
||||
const table = form.querySelector('.form-table');
|
||||
const saveChangesButton = form.querySelector('.woocommerce-save-button');
|
||||
const publishButtonClassName = PcpPayLaterConfigurator.publishButtonClassName;
|
||||
|
||||
table.insertAdjacentHTML('afterend', '<div id="messaging-configurator"></div>');
|
||||
|
||||
|
||||
saveChangesButton.addEventListener('click', () => {
|
||||
form.querySelector('.' + publishButtonClassName).click();
|
||||
|
||||
// Delay the page refresh by a few milliseconds to ensure changes take effect
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
merchantConfigurators.Messaging({
|
||||
config: PcpPayLaterConfigurator.config,
|
||||
merchantClientId: PcpPayLaterConfigurator.merchantClientId,
|
||||
partnerClientId: PcpPayLaterConfigurator.partnerClientId,
|
||||
partnerName: 'WooCommerce',
|
||||
bnCode: 'Woo_PPCP',
|
||||
placements: ['cart', 'checkout', 'product', 'category', 'homepage', 'custom_placement'],
|
||||
styleOverrides: {
|
||||
button: publishButtonClassName,
|
||||
header: PcpPayLaterConfigurator.headerClassName,
|
||||
subheader: PcpPayLaterConfigurator.subheaderClassName
|
||||
},
|
||||
onSave: data => {
|
||||
fetch(PcpPayLaterConfigurator.ajax.save_config.endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
nonce: PcpPayLaterConfigurator.ajax.save_config.nonce,
|
||||
config: data,
|
||||
}),
|
||||
});
|
||||
}
|
||||
})
|
||||
} );
|
38
modules/ppcp-paylater-configurator/services.php
Normal file
38
modules/ppcp-paylater-configurator/services.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* The Pay Later configurator module services.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\PayLaterConfigurator
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\PayLaterConfigurator;
|
||||
|
||||
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig;
|
||||
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'paylater-configurator.url' => static function ( ContainerInterface $container ): string {
|
||||
/**
|
||||
* Cannot return false for this path.
|
||||
*
|
||||
* @psalm-suppress PossiblyFalseArgument
|
||||
*/
|
||||
return plugins_url(
|
||||
'/modules/ppcp-paylater-configurator/',
|
||||
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
||||
);
|
||||
},
|
||||
'paylater-configurator.factory.config' => static function ( ContainerInterface $container ): ConfigFactory {
|
||||
return new ConfigFactory();
|
||||
},
|
||||
'paylater-configurator.endpoint.save-config' => static function ( ContainerInterface $container ): SaveConfig {
|
||||
return new SaveConfig(
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'button.request-data' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
},
|
||||
);
|
168
modules/ppcp-paylater-configurator/src/Endpoint/SaveConfig.php
Normal file
168
modules/ppcp-paylater-configurator/src/Endpoint/SaveConfig.php
Normal file
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
/**
|
||||
* The endpoint for saving the Pay Later messaging config from the configurator.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Throwable;
|
||||
use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
* Class SaveConfig.
|
||||
*/
|
||||
class SaveConfig {
|
||||
const ENDPOINT = 'ppc-save-message-config';
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
* @var Settings
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* The request data.
|
||||
*
|
||||
* @var RequestData
|
||||
*/
|
||||
protected $request_data;
|
||||
|
||||
/**
|
||||
* The logger.
|
||||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* SaveConfig constructor.
|
||||
*
|
||||
* @param Settings $settings The settings.
|
||||
* @param RequestData $request_data The request data.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
*/
|
||||
public function __construct(
|
||||
Settings $settings,
|
||||
RequestData $request_data,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
$this->request_data = $request_data;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the nonce.
|
||||
*/
|
||||
public static function nonce(): string {
|
||||
return self::ENDPOINT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the request.
|
||||
*/
|
||||
public function handle_request(): bool {
|
||||
if ( ! current_user_can( 'manage_woocommerce' ) ) {
|
||||
wp_send_json_error( 'Not admin.', 403 );
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = $this->request_data->read_request( $this->nonce() );
|
||||
|
||||
$this->save_config( $data['config']['config'] );
|
||||
|
||||
wp_send_json_success();
|
||||
return true;
|
||||
} catch ( Throwable $error ) {
|
||||
$this->logger->error( "SaveConfig execution failed. {$error->getMessage()} {$error->getFile()}:{$error->getLine()}" );
|
||||
|
||||
wp_send_json_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the config into the old settings.
|
||||
*
|
||||
* @param array $config The configurator config.
|
||||
*/
|
||||
private function save_config( array $config ): void {
|
||||
$this->settings->set( 'pay_later_enable_styling_per_messaging_location', true );
|
||||
$this->settings->set( 'pay_later_messaging_enabled', true );
|
||||
|
||||
$enabled_locations = array();
|
||||
|
||||
foreach ( $config as $placement => $data ) {
|
||||
$location = $this->configurator_placement_to_location( $placement );
|
||||
|
||||
$this->save_config_for_location( $data, $location );
|
||||
|
||||
if ( $data['status'] === 'enabled' ) {
|
||||
$enabled_locations[] = $location;
|
||||
}
|
||||
}
|
||||
|
||||
$this->settings->set( 'pay_later_messaging_locations', $enabled_locations );
|
||||
|
||||
$this->settings->persist();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the config for a location into the old settings.
|
||||
*
|
||||
* @param array $config The configurator config for a location.
|
||||
* @param string $location The location name in the old settings.
|
||||
*/
|
||||
private function save_config_for_location( array $config, string $location ): void {
|
||||
$this->set_value_if_present( $config, 'layout', "pay_later_{$location}_message_layout" );
|
||||
|
||||
$this->set_value_if_present( $config, 'color', "pay_later_{$location}_message_flex_color" );
|
||||
$this->set_value_if_present( $config, 'ratio', "pay_later_{$location}_message_flex_ratio" );
|
||||
|
||||
$this->set_value_if_present( $config, 'logo-position', "pay_later_{$location}_message_position" );
|
||||
$this->set_value_if_present( $config, 'logo-type', "pay_later_{$location}_message_logo" );
|
||||
$this->set_value_if_present( $config, 'logo-color', "pay_later_{$location}_message_color" );
|
||||
$this->set_value_if_present( $config, 'text-size', "pay_later_{$location}_message_text_size" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value in the settings if it is available in the config.
|
||||
*
|
||||
* @param array $config The configurator config.
|
||||
* @param string $key The key in the config.
|
||||
* @param string $settings_key The key in the settings.
|
||||
*/
|
||||
private function set_value_if_present( array $config, string $key, string $settings_key ): void {
|
||||
if ( isset( $config[ $key ] ) ) {
|
||||
$this->settings->set( $settings_key, $config[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the configurator placement into location in the old settings.
|
||||
*
|
||||
* @param string $placement The configurator placement.
|
||||
*/
|
||||
private function configurator_placement_to_location( string $placement ): string {
|
||||
switch ( $placement ) {
|
||||
case 'cart':
|
||||
case 'checkout':
|
||||
case 'product':
|
||||
return $placement;
|
||||
case 'category':
|
||||
return 'shop';
|
||||
case 'homepage':
|
||||
return 'home';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
107
modules/ppcp-paylater-configurator/src/Factory/ConfigFactory.php
Normal file
107
modules/ppcp-paylater-configurator/src/Factory/ConfigFactory.php
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
/**
|
||||
* The factory the Pay Later messaging configurator configs.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory;
|
||||
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
* Class ConfigFactory.
|
||||
*/
|
||||
class ConfigFactory {
|
||||
/**
|
||||
* Returns the configurator config for the given old settings.
|
||||
*
|
||||
* @param Settings $settings The settings.
|
||||
*/
|
||||
public function from_settings( Settings $settings ): array {
|
||||
return array(
|
||||
$this->location_to_configurator_placement( 'cart' ) => $this->for_location( $settings, 'cart' ),
|
||||
$this->location_to_configurator_placement( 'checkout' ) => $this->for_location( $settings, 'checkout' ),
|
||||
$this->location_to_configurator_placement( 'product' ) => $this->for_location( $settings, 'product' ),
|
||||
$this->location_to_configurator_placement( 'shop' ) => $this->for_location( $settings, 'shop' ),
|
||||
$this->location_to_configurator_placement( 'home' ) => $this->for_location( $settings, 'home' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configurator config for a location.
|
||||
*
|
||||
* @param Settings $settings The settings.
|
||||
* @param string $location The location name in the old settings.
|
||||
*/
|
||||
private function for_location( Settings $settings, string $location ): array {
|
||||
$selected_locations = $settings->has( 'pay_later_messaging_locations' ) ? $settings->get( 'pay_later_messaging_locations' ) : array();
|
||||
|
||||
$placement = $this->location_to_configurator_placement( $location );
|
||||
if ( in_array( $placement, array( 'category', 'homepage' ), true ) ) {
|
||||
$config = array(
|
||||
'layout' => 'flex',
|
||||
'color' => $this->get_or_default( $settings, "pay_later_{$location}_message_flex_color", 'black', array( 'black', 'blue', 'white', 'white-no-border' ) ),
|
||||
'ratio' => $this->get_or_default( $settings, "pay_later_{$location}_message_flex_ratio", '8x1', array( '8x1', '20x1' ) ),
|
||||
);
|
||||
} else {
|
||||
$config = array(
|
||||
'layout' => 'text',
|
||||
'logo-position' => $this->get_or_default( $settings, "pay_later_{$location}_message_position", 'left' ),
|
||||
'logo-type' => $this->get_or_default( $settings, "pay_later_{$location}_message_logo", 'inline' ),
|
||||
'text-color' => $this->get_or_default( $settings, "pay_later_{$location}_message_color", 'black' ),
|
||||
'text-size' => $this->get_or_default( $settings, "pay_later_{$location}_message_text_size", '12' ),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
array(
|
||||
'status' => in_array( $location, $selected_locations, true ) ? 'enabled' : 'disabled',
|
||||
'placement' => $placement,
|
||||
),
|
||||
$config
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the location name from the old settings into the configurator placement.
|
||||
*
|
||||
* @param string $location The location name in the old settings.
|
||||
*/
|
||||
private function location_to_configurator_placement( string $location ): string {
|
||||
switch ( $location ) {
|
||||
case 'cart':
|
||||
case 'checkout':
|
||||
case 'product':
|
||||
return $location;
|
||||
case 'shop':
|
||||
return 'category';
|
||||
case 'home':
|
||||
return 'homepage';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the settings value or default, if does not exist or not allowed value.
|
||||
*
|
||||
* @param Settings $settings The settings.
|
||||
* @param string $key The key.
|
||||
* @param mixed $default The default value.
|
||||
* @param array|null $allowed_values The list of allowed values, or null if all values are allowed.
|
||||
* @return mixed
|
||||
*/
|
||||
private function get_or_default( Settings $settings, string $key, $default, ?array $allowed_values = null ) {
|
||||
if ( $settings->has( $key ) ) {
|
||||
$value = $settings->get( $key );
|
||||
if ( ! $allowed_values || in_array( $value, $allowed_values, true ) ) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
/**
|
||||
* The Pay Later configurator module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\PayLaterConfigurator
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\PayLaterConfigurator;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
||||
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig;
|
||||
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
* Class PayLaterConfiguratorModule
|
||||
*/
|
||||
class PayLaterConfiguratorModule implements ModuleInterface {
|
||||
/**
|
||||
* Returns whether the module should be loaded.
|
||||
*/
|
||||
public static function is_enabled(): bool {
|
||||
return apply_filters(
|
||||
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||
'woocommerce.feature-flags.woocommerce_paypal_payments.paylater_configurator_enabled',
|
||||
getenv( 'PCP_PAYLATER_CONFIGURATOR' ) !== '0'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setup(): ServiceProviderInterface {
|
||||
return new ServiceProvider(
|
||||
require __DIR__ . '/../services.php',
|
||||
require __DIR__ . '/../extensions.php'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function run( ContainerInterface $c ): void {
|
||||
$messages_apply = $c->get( 'button.helper.messages-apply' );
|
||||
assert( $messages_apply instanceof MessagesApply );
|
||||
|
||||
if ( ! $messages_apply->for_country() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action(
|
||||
'wc_ajax_' . SaveConfig::ENDPOINT,
|
||||
static function () use ( $c ) {
|
||||
$endpoint = $c->get( 'paylater-configurator.endpoint.save-config' );
|
||||
assert( $endpoint instanceof SaveConfig );
|
||||
$endpoint->handle_request();
|
||||
}
|
||||
);
|
||||
|
||||
$current_page_id = $c->get( 'wcgateway.current-ppcp-settings-page-id' );
|
||||
|
||||
if ( $current_page_id !== Settings::PAY_LATER_TAB_ID ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
add_action(
|
||||
'init',
|
||||
static function () use ( $c, $settings ) {
|
||||
wp_enqueue_script(
|
||||
'ppcp-paylater-configurator-lib',
|
||||
'https://www.paypalobjects.com/merchant-library/preview/merchant-configurator.js',
|
||||
array(),
|
||||
$c->get( 'ppcp.asset-version' ),
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'ppcp-paylater-configurator',
|
||||
$c->get( 'paylater-configurator.url' ) . '/assets/js/paylater-configurator.js',
|
||||
array(),
|
||||
$c->get( 'ppcp.asset-version' ),
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_style(
|
||||
'ppcp-paylater-configurator-style',
|
||||
$c->get( 'paylater-configurator.url' ) . '/assets/css/paylater-configurator.css',
|
||||
array(),
|
||||
$c->get( 'ppcp.asset-version' )
|
||||
);
|
||||
|
||||
$config_factory = $c->get( 'paylater-configurator.factory.config' );
|
||||
assert( $config_factory instanceof ConfigFactory );
|
||||
|
||||
wp_localize_script(
|
||||
'ppcp-paylater-configurator',
|
||||
'PcpPayLaterConfigurator',
|
||||
array(
|
||||
'ajax' => array(
|
||||
'save_config' => array(
|
||||
'endpoint' => \WC_AJAX::get_endpoint( SaveConfig::ENDPOINT ),
|
||||
'nonce' => wp_create_nonce( SaveConfig::nonce() ),
|
||||
),
|
||||
),
|
||||
'config' => $config_factory->from_settings( $settings ),
|
||||
'merchantClientId' => $settings->get( 'client_id' ),
|
||||
'partnerClientId' => $c->get( 'api.partner_merchant_id' ),
|
||||
'publishButtonClassName' => 'ppcp-paylater-configurator-publishButton',
|
||||
'headerClassName' => 'ppcp-paylater-configurator-header',
|
||||
'subheaderClassName' => 'ppcp-paylater-configurator-subheader',
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the module.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function getKey() {
|
||||
}
|
||||
}
|
39
modules/ppcp-paylater-configurator/webpack.config.js
Normal file
39
modules/ppcp-paylater-configurator/webpack.config.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
const path = require('path');
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
|
||||
const DependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' );
|
||||
|
||||
module.exports = {
|
||||
devtool: isProduction ? 'source-map' : 'eval-source-map',
|
||||
mode: isProduction ? 'production' : 'development',
|
||||
target: 'web',
|
||||
plugins: [ new DependencyExtractionWebpackPlugin() ],
|
||||
entry: {
|
||||
'paylater-configurator': path.resolve('./resources/js/paylater-configurator.js'),
|
||||
'paylater-configurator-style': path.resolve('./resources/css/paylater-configurator.scss'),
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'assets/'),
|
||||
filename: 'js/[name].js',
|
||||
},
|
||||
module: {
|
||||
rules: [{
|
||||
test: /\.js?$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
exclude: /node_modules/,
|
||||
use: [
|
||||
{
|
||||
loader: 'file-loader',
|
||||
options: {
|
||||
name: 'css/[name].css',
|
||||
}
|
||||
},
|
||||
{loader:'sass-loader'}
|
||||
]
|
||||
}]
|
||||
}
|
||||
};
|
2201
modules/ppcp-paylater-configurator/yarn.lock
Normal file
2201
modules/ppcp-paylater-configurator/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
|
@ -58,6 +58,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'AT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'BE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -346,6 +370,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -394,6 +442,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LI' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
@ -466,6 +538,30 @@ return array(
|
|||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'NO' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'NL' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
|
|
|
@ -910,11 +910,6 @@ return array(
|
|||
unset( $fields['subscriptions_mode'] );
|
||||
}
|
||||
|
||||
$billing_agreements_endpoint = $container->get( 'api.endpoint.billing-agreements' );
|
||||
if ( ! $billing_agreements_endpoint->reference_transaction_enabled() ) {
|
||||
unset( $fields['vault_enabled'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Depending on your store location, some credit cards can't be used.
|
||||
* Here, we filter them out.
|
||||
|
|
|
@ -9,12 +9,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\RefreshFeatureStatusEndpoint;
|
||||
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\ResubscribeEndpoint;
|
||||
|
||||
/**
|
||||
* Class SettingsPageAssets
|
||||
|
@ -105,21 +105,29 @@ class SettingsPageAssets {
|
|||
*/
|
||||
private $is_acdc_enabled;
|
||||
|
||||
/**
|
||||
* Billing Agreements endpoint.
|
||||
*
|
||||
* @var BillingAgreementsEndpoint
|
||||
*/
|
||||
private $billing_agreements_endpoint;
|
||||
|
||||
/**
|
||||
* Assets constructor.
|
||||
*
|
||||
* @param string $module_url The url of this module.
|
||||
* @param string $version The assets version.
|
||||
* @param SubscriptionHelper $subscription_helper The subscription helper.
|
||||
* @param string $client_id The PayPal SDK client ID.
|
||||
* @param string $currency 3-letter currency code of the shop.
|
||||
* @param string $country 2-letter country code of the shop.
|
||||
* @param Environment $environment The environment object.
|
||||
* @param bool $is_pay_later_button_enabled Whether Pay Later button is enabled either for checkout, cart or product page.
|
||||
* @param array $disabled_sources The list of disabled funding sources.
|
||||
* @param array $all_funding_sources The list of all existing funding sources.
|
||||
* @param bool $is_settings_page Whether it's a settings page of this plugin.
|
||||
* @param bool $is_acdc_enabled Whether the ACDC gateway is enabled.
|
||||
* @param string $module_url The url of this module.
|
||||
* @param string $version The assets version.
|
||||
* @param SubscriptionHelper $subscription_helper The subscription helper.
|
||||
* @param string $client_id The PayPal SDK client ID.
|
||||
* @param string $currency 3-letter currency code of the shop.
|
||||
* @param string $country 2-letter country code of the shop.
|
||||
* @param Environment $environment The environment object.
|
||||
* @param bool $is_pay_later_button_enabled Whether Pay Later button is enabled either for checkout, cart or product page.
|
||||
* @param array $disabled_sources The list of disabled funding sources.
|
||||
* @param array $all_funding_sources The list of all existing funding sources.
|
||||
* @param bool $is_settings_page Whether it's a settings page of this plugin.
|
||||
* @param bool $is_acdc_enabled Whether the ACDC gateway is enabled.
|
||||
* @param BillingAgreementsEndpoint $billing_agreements_endpoint Billing Agreements endpoint.
|
||||
*/
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
|
@ -133,7 +141,8 @@ class SettingsPageAssets {
|
|||
array $disabled_sources,
|
||||
array $all_funding_sources,
|
||||
bool $is_settings_page,
|
||||
bool $is_acdc_enabled
|
||||
bool $is_acdc_enabled,
|
||||
BillingAgreementsEndpoint $billing_agreements_endpoint
|
||||
) {
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
|
@ -147,6 +156,7 @@ class SettingsPageAssets {
|
|||
$this->all_funding_sources = $all_funding_sources;
|
||||
$this->is_settings_page = $is_settings_page;
|
||||
$this->is_acdc_enabled = $is_acdc_enabled;
|
||||
$this->billing_agreements_endpoint = $billing_agreements_endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,6 +260,13 @@ class SettingsPageAssets {
|
|||
),
|
||||
),
|
||||
),
|
||||
'reference_transaction_enabled' => $this->billing_agreements_endpoint->reference_transaction_enabled(),
|
||||
'vaulting_must_enable_advanced_wallet_message' => sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
|
||||
esc_html__( 'Your PayPal account must be enabled for the %1$sAdvanced PayPal Wallet%2$s to use PayPal Vaulting.', 'woocommerce-paypal-payments' ),
|
||||
'<a href="/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=ppcp-connection#field-credentials_feature_onboarding_heading">',
|
||||
'</a>'
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -40,20 +40,18 @@ trait CreditCardOrderInfoHandlingTrait {
|
|||
}
|
||||
|
||||
$authentication_result = $payment_source->properties()->authentication_result ?? null;
|
||||
$card_brand = $payment_source->properties()->brand ?? __( 'N/A', 'woocommerce-paypal-payments' );
|
||||
|
||||
if ( $authentication_result ) {
|
||||
$card_authentication_result_factory = new CardAuthenticationResultFactory();
|
||||
$result = $card_authentication_result_factory->from_paypal_response( $authentication_result );
|
||||
|
||||
$three_d_response_order_note_title = __( '3DS authentication result', 'woocommerce-paypal-payments' );
|
||||
$three_d_response_order_note_title = __( '3DS Authentication Result', 'woocommerce-paypal-payments' );
|
||||
/* translators: %1$s is 3DS order note title, %2$s is 3DS order note result markup */
|
||||
$three_d_response_order_note_format = __( '%1$s %2$s', 'woocommerce-paypal-payments' );
|
||||
$three_d_response_order_note_result_format = '<ul class="ppcp_3ds_result">
|
||||
<li>%1$s</li>
|
||||
<li>%2$s</li>
|
||||
<li>%3$s</li>
|
||||
<li>%4$s</li>
|
||||
</ul>';
|
||||
$three_d_response_order_note_result = sprintf(
|
||||
$three_d_response_order_note_result_format,
|
||||
|
@ -62,9 +60,7 @@ trait CreditCardOrderInfoHandlingTrait {
|
|||
/* translators: %s is enrollment status */
|
||||
sprintf( __( 'Enrollment Status: %s', 'woocommerce-paypal-payments' ), esc_html( $result->enrollment_status() ) ),
|
||||
/* translators: %s is authentication status */
|
||||
sprintf( __( 'Authentication Status: %s', 'woocommerce-paypal-payments' ), esc_html( $result->authentication_result() ) ),
|
||||
/* translators: %s is card brand */
|
||||
sprintf( __( 'Card Brand: %s', 'woocommerce-paypal-payments' ), esc_html( $card_brand ) )
|
||||
sprintf( __( 'Authentication Status: %s', 'woocommerce-paypal-payments' ), esc_html( $result->authentication_result() ) )
|
||||
);
|
||||
$three_d_response_order_note = sprintf(
|
||||
$three_d_response_order_note_format,
|
||||
|
@ -74,8 +70,7 @@ trait CreditCardOrderInfoHandlingTrait {
|
|||
|
||||
$wc_order->add_order_note( $three_d_response_order_note );
|
||||
|
||||
$meta_details = array_merge( $result->to_array(), array( 'card_brand' => $card_brand ) );
|
||||
$wc_order->update_meta_data( PayPalGateway::THREE_D_AUTH_RESULT_META_KEY, $meta_details );
|
||||
$wc_order->update_meta_data( PayPalGateway::THREE_D_AUTH_RESULT_META_KEY, $result->to_array() );
|
||||
$wc_order->save_meta_data();
|
||||
|
||||
/**
|
||||
|
@ -101,7 +96,9 @@ trait CreditCardOrderInfoHandlingTrait {
|
|||
return;
|
||||
}
|
||||
|
||||
$fraud_responses = $fraud->to_array();
|
||||
$fraud_responses = $fraud->to_array();
|
||||
$card_brand = $payment_source->properties()->brand ?? __( 'N/A', 'woocommerce-paypal-payments' );
|
||||
|
||||
$avs_response_order_note_title = __( 'Address Verification Result', 'woocommerce-paypal-payments' );
|
||||
/* translators: %1$s is AVS order note title, %2$s is AVS order note result markup */
|
||||
$avs_response_order_note_format = __( '%1$s %2$s', 'woocommerce-paypal-payments' );
|
||||
|
@ -111,6 +108,7 @@ trait CreditCardOrderInfoHandlingTrait {
|
|||
<li>%2$s</li>
|
||||
<li>%3$s</li>
|
||||
</ul>
|
||||
<li>%4$s</li>
|
||||
</ul>';
|
||||
$avs_response_order_note_result = sprintf(
|
||||
$avs_response_order_note_result_format,
|
||||
|
@ -119,7 +117,9 @@ trait CreditCardOrderInfoHandlingTrait {
|
|||
/* translators: %s is fraud AVS address match */
|
||||
sprintf( __( 'Address Match: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['address_match'] ) ),
|
||||
/* translators: %s is fraud AVS postal match */
|
||||
sprintf( __( 'Postal Match: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['postal_match'] ) )
|
||||
sprintf( __( 'Postal Match: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['postal_match'] ) ),
|
||||
/* translators: %s is card brand */
|
||||
sprintf( __( 'Card Brand: %s', 'woocommerce-paypal-payments' ), esc_html( $card_brand ) )
|
||||
);
|
||||
$avs_response_order_note = sprintf(
|
||||
$avs_response_order_note_format,
|
||||
|
@ -136,7 +136,8 @@ trait CreditCardOrderInfoHandlingTrait {
|
|||
);
|
||||
$wc_order->add_order_note( $cvv_response_order_note );
|
||||
|
||||
$wc_order->update_meta_data( PayPalGateway::FRAUD_RESULT_META_KEY, $fraud_responses );
|
||||
$meta_details = array_merge( $fraud_responses, array( 'card_brand' => $card_brand ) );
|
||||
$wc_order->update_meta_data( PayPalGateway::FRAUD_RESULT_META_KEY, $meta_details );
|
||||
$wc_order->save_meta_data();
|
||||
|
||||
/**
|
||||
|
|
|
@ -381,6 +381,11 @@ class SettingsListener {
|
|||
|
||||
$reference_transaction_enabled = $this->billing_agreements_endpoint->reference_transaction_enabled();
|
||||
|
||||
if ( $reference_transaction_enabled !== true ) {
|
||||
$this->settings->set( 'vault_enabled', false );
|
||||
$this->settings->persist();
|
||||
}
|
||||
|
||||
if ( $subscription_mode === 'vaulting_api' && $vault_enabled !== '1' && $reference_transaction_enabled === true ) {
|
||||
$this->settings->set( 'vault_enabled', true );
|
||||
$this->settings->persist();
|
||||
|
|
|
@ -181,7 +181,8 @@ class WCGatewayModule implements ModuleInterface {
|
|||
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
|
||||
$c->get( 'wcgateway.settings.funding-sources' ),
|
||||
$c->get( 'wcgateway.is-ppcp-settings-page' ),
|
||||
$settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' )
|
||||
$settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ),
|
||||
$c->get( 'api.endpoint.billing-agreements' )
|
||||
);
|
||||
$assets->register_assets();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue