mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge PCP-412-when-there-is-a-payment-saved-th
This commit is contained in:
commit
5d7de0a212
11 changed files with 212 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
|||
*** Changelog ***
|
||||
|
||||
= 1.7.0 - TBD =
|
||||
= 1.7.0 - 2022-02-28 =
|
||||
* Fix - DCC orders randomly failing #503
|
||||
* Fix - Multi-currency broke #481
|
||||
* Fix - Address information from PayPal shortcut flow not loaded #451
|
||||
|
|
|
@ -22,9 +22,12 @@ class MiniCartBootstap {
|
|||
}
|
||||
|
||||
shouldRender() {
|
||||
return document.querySelector(this.gateway.button.mini_cart_wrapper) !==
|
||||
null || document.querySelector(this.gateway.hosted_fields.mini_cart_wrapper) !==
|
||||
null;
|
||||
if (!this.gateway.can_save_vault_token) {
|
||||
return;
|
||||
}
|
||||
|
||||
return document.querySelector(this.gateway.button.mini_cart_wrapper) !== null
|
||||
|| document.querySelector(this.gateway.hosted_fields.mini_cart_wrapper) !== null;
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -40,4 +43,4 @@ class MiniCartBootstap {
|
|||
}
|
||||
}
|
||||
|
||||
export default MiniCartBootstap;
|
||||
export default MiniCartBootstap;
|
||||
|
|
|
@ -181,7 +181,7 @@ class CreditCardRenderer {
|
|||
this.errorHandler.clear();
|
||||
|
||||
if (this.formValid && this.cardValid) {
|
||||
const save_card = this.defaultConfig.save_card ? true : false;
|
||||
const save_card = this.defaultConfig.can_save_vault_token ? true : false;
|
||||
let vault = document.getElementById('ppcp-credit-card-vault') ?
|
||||
document.getElementById('ppcp-credit-card-vault').checked : save_card;
|
||||
if (this.defaultConfig.enforce_vault) {
|
||||
|
@ -216,8 +216,11 @@ class CreditCardRenderer {
|
|||
this.spinner.unblock();
|
||||
return contextConfig.onApprove(payload);
|
||||
}).catch(err => {
|
||||
console.error(err);
|
||||
this.spinner.unblock();
|
||||
this.errorHandler.clear();
|
||||
if (err.details.length > 0) {
|
||||
this.errorHandler.message(err.details.map(d => `${d.issue} ${d.description}`).join('<br/>'), true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.spinner.unblock();
|
||||
|
|
|
@ -686,7 +686,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
),
|
||||
),
|
||||
'enforce_vault' => $this->has_subscriptions(),
|
||||
'save_card' => $this->can_save_vault_token(),
|
||||
'can_save_vault_token' => $this->can_save_vault_token(),
|
||||
'bn_codes' => $this->bn_codes(),
|
||||
'payer' => $this->payerData(),
|
||||
'button' => array(
|
||||
|
|
|
@ -216,6 +216,7 @@ return array(
|
|||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
$subscription_helper = $container->get( 'subscription.helper' );
|
||||
return new OrderProcessor(
|
||||
$session_handler,
|
||||
$order_endpoint,
|
||||
|
@ -224,7 +225,8 @@ return array(
|
|||
$authorized_payments_processor,
|
||||
$settings,
|
||||
$logger,
|
||||
$environment
|
||||
$environment,
|
||||
$subscription_helper
|
||||
);
|
||||
},
|
||||
'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
|
||||
|
@ -238,7 +240,16 @@ return array(
|
|||
$payments_endpoint = $container->get( 'api.endpoint.payments' );
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
$notice = $container->get( 'wcgateway.notice.authorize-order-action' );
|
||||
return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint, $logger, $notice );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$subscription_helper = $container->get( 'subscription.helper' );
|
||||
return new AuthorizedPaymentsProcessor(
|
||||
$order_endpoint,
|
||||
$payments_endpoint,
|
||||
$logger,
|
||||
$notice,
|
||||
$settings,
|
||||
$subscription_helper
|
||||
);
|
||||
},
|
||||
'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction {
|
||||
$column = $container->get( 'wcgateway.admin.orders-payment-status-column' );
|
||||
|
|
|
@ -10,8 +10,6 @@ declare( strict_types=1 );
|
|||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
|
||||
|
||||
use Exception;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
|
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\WcGateway\Processor;
|
||||
|
||||
use Exception;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WC_Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
|
@ -20,6 +21,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\CaptureStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
||||
|
||||
|
@ -74,6 +76,18 @@ class AuthorizedPaymentsProcessor {
|
|||
*/
|
||||
private $notice;
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var SubscriptionHelper
|
||||
*/
|
||||
private $subscription_helper;
|
||||
|
||||
/**
|
||||
* AuthorizedPaymentsProcessor constructor.
|
||||
*
|
||||
|
@ -81,18 +95,23 @@ class AuthorizedPaymentsProcessor {
|
|||
* @param PaymentsEndpoint $payments_endpoint The Payments endpoint.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param AuthorizeOrderActionNotice $notice The notice.
|
||||
* @param ContainerInterface $config The settings.
|
||||
*/
|
||||
public function __construct(
|
||||
OrderEndpoint $order_endpoint,
|
||||
PaymentsEndpoint $payments_endpoint,
|
||||
LoggerInterface $logger,
|
||||
AuthorizeOrderActionNotice $notice
|
||||
AuthorizeOrderActionNotice $notice,
|
||||
ContainerInterface $config,
|
||||
SubscriptionHelper $subscription_helper
|
||||
) {
|
||||
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->payments_endpoint = $payments_endpoint;
|
||||
$this->logger = $logger;
|
||||
$this->notice = $notice;
|
||||
$this->config = $config;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,6 +209,27 @@ class AuthorizedPaymentsProcessor {
|
|||
return false;
|
||||
}
|
||||
|
||||
public function capture_authorized_payments_for_customer(int $customer_id) {
|
||||
|
||||
$wc_orders = wc_get_orders(array(
|
||||
'customer_id' => $customer_id,
|
||||
'status' => array('wc-on-hold'),
|
||||
'limit' => -1,
|
||||
));
|
||||
|
||||
if ($this->config->has('intent') && strtoupper((string)$this->config->get('intent')) === 'CAPTURE') {
|
||||
foreach ($wc_orders as $wc_order) {
|
||||
if(
|
||||
$this->subscription_helper->has_subscription( $wc_order->get_id() )
|
||||
&& $wc_order->get_meta('_ppcp_captured_vault_webhook') === 'false'
|
||||
) {
|
||||
$this->capture_authorized_payment($wc_order);
|
||||
$wc_order->update_meta_data('_ppcp_captured_vault_webhook', 'true');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the notice for a status.
|
||||
*
|
||||
|
|
|
@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
|
|||
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
@ -98,6 +99,11 @@ class OrderProcessor {
|
|||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @var SubscriptionHelper
|
||||
*/
|
||||
private $subscription_helper;
|
||||
|
||||
/**
|
||||
* OrderProcessor constructor.
|
||||
*
|
||||
|
@ -118,7 +124,8 @@ class OrderProcessor {
|
|||
AuthorizedPaymentsProcessor $authorized_payments_processor,
|
||||
Settings $settings,
|
||||
LoggerInterface $logger,
|
||||
Environment $environment
|
||||
Environment $environment,
|
||||
SubscriptionHelper $subscription_helper
|
||||
) {
|
||||
|
||||
$this->session_handler = $session_handler;
|
||||
|
@ -129,6 +136,7 @@ class OrderProcessor {
|
|||
$this->settings = $settings;
|
||||
$this->environment = $environment;
|
||||
$this->logger = $logger;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,6 +181,10 @@ class OrderProcessor {
|
|||
$order = $this->order_endpoint->authorize( $order );
|
||||
|
||||
$wc_order->update_meta_data( AuthorizedPaymentsProcessor::CAPTURED_META_KEY, 'false' );
|
||||
|
||||
if($this->subscription_helper->has_subscription( $wc_order->get_id() )) {
|
||||
$wc_order->update_meta_data('_ppcp_captured_vault_webhook', 'false');
|
||||
}
|
||||
}
|
||||
|
||||
$transaction_id = $this->get_paypal_order_transaction_id( $order );
|
||||
|
|
|
@ -23,6 +23,8 @@ use WooCommerce\PayPalCommerce\Webhooks\Handler\PaymentCaptureCompleted;
|
|||
use WooCommerce\PayPalCommerce\Webhooks\Handler\PaymentCaptureRefunded;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\PaymentCaptureReversed;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\VaultCreditCardCreated;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\VaultPaymentTokenCreated;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Status\Assets\WebhooksStatusPageAssets;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Status\WebhookSimulation;
|
||||
|
||||
|
@ -67,12 +69,15 @@ return array(
|
|||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
$prefix = $container->get( 'api.prefix' );
|
||||
$order_endpoint = $container->get( 'api.endpoint.order' );
|
||||
$authorized_payments_processor = $container->get('wcgateway.processor.authorized-payments');
|
||||
return array(
|
||||
new CheckoutOrderApproved( $logger, $prefix, $order_endpoint ),
|
||||
new CheckoutOrderCompleted( $logger, $prefix ),
|
||||
new PaymentCaptureRefunded( $logger, $prefix ),
|
||||
new PaymentCaptureReversed( $logger, $prefix ),
|
||||
new PaymentCaptureCompleted( $logger, $prefix, $order_endpoint ),
|
||||
new VaultPaymentTokenCreated($logger, $prefix, $authorized_payments_processor),
|
||||
new VaultCreditCardCreated($logger, $prefix),
|
||||
);
|
||||
},
|
||||
|
||||
|
|
55
modules/ppcp-webhooks/src/Handler/VaultCreditCardCreated.php
Normal file
55
modules/ppcp-webhooks/src/Handler/VaultCreditCardCreated.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/**
|
||||
* Handles the Webhook VAULT.PAYMENT-TOKEN.CREATED
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Webhooks\Handler
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Webhooks\Handler;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class VaultCreditCardCreated implements RequestHandler
|
||||
{
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
public function __construct(LoggerInterface $logger, string $prefix)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
public function event_types(): array
|
||||
{
|
||||
return array(
|
||||
'VAULT.CREDIT-CARD.CREATED',
|
||||
);
|
||||
}
|
||||
|
||||
public function responsible_for_request(\WP_REST_Request $request): bool
|
||||
{
|
||||
return in_array( $request['event_type'], $this->event_types(), true );
|
||||
}
|
||||
|
||||
public function handle_request(\WP_REST_Request $request): \WP_REST_Response
|
||||
{
|
||||
$message = 'VAULT.CREDIT-CARD.CREATED received.';
|
||||
$this->logger->log('info', $message);
|
||||
$response = array(
|
||||
'success' => true,
|
||||
'message' => $message,
|
||||
);
|
||||
|
||||
return rest_ensure_response($response);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Handles the Webhook VAULT.PAYMENT-TOKEN.CREATED
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Webhooks\Handler
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Webhooks\Handler;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||
|
||||
class VaultPaymentTokenCreated implements RequestHandler
|
||||
{
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* @var AuthorizedPaymentsProcessor
|
||||
*/
|
||||
protected $authorized_payments_processor;
|
||||
|
||||
public function __construct(LoggerInterface $logger, string $prefix, AuthorizedPaymentsProcessor $authorized_payments_processor)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->prefix = $prefix;
|
||||
$this->authorized_payments_processor = $authorized_payments_processor;
|
||||
}
|
||||
|
||||
public function event_types(): array
|
||||
{
|
||||
return array(
|
||||
'VAULT.PAYMENT-TOKEN.CREATED',
|
||||
);
|
||||
}
|
||||
|
||||
public function responsible_for_request(\WP_REST_Request $request): bool
|
||||
{
|
||||
return in_array( $request['event_type'], $this->event_types(), true );
|
||||
}
|
||||
|
||||
public function handle_request(\WP_REST_Request $request): \WP_REST_Response
|
||||
{
|
||||
$response = array( 'success' => false );
|
||||
$webhook_id = (string) ( $request['id'] ?? '' );
|
||||
|
||||
$customer_id = $request['resource']['customer_id'] ?? '';
|
||||
if(!$customer_id) {
|
||||
$message = sprintf( 'No customer id for webhook event %s was found.', $webhook_id );
|
||||
$this->logger->warning( $message, array( 'request' => $request ) );
|
||||
$response['message'] = $message;
|
||||
return new \WP_REST_Response( $response );
|
||||
}
|
||||
|
||||
$customer_id_parts = explode('-', $customer_id);
|
||||
$wc_customer_id = (int) end($customer_id_parts);
|
||||
$this->authorized_payments_processor->capture_authorized_payments_for_customer($wc_customer_id);
|
||||
|
||||
$response['success'] = true;
|
||||
return rest_ensure_response($response);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue