mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Add 3ds verification method
This commit is contained in:
parent
fe089484a0
commit
c3d0039f83
4 changed files with 46 additions and 19 deletions
|
@ -69,6 +69,7 @@ const init = () => {
|
|||
const result = await response.json();
|
||||
if(result.success === true) {
|
||||
window.location.href = ppcp_add_payment_method.payment_methods_page;
|
||||
return;
|
||||
}
|
||||
|
||||
errorHandler.message(ppcp_add_payment_method.error_message);
|
||||
|
@ -105,7 +106,8 @@ const init = () => {
|
|||
},
|
||||
body: JSON.stringify({
|
||||
nonce: ppcp_add_payment_method.ajax.create_setup_token.nonce,
|
||||
payment_method: PaymentMethods.CARDS
|
||||
payment_method: PaymentMethods.CARDS,
|
||||
verification_method: ppcp_add_payment_method.verification_method
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -133,6 +135,7 @@ const init = () => {
|
|||
const result = await response.json();
|
||||
if(result.success === true) {
|
||||
window.location.href = ppcp_add_payment_method.payment_methods_page;
|
||||
return;
|
||||
}
|
||||
|
||||
errorHandler.message(ppcp_add_payment_method.error_message);
|
||||
|
|
|
@ -101,7 +101,7 @@ class CreatePaymentToken implements EndpointInterface {
|
|||
update_user_meta( get_current_user_id(), '_ppcp_target_customer_id', $result->customer->id );
|
||||
|
||||
$payment_method = $data['payment_method'] ?? '';
|
||||
if($payment_method === PayPalGateway::ID) {
|
||||
if ( $payment_method === PayPalGateway::ID ) {
|
||||
$email = '';
|
||||
if ( isset( $result->payment_source->paypal->email_address ) ) {
|
||||
$email = $result->payment_source->paypal->email_address;
|
||||
|
@ -114,17 +114,21 @@ class CreatePaymentToken implements EndpointInterface {
|
|||
);
|
||||
}
|
||||
|
||||
if ($payment_method === CreditCardGateway::ID) {
|
||||
if ( $payment_method === CreditCardGateway::ID ) {
|
||||
$token = new \WC_Payment_Token_CC();
|
||||
$token->set_token($result->id);
|
||||
$token->set_user_id(get_current_user_id());
|
||||
$token->set_gateway_id(CreditCardGateway::ID);
|
||||
$token->set_token( $result->id );
|
||||
$token->set_user_id( get_current_user_id() );
|
||||
$token->set_gateway_id( CreditCardGateway::ID );
|
||||
|
||||
$token->set_last4($result->payment_source->card->last_digits ?? '');
|
||||
$expiry = explode('-', $result->payment_source->card->expiry ?? '');
|
||||
$token->set_expiry_year($expiry[0] ?? '');
|
||||
$token->set_expiry_month($expiry[1] ?? '');
|
||||
$token->set_card_type($result->payment_source->card->brand ?? '');
|
||||
$token->set_last4( $result->payment_source->card->last_digits ?? '' );
|
||||
$expiry = explode( '-', $result->payment_source->card->expiry ?? '' );
|
||||
$token->set_expiry_year( $expiry[0] ?? '' );
|
||||
$token->set_expiry_month( $expiry[1] ?? '' );
|
||||
|
||||
$brand = $result->payment_source->card->brand ?? __( 'N/A', 'woocommerce-paypal-payments' );
|
||||
if ( $brand ) {
|
||||
$token->set_card_type( $brand );
|
||||
}
|
||||
|
||||
$token->save();
|
||||
}
|
||||
|
|
|
@ -82,10 +82,24 @@ class CreateSetupToken implements EndpointInterface {
|
|||
);
|
||||
|
||||
$payment_method = $data['payment_method'] ?? '';
|
||||
if($payment_method === CreditCardGateway::ID) {
|
||||
if ( $payment_method === CreditCardGateway::ID ) {
|
||||
$properties = (object) array();
|
||||
|
||||
$verification_method = $data['verification_method'] ?? '';
|
||||
if ( $verification_method === 'SCA_WHEN_REQUIRED' || $verification_method === 'SCA_ALWAYS' ) {
|
||||
$properties = (object) array(
|
||||
'verification_method' => $verification_method,
|
||||
'usage_type' => 'MERCHANT',
|
||||
'experience_context' => (object) array(
|
||||
'return_url' => esc_url( wc_get_account_endpoint_url( 'payment-methods' ) ),
|
||||
'cancel_url' => esc_url( wc_get_account_endpoint_url( 'add-payment-method' ) ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$payment_source = new PaymentSource(
|
||||
'card',
|
||||
(object) array()
|
||||
$properties
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface
|
|||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
* Class SavePaymentMethodsModule
|
||||
|
@ -218,6 +219,10 @@ class SavePaymentMethodsModule implements ModuleInterface {
|
|||
|
||||
$id_token = $api->id_token( $target_customer_id );
|
||||
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
$verification_method = $settings->has( '3d_secure_contingency' ) ? $settings->get( '3d_secure_contingency' ) : '';
|
||||
|
||||
wp_localize_script(
|
||||
'ppcp-add-payment-method',
|
||||
'ppcp_add_payment_method',
|
||||
|
@ -225,8 +230,9 @@ class SavePaymentMethodsModule implements ModuleInterface {
|
|||
'client_id' => $c->get( 'button.client_id' ),
|
||||
'merchant_id' => $c->get( 'api.merchant_id' ),
|
||||
'id_token' => $id_token,
|
||||
'payment_methods_page' => wc_get_account_endpoint_url('payment-methods'),
|
||||
'payment_methods_page' => wc_get_account_endpoint_url( 'payment-methods' ),
|
||||
'error_message' => __( 'Could not save payment method.', 'woocommerce-paypal-payments' ),
|
||||
'verification_method' => $verification_method,
|
||||
'ajax' => array(
|
||||
'create_setup_token' => array(
|
||||
'endpoint' => \WC_AJAX::get_endpoint( CreateSetupToken::ENDPOINT ),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue