Add PayPal WC payment token (WIP)

This commit is contained in:
emilicastells 2022-11-23 17:00:04 +01:00
parent e5cced2008
commit f9e6fe7aed
No known key found for this signature in database
GPG key ID: 1520C07081754570
6 changed files with 74 additions and 3 deletions

View file

@ -73,6 +73,8 @@ return array(
$prefix = $container->get( 'api.prefix' );
$order_endpoint = $container->get( 'api.endpoint.order' );
$authorized_payments_processor = $container->get( 'wcgateway.processor.authorized-payments' );
$payment_token_paypal = $container->get('vaulting.payment-token-paypal');
return array(
new CheckoutOrderApproved( $logger, $prefix, $order_endpoint ),
new CheckoutOrderCompleted( $logger, $prefix ),
@ -80,7 +82,7 @@ return array(
new PaymentCaptureRefunded( $logger, $prefix ),
new PaymentCaptureReversed( $logger, $prefix ),
new PaymentCaptureCompleted( $logger, $prefix, $order_endpoint ),
new VaultPaymentTokenCreated( $logger, $prefix, $authorized_payments_processor ),
new VaultPaymentTokenCreated( $logger, $prefix, $authorized_payments_processor, $payment_token_paypal ),
new VaultCreditCardCreated( $logger, $prefix ),
new PaymentCapturePending( $logger ),
);

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Webhooks\Handler;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenPayPal;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
use WP_REST_Request;
use WP_REST_Response;
@ -40,17 +41,31 @@ class VaultPaymentTokenCreated implements RequestHandler {
*/
protected $authorized_payments_processor;
/**
* WooCommerce Payment token PayPal.
*
* @var PaymentTokenPayPal
*/
private $payment_token_paypal;
/**
* VaultPaymentTokenCreated constructor.
*
* @param LoggerInterface $logger The logger.
* @param string $prefix The prefix.
* @param AuthorizedPaymentsProcessor $authorized_payments_processor The authorized payment processor.
* @param PaymentTokenPayPal $payment_token_paypal WooCommerce Payment token PayPal.
*/
public function __construct( LoggerInterface $logger, string $prefix, AuthorizedPaymentsProcessor $authorized_payments_processor ) {
public function __construct(
LoggerInterface $logger,
string $prefix,
AuthorizedPaymentsProcessor $authorized_payments_processor,
PaymentTokenPayPal $payment_token_paypal
) {
$this->logger = $logger;
$this->prefix = $prefix;
$this->authorized_payments_processor = $authorized_payments_processor;
$this->payment_token_paypal = $payment_token_paypal;
}
/**
@ -98,6 +113,13 @@ class VaultPaymentTokenCreated implements RequestHandler {
$wc_customer_id = (int) str_replace( $this->prefix, '', $customer_id );
$this->authorized_payments_processor->capture_authorized_payments_for_customer( $wc_customer_id );
if(isset($request['resource']['id'])) {
$this->logger->info("Setting token {$request['resource']['id']} for user {$wc_customer_id}");
$this->payment_token_paypal->set_token($request['resource']['id']);
$this->payment_token_paypal->set_user_id($wc_customer_id);
$this->payment_token_paypal->save();
}
$response['success'] = true;
return new WP_REST_Response( $response );
}