mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Move SCA payment indicator from application_context
to payment_source
This commit is contained in:
parent
08a2b15fcb
commit
38bf05577e
3 changed files with 9 additions and 35 deletions
|
@ -361,14 +361,12 @@ return array(
|
||||||
$application_context_repository = $container->get( 'api.repository.application-context' );
|
$application_context_repository = $container->get( 'api.repository.application-context' );
|
||||||
$application_context_factory = $container->get( 'api.factory.application-context' );
|
$application_context_factory = $container->get( 'api.factory.application-context' );
|
||||||
$payment_source_factory = $container->get( 'api.factory.payment-source' );
|
$payment_source_factory = $container->get( 'api.factory.payment-source' );
|
||||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
|
||||||
return new OrderFactory(
|
return new OrderFactory(
|
||||||
$purchase_unit_factory,
|
$purchase_unit_factory,
|
||||||
$payer_factory,
|
$payer_factory,
|
||||||
$application_context_repository,
|
$application_context_repository,
|
||||||
$application_context_factory,
|
$application_context_factory,
|
||||||
$payment_source_factory,
|
$payment_source_factory
|
||||||
$logger
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.factory.payments' => static function ( ContainerInterface $container ): PaymentsFactory {
|
'api.factory.payments' => static function ( ContainerInterface $container ): PaymentsFactory {
|
||||||
|
|
|
@ -9,7 +9,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
||||||
|
@ -56,13 +55,6 @@ class OrderFactory {
|
||||||
*/
|
*/
|
||||||
private $payment_source_factory;
|
private $payment_source_factory;
|
||||||
|
|
||||||
/**
|
|
||||||
* The logger.
|
|
||||||
*
|
|
||||||
* @var LoggerInterface
|
|
||||||
*/
|
|
||||||
private LoggerInterface $logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OrderFactory constructor.
|
* OrderFactory constructor.
|
||||||
*
|
*
|
||||||
|
@ -71,15 +63,13 @@ class OrderFactory {
|
||||||
* @param ApplicationContextRepository $application_context_repository The Application Context repository.
|
* @param ApplicationContextRepository $application_context_repository The Application Context repository.
|
||||||
* @param ApplicationContextFactory $application_context_factory The Application Context factory.
|
* @param ApplicationContextFactory $application_context_factory The Application Context factory.
|
||||||
* @param PaymentSourceFactory $payment_source_factory The Payment Source factory.
|
* @param PaymentSourceFactory $payment_source_factory The Payment Source factory.
|
||||||
* @param LoggerInterface $logger The logger.
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
PurchaseUnitFactory $purchase_unit_factory,
|
PurchaseUnitFactory $purchase_unit_factory,
|
||||||
PayerFactory $payer_factory,
|
PayerFactory $payer_factory,
|
||||||
ApplicationContextRepository $application_context_repository,
|
ApplicationContextRepository $application_context_repository,
|
||||||
ApplicationContextFactory $application_context_factory,
|
ApplicationContextFactory $application_context_factory,
|
||||||
PaymentSourceFactory $payment_source_factory,
|
PaymentSourceFactory $payment_source_factory
|
||||||
LoggerInterface $logger
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||||
|
@ -87,7 +77,6 @@ class OrderFactory {
|
||||||
$this->application_context_repository = $application_context_repository;
|
$this->application_context_repository = $application_context_repository;
|
||||||
$this->application_context_factory = $application_context_factory;
|
$this->application_context_factory = $application_context_factory;
|
||||||
$this->payment_source_factory = $payment_source_factory;
|
$this->payment_source_factory = $payment_source_factory;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -123,29 +123,16 @@ class SubscriptionModule implements ModuleInterface {
|
||||||
&& isset( $data['payment_source']['token'] ) && $data['payment_source']['token']['type'] === 'PAYMENT_METHOD_TOKEN'
|
&& isset( $data['payment_source']['token'] ) && $data['payment_source']['token']['type'] === 'PAYMENT_METHOD_TOKEN'
|
||||||
&& isset( $data['payment_source']['token']['source']->card )
|
&& isset( $data['payment_source']['token']['source']->card )
|
||||||
) {
|
) {
|
||||||
$renewal_order_id = absint( $data['purchase_units'][0]['custom_id'] );
|
$data['payment_source'] = array(
|
||||||
$subscriptions = wcs_get_subscriptions_for_renewal_order( $renewal_order_id );
|
'card' => array(
|
||||||
$subscriptions_values = array_values( $subscriptions );
|
'vault_id' => $data['payment_source']['token']['id'],
|
||||||
$latest_subscription = array_shift( $subscriptions_values );
|
'stored_credential' => array(
|
||||||
if ( is_a( $latest_subscription, WC_Subscription::class ) ) {
|
|
||||||
$related_renewal_orders = $latest_subscription->get_related_orders( 'ids', 'renewal' );
|
|
||||||
$latest_order_id_with_transaction = array_slice( $related_renewal_orders, 1, 1, false );
|
|
||||||
$order_id = ! empty( $latest_order_id_with_transaction ) ? $latest_order_id_with_transaction[0] : 0;
|
|
||||||
if ( count( $related_renewal_orders ) === 1 ) {
|
|
||||||
$order_id = $latest_subscription->get_parent_id();
|
|
||||||
}
|
|
||||||
|
|
||||||
$wc_order = wc_get_order( $order_id );
|
|
||||||
if ( is_a( $wc_order, WC_Order::class ) ) {
|
|
||||||
$transaction_id = $wc_order->get_transaction_id();
|
|
||||||
$data['application_context']['stored_payment_source'] = array(
|
|
||||||
'payment_initiator' => 'MERCHANT',
|
'payment_initiator' => 'MERCHANT',
|
||||||
'payment_type' => 'RECURRING',
|
'payment_type' => 'RECURRING',
|
||||||
'usage' => 'SUBSEQUENT',
|
'usage' => 'SUBSEQUENT',
|
||||||
'previous_transaction_reference' => $transaction_id,
|
),
|
||||||
);
|
),
|
||||||
}
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue