mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Merge pull request #287 from woocommerce/PCP-302-using-a-saved-card-it-showed-an-
Add authorization flow for saved credit cards
This commit is contained in:
commit
62b5682733
4 changed files with 37 additions and 4 deletions
|
@ -390,7 +390,7 @@ class OrderEndpoint {
|
|||
}
|
||||
$json = json_decode( $response['body'] );
|
||||
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
if ( 201 !== $status_code ) {
|
||||
if ( ! in_array( $status_code, array( 200, 201 ), true ) ) {
|
||||
if ( false !== strpos( $response['body'], ErrorResponse::ORDER_ALREADY_AUTHORIZED ) ) {
|
||||
return $this->order( $order->id() );
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ return array(
|
|||
$payer_factory = $container->get( 'api.factory.payer' );
|
||||
$order_endpoint = $container->get( 'api.endpoint.order' );
|
||||
$subscription_helper = $container->get( 'subscription.helper' );
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
return new CreditCardGateway(
|
||||
$settings_renderer,
|
||||
$order_processor,
|
||||
|
@ -98,7 +99,8 @@ return array(
|
|||
$purchase_unit_factory,
|
||||
$payer_factory,
|
||||
$order_endpoint,
|
||||
$subscription_helper
|
||||
$subscription_helper,
|
||||
$logger
|
||||
);
|
||||
},
|
||||
'wcgateway.disabler' => static function ( $container ): DisableGateways {
|
||||
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
|
@ -46,6 +47,13 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
*/
|
||||
protected $subscription_helper;
|
||||
|
||||
/**
|
||||
* The logger.
|
||||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* The URL to the module.
|
||||
*
|
||||
|
@ -104,8 +112,9 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
* @param PaymentTokenRepository $payment_token_repository The payment token repository.
|
||||
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
|
||||
* @param PayerFactory $payer_factory The payer factory.
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param SubscriptionHelper $subscription_helper The subscription helper.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
*/
|
||||
public function __construct(
|
||||
SettingsRenderer $settings_renderer,
|
||||
|
@ -122,7 +131,8 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
PurchaseUnitFactory $purchase_unit_factory,
|
||||
PayerFactory $payer_factory,
|
||||
OrderEndpoint $order_endpoint,
|
||||
SubscriptionHelper $subscription_helper
|
||||
SubscriptionHelper $subscription_helper,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
|
||||
$this->id = self::ID;
|
||||
|
@ -190,6 +200,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
$this->order_endpoint = $order_endpoint;
|
||||
$this->transaction_url_provider = $transaction_url_provider;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,7 +85,27 @@ trait ProcessPaymentTrait {
|
|||
'redirect' => $this->get_return_url( $wc_order ),
|
||||
);
|
||||
}
|
||||
|
||||
if ( $order->status()->is( OrderStatus::COMPLETED ) && $order->intent() === 'AUTHORIZE' ) {
|
||||
$this->order_endpoint->authorize( $order );
|
||||
$wc_order->update_meta_data( PayPalGateway::CAPTURED_META_KEY, 'false' );
|
||||
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $order->id() );
|
||||
$wc_order->update_status(
|
||||
'on-hold',
|
||||
__( 'Awaiting payment.', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
|
||||
$this->session_handler->destroy_session_data();
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'redirect' => $this->get_return_url( $wc_order ),
|
||||
);
|
||||
}
|
||||
|
||||
$this->logger->warning( "Could neither capture nor authorize order {$order->id()} using a saved credit card:" . 'Status: ' . $order->status()->name() . ' Intent: ' . $order->intent() );
|
||||
|
||||
} catch ( RuntimeException $error ) {
|
||||
$this->logger->error( $error->getMessage() );
|
||||
$this->session_handler->destroy_session_data();
|
||||
wc_add_notice( $error->getMessage(), 'error' );
|
||||
return null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue