mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
check in approve order endpoint whether card is disabled and return error message accordingly.
This commit is contained in:
parent
1dc9a05452
commit
c748c145db
4 changed files with 28 additions and 6 deletions
|
@ -10,7 +10,11 @@ const onApprove = (context, errorHandler) => {
|
|||
return res.json();
|
||||
}).then((data)=>{
|
||||
if (!data.success) {
|
||||
if (data.data.code === 100) {
|
||||
errorHandler.message(data.data.message);
|
||||
} else {
|
||||
errorHandler.genericError();
|
||||
}
|
||||
console.error(data);
|
||||
if (typeof actions.restart !== 'undefined') {
|
||||
return actions.restart();
|
||||
|
|
|
@ -137,7 +137,8 @@ return array(
|
|||
$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 );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
return new ApproveOrderEndpoint( $request_data, $order_endpoint, $session_handler, $three_d_secure, $settings );
|
||||
},
|
||||
'button.endpoint.data-client-id' => static function( $container ) : DataClientIdEndpoint {
|
||||
$request_data = $container->get( 'button.request-data' );
|
||||
|
|
|
@ -684,8 +684,8 @@ 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' );
|
||||
return $smart_button_url;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
|||
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 +54,8 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
*/
|
||||
private $threed_secure;
|
||||
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* ApproveOrderEndpoint constructor.
|
||||
*
|
||||
|
@ -65,13 +68,15 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
RequestData $request_data,
|
||||
OrderEndpoint $order_endpoint,
|
||||
SessionHandler $session_handler,
|
||||
ThreeDSecure $three_d_secure
|
||||
ThreeDSecure $three_d_secure,
|
||||
Settings $settings
|
||||
) {
|
||||
|
||||
$this->request_data = $request_data;
|
||||
$this->api_endpoint = $order_endpoint;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->threed_secure = $three_d_secure;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,6 +115,18 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
}
|
||||
|
||||
if ( $order->payment_source() && $order->payment_source()->card() ) {
|
||||
if (
|
||||
$this->settings->has('disable_cards')
|
||||
&& in_array( strtolower($order->payment_source()->card()->brand()), (array) $this->settings->get( 'disable_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