mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
Add PayPal WC payment token (WIP)
This commit is contained in:
parent
e5cced2008
commit
f9e6fe7aed
6 changed files with 74 additions and 3 deletions
|
@ -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 ),
|
||||
);
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue