Fix pay now button

not sure if the action parameter in order creation request affects anything, but the docs say that it should match the js sdk commit parameter
This commit is contained in:
Alex P 2023-04-24 08:15:22 +03:00
parent 37959ad2d8
commit 8efa0e6da3
No known key found for this signature in database
GPG key ID: 54487A734A204D71
5 changed files with 38 additions and 2 deletions

View file

@ -53,4 +53,14 @@ return array(
)
);
},
'button.pay-now-contexts' => function ( ContainerInterface $container, array $contexts ): array {
$contexts[] = 'checkout-block';
if ( ! $container->get( 'blocks.settings.final_review_enabled' ) ) {
$contexts[] = 'cart-block';
}
return $contexts;
},
);

View file

@ -110,6 +110,7 @@ return array(
$container->get( 'wcgateway.all-funding-sources' ),
$container->get( 'button.basic-checkout-validation-enabled' ),
$container->get( 'button.early-wc-checkout-validation-enabled' ),
$container->get( 'button.pay-now-contexts' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
@ -119,6 +120,9 @@ return array(
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
);
},
'button.pay-now-contexts' => static function ( ContainerInterface $container ): array {
return array( 'checkout', 'pay-now' );
},
'button.request-data' => static function ( ContainerInterface $container ): RequestData {
return new RequestData();
},
@ -156,6 +160,7 @@ return array(
$registration_needed,
$container->get( 'wcgateway.settings.card_billing_data_mode' ),
$container->get( 'button.early-wc-checkout-validation-enabled' ),
$container->get( 'button.pay-now-contexts' ),
$logger
);
},

View file

@ -165,6 +165,13 @@ class SmartButton implements SmartButtonInterface {
*/
protected $early_validation_enabled;
/**
* The contexts that should have the Pay Now button.
*
* @var string[]
*/
private $pay_now_contexts;
/**
* The logger.
*
@ -199,6 +206,7 @@ class SmartButton implements SmartButtonInterface {
* @param array $all_funding_sources All existing funding sources.
* @param bool $basic_checkout_validation_enabled Whether the basic JS validation of the form iss enabled.
* @param bool $early_validation_enabled Whether to execute WC validation of the checkout form.
* @param string[] $pay_now_contexts The contexts that should have the Pay Now button.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
@ -219,6 +227,7 @@ class SmartButton implements SmartButtonInterface {
array $all_funding_sources,
bool $basic_checkout_validation_enabled,
bool $early_validation_enabled,
array $pay_now_contexts,
LoggerInterface $logger
) {
@ -239,6 +248,7 @@ class SmartButton implements SmartButtonInterface {
$this->all_funding_sources = $all_funding_sources;
$this->basic_checkout_validation_enabled = $basic_checkout_validation_enabled;
$this->early_validation_enabled = $early_validation_enabled;
$this->pay_now_contexts = $pay_now_contexts;
$this->logger = $logger;
}
@ -971,7 +981,7 @@ class SmartButton implements SmartButtonInterface {
'integration-date' => PAYPAL_INTEGRATION_DATE,
'components' => implode( ',', $this->components() ),
'vault' => $this->can_save_vault_token() ? 'true' : 'false',
'commit' => in_array( $context, array( 'checkout', 'pay-now' ), true ) ? 'true' : 'false',
'commit' => in_array( $context, $this->pay_now_contexts, true ) ? 'true' : 'false',
'intent' => $context === 'product' ? $product_intent : $other_context_intent,
);
if (

View file

@ -138,6 +138,13 @@ class CreateOrderEndpoint implements EndpointInterface {
*/
protected $early_validation_enabled;
/**
* The contexts that should have the Pay Now button.
*
* @var string[]
*/
private $pay_now_contexts;
/**
* The logger.
*
@ -159,6 +166,7 @@ class CreateOrderEndpoint implements EndpointInterface {
* @param bool $registration_needed Whether a new user must be registered during checkout.
* @param string $card_billing_data_mode The value of card_billing_data_mode from the settings.
* @param bool $early_validation_enabled Whether to execute WC validation of the checkout form.
* @param string[] $pay_now_contexts The contexts that should have the Pay Now button.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
@ -173,6 +181,7 @@ class CreateOrderEndpoint implements EndpointInterface {
bool $registration_needed,
string $card_billing_data_mode,
bool $early_validation_enabled,
array $pay_now_contexts,
LoggerInterface $logger
) {
@ -187,6 +196,7 @@ class CreateOrderEndpoint implements EndpointInterface {
$this->registration_needed = $registration_needed;
$this->card_billing_data_mode = $card_billing_data_mode;
$this->early_validation_enabled = $early_validation_enabled;
$this->pay_now_contexts = $pay_now_contexts;
$this->logger = $logger;
}
@ -385,7 +395,7 @@ class CreateOrderEndpoint implements EndpointInterface {
$funding_source
);
$action = in_array( $this->parsed_request_data['context'], array( 'checkout' ), true ) ?
$action = in_array( $this->parsed_request_data['context'], $this->pay_now_contexts, true ) ?
ApplicationContext::USER_ACTION_PAY_NOW : ApplicationContext::USER_ACTION_CONTINUE;
if ( 'card' === $funding_source ) {

View file

@ -167,6 +167,7 @@ class CreateOrderEndpointTest extends TestCase
false,
CardBillingMode::MINIMAL_INPUT,
false,
['checkout'],
new NullLogger()
);
return array($payer_factory, $testee);