mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Move vaulted subscriptions intent logic to module
This commit is contained in:
parent
80cc94939d
commit
7d17e4a892
3 changed files with 24 additions and 7 deletions
|
@ -194,7 +194,7 @@ class OrderEndpoint {
|
||||||
): Order {
|
): Order {
|
||||||
$bearer = $this->bearer->bearer();
|
$bearer = $this->bearer->bearer();
|
||||||
$data = array(
|
$data = array(
|
||||||
'intent' => ( $this->subscription_helper->cart_contains_subscription() || $this->subscription_helper->current_product_is_subscription() ) ? 'AUTHORIZE' : $this->intent,
|
'intent' => apply_filters( 'woocommerce_paypal_payments_saved_payment_subscription_intent', $this->intent ),
|
||||||
'purchase_units' => array_map(
|
'purchase_units' => array_map(
|
||||||
static function ( PurchaseUnit $item ) use ( $shipping_preference ): array {
|
static function ( PurchaseUnit $item ) use ( $shipping_preference ): array {
|
||||||
$data = $item->to_array();
|
$data = $item->to_array();
|
||||||
|
|
|
@ -1547,16 +1547,14 @@ class SmartButton implements SmartButtonInterface {
|
||||||
* @throws NotFoundException If intent is not found.
|
* @throws NotFoundException If intent is not found.
|
||||||
*/
|
*/
|
||||||
private function intent(): string {
|
private function intent(): string {
|
||||||
$intent = ( $this->settings->has( 'intent' ) ) ? $this->settings->get( 'intent' ) : 'capture';
|
|
||||||
$product_intent = $this->subscription_helper->current_product_is_subscription() ? 'authorize' : $intent;
|
|
||||||
$other_context_intent = $this->subscription_helper->cart_contains_subscription() ? 'authorize' : $intent;
|
|
||||||
|
|
||||||
$subscription_mode = $this->settings->has( 'subscriptions_mode' ) ? $this->settings->get( 'subscriptions_mode' ) : '';
|
$subscription_mode = $this->settings->has( 'subscriptions_mode' ) ? $this->settings->get( 'subscriptions_mode' ) : '';
|
||||||
if ( $this->subscription_helper->need_subscription_intent( $subscription_mode ) ) {
|
if ( $this->subscription_helper->need_subscription_intent( $subscription_mode ) ) {
|
||||||
return 'subscription';
|
return 'subscription';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->context() === 'product' ? $product_intent : $other_context_intent;
|
$intent = $this->settings->has( 'intent' ) ? $this->settings->get( 'intent' ) : 'capture';
|
||||||
|
|
||||||
|
return strtolower( apply_filters( 'woocommerce_paypal_payments_saved_payment_subscription_intent', $intent ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\SavedPaymentChecker;
|
namespace WooCommerce\PayPalCommerce\SavedPaymentChecker;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||||
|
@ -32,5 +33,23 @@ class SavedPaymentCheckerModule implements ModuleInterface {
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function run( ContainerInterface $c ): void {}
|
public function run( ContainerInterface $c ): void {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set authorize intent for vaulted subscriptions, so we can void if payment not saved.
|
||||||
|
*/
|
||||||
|
add_filter(
|
||||||
|
'woocommerce_paypal_payments_saved_payment_subscription_intent',
|
||||||
|
function( string $intent ) use ( $c ) {
|
||||||
|
$subscription_helper = $c->get( 'subscription.helper' );
|
||||||
|
assert( $subscription_helper instanceof SubscriptionHelper );
|
||||||
|
|
||||||
|
if ( $subscription_helper->cart_contains_subscription() || $subscription_helper->current_product_is_subscription() ) {
|
||||||
|
return 'AUTHORIZE';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $intent;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue