mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
Merge pull request #134 from woocommerce/feature/PCP-88-payment-token-vaulting
Introduce client-side vaulting and allow Subscription renewals through payment tokens
This commit is contained in:
commit
d257b270df
39 changed files with 5357 additions and 185 deletions
|
@ -252,7 +252,10 @@ class OrderEndpoint {
|
|||
);
|
||||
$this->logger->log(
|
||||
'warning',
|
||||
$error->getMessage(),
|
||||
sprintf(
|
||||
'Failed to create order. PayPal API response: %1$s',
|
||||
$error->getMessage()
|
||||
),
|
||||
array(
|
||||
'args' => $args,
|
||||
'response' => $response,
|
||||
|
@ -321,7 +324,10 @@ class OrderEndpoint {
|
|||
}
|
||||
$this->logger->log(
|
||||
'warning',
|
||||
$error->getMessage(),
|
||||
sprintf(
|
||||
'Failed to capture order. PayPal API response: %1$s',
|
||||
$error->getMessage()
|
||||
),
|
||||
array(
|
||||
'args' => $args,
|
||||
'response' => $response,
|
||||
|
@ -394,7 +400,10 @@ class OrderEndpoint {
|
|||
);
|
||||
$this->logger->log(
|
||||
'warning',
|
||||
$error->getMessage(),
|
||||
sprintf(
|
||||
'Failed to authorize order. PayPal API response: %1$s',
|
||||
$error->getMessage()
|
||||
),
|
||||
array(
|
||||
'args' => $args,
|
||||
'response' => $response,
|
||||
|
|
|
@ -36,21 +36,30 @@ class PaymentToken {
|
|||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* The payment source.
|
||||
*
|
||||
* @var \stdClass
|
||||
*/
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* PaymentToken constructor.
|
||||
*
|
||||
* @param string $id The Id.
|
||||
* @param string $type The type.
|
||||
* @param string $id The Id.
|
||||
* @param string $type The type.
|
||||
* @param \stdClass $source The source.
|
||||
* @throws RuntimeException When the type is not valid.
|
||||
*/
|
||||
public function __construct( string $id, string $type = self::TYPE_PAYMENT_METHOD_TOKEN ) {
|
||||
public function __construct( string $id, string $type = self::TYPE_PAYMENT_METHOD_TOKEN, \stdClass $source ) {
|
||||
if ( ! in_array( $type, self::VALID_TYPES, true ) ) {
|
||||
throw new RuntimeException(
|
||||
__( 'Not a valid payment source type.', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
}
|
||||
$this->id = $id;
|
||||
$this->type = $type;
|
||||
$this->id = $id;
|
||||
$this->type = $type;
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,6 +80,15 @@ class PaymentToken {
|
|||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function source(): \stdClass {
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object as array.
|
||||
*
|
||||
|
@ -78,8 +96,9 @@ class PaymentToken {
|
|||
*/
|
||||
public function to_array(): array {
|
||||
return array(
|
||||
'id' => $this->id(),
|
||||
'type' => $this->type(),
|
||||
'id' => $this->id(),
|
||||
'type' => $this->type(),
|
||||
'source' => $this->source(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,11 @@ class PaymentTokenFactory {
|
|||
__( 'No id for payment token given', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
}
|
||||
|
||||
return new PaymentToken(
|
||||
$data->id,
|
||||
( isset( $data->type ) ) ? $data->type : PaymentToken::TYPE_PAYMENT_METHOD_TOKEN
|
||||
( isset( $data->type ) ) ? $data->type : PaymentToken::TYPE_PAYMENT_METHOD_TOKEN,
|
||||
$data->source
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ document.addEventListener(
|
|||
}
|
||||
);
|
||||
|
||||
if (PayPalCommerceGateway.data_client_id.set_attribute) {
|
||||
if (PayPalCommerceGateway.data_client_id.set_attribute || PayPalCommerceGateway.data_client_id.save_paypal_account) {
|
||||
dataClientIdAttributeHandler(script, PayPalCommerceGateway.data_client_id);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,20 @@ class CheckoutBootstap {
|
|||
|
||||
jQuery(document.body).on('updated_checkout', () => {
|
||||
this.render();
|
||||
|
||||
jQuery('#saved-credit-card').on('change', () => {
|
||||
if(jQuery('#saved-credit-card').val() !== '') {
|
||||
this.renderer.hideButtons(this.gateway.button.wrapper);
|
||||
this.renderer.hideButtons(this.gateway.messages.wrapper);
|
||||
this.renderer.hideButtons(this.gateway.hosted_fields.wrapper);
|
||||
jQuery('#place_order').show();
|
||||
} else {
|
||||
jQuery('#place_order').hide();
|
||||
this.renderer.hideButtons(this.gateway.button.wrapper);
|
||||
this.renderer.hideButtons(this.gateway.messages.wrapper);
|
||||
this.renderer.showButtons(this.gateway.hosted_fields.wrapper);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
jQuery(document.body).
|
||||
|
@ -79,4 +93,4 @@ class CheckoutBootstap {
|
|||
}
|
||||
}
|
||||
|
||||
export default CheckoutBootstap;
|
||||
export default CheckoutBootstap;
|
||||
|
|
|
@ -25,6 +25,11 @@ const storeToken = (token) => {
|
|||
}
|
||||
|
||||
const dataClientIdAttributeHandler = (script, config) => {
|
||||
if(config.user === 0) {
|
||||
document.body.append(script);
|
||||
return;
|
||||
}
|
||||
|
||||
const token = storedTokenForUser(config.user);
|
||||
if (token) {
|
||||
script.setAttribute('data-client-token', token);
|
||||
|
@ -49,4 +54,4 @@ const dataClientIdAttributeHandler = (script, config) => {
|
|||
});
|
||||
}
|
||||
|
||||
export default dataClientIdAttributeHandler;
|
||||
export default dataClientIdAttributeHandler;
|
||||
|
|
|
@ -103,14 +103,12 @@ class CreditCardRenderer {
|
|||
});
|
||||
|
||||
if (formValid && this.cardValid) {
|
||||
|
||||
let vault = document.querySelector(wrapper + ' .ppcp-credit-card-vault') ?
|
||||
document.querySelector(wrapper + ' .ppcp-credit-card-vault').checked : false;
|
||||
vault = this.defaultConfig.enforce_vault || vault;
|
||||
|
||||
const vault_card_setting_enabled = this.defaultConfig.vault_card_setting_enabled ? true : false;
|
||||
const vault = document.getElementById('ppcp-credit-card-vault') ?
|
||||
document.getElementById('ppcp-credit-card-vault').checked : vault_card_setting_enabled;
|
||||
hostedFields.submit({
|
||||
contingencies: ['3D_SECURE'],
|
||||
vault
|
||||
vault: vault
|
||||
}).then((payload) => {
|
||||
payload.orderID = payload.orderId;
|
||||
this.spinner.unblock();
|
||||
|
|
|
@ -68,6 +68,7 @@ return array(
|
|||
$subscription_helper = $container->get( 'subscription.helper' );
|
||||
$messages_apply = $container->get( 'button.helper.messages-apply' );
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$payment_token_repository = $container->get( 'subscription.repository.payment-token' );
|
||||
return new SmartButton(
|
||||
$container->get( 'button.url' ),
|
||||
$container->get( 'session.handler' ),
|
||||
|
@ -79,7 +80,8 @@ return array(
|
|||
$dcc_applies,
|
||||
$subscription_helper,
|
||||
$messages_apply,
|
||||
$environment
|
||||
$environment,
|
||||
$payment_token_repository
|
||||
);
|
||||
},
|
||||
'button.url' => static function ( $container ): string {
|
||||
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Button\Assets;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayeeRepository;
|
||||
|
@ -21,6 +22,8 @@ use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
|||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||
use WooCommerce\PayPalCommerce\Subscription\Repository\PaymentTokenRepository;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
|
@ -105,20 +108,28 @@ class SmartButton implements SmartButtonInterface {
|
|||
*/
|
||||
private $environment;
|
||||
|
||||
/**
|
||||
* The payment token repository.
|
||||
*
|
||||
* @var PaymentTokenRepository
|
||||
*/
|
||||
private $payment_token_repository;
|
||||
|
||||
/**
|
||||
* SmartButton constructor.
|
||||
*
|
||||
* @param string $module_url The URL to the module.
|
||||
* @param SessionHandler $session_handler The Session Handler.
|
||||
* @param Settings $settings The Settings.
|
||||
* @param PayeeRepository $payee_repository The Payee Repository.
|
||||
* @param PayerFactory $payer_factory The Payer factory.
|
||||
* @param string $client_id The client ID.
|
||||
* @param RequestData $request_data The Request Data helper.
|
||||
* @param DccApplies $dcc_applies The DCC applies helper.
|
||||
* @param SubscriptionHelper $subscription_helper The subscription helper.
|
||||
* @param MessagesApply $messages_apply The Messages apply helper.
|
||||
* @param Environment $environment The environment object.
|
||||
* @param string $module_url The URL to the module.
|
||||
* @param SessionHandler $session_handler The Session Handler.
|
||||
* @param Settings $settings The Settings.
|
||||
* @param PayeeRepository $payee_repository The Payee Repository.
|
||||
* @param PayerFactory $payer_factory The Payer factory.
|
||||
* @param string $client_id The client ID.
|
||||
* @param RequestData $request_data The Request Data helper.
|
||||
* @param DccApplies $dcc_applies The DCC applies helper.
|
||||
* @param SubscriptionHelper $subscription_helper The subscription helper.
|
||||
* @param MessagesApply $messages_apply The Messages apply helper.
|
||||
* @param Environment $environment The environment object.
|
||||
* @param PaymentTokenRepository $payment_token_repository The payment token repository.
|
||||
*/
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
|
@ -131,20 +142,22 @@ class SmartButton implements SmartButtonInterface {
|
|||
DccApplies $dcc_applies,
|
||||
SubscriptionHelper $subscription_helper,
|
||||
MessagesApply $messages_apply,
|
||||
Environment $environment
|
||||
Environment $environment,
|
||||
PaymentTokenRepository $payment_token_repository
|
||||
) {
|
||||
|
||||
$this->module_url = $module_url;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->payee_repository = $payee_repository;
|
||||
$this->payer_factory = $payer_factory;
|
||||
$this->client_id = $client_id;
|
||||
$this->request_data = $request_data;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
$this->messages_apply = $messages_apply;
|
||||
$this->environment = $environment;
|
||||
$this->module_url = $module_url;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->payee_repository = $payee_repository;
|
||||
$this->payer_factory = $payer_factory;
|
||||
$this->client_id = $client_id;
|
||||
$this->request_data = $request_data;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
$this->messages_apply = $messages_apply;
|
||||
$this->environment = $environment;
|
||||
$this->payment_token_repository = $payment_token_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,6 +199,45 @@ class SmartButton implements SmartButtonInterface {
|
|||
),
|
||||
11
|
||||
);
|
||||
|
||||
$payment_token_repository = $this->payment_token_repository;
|
||||
add_filter(
|
||||
'woocommerce_credit_card_form_fields',
|
||||
function ( $default_fields, $id ) use ( $payment_token_repository ) {
|
||||
if ( $this->can_save_credit_card() ) {
|
||||
$default_fields['card-vault'] = sprintf(
|
||||
'<p class="form-row form-row-wide"><label for="vault"><input class="ppcp-credit-card-vault" type="checkbox" id="ppcp-credit-card-vault" name="vault">%s</label></p>',
|
||||
esc_html__( 'Save your Credit Card', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
|
||||
$tokens = $payment_token_repository->all_for_user_id( get_current_user_id() );
|
||||
if ( $tokens && $this->tokens_contains_card( $tokens ) ) {
|
||||
$output = sprintf(
|
||||
'<p class="form-row form-row-wide"><label>%1$s</label><select id="saved-credit-card" name="saved_credit_card"><option value="">%2$s</option>',
|
||||
esc_html__( 'Or select a saved Credit Card payment', 'woocommerce-paypal-payments' ),
|
||||
esc_html__( 'Choose a saved payment', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
foreach ( $tokens as $token ) {
|
||||
if ( isset( $token->source()->card ) ) {
|
||||
$output .= sprintf(
|
||||
'<option value="%1$s">%2$s ...%3$s</option>',
|
||||
$token->id(),
|
||||
$token->source()->card->brand,
|
||||
$token->source()->card->last_digits
|
||||
);
|
||||
}
|
||||
}
|
||||
$output .= '</select></p>';
|
||||
|
||||
$default_fields['saved-credit-card'] = $output;
|
||||
}
|
||||
}
|
||||
|
||||
return $default_fields;
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -506,33 +558,13 @@ class SmartButton implements SmartButtonInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
$save_card = $this->can_save_vault_token() ? sprintf(
|
||||
'<div>
|
||||
|
||||
<label for="ppcp-vault-%1$s">%2$s</label>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="ppcp-vault-%1$s"
|
||||
class="ppcp-credit-card-vault"
|
||||
name="vault"
|
||||
>
|
||||
</div>',
|
||||
esc_attr( $id ),
|
||||
esc_html__( 'Save your card', 'woocommerce-paypal-payments' )
|
||||
) : '';
|
||||
|
||||
$label = 'checkout' === $this->context() ? __( 'Place order', 'woocommerce-paypal-payments' ) : __( 'Pay for order', 'woocommerce-paypal-payments' );
|
||||
|
||||
printf(
|
||||
'<div id="%1$s" style="display:none;">
|
||||
<button class="button alt">%6$s</button>
|
||||
<button class="button alt">%2$s</button>
|
||||
</div><div id="payments-sdk__contingency-lightbox"></div><style id="ppcp-hide-dcc">.payment_method_ppcp-credit-card-gateway {display:none;}</style>',
|
||||
esc_attr( $id ),
|
||||
esc_html__( 'Credit Card number', 'woocommerce-paypal-payments' ),
|
||||
esc_html__( 'Expiration', 'woocommerce-paypal-payments' ),
|
||||
esc_html__( 'CVV', 'woocommerce-paypal-payments' ),
|
||||
//phpcs:ignore
|
||||
$save_card,
|
||||
esc_html( $label )
|
||||
);
|
||||
}
|
||||
|
@ -548,7 +580,23 @@ class SmartButton implements SmartButtonInterface {
|
|||
if ( ! $this->settings->has( 'client_id' ) || ! $this->settings->get( 'client_id' ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $this->settings->has( 'vault_enabled' ) || ! $this->settings->get( 'vault_enabled' ) ) {
|
||||
if ( ! $this->vault_settings_enabled() ) {
|
||||
return false;
|
||||
}
|
||||
return is_user_logged_in();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether it can save credit cards.
|
||||
*
|
||||
* @return bool
|
||||
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException When nothing was found.
|
||||
*/
|
||||
private function can_save_credit_card() {
|
||||
if ( ! $this->settings->has( 'client_id' ) || ! $this->settings->get( 'client_id' ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $this->settings->has( 'dcc_save_card' ) || ! $this->settings->get( 'dcc_save_card' ) ) {
|
||||
return false;
|
||||
}
|
||||
return is_user_logged_in();
|
||||
|
@ -580,17 +628,18 @@ class SmartButton implements SmartButtonInterface {
|
|||
|
||||
$this->request_data->enqueue_nonce_fix();
|
||||
$localize = array(
|
||||
'script_attributes' => $this->attributes(),
|
||||
'data_client_id' => array(
|
||||
'set_attribute' => ( is_checkout() && $this->dcc_is_enabled() )
|
||||
'script_attributes' => $this->attributes(),
|
||||
'data_client_id' => array(
|
||||
'set_attribute' => ( is_checkout() && $this->dcc_is_enabled() )
|
||||
|| $this->can_save_vault_token(),
|
||||
'endpoint' => home_url( \WC_AJAX::get_endpoint( DataClientIdEndpoint::ENDPOINT ) ),
|
||||
'nonce' => wp_create_nonce( DataClientIdEndpoint::nonce() ),
|
||||
'user' => get_current_user_id(),
|
||||
'save_paypal_account' => $this->save_paypal_account(),
|
||||
'endpoint' => home_url( \WC_AJAX::get_endpoint( DataClientIdEndpoint::ENDPOINT ) ),
|
||||
'nonce' => wp_create_nonce( DataClientIdEndpoint::nonce() ),
|
||||
'user' => get_current_user_id(),
|
||||
),
|
||||
'redirect' => wc_get_checkout_url(),
|
||||
'context' => $this->context(),
|
||||
'ajax' => array(
|
||||
'redirect' => wc_get_checkout_url(),
|
||||
'context' => $this->context(),
|
||||
'ajax' => array(
|
||||
'change_cart' => array(
|
||||
'endpoint' => home_url( \WC_AJAX::get_endpoint( ChangeCartEndpoint::ENDPOINT ) ),
|
||||
'nonce' => wp_create_nonce( ChangeCartEndpoint::nonce() ),
|
||||
|
@ -604,10 +653,11 @@ class SmartButton implements SmartButtonInterface {
|
|||
'nonce' => wp_create_nonce( ApproveOrderEndpoint::nonce() ),
|
||||
),
|
||||
),
|
||||
'enforce_vault' => $this->has_subscriptions(),
|
||||
'bn_codes' => $this->bn_codes(),
|
||||
'payer' => $this->payerData(),
|
||||
'button' => array(
|
||||
'enforce_vault' => $this->has_subscriptions(),
|
||||
'vault_card_setting_enabled' => $this->vault_card_setting_enabled(),
|
||||
'bn_codes' => $this->bn_codes(),
|
||||
'payer' => $this->payerData(),
|
||||
'button' => array(
|
||||
'wrapper' => '#ppc-button',
|
||||
'mini_cart_wrapper' => '#ppc-button-minicart',
|
||||
'cancel_wrapper' => '#ppcp-cancel',
|
||||
|
@ -627,7 +677,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
'tagline' => $this->style_for_context( 'tagline', $this->context() ),
|
||||
),
|
||||
),
|
||||
'hosted_fields' => array(
|
||||
'hosted_fields' => array(
|
||||
'wrapper' => '#ppcp-hosted-fields',
|
||||
'mini_cart_wrapper' => '#ppcp-hosted-fields-mini-cart',
|
||||
'labels' => array(
|
||||
|
@ -645,8 +695,8 @@ class SmartButton implements SmartButtonInterface {
|
|||
),
|
||||
'valid_cards' => $this->dcc_applies->valid_cards(),
|
||||
),
|
||||
'messages' => $this->message_values(),
|
||||
'labels' => array(
|
||||
'messages' => $this->message_values(),
|
||||
'labels' => array(
|
||||
'error' => array(
|
||||
'generic' => __(
|
||||
'Something went wrong. Please try again or choose another payment source.',
|
||||
|
@ -654,7 +704,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
),
|
||||
),
|
||||
),
|
||||
'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0,
|
||||
'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0,
|
||||
);
|
||||
|
||||
if ( $this->style_for_context( 'layout', 'mini-cart' ) !== 'horizontal' ) {
|
||||
|
@ -877,6 +927,19 @@ class SmartButton implements SmartButtonInterface {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if can save PayPal accounts.
|
||||
*
|
||||
* @return bool Whether it can save it or not.
|
||||
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException If a setting has not been found.
|
||||
*/
|
||||
private function save_paypal_account(): bool {
|
||||
if ( ! $this->settings->has( 'save_paypal_account' ) || ! $this->settings->get( 'save_paypal_account' ) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the style for a given indicator in a given context.
|
||||
*
|
||||
|
@ -908,4 +971,53 @@ class SmartButton implements SmartButtonInterface {
|
|||
}
|
||||
return (string) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if vault enabled setting for PayPal or credit card is enabled.
|
||||
*
|
||||
* @return bool Whether any of them is enabled or not.
|
||||
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException When a setting hasn't been found.
|
||||
*/
|
||||
protected function vault_settings_enabled(): bool {
|
||||
if ( $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ) ) {
|
||||
return true;
|
||||
}
|
||||
if ( $this->settings->has( 'dcc_vault_enabled' ) && $this->settings->get( 'dcc_vault_enabled' ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if vaulting for credit card is enabled.
|
||||
*
|
||||
* @return bool Whether if it is enabled or not.
|
||||
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException When a setting hasn't been found.
|
||||
*/
|
||||
protected function vault_card_setting_enabled(): bool {
|
||||
try {
|
||||
if ( ! $this->settings->has( 'dcc_vault_enabled' ) && ! $this->settings->get( 'dcc_vault_enabled' ) ) {
|
||||
return false;
|
||||
}
|
||||
} catch ( NotFoundException $exception ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if tokens has card source.
|
||||
*
|
||||
* @param PaymentToken[] $tokens The tokens.
|
||||
* @return bool Wether tokens contains card or not.
|
||||
*/
|
||||
protected function tokens_contains_card( $tokens ) {
|
||||
foreach ( $tokens as $token ) {
|
||||
if ( isset( $token->source()->card ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ class DataClientIdEndpoint implements EndpointInterface {
|
|||
array(
|
||||
'token' => $token->token(),
|
||||
'expiration' => $token->expiration_timestamp(),
|
||||
'user' => get_current_user_id(),
|
||||
'user' => $user_id,
|
||||
)
|
||||
);
|
||||
return true;
|
||||
|
|
|
@ -25,6 +25,7 @@ class MessagesApply {
|
|||
'DE',
|
||||
'GB',
|
||||
'FR',
|
||||
'AU',
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
53
modules/ppcp-button/src/Helper/class-messagesdisclaimers.php
Normal file
53
modules/ppcp-button/src/Helper/class-messagesdisclaimers.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper class to determine which disclaimer content should display based on shop location country.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Button\Helper
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Button\Helper;
|
||||
|
||||
/**
|
||||
* Class MessagesDisclaimers
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Button\Helper
|
||||
*/
|
||||
class MessagesDisclaimers {
|
||||
|
||||
/**
|
||||
* Disclainers content by country.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $disclaimers = array(
|
||||
'US' => array(
|
||||
'link' => 'https://developer.paypal.com/docs/commerce-platforms/admin-panel/woocommerce/us/',
|
||||
),
|
||||
'GB' => array(
|
||||
'link' => 'https://developer.paypal.com/docs/commerce-platforms/admin-panel/woocommerce/uk/',
|
||||
),
|
||||
'DE' => array(
|
||||
'link' => 'https://developer.paypal.com/docs/commerce-platforms/admin-panel/woocommerce/de/',
|
||||
),
|
||||
'AU' => array(
|
||||
'link' => 'https://developer.paypal.com/docs/commerce-platforms/admin-panel/woocommerce/au/',
|
||||
),
|
||||
'FR' => array(
|
||||
'link' => 'https://developer.paypal.com/docs/commerce-platforms/admin-panel/woocommerce/fr/',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns a disclaimer link based on country.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function link_for_country(): string {
|
||||
$region = wc_get_base_location();
|
||||
$country = $region['country'];
|
||||
|
||||
return $this->disclaimers[ $country ]['link'] ?? '';
|
||||
}
|
||||
}
|
|
@ -72,6 +72,23 @@ class PaymentTokenRepository {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all tokens for a user.
|
||||
*
|
||||
* @param int $id The user id.
|
||||
* @return PaymentToken[]
|
||||
*/
|
||||
public function all_for_user_id( int $id ) {
|
||||
$tokens_array = array();
|
||||
try {
|
||||
$tokens = $this->endpoint->for_user( $id );
|
||||
update_user_meta( $id, self::USER_META, $tokens );
|
||||
return $tokens;
|
||||
} catch ( RuntimeException $exception ) {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a token for a user.
|
||||
*
|
||||
|
|
|
@ -120,7 +120,7 @@ class RenewalHandler {
|
|||
'order' => $wc_order,
|
||||
)
|
||||
);
|
||||
\WC_Subscriptions_Manager::process_subscription_payment_failure_on_order( $wc_order );
|
||||
|
||||
return;
|
||||
}
|
||||
$this->logger->log(
|
||||
|
@ -156,12 +156,13 @@ class RenewalHandler {
|
|||
}
|
||||
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||
$payer = $this->payer_factory->from_customer( $customer );
|
||||
$order = $this->order_endpoint->create(
|
||||
|
||||
$order = $this->order_endpoint->create(
|
||||
array( $purchase_unit ),
|
||||
$payer,
|
||||
$token,
|
||||
(string) $wc_order->get_id()
|
||||
$token
|
||||
);
|
||||
|
||||
$this->capture_order( $order, $wc_order );
|
||||
}
|
||||
|
||||
|
@ -192,7 +193,6 @@ class RenewalHandler {
|
|||
'order' => $wc_order,
|
||||
)
|
||||
);
|
||||
\WC_Subscriptions_Manager::process_subscription_payment_failure_on_order( $wc_order );
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
|
@ -210,13 +210,11 @@ class RenewalHandler {
|
|||
'processing',
|
||||
__( 'Payment received.', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
\WC_Subscriptions_Manager::process_subscription_payments_on_order( $wc_order );
|
||||
}
|
||||
|
||||
if ( $order->intent() === 'AUTHORIZE' ) {
|
||||
$this->order_endpoint->authorize( $order );
|
||||
$wc_order->update_meta_data( PayPalGateway::CAPTURED_META_KEY, 'false' );
|
||||
\WC_Subscriptions_Manager::process_subscription_payments_on_order( $wc_order );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,10 @@ namespace WooCommerce\PayPalCommerce\Subscription;
|
|||
|
||||
use Dhii\Container\ServiceProvider;
|
||||
use Dhii\Modular\Module\ModuleInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokenEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use Interop\Container\ServiceProviderInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
|
@ -40,16 +43,37 @@ class SubscriptionModule implements ModuleInterface {
|
|||
public function run( ContainerInterface $container = null ) {
|
||||
add_action(
|
||||
'woocommerce_scheduled_subscription_payment_' . PayPalGateway::ID,
|
||||
static function ( $amount, $order ) use ( $container ) {
|
||||
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||
return;
|
||||
}
|
||||
$handler = $container->get( 'subscription.renewal-handler' );
|
||||
$handler->renew( $order );
|
||||
function ( $amount, $order ) use ( $container ) {
|
||||
$this->renew( $order, $container );
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
|
||||
add_action(
|
||||
'woocommerce_scheduled_subscription_payment_' . CreditCardGateway::ID,
|
||||
function ( $amount, $order ) use ( $container ) {
|
||||
$this->renew( $order, $container );
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a Subscription product renewal.
|
||||
*
|
||||
* @param \WC_Order $order WooCommerce order.
|
||||
* @param ContainerInterface|null $container The container.
|
||||
* @return void
|
||||
*/
|
||||
protected function renew( $order, $container ) {
|
||||
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$handler = $container->get( 'subscription.renewal-handler' );
|
||||
$handler->renew( $order );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
21
modules/ppcp-wc-gateway/package.json
Normal file
21
modules/ppcp-wc-gateway/package.json
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "ppcp-wc-gateway",
|
||||
"version": "1.0.0",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"main": "resources/js/gateway-settings.js",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.9.0",
|
||||
"@babel/preset-env": "^7.9.5",
|
||||
"babel-loader": "^8.1.0",
|
||||
"cross-env": "^5.0.1",
|
||||
"file-loader": "^4.2.0",
|
||||
"webpack": "^4.42.1",
|
||||
"webpack-cli": "^3.1.2",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.26.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
|
||||
"watch": "cross-env BABEL_ENV=default NODE_ENV=production webpack --watch",
|
||||
"dev": "cross-env BABEL_ENV=default webpack --watch"
|
||||
}
|
||||
}
|
34
modules/ppcp-wc-gateway/resources/js/gateway-settings.js
Normal file
34
modules/ppcp-wc-gateway/resources/js/gateway-settings.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
;document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
const payLaterMessagingCheckboxes = document.querySelectorAll(
|
||||
"#ppcp-message_enabled, #ppcp-message_cart_enabled, #ppcp-message_product_enabled"
|
||||
)
|
||||
|
||||
const vaultingCheckboxes = document.querySelectorAll(
|
||||
"#ppcp-vault_enabled, #ppcp-save_paypal_account"
|
||||
)
|
||||
|
||||
function atLeastOneChecked(checkboxesNodeList) {
|
||||
return Array.prototype.slice.call(checkboxesNodeList).filter(node => !node.disabled && node.checked).length > 0
|
||||
}
|
||||
|
||||
function disableAll(nodeList){
|
||||
nodeList.forEach(node => node.setAttribute('disabled', 'true'))
|
||||
}
|
||||
|
||||
function enableAll(nodeList){
|
||||
nodeList.forEach(node => node.removeAttribute('disabled'))
|
||||
}
|
||||
|
||||
function updateCheckboxes() {
|
||||
atLeastOneChecked(payLaterMessagingCheckboxes) ? disableAll(vaultingCheckboxes) : enableAll(vaultingCheckboxes)
|
||||
atLeastOneChecked(vaultingCheckboxes) ? disableAll(payLaterMessagingCheckboxes) : enableAll(payLaterMessagingCheckboxes)
|
||||
}
|
||||
|
||||
updateCheckboxes()
|
||||
|
||||
payLaterMessagingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes))
|
||||
vaultingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes));
|
||||
}
|
||||
);
|
|
@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesDisclaimers;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
|
||||
|
@ -69,7 +70,10 @@ return array(
|
|||
$refund_processor = $container->get( 'wcgateway.processor.refunds' );
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$transaction_url_provider = $container->get( 'wcgateway.transaction-url-provider' );
|
||||
|
||||
$payment_token_repository = $container->get( 'subscription.repository.payment-token' );
|
||||
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
|
||||
$payer_factory = $container->get( 'api.factory.payer' );
|
||||
$order_endpoint = $container->get( 'api.endpoint.order' );
|
||||
return new CreditCardGateway(
|
||||
$settings_renderer,
|
||||
$order_processor,
|
||||
|
@ -80,7 +84,11 @@ return array(
|
|||
$session_handler,
|
||||
$refund_processor,
|
||||
$state,
|
||||
$transaction_url_provider
|
||||
$transaction_url_provider,
|
||||
$payment_token_repository,
|
||||
$purchase_unit_factory,
|
||||
$payer_factory,
|
||||
$order_endpoint
|
||||
);
|
||||
},
|
||||
'wcgateway.disabler' => static function ( $container ): DisableGateways {
|
||||
|
@ -174,13 +182,8 @@ return array(
|
|||
'wcgateway.settings.fields' => static function ( $container ): array {
|
||||
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
/**
|
||||
* The state.
|
||||
*
|
||||
* @var State $state
|
||||
*/
|
||||
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$messages_disclaimers = $container->get( 'button.helper.messages-disclaimers' );
|
||||
|
||||
$fields = array(
|
||||
'sandbox_on' => array(
|
||||
|
@ -485,6 +488,34 @@ return array(
|
|||
),
|
||||
'gateway' => 'dcc',
|
||||
),
|
||||
'dcc_vault_enabled' => array(
|
||||
'title' => __( 'Vaulting For Credit Cards', 'woocommerce-paypal-payments' ),
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'Enable Payment Tokens for WooCommerce Subscription renewals', 'woocommerce-paypal-payments' ),
|
||||
'label' => __( 'Enable Vaulting For Credit Cards', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'default' => false,
|
||||
'gateway' => 'dcc',
|
||||
'requirements' => array(
|
||||
'dcc',
|
||||
),
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
),
|
||||
'dcc_save_card' => array(
|
||||
'title' => __( 'Save Credit Card', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
'label' => __( 'Allow Registered Buyers to Save Credit Card', 'woocommerce-paypal-payments' ),
|
||||
'description' => __( 'Buyers that create an account on your store may save their Credit Card for faster checkout.', 'woocommerce-paypal-payments' ),
|
||||
'default' => true,
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'dcc',
|
||||
),
|
||||
'description' => array(
|
||||
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'text',
|
||||
|
@ -628,19 +659,31 @@ return array(
|
|||
'gateway' => 'paypal',
|
||||
),
|
||||
'vault_enabled' => array(
|
||||
'title' => __( 'Vaulting', 'woocommerce-paypal-payments' ),
|
||||
'title' => __( 'Vaulting for PayPal Accounts', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
'label' => __( 'Enable vaulting', 'woocommerce-paypal-payments' ),
|
||||
'description' => __( 'Enables you to store payment tokens for subscriptions.', 'woocommerce-paypal-payments' ),
|
||||
'default' => true,
|
||||
'label' => __( 'Enable Vaulting for PayPal Accounts', 'woocommerce-paypal-payments' ),
|
||||
'description' => __( 'Enable Payment Tokens for WooCommerce Subscription renewals', 'woocommerce-paypal-payments' ),
|
||||
'default' => false,
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
'save_paypal_account' => array(
|
||||
'title' => __( 'Save PayPal Account', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
'label' => __( 'Allow Registered Buyers to Save PayPal Account', 'woocommerce-paypal-payments' ),
|
||||
'description' => __( 'Buyers that create an account on your store may save their PayPal account for faster checkout. Note that you may not present Pay Later messages when using this feature.', 'woocommerce-paypal-payments' ),
|
||||
'default' => false,
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
|
||||
'logging_enabled' => array(
|
||||
'title' => __( 'Logging', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
|
@ -659,8 +702,13 @@ return array(
|
|||
'title' => __( 'Invoice prefix', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'text',
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'If you use your PayPal account with more than one installation, please use a distinct prefix to seperate those installations. Please do not use numbers in your prefix.', 'woocommerce-paypal-payments' ),
|
||||
'default' => 'WC-',
|
||||
'description' => __( 'If you use your PayPal account with more than one installation, please use a distinct prefix to separate those installations. Please do not use numbers in your prefix.', 'woocommerce-paypal-payments' ),
|
||||
'default' => ( static function (): string {
|
||||
$site_url = get_site_url( get_current_blog_id() );
|
||||
$hash = md5( $site_url );
|
||||
$letters = preg_replace( '~\d~', '', $hash );
|
||||
return substr( $letters, 0, 6 ) . '-';
|
||||
} )(),
|
||||
'screens' => array(
|
||||
State::STATE_PROGRESSIVE,
|
||||
State::STATE_ONBOARDED,
|
||||
|
@ -811,7 +859,7 @@ return array(
|
|||
),
|
||||
'requirements' => array( 'messages' ),
|
||||
'gateway' => 'paypal',
|
||||
'description' => str_replace( '<a>', '<a href="https://www.paypal.com/us/business/buy-now-pay-later">', __( 'Customize the appearance of <a>Pay Later messages</a> on checkout to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) ),
|
||||
'description' => str_replace( '<a>', '<a href="' . $messages_disclaimers->link_for_country() . '" target="_blank">', __( 'Displays Pay Later messaging for available offers. Restrictions apply. <a>Click here to learn more.</a>', 'woocommerce-paypal-payments' ) ),
|
||||
'class' => array( 'ppcp-subheading' ),
|
||||
),
|
||||
'message_enabled' => array(
|
||||
|
@ -1114,7 +1162,7 @@ return array(
|
|||
),
|
||||
'requirements' => array( 'messages' ),
|
||||
'gateway' => 'paypal',
|
||||
'description' => str_replace( '<a>', '<a href="https://www.paypal.com/us/business/buy-now-pay-later">', __( 'Customize the appearance of <a>Pay Later messages</a> on product pages to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) ),
|
||||
'description' => str_replace( '<a>', '<a href="' . $messages_disclaimers->link_for_country() . '" target="_blank">', __( 'Displays Pay Later messaging for available offers. Restrictions apply. <a>Click here to learn more.</a>', 'woocommerce-paypal-payments' ) ),
|
||||
'class' => array( 'ppcp-subheading' ),
|
||||
),
|
||||
'message_product_enabled' => array(
|
||||
|
@ -1417,7 +1465,7 @@ return array(
|
|||
),
|
||||
'requirements' => array( 'messages' ),
|
||||
'gateway' => 'paypal',
|
||||
'description' => str_replace( '<a>', '<a href="https://www.paypal.com/us/business/buy-now-pay-later">', __( 'Customize the appearance of <a>Pay Later messages</a> on your cart page to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) ),
|
||||
'description' => str_replace( '<a>', '<a href="' . $messages_disclaimers->link_for_country() . '" target="_blank">', __( 'Displays Pay Later messaging for available offers. Restrictions apply. <a>Click here to learn more.</a>', 'woocommerce-paypal-payments' ) ),
|
||||
'class' => array( 'ppcp-subheading' ),
|
||||
),
|
||||
'message_cart_enabled' => array(
|
||||
|
@ -1792,51 +1840,6 @@ return array(
|
|||
unset( $fields['disable_funding']['options']['card'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Pay in 3 heading and description for UK.
|
||||
*/
|
||||
if ( 'GB' === $country ) {
|
||||
$fields['message_heading']['heading'] = __( 'Pay Later Messaging on Checkout', 'woocommerce-paypal-payments' );
|
||||
$fields['message_heading']['description'] = __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' );
|
||||
|
||||
$fields['message_product_heading']['heading'] = __( 'Pay Later Messaging on Single Product Page', 'woocommerce-paypal-payments' );
|
||||
$fields['message_product_heading']['description'] = __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' );
|
||||
|
||||
$fields['message_cart_heading']['heading'] = __( 'Pay Later Messaging on Cart', 'woocommerce-paypal-payments' );
|
||||
$fields['message_cart_heading']['description'] = __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' );
|
||||
}
|
||||
|
||||
if ( 'FR' === $country ) {
|
||||
// todo: replace this with the text in English and use this text for French translation when it will be created.
|
||||
$french_pay_later_description = 'Affichez le Paiement en 4X PayPal sur votre site.' .
|
||||
'Le Paiement en 4X PayPal permet aux consommateurs français de payer en 4 versements égaux.' .
|
||||
'Vous pouvez promouvoir le Paiement en 4X PayPal uniquement si vous êtes un commerçant basé en France, ' .
|
||||
'avec un site internet en français et uneintégration PayPal standard. ' .
|
||||
'Les marchands ayantl’outil Vaulting(coffre-fort numérique) ou une intégration de paiements récurrents/abonnement, ' .
|
||||
'ainsi que ceux présentant certaines activités (vente de biens numériques / de biens non physiques) ' .
|
||||
'ne sont pas éligibles pour promouvoir le Paiement en 4X PayPal.' .
|
||||
'Nous afficherons des messages sur votre site pour promouvoir le Paiement en 4X PayPal. ' .
|
||||
'Vous ne pouvez pas promouvoir le Paiement en 4X PayPal avec un autre contenu, quel qu’il soit.';
|
||||
|
||||
$fields['message_heading']['heading'] = __( 'Pay Later Messaging on Checkout', 'woocommerce-paypal-payments' );
|
||||
$fields['message_heading']['description'] = $french_pay_later_description;
|
||||
|
||||
$fields['message_product_heading']['heading'] = __( 'Pay Later Messaging on Single Product Page', 'woocommerce-paypal-payments' );
|
||||
$fields['message_product_heading']['description'] = $french_pay_later_description;
|
||||
|
||||
$fields['message_cart_heading']['heading'] = __( 'Pay Later Messaging on Cart', 'woocommerce-paypal-payments' );
|
||||
$fields['message_cart_heading']['description'] = $french_pay_later_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Pay Later link for DE
|
||||
*/
|
||||
if ( 'DE' === $country ) {
|
||||
$fields['message_heading']['description'] = str_replace( '<a>', '<a href="https://www.paypal.com/de/webapps/mpp/installments">', __( 'Customize the appearance of <a>Pay Later messages</a> on checkout to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) );
|
||||
$fields['message_product_heading']['description'] = str_replace( '<a>', '<a href="https://www.paypal.com/de/webapps/mpp/installments">', __( 'Customize the appearance of <a>Pay Later messages</a> on checkout to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) );
|
||||
$fields['message_cart_heading']['description'] = str_replace( '<a>', '<a href="https://www.paypal.com/de/webapps/mpp/installments">', __( 'Customize the appearance of <a>Pay Later messages</a> on checkout to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) );
|
||||
}
|
||||
|
||||
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
||||
/**
|
||||
* Depending on your store location, some credit cards can't be used.
|
||||
|
@ -1866,10 +1869,19 @@ return array(
|
|||
},
|
||||
'wcgateway.url' => static function ( $container ): string {
|
||||
return plugins_url(
|
||||
'/modules/ppcp-wc-gateway/',
|
||||
$container->get( 'wcgateway.relative-path' ),
|
||||
dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php'
|
||||
);
|
||||
},
|
||||
'wcgateway.relative-path' => static function( $container ): string {
|
||||
return 'modules/ppcp-wc-gateway/';
|
||||
},
|
||||
'wcgateway.absolute-path' => static function( $container ): string {
|
||||
return plugin_dir_path(
|
||||
dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php'
|
||||
) .
|
||||
$container->get( 'wcgateway.relative-path' );
|
||||
},
|
||||
'wcgateway.endpoint.return-url' => static function ( $container ) : ReturnUrlEndpoint {
|
||||
$gateway = $container->get( 'wcgateway.paypal-gateway' );
|
||||
$endpoint = $container->get( 'api.endpoint.order' );
|
||||
|
@ -1902,4 +1914,8 @@ return array(
|
|||
$partner_endpoint = $container->get( 'api.endpoint.partners' );
|
||||
return new DccProductStatus( $settings, $partner_endpoint );
|
||||
},
|
||||
|
||||
'button.helper.messages-disclaimers' => static function ( $container ): MessagesDisclaimers {
|
||||
return new MessagesDisclaimers();
|
||||
},
|
||||
);
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* Register and configure assets provided by this module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\WcGateway\Assets
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
|
||||
|
||||
/**
|
||||
* Class SettingsPageAssets
|
||||
*/
|
||||
class SettingsPageAssets {
|
||||
|
||||
/**
|
||||
* The URL of this module.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $module_url;
|
||||
/**
|
||||
* The filesystem path to the module dir.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $module_path;
|
||||
|
||||
/**
|
||||
* Assets constructor.
|
||||
*
|
||||
* @param string $module_url The url of this module.
|
||||
* @param string $module_path The filesystem path to this module.
|
||||
*/
|
||||
public function __construct( string $module_url, string $module_path ) {
|
||||
$this->module_url = $module_url;
|
||||
$this->module_path = $module_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register assets provided by this module.
|
||||
*/
|
||||
public function register_assets() {
|
||||
add_action(
|
||||
'admin_enqueue_scripts',
|
||||
function() {
|
||||
if ( ! is_admin() || is_ajax() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $this->is_paypal_payment_method_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->register_admin_assets();
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the current page is PayPal payment method settings.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_paypal_payment_method_page(): bool {
|
||||
|
||||
if ( ! function_exists( 'get_current_screen' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
$tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING );
|
||||
$section = filter_input( INPUT_GET, 'section', FILTER_SANITIZE_STRING );
|
||||
|
||||
if ( ! 'woocommerce_page_wc-settings' === $screen->id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 'checkout' === $tab && 'ppcp-gateway' === $section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register assets for admin pages.
|
||||
*/
|
||||
private function register_admin_assets() {
|
||||
$gateway_settings_script_path = trailingslashit( $this->module_path ) . 'assets/js/gateway-settings.js';
|
||||
|
||||
wp_enqueue_script(
|
||||
'ppcp-gateway-settings',
|
||||
trailingslashit( $this->module_url ) . 'assets/js/gateway-settings.js',
|
||||
array(),
|
||||
file_exists( $gateway_settings_script_path ) ? (string) filemtime( $gateway_settings_script_path ) : null,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
|
@ -79,7 +79,10 @@ class DisableGateways {
|
|||
}
|
||||
|
||||
if ( $this->is_credit_card() ) {
|
||||
return array( CreditCardGateway::ID => $methods[ CreditCardGateway::ID ] );
|
||||
return array(
|
||||
CreditCardGateway::ID => $methods[ CreditCardGateway::ID ],
|
||||
PayPalGateway::ID => $methods[ PayPalGateway::ID ],
|
||||
);
|
||||
}
|
||||
return array( PayPalGateway::ID => $methods[ PayPalGateway::ID ] );
|
||||
}
|
||||
|
|
|
@ -9,8 +9,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Subscription\Repository\PaymentTokenRepository;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
||||
|
@ -48,6 +52,34 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
*/
|
||||
private $refund_processor;
|
||||
|
||||
/**
|
||||
* The payment token repository.
|
||||
*
|
||||
* @var PaymentTokenRepository
|
||||
*/
|
||||
private $payment_token_repository;
|
||||
|
||||
/**
|
||||
* The purchase unit factory.
|
||||
*
|
||||
* @var PurchaseUnitFactory
|
||||
*/
|
||||
private $purchase_unit_factory;
|
||||
|
||||
/**
|
||||
* The payer factory.
|
||||
*
|
||||
* @var PayerFactory
|
||||
*/
|
||||
private $payer_factory;
|
||||
|
||||
/**
|
||||
* The order endpoint.
|
||||
*
|
||||
* @var OrderEndpoint
|
||||
*/
|
||||
private $order_endpoint;
|
||||
|
||||
/**
|
||||
* CreditCardGateway constructor.
|
||||
*
|
||||
|
@ -61,6 +93,10 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
* @param RefundProcessor $refund_processor The refund processor.
|
||||
* @param State $state The state.
|
||||
* @param TransactionUrlProvider $transaction_url_provider Service able to provide view transaction url base.
|
||||
* @param PaymentTokenRepository $payment_token_repository The payment token repository.
|
||||
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
|
||||
* @param PayerFactory $payer_factory The payer factory.
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
*/
|
||||
public function __construct(
|
||||
SettingsRenderer $settings_renderer,
|
||||
|
@ -72,7 +108,11 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
SessionHandler $session_handler,
|
||||
RefundProcessor $refund_processor,
|
||||
State $state,
|
||||
TransactionUrlProvider $transaction_url_provider
|
||||
TransactionUrlProvider $transaction_url_provider,
|
||||
PaymentTokenRepository $payment_token_repository,
|
||||
PurchaseUnitFactory $purchase_unit_factory,
|
||||
PayerFactory $payer_factory,
|
||||
OrderEndpoint $order_endpoint
|
||||
) {
|
||||
|
||||
$this->id = self::ID;
|
||||
|
@ -90,8 +130,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
if (
|
||||
defined( 'PPCP_FLAG_SUBSCRIPTION' )
|
||||
&& PPCP_FLAG_SUBSCRIPTION
|
||||
&& $this->config->has( 'vault_enabled' )
|
||||
&& $this->config->get( 'vault_enabled' )
|
||||
&& $this->vault_settings_enabled()
|
||||
) {
|
||||
$this->supports = array(
|
||||
'refunds',
|
||||
|
@ -106,7 +145,6 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
'subscription_payment_method_change_customer',
|
||||
'subscription_payment_method_change_admin',
|
||||
'multiple_subscriptions',
|
||||
'credit_card_form_cvc_on_saved_method',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -135,6 +173,10 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
);
|
||||
|
||||
$this->module_url = $module_url;
|
||||
$this->payment_token_repository = $payment_token_repository;
|
||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||
$this->payer_factory = $payer_factory;
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->transaction_url_provider = $transaction_url_provider;
|
||||
}
|
||||
|
||||
|
|
|
@ -129,8 +129,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
if (
|
||||
defined( 'PPCP_FLAG_SUBSCRIPTION' )
|
||||
&& PPCP_FLAG_SUBSCRIPTION
|
||||
&& $this->config->has( 'vault_enabled' )
|
||||
&& $this->config->get( 'vault_enabled' )
|
||||
&& $this->vault_settings_enabled()
|
||||
) {
|
||||
$this->supports = array(
|
||||
'refunds',
|
||||
|
|
|
@ -9,6 +9,7 @@ declare( strict_types=1 );
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
|
||||
|
@ -40,6 +41,56 @@ trait ProcessPaymentTrait {
|
|||
return $failure_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* If customer has chosed a saved credit card payment.
|
||||
*/
|
||||
$saved_credit_card = filter_input( INPUT_POST, 'saved_credit_card', FILTER_SANITIZE_STRING );
|
||||
if ( $saved_credit_card ) {
|
||||
|
||||
$user_id = (int) $wc_order->get_customer_id();
|
||||
$customer = new \WC_Customer( $user_id );
|
||||
$tokens = $this->payment_token_repository->all_for_user_id( (int) $customer->get_id() );
|
||||
|
||||
$selected_token = null;
|
||||
foreach ( $tokens as $token ) {
|
||||
if ( $token->id() === $saved_credit_card ) {
|
||||
$selected_token = $token;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $selected_token ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||
$payer = $this->payer_factory->from_customer( $customer );
|
||||
try {
|
||||
$order = $this->order_endpoint->create(
|
||||
array( $purchase_unit ),
|
||||
$payer,
|
||||
$selected_token
|
||||
);
|
||||
|
||||
if ( $order->status()->is( OrderStatus::COMPLETED ) && $order->intent() === 'CAPTURE' ) {
|
||||
$wc_order->update_status(
|
||||
'processing',
|
||||
__( 'Payment received.', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
|
||||
$this->session_handler->destroy_session_data();
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'redirect' => $this->get_return_url( $wc_order ),
|
||||
);
|
||||
}
|
||||
} catch ( RuntimeException $error ) {
|
||||
$this->session_handler->destroy_session_data();
|
||||
wc_add_notice( $error->getMessage(), 'error' );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the WC_Order is payed through the approved webhook.
|
||||
*/
|
||||
|
@ -95,4 +146,20 @@ trait ProcessPaymentTrait {
|
|||
|
||||
return $failure_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if vault enabled setting for PayPal or credit card is enabled.
|
||||
*
|
||||
* @return bool Whether vault settings are enabled or not.
|
||||
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException When a setting hasn't been found.
|
||||
*/
|
||||
protected function vault_settings_enabled(): bool {
|
||||
if ( $this->config->has( 'vault_enabled' ) && $this->config->get( 'vault_enabled' ) ) {
|
||||
return true;
|
||||
}
|
||||
if ( $this->config->has( 'dcc_vault_enabled' ) && $this->config->get( 'dcc_vault_enabled' ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,34 @@ class SettingsListener {
|
|||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent enabling both Pay Later messaging and PayPal vaulting
|
||||
*/
|
||||
public function listen_for_vaulting_enabled() {
|
||||
if ( ! $this->is_valid_site_request() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* No need to verify nonce here.
|
||||
*
|
||||
* phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
* phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
*/
|
||||
if ( ! isset( $_POST['ppcp']['vault_enabled'] ) && ! isset( $_POST['ppcp']['save_paypal_account'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->settings->set( 'message_enabled', false );
|
||||
$this->settings->set( 'message_product_enabled', false );
|
||||
$this->settings->set( 'message_cart_enabled', false );
|
||||
$this->settings->persist();
|
||||
|
||||
$redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' );
|
||||
wp_safe_redirect( $redirect_url, 302 );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens to the request.
|
||||
*
|
||||
|
|
|
@ -10,7 +10,6 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
|
||||
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
|
@ -93,33 +92,113 @@ class SettingsRenderer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the notice, when onboarding failed.
|
||||
* Returns notices list.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages() : array {
|
||||
|
||||
$messages = array();
|
||||
|
||||
if ( $this->is_paypal_checkout_screen() && $this->paypal_vaulting_is_enabled()
|
||||
|| $this->is_paypal_checkout_screen() && $this->pay_later_messaging_is_enabled() ) {
|
||||
|
||||
$vaulting_title = __( 'PayPal vaulting', 'woocommerce-paypal-payments' );
|
||||
$pay_later_messages_title = __( 'Pay Later Messaging', 'woocommerce-paypal-payments' );
|
||||
|
||||
$enabled = $this->paypal_vaulting_is_enabled() ? $vaulting_title : $pay_later_messages_title;
|
||||
$disabled = $this->pay_later_messaging_is_enabled() ? $vaulting_title : $pay_later_messages_title;
|
||||
|
||||
$pay_later_messages_or_vaulting_text = sprintf(
|
||||
// translators: %1$s and %2$s is translated PayPal vaulting and Pay Later Messaging strings.
|
||||
__(
|
||||
'You have %1$s enabled, that\'s why %2$s options are unavailable now. You cannot use both features at the same time',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
$enabled,
|
||||
$disabled
|
||||
);
|
||||
$messages[] = new Message( $pay_later_messages_or_vaulting_text, 'warning' );
|
||||
}
|
||||
|
||||
//phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
//phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
if ( ! isset( $_GET['ppcp-onboarding-error'] ) || ! empty( $_POST ) ) {
|
||||
return array();
|
||||
return $messages;
|
||||
}
|
||||
//phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
//phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
|
||||
$messages = array(
|
||||
new Message(
|
||||
__(
|
||||
'We could not complete the onboarding process. Some features, such as card processing, will not be available. To fix this, please try again.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'error',
|
||||
false
|
||||
$messages[] = new Message(
|
||||
__(
|
||||
'We could not complete the onboarding process. Some features, such as card processing, will not be available. To fix this, please try again.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether PayPal vaulting is enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function paypal_vaulting_is_enabled(): bool {
|
||||
$saving_paypal_account_is_enabled = $this->settings->has( 'save_paypal_account' ) &&
|
||||
(bool) $this->settings->get( 'save_paypal_account' );
|
||||
|
||||
$vault_is_enabled = $this->settings->has( 'vault_enabled' ) &&
|
||||
(bool) $this->settings->get( 'vault_enabled' );
|
||||
|
||||
return $saving_paypal_account_is_enabled || $vault_is_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether Pay Later message is enabled either for checkout, cart or product page.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function pay_later_messaging_is_enabled(): bool {
|
||||
$pay_later_message_enabled_for_checkout = $this->settings->has( 'message_enabled' )
|
||||
&& (bool) $this->settings->get( 'message_enabled' );
|
||||
|
||||
$pay_later_message_enabled_for_cart = $this->settings->has( 'message_cart_enabled' )
|
||||
&& (bool) $this->settings->get( 'message_cart_enabled' );
|
||||
|
||||
$pay_later_message_enabled_for_product = $this->settings->has( 'message_product_enabled' )
|
||||
&& (bool) $this->settings->get( 'message_product_enabled' );
|
||||
|
||||
return $pay_later_message_enabled_for_checkout ||
|
||||
$pay_later_message_enabled_for_cart ||
|
||||
$pay_later_message_enabled_for_product;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current screen is PayPal checkout settings screen.
|
||||
*
|
||||
* @return bool Whether is PayPal checkout screen or not.
|
||||
*/
|
||||
private function is_paypal_checkout_screen(): bool {
|
||||
$current_screen = get_current_screen();
|
||||
//phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
//phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
if ( isset( $current_screen->id ) && 'woocommerce_page_wc-settings' === $current_screen->id
|
||||
&& isset( $_GET['section'] ) && 'ppcp-gateway' === $_GET['section'] ) {
|
||||
|
||||
if ( isset( $_GET['ppcp-tab'] ) && 'ppcp-gateway' !== $_GET['ppcp-tab'] ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//phpcs:enable
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the multiselect field.
|
||||
*
|
||||
|
@ -295,7 +374,7 @@ class SettingsRenderer {
|
|||
$key = 'ppcp[' . $field . ']';
|
||||
$id = 'ppcp-' . $field;
|
||||
$config['id'] = $id;
|
||||
$th_td = 'ppcp-heading' !== $config['type'] ? 'td' : 'td';
|
||||
$th_td = 'ppcp-heading' !== $config['type'] ? 'td' : 'th';
|
||||
$colspan = 'ppcp-heading' !== $config['type'] ? 1 : 2;
|
||||
$classes = isset( $config['classes'] ) ? $config['classes'] : array();
|
||||
$classes[] = sprintf( 'ppcp-settings-field-%s', str_replace( 'ppcp-', '', $config['type'] ) );
|
||||
|
|
|
@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\RenderAuthorizeAction;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Assets\SettingsPageAssets;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Checkout\CheckoutPayPalAddressPreset;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Checkout\DisableGateways;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
|
||||
|
@ -72,6 +73,14 @@ class WcGatewayModule implements ModuleInterface {
|
|||
}
|
||||
);
|
||||
|
||||
if ( $container->has( 'wcgateway.url' ) ) {
|
||||
$assets = new SettingsPageAssets(
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'wcgateway.absolute-path' )
|
||||
);
|
||||
$assets->register_assets();
|
||||
}
|
||||
|
||||
add_filter(
|
||||
Repository::NOTICES_FILTER,
|
||||
static function ( $notices ) use ( $container ): array {
|
||||
|
@ -223,6 +232,7 @@ class WcGatewayModule implements ModuleInterface {
|
|||
* @var SettingsListener $listener
|
||||
*/
|
||||
$listener->listen_for_merchant_id();
|
||||
$listener->listen_for_vaulting_enabled();
|
||||
}
|
||||
);
|
||||
|
||||
|
|
22
modules/ppcp-wc-gateway/webpack.config.js
Normal file
22
modules/ppcp-wc-gateway/webpack.config.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const path = require('path');
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
|
||||
module.exports = {
|
||||
devtool: 'sourcemap',
|
||||
mode: isProduction ? 'production' : 'development',
|
||||
target: 'web',
|
||||
entry: {
|
||||
'gateway-settings': path.resolve('./resources/js/gateway-settings.js'),
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'assets/'),
|
||||
filename: 'js/[name].js',
|
||||
},
|
||||
module: {
|
||||
rules: [{
|
||||
test: /\.js?$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
}]
|
||||
}
|
||||
};
|
3908
modules/ppcp-wc-gateway/yarn.lock
Normal file
3908
modules/ppcp-wc-gateway/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue