mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge pull request #8 from woocommerce/issue-4-disable-card
Prevents DCC payments of disabled card brands
This commit is contained in:
commit
ce870122f2
8 changed files with 200 additions and 423 deletions
|
@ -10,7 +10,11 @@ const onApprove = (context, errorHandler) => {
|
|||
return res.json();
|
||||
}).then((data)=>{
|
||||
if (!data.success) {
|
||||
errorHandler.genericError();
|
||||
if (data.data.code === 100) {
|
||||
errorHandler.message(data.data.message);
|
||||
} else {
|
||||
errorHandler.genericError();
|
||||
}
|
||||
console.error(data);
|
||||
if (typeof actions.restart !== 'undefined') {
|
||||
return actions.restart();
|
||||
|
|
|
@ -5,6 +5,7 @@ class CreditCardRenderer {
|
|||
constructor(defaultConfig, errorHandler) {
|
||||
this.defaultConfig = defaultConfig;
|
||||
this.errorHandler = errorHandler;
|
||||
this.cardValid = false;
|
||||
}
|
||||
|
||||
render(wrapper, contextConfig) {
|
||||
|
@ -96,7 +97,7 @@ class CreditCardRenderer {
|
|||
return state.fields[key].isValid;
|
||||
});
|
||||
|
||||
if (formValid) {
|
||||
if (formValid && this.cardValid) {
|
||||
|
||||
let vault = document.querySelector(wrapper + ' .ppcp-credit-card-vault') ?
|
||||
document.querySelector(wrapper + ' .ppcp-credit-card-vault').checked : false;
|
||||
|
@ -110,12 +111,21 @@ class CreditCardRenderer {
|
|||
return contextConfig.onApprove(payload);
|
||||
});
|
||||
} else {
|
||||
this.errorHandler.message(this.defaultConfig.hosted_fields.labels.fields_not_valid);
|
||||
const message = ! this.cardValid ? this.defaultConfig.hosted_fields.labels.card_not_supported : this.defaultConfig.hosted_fields.labels.fields_not_valid;
|
||||
this.errorHandler.message(message);
|
||||
}
|
||||
}
|
||||
hostedFields.on('inputSubmitRequest', function () {
|
||||
submitEvent(null);
|
||||
});
|
||||
hostedFields.on('cardTypeChange', (event) => {
|
||||
if ( ! event.cards.length ) {
|
||||
this.cardValid = false;
|
||||
return;
|
||||
}
|
||||
const validCards = this.defaultConfig.hosted_fields.valid_cards;
|
||||
this.cardValid = validCards.indexOf(event.cards[0].type) !== -1;
|
||||
})
|
||||
document.querySelector(wrapper + ' button').addEventListener(
|
||||
'click',
|
||||
submitEvent
|
||||
|
|
|
@ -9,7 +9,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Button;
|
||||
|
||||
use Dhii\Data\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\DisabledSmartButton;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButton;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
||||
|
@ -134,10 +133,19 @@ return array(
|
|||
},
|
||||
'button.endpoint.approve-order' => static function ( $container ): ApproveOrderEndpoint {
|
||||
$request_data = $container->get( 'button.request-data' );
|
||||
$order_endpoint = $container->get( 'api.endpoint.order' );
|
||||
$order_endpoint = $container->get( 'api.endpoint.order' );
|
||||
$session_handler = $container->get( 'session.handler' );
|
||||
$three_d_secure = $container->get( 'button.helper.three-d-secure' );
|
||||
return new ApproveOrderEndpoint( $request_data, $order_endpoint, $session_handler, $three_d_secure );
|
||||
$three_d_secure = $container->get( 'button.helper.three-d-secure' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
||||
return new ApproveOrderEndpoint(
|
||||
$request_data,
|
||||
$order_endpoint,
|
||||
$session_handler,
|
||||
$three_d_secure,
|
||||
$settings,
|
||||
$dcc_applies
|
||||
);
|
||||
},
|
||||
'button.endpoint.data-client-id' => static function( $container ) : DataClientIdEndpoint {
|
||||
$request_data = $container->get( 'button.request-data' );
|
||||
|
|
|
@ -615,7 +615,12 @@ class SmartButton implements SmartButtonInterface {
|
|||
'Unfortunatly, your credit card details are not valid.',
|
||||
'paypal-payments-for-woocommerce'
|
||||
),
|
||||
'card_not_supported' => __(
|
||||
'Unfortunatly, we do not support your credit card.',
|
||||
'paypal-payments-for-woocommerce'
|
||||
),
|
||||
),
|
||||
'valid_cards' => $this->dcc_applies->valid_cards(),
|
||||
),
|
||||
'messages' => $this->message_values(),
|
||||
'labels' => array(
|
||||
|
@ -698,9 +703,9 @@ class SmartButton implements SmartButtonInterface {
|
|||
if ( 'GB' === $country ) {
|
||||
$disable_funding[] = 'card';
|
||||
}
|
||||
|
||||
$params['disable-funding'] = implode( ',', array_unique( $disable_funding ) );
|
||||
$smart_button_url = add_query_arg( $params, 'https://www.paypal.com/sdk/js' );
|
||||
|
||||
$smart_button_url = add_query_arg( $params, 'https://www.paypal.com/sdk/js' );
|
||||
return $smart_button_url;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,11 @@ namespace WooCommerce\PayPalCommerce\Button\Endpoint;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
* Class ApproveOrderEndpoint
|
||||
|
@ -53,6 +55,20 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
*/
|
||||
private $threed_secure;
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
* @var Settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* The DCC applies object.
|
||||
*
|
||||
* @var DccApplies
|
||||
*/
|
||||
private $dcc_applies;
|
||||
|
||||
/**
|
||||
* ApproveOrderEndpoint constructor.
|
||||
*
|
||||
|
@ -60,18 +76,24 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param SessionHandler $session_handler The session handler.
|
||||
* @param ThreeDSecure $three_d_secure The 3d secure helper object.
|
||||
* @param Settings $settings The settings.
|
||||
* @param DccApplies $dcc_applies The DCC applies object.
|
||||
*/
|
||||
public function __construct(
|
||||
RequestData $request_data,
|
||||
OrderEndpoint $order_endpoint,
|
||||
SessionHandler $session_handler,
|
||||
ThreeDSecure $three_d_secure
|
||||
ThreeDSecure $three_d_secure,
|
||||
Settings $settings,
|
||||
DccApplies $dcc_applies
|
||||
) {
|
||||
|
||||
$this->request_data = $request_data;
|
||||
$this->api_endpoint = $order_endpoint;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->threed_secure = $three_d_secure;
|
||||
$this->settings = $settings;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,6 +132,23 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
}
|
||||
|
||||
if ( $order->payment_source() && $order->payment_source()->card() ) {
|
||||
if ( $this->settings->has( 'disable_cards' ) ) {
|
||||
$disabled_cards = (array) $this->settings->get( 'disable_cards' );
|
||||
$card = strtolower( $order->payment_source()->card()->brand() );
|
||||
if ( 'master_card' === $card ) {
|
||||
$card = 'mastercard';
|
||||
}
|
||||
|
||||
if ( ! $this->dcc_applies->can_process_card( $card ) || in_array( $card, $disabled_cards, true ) ) {
|
||||
throw new RuntimeException(
|
||||
__(
|
||||
'Unfortunately, we do not accept this card.',
|
||||
'paypal-payments-for-woocommerce'
|
||||
),
|
||||
100
|
||||
);
|
||||
}
|
||||
}
|
||||
$proceed = $this->threed_secure->proceed_with_order( $order );
|
||||
if ( ThreeDSecure::RETRY === $proceed ) {
|
||||
throw new RuntimeException(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue