mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Add sca payment indicator for credit card renewals
This commit is contained in:
parent
9533528c5c
commit
29c8c04dc9
1 changed files with 32 additions and 0 deletions
|
@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\Subscription;
|
||||||
use Dhii\Container\ServiceProvider;
|
use Dhii\Container\ServiceProvider;
|
||||||
use Dhii\Modular\Module\ModuleInterface;
|
use Dhii\Modular\Module\ModuleInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use WC_Order;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||||
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
||||||
|
@ -94,6 +95,37 @@ class SubscriptionModule implements ModuleInterface {
|
||||||
20,
|
20,
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
add_filter(
|
||||||
|
'ppcp_create_order_request_body_data',
|
||||||
|
function( $data ) use ( $c ) {
|
||||||
|
$wc_order_action = filter_input( INPUT_POST, 'wc_order_action', FILTER_SANITIZE_STRING ) ?? '';
|
||||||
|
if ( $wc_order_action === 'wcs_process_renewal' ) {
|
||||||
|
if ( isset( $data['payment_source']['token'] ) && $data['payment_source']['token']['type'] === 'PAYMENT_METHOD_TOKEN' ) {
|
||||||
|
if ( isset( $data['payment_source']['token']['source']->card ) ) {
|
||||||
|
$renewal_order_id = absint( $data['purchase_units'][0]['custom_id'] );
|
||||||
|
$subscriptions = wcs_get_subscriptions_for_renewal_order( $renewal_order_id );
|
||||||
|
$subscriptions_values = array_values( $subscriptions );
|
||||||
|
$latest_subscription = array_shift( $subscriptions_values );
|
||||||
|
$latest_order_id_with_transaction = array_slice( $latest_subscription->get_related_orders( 'ids', 'renewal' ), 1, 1, false );
|
||||||
|
|
||||||
|
$wc_order = wc_get_order( $latest_order_id_with_transaction[0] );
|
||||||
|
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_type' => 'RECURRING',
|
||||||
|
'usage' => 'SUBSEQUENT',
|
||||||
|
'previous_transaction_reference' => $transaction_id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue