Fix merge conflict

This commit is contained in:
dinamiko 2022-02-23 09:47:03 +01:00
commit 1beebbb1fc
64 changed files with 2507 additions and 1294 deletions

3
.gitignore vendored
View file

@ -5,7 +5,8 @@ node_modules
.phpunit.result.cache
yarn-error.log
modules/ppcp-button/assets/*
modules/ppcp-wc-gateway/assets/*
modules/ppcp-wc-gateway/assets/js
modules/ppcp-wc-gateway/assets/css
*.zip
.env
auth.json

View file

@ -1,5 +1,20 @@
*** Changelog ***
= 1.7.0 - TBD =
* Fix - DCC orders randomly failing #503
* Fix - Multi-currency broke #481
* Fix - Address information from PayPal shortcut flow not loaded #451
* Enhancement - Improve onboarding flow, allow no card processing #443
* Enhancement - Add Germany to supported ACDC countries #459
* Enhancement - Add filters to allow ACDC for countries #437
* Enhancement - Update 3D Secure #464
* Enhancement - Extend event, error logging & order notes #456
* Enhancement - Display API response errors in checkout page with user-friendly error message #457
* Enhancement - Pass address details to credit card fields #479
* Enhancement - Improve onboarding notice #465
* Enhancement - Add transaction ID to WC order and order note when refund is received #473
* Enhancement - Asset caching may cause bugs on upgrades #501
= 1.6.5 - 2022-01-31 =
* Fix - Allow guest users to purchase subscription products from checkout page #422
* Fix - Transaction ID missing for renewal order #424

View file

@ -12,7 +12,10 @@
"dhii/containers": "^0.1.0-alpha1",
"psr/log": "^1.1",
"ralouphie/getallheaders": "^3.0",
"wikimedia/composer-merge-plugin": "^1.4"
"wikimedia/composer-merge-plugin": "^1.4",
"wp-oop/wordpress-interface": "^0.1.0-alpha1",
"dhii/versions": "^0.1.0-alpha1",
"symfony/polyfill-php80": "^1.19"
},
"require-dev": {
"woocommerce/woocommerce-sniffs": "^0.1.0",

869
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -25,6 +25,9 @@ class Repository implements RepositoryInterface {
*/
public function current_message(): array {
return array_filter(
/**
* Returns the list of admin messages.
*/
(array) apply_filters(
self::NOTICES_FILTER,
array()

View file

@ -127,7 +127,6 @@ return array(
return new PartnerReferrals(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'api.repository.partner-referrals-data' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
@ -209,9 +208,8 @@ return array(
},
'api.repository.partner-referrals-data' => static function ( ContainerInterface $container ) : PartnerReferralsData {
$merchant_email = $container->get( 'api.merchant_email' );
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
return new PartnerReferralsData( $merchant_email, $dcc_applies );
return new PartnerReferralsData( $dcc_applies );
},
'api.repository.cart' => static function ( ContainerInterface $container ): CartRepository {
$factory = $container->get( 'api.factory.purchase-unit' );
@ -327,12 +325,16 @@ return array(
},
'api.shop.currency' => static function ( ContainerInterface $container ) : string {
// We use option instead of get_woocommerce_currency
// because it will not be overridden by currency switching plugins.
$currency = get_woocommerce_currency();
if ( $currency ) {
return $currency;
}
$currency = get_option( 'woocommerce_currency' );
if ( ! $currency ) {
return 'NO_CURRENCY'; // Unlikely to happen.
}
return $currency;
},
'api.shop.country' => static function ( ContainerInterface $container ) : string {
@ -393,7 +395,12 @@ return array(
* The matrix which countries and currency combinations can be used for DCC.
*/
'api.dcc-supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
return array(
/**
* Returns which countries and currency combinations can be used for DCC.
*/
return apply_filters(
'woocommerce_paypal_payments_supported_country_currency_matrix',
array(
'AU' => array(
'AUD',
'CAD',
@ -528,6 +535,7 @@ return array(
'SGD',
'USD',
),
)
);
},
@ -535,7 +543,12 @@ return array(
* Which countries support which credit cards. Empty credit card arrays mean no restriction on currency.
*/
'api.dcc-supported-country-card-matrix' => static function ( ContainerInterface $container ) : array {
return array(
/**
* Returns which countries support which credit cards. Empty credit card arrays mean no restriction on currency.
*/
return apply_filters(
'woocommerce_paypal_payments_supported_country_card_matrix',
array(
'AU' => array(
'mastercard' => array(),
'visa' => array(),
@ -578,6 +591,7 @@ return array(
'amex' => array( 'CAD' ),
'jcb' => array( 'CAD' ),
),
)
);
},

View file

@ -12,7 +12,6 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
use Psr\Log\LoggerInterface;
/**
@ -36,13 +35,6 @@ class PartnerReferrals {
*/
private $bearer;
/**
* The PartnerReferralsData.
*
* @var PartnerReferralsData
*/
private $data;
/**
* The logger.
*
@ -55,30 +47,27 @@ class PartnerReferrals {
*
* @param string $host The host.
* @param Bearer $bearer The bearer.
* @param PartnerReferralsData $data The partner referrals data.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
string $host,
Bearer $bearer,
PartnerReferralsData $data,
LoggerInterface $logger
) {
$this->host = $host;
$this->bearer = $bearer;
$this->data = $data;
$this->logger = $logger;
}
/**
* Fetch the signup link.
*
* @param array $data The partner referrals data.
* @return string
* @throws RuntimeException If the request fails.
*/
public function signup_link(): string {
$data = $this->data->data();
public function signup_link( array $data ): string {
$bearer = $this->bearer->bearer();
$args = array(
'method' => 'POST',

View file

@ -105,6 +105,9 @@ class PaymentToken {
* @return array
*/
public static function get_valid_types() {
/**
* Returns a list of valid payment token types.
*/
return apply_filters(
'woocommerce_paypal_payments_valid_payment_token_types',
array(

View file

@ -55,11 +55,13 @@ class PayerFactory {
$national_number = preg_replace( '/[^0-9]/', '', $national_number );
$national_number = substr( $national_number, 0, 14 );
if ( $national_number ) {
$phone = new PhoneWithType(
'HOME',
new Phone( $national_number )
);
}
}
return new Payer(
new PayerName(
$wc_order->get_billing_first_name(),
@ -91,11 +93,13 @@ class PayerFactory {
$national_number = preg_replace( '/[^0-9]/', '', $national_number );
$national_number = substr( $national_number, 0, 14 );
if ( $national_number ) {
$phone = new PhoneWithType(
'HOME',
new Phone( $national_number )
);
}
}
return new Payer(
new PayerName(
$customer->get_billing_first_name(),
@ -176,12 +180,14 @@ class PayerFactory {
if ( null !== $national_number ) {
$national_number = substr( $national_number, 0, 14 );
if ( $national_number ) {
$phone = new PhoneWithType(
'HOME',
new Phone( $national_number )
);
}
}
}
return new Payer(
new PayerName( $first_name, $last_name ),

View file

@ -134,6 +134,9 @@ class PurchaseUnitFactory {
$invoice_id,
$soft_descriptor
);
/**
* Returns PurchaseUnit for the WC order.
*/
return apply_filters(
'woocommerce_paypal_payments_purchase_unit_from_wc_order',
$purchase_unit,

View file

@ -74,7 +74,10 @@ class ApplicationContextRepository {
$parts = explode( '-', $locale );
if ( count( $parts ) === 3 ) {
return substr( $locale, 0, strrpos( $locale, '-' ) );
$ret = substr( $locale, 0, strrpos( $locale, '-' ) );
if ( false !== $ret ) {
return $ret;
}
}
return 'en';

View file

@ -45,6 +45,8 @@ class CustomerRepository {
}
$unique_id = substr( $this->prefix . strrev( uniqid() ), 0, self::CLIENT_ID_MAX_LENGTH );
assert( is_string( $unique_id ) );
WC()->session->set( 'ppcp_guest_customer_id', $unique_id );
return $unique_id;

View file

@ -15,14 +15,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
* Class PartnerReferralsData
*/
class PartnerReferralsData {
/**
* The merchant email.
*
* @var string
*/
private $merchant_email;
/**
* The DCC Applies Helper object.
*
@ -30,19 +22,39 @@ class PartnerReferralsData {
*/
private $dcc_applies;
/**
* The list of products ('PPCP', 'EXPRESS_CHECKOUT').
*
* @var string[]
*/
private $products;
/**
* PartnerReferralsData constructor.
*
* @param string $merchant_email The email of the merchant.
* @param DccApplies $dcc_applies The DCC Applies helper.
*/
public function __construct(
string $merchant_email,
DccApplies $dcc_applies
) {
$this->merchant_email = $merchant_email;
$this->dcc_applies = $dcc_applies;
$this->products = array(
$this->dcc_applies->for_country_currency() ? 'PPCP' : 'EXPRESS_CHECKOUT',
);
}
/**
* Returns a new copy of this object with the given value set.
*
* @param string[] $products The list of products ('PPCP', 'EXPRESS_CHECKOUT').
* @return static
*/
public function with_products( array $products ): self {
$obj = clone $this;
$obj->products = $products;
return $obj;
}
/**
@ -60,33 +72,26 @@ class PartnerReferralsData {
* @return array
*/
public function data(): array {
$data = $this->default_data();
return $data;
}
/**
* Returns the default data.
*
* @return array
*/
private function default_data(): array {
return array(
'partner_config_override' => array(
'partner_logo_url' => 'https://connect.woocommerce.com/images/woocommerce_logo.png',
/**
* Returns the URL which will be opened at the end of onboarding.
*/
'return_url' => apply_filters(
'woocommerce_paypal_payments_partner_config_override_return_url',
admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' )
),
/**
* Returns the description of the URL which will be opened at the end of onboarding.
*/
'return_url_description' => apply_filters(
'woocommerce_paypal_payments_partner_config_override_return_url_description',
__( 'Return to your shop.', 'woocommerce-paypal-payments' )
),
'show_add_credit_card' => true,
),
'products' => array(
$this->dcc_applies->for_country_currency() ? 'PPCP' : 'EXPRESS_CHECKOUT',
),
'products' => $this->products,
'legal_consents' => array(
array(
'type' => 'SHARE_DATA_CONSENT',

View file

@ -9,7 +9,6 @@ class CreditCardRenderer {
this.cardValid = false;
this.formValid = false;
this.currentHostedFieldsInstance = null;
this.formSubmissionSubscribed = false;
}
render(wrapper, contextConfig) {
@ -122,7 +121,7 @@ class CreditCardRenderer {
});
if (!this.formSubmissionSubscribed) {
if (document.querySelector(wrapper).getAttribute('data-ppcp-subscribed') !== true) {
document.querySelector(wrapper + ' button').addEventListener(
'click',
event => {
@ -130,7 +129,8 @@ class CreditCardRenderer {
this._submit(contextConfig);
}
);
this.formSubmissionSubscribed = true;
document.querySelector(wrapper).setAttribute('data-ppcp-subscribed', true);
}
});

View file

@ -52,7 +52,7 @@ return array(
*
* @var State $state
*/
if ( $state->current_state() <= State::STATE_PROGRESSIVE ) {
if ( $state->current_state() !== State::STATE_ONBOARDED ) {
return new DisabledSmartButton();
}
$settings = $container->get( 'wcgateway.settings' );
@ -73,6 +73,7 @@ return array(
$currency = $container->get( 'api.shop.currency' );
return new SmartButton(
$container->get( 'button.url' ),
$container->get( 'ppcp.asset-version' ),
$container->get( 'session.handler' ),
$settings,
$payer_factory,

View file

@ -44,6 +44,13 @@ class SmartButton implements SmartButtonInterface {
*/
private $module_url;
/**
* The assets version.
*
* @var string
*/
private $version;
/**
* The Session Handler.
*
@ -125,6 +132,7 @@ class SmartButton implements SmartButtonInterface {
* SmartButton constructor.
*
* @param string $module_url The URL to the module.
* @param string $version The assets version.
* @param SessionHandler $session_handler The Session Handler.
* @param Settings $settings The Settings.
* @param PayerFactory $payer_factory The Payer factory.
@ -140,6 +148,7 @@ class SmartButton implements SmartButtonInterface {
*/
public function __construct(
string $module_url,
string $version,
SessionHandler $session_handler,
Settings $settings,
PayerFactory $payer_factory,
@ -155,6 +164,7 @@ class SmartButton implements SmartButtonInterface {
) {
$this->module_url = $module_url;
$this->version = $version;
$this->session_handler = $session_handler;
$this->settings = $settings;
$this->payer_factory = $payer_factory;
@ -406,7 +416,7 @@ class SmartButton implements SmartButtonInterface {
'ppcp-hosted-fields',
untrailingslashit( $this->module_url ) . '/assets/css/hosted-fields.css',
array(),
1
$this->version
);
}
if ( $load_script ) {
@ -414,7 +424,7 @@ class SmartButton implements SmartButtonInterface {
'ppcp-smart-button',
untrailingslashit( $this->module_url ) . '/assets/js/button.js',
array( 'jquery' ),
'1.3.2',
$this->version,
true
);
@ -1012,38 +1022,50 @@ class SmartButton implements SmartButtonInterface {
}
/**
* Return action name PayPal buttons will be rendered at on checkout page.
* Returns the action name that PayPal button will use for rendering on the checkout page.
*
* @return string Action name.
*/
private function checkout_button_renderer_hook(): string {
/**
* The filter returning the action name that PayPal button will use for rendering on the checkout page.
*/
return (string) apply_filters( 'woocommerce_paypal_payments_checkout_button_renderer_hook', 'woocommerce_review_order_after_payment' );
}
/**
* Return action name PayPal DCC button will be rendered at on checkout page.
* Returns the action name that PayPal DCC button will use for rendering on the checkout page.
*
* @return string
*/
private function checkout_dcc_button_renderer_hook(): string {
/**
* The filter returning the action name that PayPal DCC button will use for rendering on the checkout page.
*/
return (string) apply_filters( 'woocommerce_paypal_payments_checkout_dcc_renderer_hook', 'woocommerce_review_order_after_submit' );
}
/**
* Return action name PayPal button and Pay Later message will be rendered at on pay-order page.
* Returns the action name that PayPal button and Pay Later message will use for rendering on the pay-order page.
*
* @return string
*/
private function pay_order_renderer_hook(): string {
/**
* The filter returning the action name that PayPal button and Pay Later message will use for rendering on the pay-order page.
*/
return (string) apply_filters( 'woocommerce_paypal_payments_pay_order_dcc_renderer_hook', 'woocommerce_pay_order_after_submit' );
}
/**
* Return action name PayPal button will be rendered next to Proceed to checkout button (normally displayed in cart).
* Returns action name that PayPal button will use for rendering next to Proceed to checkout button (normally displayed in cart).
*
* @return string
*/
private function proceed_to_checkout_button_renderer_hook(): string {
/**
* The filter returning the action name that PayPal button will use for rendering next to Proceed to checkout button (normally displayed in cart).
*/
return (string) apply_filters(
'woocommerce_paypal_payments_proceed_to_checkout_button_renderer_hook',
'woocommerce_proceed_to_checkout'
@ -1051,11 +1073,14 @@ class SmartButton implements SmartButtonInterface {
}
/**
* Return action name PayPal button will be rendered in the WC mini cart.
* Returns the action name that PayPal button will use for rendering in the WC mini cart.
*
* @return string
*/
private function mini_cart_button_renderer_hook(): string {
/**
* The filter returning the action name that PayPal button will use for rendering in the WC mini cart.
*/
return (string) apply_filters(
'woocommerce_paypal_payments_mini_cart_button_renderer_hook',
'woocommerce_widget_shopping_cart_after_buttons'
@ -1063,11 +1088,14 @@ class SmartButton implements SmartButtonInterface {
}
/**
* Return action name PayPal button and Pay Later message will be rendered at on the single product page.
* Returns the action name that PayPal button and Pay Later message will use for rendering on the single product page.
*
* @return string
*/
private function single_product_renderer_hook(): string {
/**
* The filter returning the action name that PayPal button and Pay Later message will use for rendering on the single product page.
*/
return (string) apply_filters( 'woocommerce_paypal_payments_single_product_renderer_hook', 'woocommerce_single_product_summary' );
}
}

View file

@ -89,6 +89,9 @@ class PPECHelper {
* @return bool
*/
public static function use_ppec_compat_layer_for_subscriptions() {
/**
* The filter returning whether the compatibility layer for PPEC Subscriptions should be initialized.
*/
return ( ! self::is_gateway_available() ) && self::site_has_ppec_subscriptions() && apply_filters( 'woocommerce_paypal_payments_process_legacy_subscriptions', true );
}

View file

@ -2,41 +2,28 @@
display: none;
}
#field-merchant_email_production,
#field-ppcp_disconnect_sandbox,
#field-ppcp_disconnect_production,
#field-merchant_id_production,
#field-client_id_production,
#field-client_secret_production,
#field-merchant_email_sandbox,
#field-merchant_id_sandbox,
#field-client_id_sandbox,
#field-client_secret_sandbox{
.ppcp-onboarded .ppcp-onboarding-element:not(.ppcp-always-shown-element) {
display: none;
}
#field-merchant_email_production.show,
#field-ppcp_disconnect_sandbox.show,
#field-ppcp_disconnect_production.show,
#field-merchant_id_production.show,
#field-client_id_production.show,
#field-client_secret_production.show,
#field-merchant_email_sandbox.show,
#field-merchant_id_sandbox.show,
#field-client_id_sandbox.show,
#field-client_secret_sandbox.show {
.ppcp-onboarding .ppcp-settings-field:not(.ppcp-onboarding-element):not(.ppcp-always-shown-element) {
display: none;
}
.ppcp-settings-field.hide {
display: none;
}
.ppcp-settings-field.show {
display: table-row;
}
#field-toggle_manual_input span.hide,
#field-toggle_manual_input.show span.show{
display: none;
}
#field-toggle_manual_input.show span.hide {
display: unset;
label.error {
color: red;
font-weight: bold;
}
#field-production_toggle_manual_input button,
#field-sandbox_toggle_manual_input button {
#field-toggle_manual_input button {
color: #0073aa;
transition-property: border, background, color;
transition-duration: .05s;
@ -49,39 +36,8 @@
padding: 0;
}
#field-sandbox_toggle_manual_input.onboarded,
#field-production_toggle_manual_input.onboarded {
display: none;
}
#field-ppcp_disconnect_sandbox.onboarded,
#field-ppcp_disconnect_production.onboarded,
#field-merchant_email_sandbox.onboarded,
#field-merchant_id_sandbox.onboarded,
#field-client_id_sandbox.onboarded,
#field-client_secret_sandbox.onboarded,
#field-merchant_email_production.onboarded,
#field-merchant_id_production.onboarded,
#field-client_id_production.onboarded,
#field-client_secret_production.onboarded {
display:table-row;
}
#field-ppcp_disconnect_sandbox.onboarded.hide,
#field-ppcp_disconnect_production.onboarded.hide,
#field-merchant_email_sandbox.onboarded.hide,
#field-merchant_id_sandbox.onboarded.hide,
#field-client_id_sandbox.onboarded.hide,
#field-client_secret_sandbox.onboarded.hide,
#field-merchant_email_production.onboarded.hide,
#field-merchant_id_production.onboarded.hide,
#field-client_id_production.onboarded.hide,
#field-client_secret_production.onboarded.hide {
display:none;
}
/* Probably not the best location for this but will do until there's a general purpose settings CSS file. */
.ppcp-settings-field-heading td, .ppcp-settings-field-heading th {
.ppcp-settings-field-heading td, .ppcp-settings-field-heading th, .ppcp-settings-no-title-col td {
padding-left: 0;
}
@ -92,3 +48,83 @@
.input-text[pattern]:invalid {
border: red solid 2px;
}
ul.ppcp-onboarding-options, ul.ppcp-onboarding-options-sublist {
list-style: none;
}
ul.ppcp-onboarding-options-sublist {
margin-left: 15px;
}
.ppcp-muted-text {
opacity: 0.6;
font-size: 85%;
}
#field-ppcp_onboarading_header > td, #field-ppcp_onboarading_options > td {
padding: 0;
}
.ppcp-onboarding-header, .ppcp-onboarding-cards-options {
display: flex;
width: 1200px;
}
.ppcp-onboarding-header-left, .ppcp-onboarding-header-right {
flex: 50%;
}
.ppcp-onboarding-header-right {
text-align: right;
}
.ppcp-onboarding-header h2 {
margin-top: 0;
}
.ppcp-onboarding-header-left img {
height: 60px;
}
.ppcp-onboarding-header-cards img, .ppcp-onboarding-header-paypal-logos img {
margin: 5px;
}
.ppcp-onboarding-header-cards img {
height: 37px;
}
.ppcp-onboarding-header-paypal-logos img {
height: 32px;
}
.ppcp-onboarding-cards-options table {
margin-left: 35px;
margin-right: 15px;
}
.ppcp-onboarding-cards-options table td {
padding-top: 2px;
}
.ppcp-onboarding-cards-options table td:first-child {
vertical-align: top;
}
.ppcp-onboarding-cards-options table tr:not(:last-child) td {
padding-bottom: 0;
}
.ppcp-onboarding-cards-options table tr td:first-child {
width: 350px;
}
.ppcp-onboarding-cards-screen {
flex: 1;
align-self: center;
}
.ppcp-onboarding-cards-screen img {
width: 100%;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

View file

@ -1,9 +1,11 @@
// Onboarding.
const ppcp_onboarding = {
BUTTON_SELECTOR: '[data-paypal-onboard-button]',
PAYPAL_JS_ID: 'ppcp-onboarding-paypal-js',
_timeout: false,
STATE_START: 'start',
STATE_ONBOARDED: 'onboarded',
init: function() {
document.addEventListener('DOMContentLoaded', this.reload);
},
@ -15,7 +17,7 @@ const ppcp_onboarding = {
return;
}
// Add event listeners to buttons.
// Add event listeners to buttons preventing link clicking if PayPal init failed.
buttons.forEach(
(element) => {
if (element.hasAttribute('data-ppcp-button-initialized')) {
@ -83,14 +85,13 @@ const ppcp_onboarding = {
authCode: authCode,
sharedId: sharedId,
nonce: PayPalCommerceGatewayOnboarding.nonce,
env: env
env: env,
acceptCards: document.querySelector('#ppcp-onboarding-accept-cards').checked,
}
)
}
);
},
};
function ppcp_onboarding_sandboxCallback(...args) {
@ -101,151 +102,152 @@ function ppcp_onboarding_productionCallback(...args) {
return ppcp_onboarding.loginSeller('production', ...args);
}
/**
* Since the PayPal modal will redirect the user a dirty form
* provokes an alert if the user wants to leave the page. Since the user
* needs to toggle the sandbox switch, we disable this dirty state with the
* following workaround for checkboxes.
*
* @param event
*/
const checkBoxOnClick = (event) => {
const value = event.target.checked;
if (event.target.getAttribute('id') === 'ppcp-sandbox_on') {
toggleSandboxProduction(! value);
(() => {
const productionCredentialElementsSelectors = [
'#field-merchant_email_production',
'#field-merchant_id_production',
'#field-client_id_production',
'#field-client_secret_production',
];
const sandboxCredentialElementsSelectors = [
'#field-merchant_email_sandbox',
'#field-merchant_id_sandbox',
'#field-client_id_sandbox',
'#field-client_secret_sandbox',
];
const updateOptionsState = () => {
const cardsChk = document.querySelector('#ppcp-onboarding-accept-cards');
if (!cardsChk) {
return;
}
document.querySelectorAll('#ppcp-onboarding-dcc-options input').forEach(input => {
input.disabled = !cardsChk.checked;
});
const basicRb = document.querySelector('#ppcp-onboarding-dcc-basic');
const isExpress = !cardsChk.checked || basicRb.checked;
const expressButtonSelectors = [
'#field-ppcp_onboarding_production_express',
'#field-ppcp_onboarding_sandbox_express',
];
const ppcpButtonSelectors = [
'#field-ppcp_onboarding_production_ppcp',
'#field-ppcp_onboarding_sandbox_ppcp',
];
document.querySelectorAll(expressButtonSelectors.join()).forEach(
element => element.style.display = isExpress ? '' : 'none'
);
document.querySelectorAll(ppcpButtonSelectors.join()).forEach(
element => element.style.display = !isExpress ? '' : 'none'
);
const screemImg = document.querySelector('#ppcp-onboarding-cards-screen-img');
if (screemImg) {
const currentRb = Array.from(document.querySelectorAll('#ppcp-onboarding-dcc-options input[type="radio"]'))
.filter(rb => rb.checked)[0] ?? null;
const imgUrl = currentRb.getAttribute('data-screen-url');
screemImg.src = imgUrl;
}
};
const updateManualInputControls = (shown, isSandbox, isAnyEnvOnboarded) => {
const productionElementsSelectors = productionCredentialElementsSelectors;
const sandboxElementsSelectors = sandboxCredentialElementsSelectors;
const otherElementsSelectors = [
'.woocommerce-save-button',
];
if (!isAnyEnvOnboarded) {
otherElementsSelectors.push('#field-sandbox_on');
}
document.querySelectorAll(productionElementsSelectors.join()).forEach(
element => {
element.classList.remove('hide', 'show');
element.classList.add((shown && !isSandbox) ? 'show' : 'hide');
}
);
document.querySelectorAll(sandboxElementsSelectors.join()).forEach(
element => {
element.classList.remove('hide', 'show');
element.classList.add((shown && isSandbox) ? 'show' : 'hide');
}
);
document.querySelectorAll(otherElementsSelectors.join()).forEach(
element => element.style.display = shown ? '' : 'none'
);
};
const updateEnvironmentControls = (isSandbox) => {
const productionElementsSelectors = [
'#field-ppcp_disconnect_production',
'#field-credentials_production_heading',
];
const sandboxElementsSelectors = [
'#field-ppcp_disconnect_sandbox',
'#field-credentials_sandbox_heading',
];
document.querySelectorAll(productionElementsSelectors.join()).forEach(
element => element.style.display = !isSandbox ? '' : 'none'
);
document.querySelectorAll(sandboxElementsSelectors.join()).forEach(
element => element.style.display = isSandbox ? '' : 'none'
);
};
let isDisconnecting = false;
const disconnect = (event) => {
event.preventDefault();
const fields = event.target.classList.contains('production') ? productionCredentialElementsSelectors : sandboxCredentialElementsSelectors;
document.querySelectorAll(fields.map(f => f + ' input').join()).forEach(
(element) => {
element.value = '';
}
);
isDisconnecting = true;
document.querySelector('.woocommerce-save-button').click();
};
// Prevent the message about unsaved checkbox/radiobutton when reloading the page.
// (WC listens for changes on all inputs and sets dirty flag until form submission)
const preventDirtyCheckboxPropagation = event => {
event.preventDefault();
event.stopPropagation();
const value = event.target.checked;
setTimeout( () => {
event.target.checked = value;
}, 1
);
};
/**
* Toggles the credential input fields.
*
* @param forProduction
*/
const credentialToggle = (forProduction) => {
const sandboxClassSelectors = [
'#field-ppcp_disconnect_sandbox',
'#field-merchant_email_sandbox',
'#field-merchant_id_sandbox',
'#field-client_id_sandbox',
'#field-client_secret_sandbox',
];
const productionClassSelectors = [
'#field-ppcp_disconnect_production',
'#field-merchant_email_production',
'#field-merchant_id_production',
'#field-client_id_production',
'#field-client_secret_production',
];
const selectors = forProduction ? productionClassSelectors : sandboxClassSelectors;
document.querySelectorAll(selectors.join()).forEach(
(element) => {element.classList.toggle('show')}
)
};
/**
* Toggles the visibility of the sandbox/production input fields.
*
* @param showProduction
*/
const toggleSandboxProduction = (showProduction) => {
const productionDisplaySelectors = [
'#field-credentials_production_heading',
'#field-production_toggle_manual_input',
'#field-ppcp_onboarding_production',
];
const productionClassSelectors = [
'#field-ppcp_disconnect_production',
'#field-merchant_email_production',
'#field-merchant_id_production',
'#field-client_id_production',
'#field-client_secret_production',
];
const sandboxDisplaySelectors = [
'#field-credentials_sandbox_heading',
'#field-sandbox_toggle_manual_input',
'#field-ppcp_onboarding_sandbox',
];
const sandboxClassSelectors = [
'#field-ppcp_disconnect_sandbox',
'#field-merchant_email_sandbox',
'#field-merchant_id_sandbox',
'#field-client_id_sandbox',
'#field-client_secret_sandbox',
];
if (showProduction) {
document.querySelectorAll(productionDisplaySelectors.join()).forEach(
(element) => {element.style.display = ''}
);
document.querySelectorAll(sandboxDisplaySelectors.join()).forEach(
(element) => {element.style.display = 'none'}
);
document.querySelectorAll(productionClassSelectors.join()).forEach(
(element) => {element.classList.remove('hide')}
);
document.querySelectorAll(sandboxClassSelectors.join()).forEach(
(element) => {
element.classList.remove('show');
element.classList.add('hide');
}
);
return;
}
document.querySelectorAll(productionDisplaySelectors.join()).forEach(
(element) => {element.style.display = 'none'}
);
document.querySelectorAll(sandboxDisplaySelectors.join()).forEach(
(element) => {element.style.display = ''}
);
document.querySelectorAll(sandboxClassSelectors.join()).forEach(
(element) => {element.classList.remove('hide')}
);
document.querySelectorAll(productionClassSelectors.join()).forEach(
(element) => {
element.classList.remove('show');
element.classList.add('hide');
}
)
};
const disconnect = (event) => {
event.preventDefault();
const fields = event.target.classList.contains('production') ? [
'#field-merchant_email_production input',
'#field-merchant_id_production input',
'#field-client_id_production input',
'#field-client_secret_production input',
] : [
'#field-merchant_email_sandbox input',
'#field-merchant_id_sandbox input',
'#field-client_id_sandbox input',
'#field-client_secret_sandbox input',
];
document.querySelectorAll(fields.join()).forEach(
(element) => {
element.value = '';
}
);
document.querySelector('.woocommerce-save-button').click();
};
(() => {
const sandboxSwitchElement = document.querySelector('#ppcp-sandbox_on');
if (sandboxSwitchElement) {
toggleSandboxProduction(! sandboxSwitchElement.checked);
const validate = () => {
const selectors = sandboxSwitchElement.checked ? sandboxCredentialElementsSelectors : productionCredentialElementsSelectors;
const values = selectors.map(s => document.querySelector(s + ' input')).map(el => el.value);
const errors = [];
if (values.some(v => !v)) {
errors.push(PayPalCommerceGatewayOnboarding.error_messages.no_credentials);
}
return errors;
};
const isAnyEnvOnboarded = PayPalCommerceGatewayOnboarding.sandbox_state === ppcp_onboarding.STATE_ONBOARDED ||
PayPalCommerceGatewayOnboarding.production_state === ppcp_onboarding.STATE_ONBOARDED;
document.querySelectorAll('.ppcp-disconnect').forEach(
(button) => {
button.addEventListener(
@ -255,43 +257,89 @@ const disconnect = (event) => {
}
);
// Prevent a possibly dirty form arising from this particular checkbox.
if (sandboxSwitchElement) {
document.querySelectorAll('.ppcp-onboarding-options input').forEach(
(element) => {
element.addEventListener('click', event => {
updateOptionsState();
preventDirtyCheckboxPropagation(event);
});
}
);
const isSandboxInBackend = PayPalCommerceGatewayOnboarding.current_env === 'sandbox';
if (sandboxSwitchElement.checked !== isSandboxInBackend) {
sandboxSwitchElement.checked = isSandboxInBackend;
}
updateOptionsState();
const settingsContainer = document.querySelector('#mainform .form-table');
const markCurrentOnboardingState = (isOnboarded) => {
settingsContainer.classList.remove('ppcp-onboarded', 'ppcp-onboarding');
settingsContainer.classList.add(isOnboarded ? 'ppcp-onboarded' : 'ppcp-onboarding');
}
markCurrentOnboardingState(PayPalCommerceGatewayOnboarding.current_state === ppcp_onboarding.STATE_ONBOARDED);
const manualInputToggleButton = document.querySelector('#field-toggle_manual_input button');
let isManualInputShown = PayPalCommerceGatewayOnboarding.current_state === ppcp_onboarding.STATE_ONBOARDED;
manualInputToggleButton.addEventListener(
'click',
(event) => {
event.preventDefault();
isManualInputShown = !isManualInputShown;
updateManualInputControls(isManualInputShown, sandboxSwitchElement.checked, isAnyEnvOnboarded);
}
);
sandboxSwitchElement.addEventListener(
'click',
(event) => {
const value = event.target.checked;
const isSandbox = sandboxSwitchElement.checked;
toggleSandboxProduction( ! value );
if (isAnyEnvOnboarded) {
const onboardingState = isSandbox ? PayPalCommerceGatewayOnboarding.sandbox_state : PayPalCommerceGatewayOnboarding.production_state;
const isOnboarded = onboardingState === ppcp_onboarding.STATE_ONBOARDED;
event.preventDefault();
event.stopPropagation();
setTimeout( () => {
event.target.checked = value;
}, 1
);
markCurrentOnboardingState(isOnboarded);
isManualInputShown = isOnboarded;
}
updateManualInputControls(isManualInputShown, isSandbox, isAnyEnvOnboarded);
updateEnvironmentControls(isSandbox);
preventDirtyCheckboxPropagation(event);
}
);
updateManualInputControls(isManualInputShown, sandboxSwitchElement.checked, isAnyEnvOnboarded);
updateEnvironmentControls(sandboxSwitchElement.checked);
document.querySelector('#mainform').addEventListener('submit', e => {
if (isDisconnecting) {
return;
}
// document.querySelectorAll('#mainform input[type="checkbox"]').forEach(
// (checkbox) => {
// checkbox.addEventListener('click', checkBoxOnClick);
// }
// );
const errors = validate();
if (errors.length) {
e.preventDefault();
document.querySelectorAll('#field-sandbox_toggle_manual_input button, #field-production_toggle_manual_input button').forEach(
(button) => {
button.addEventListener(
'click',
(event) => {
event.preventDefault();
const isProduction = event.target.classList.contains('production-toggle');
credentialToggle(isProduction);
const errorLabel = document.querySelector('#ppcp-form-errors-label');
errorLabel.parentElement.parentElement.classList.remove('hide');
errorLabel.innerHTML = errors.join('<br/>');
errorLabel.scrollIntoView();
window.scrollBy(0, -120); // WP + WC floating header
}
)
}
);
});
// Onboarding buttons.
ppcp_onboarding.init();

View file

@ -23,7 +23,7 @@ document.addEventListener(
}
group.forEach( (elementToShow) => {
document.querySelector(elementToShow).style.display = 'table-row';
document.querySelector(elementToShow).style.display = '';
})
if('ppcp-message_enabled' === event.target.getAttribute('id')){
@ -56,7 +56,7 @@ document.addEventListener(
return;
}
if (value === elementToToggle.value && domElement.style.display !== 'none') {
domElement.style.display = 'table-row';
domElement.style.display = '';
return;
}
domElement.style.display = 'none';
@ -69,7 +69,7 @@ document.addEventListener(
const value = event.target.value;
group.forEach( (elementToToggle) => {
if (value === elementToToggle.value) {
document.querySelector(elementToToggle.selector).style.display = 'table-row';
document.querySelector(elementToToggle.selector).style.display = '';
return;
}
document.querySelector(elementToToggle.selector).style.display = 'none';

View file

@ -18,6 +18,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnerReferrals;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\Onboarding\Assets\OnboardingAssets;
use WooCommerce\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
use WooCommerce\PayPalCommerce\Onboarding\OnboardingRESTController;
@ -117,9 +118,8 @@ return array(
);
},
'onboarding.state' => function( ContainerInterface $container ) : State {
$environment = $container->get( 'onboarding.environment' );
$settings = $container->get( 'wcgateway.settings' );
return new State( $environment, $settings );
return new State( $settings );
},
'onboarding.environment' => function( ContainerInterface $container ) : Environment {
$settings = $container->get( 'wcgateway.settings' );
@ -131,8 +131,11 @@ return array(
$login_seller_endpoint = $container->get( 'onboarding.endpoint.login-seller' );
return new OnboardingAssets(
$container->get( 'onboarding.url' ),
$container->get( 'ppcp.asset-version' ),
$state,
$login_seller_endpoint
$container->get( 'onboarding.environment' ),
$login_seller_endpoint,
$container->get( 'wcgateway.current-ppcp-settings-page-id' )
);
},
@ -188,7 +191,6 @@ return array(
return new PartnerReferrals(
CONNECT_WOO_SANDBOX_URL,
new ConnectBearer(),
$container->get( 'api.repository.partner-referrals-data' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
@ -197,7 +199,6 @@ return array(
return new PartnerReferrals(
CONNECT_WOO_URL,
new ConnectBearer(),
$container->get( 'api.repository.partner-referrals-data' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
@ -205,11 +206,18 @@ return array(
$partner_referrals = $container->get( 'api.endpoint.partner-referrals-production' );
$partner_referrals_sandbox = $container->get( 'api.endpoint.partner-referrals-sandbox' );
$partner_referrals_data = $container->get( 'api.repository.partner-referrals-data' );
$settings = $container->get( 'wcgateway.settings' );
return new OnboardingRenderer(
$settings,
$partner_referrals,
$partner_referrals_sandbox
$partner_referrals_sandbox,
$partner_referrals_data
);
},
'onboarding.render-options' => static function ( ContainerInterface $container ) : OnboardingOptionsRenderer {
return new OnboardingOptionsRenderer(
$container->get( 'onboarding.url' )
);
},
'onboarding.rest' => static function( $container ) : OnboardingRESTController {

View file

@ -10,7 +10,9 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Onboarding\Assets;
use WooCommerce\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
/**
* Class OnboardingAssets
@ -24,6 +26,13 @@ class OnboardingAssets {
*/
private $module_url;
/**
* The assets version.
*
* @var string
*/
private $version;
/**
* The State.
*
@ -31,6 +40,13 @@ class OnboardingAssets {
*/
private $state;
/**
* The Environment.
*
* @var Environment
*/
private $environment;
/**
* The LoginSeller Endpoint.
*
@ -38,22 +54,38 @@ class OnboardingAssets {
*/
private $login_seller_endpoint;
/**
* ID of the current PPCP gateway settings page, or empty if it is not such page.
*
* @var string
*/
protected $page_id;
/**
* OnboardingAssets constructor.
*
* @param string $module_url The URL to the module.
* @param string $version The assets version.
* @param State $state The State object.
* @param Environment $environment The Environment.
* @param LoginSellerEndpoint $login_seller_endpoint The LoginSeller endpoint.
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
*/
public function __construct(
string $module_url,
string $version,
State $state,
LoginSellerEndpoint $login_seller_endpoint
Environment $environment,
LoginSellerEndpoint $login_seller_endpoint,
string $page_id
) {
$this->module_url = untrailingslashit( $module_url );
$this->version = $version;
$this->state = $state;
$this->environment = $environment;
$this->login_seller_endpoint = $login_seller_endpoint;
$this->page_id = $page_id;
}
/**
@ -68,14 +100,14 @@ class OnboardingAssets {
'ppcp-onboarding',
$url,
array(),
1
$this->version
);
$url = untrailingslashit( $this->module_url ) . '/assets/js/settings.js';
wp_register_script(
'ppcp-settings',
$url,
array(),
1,
$this->version,
true
);
@ -84,7 +116,7 @@ class OnboardingAssets {
'ppcp-onboarding',
$url,
array( 'jquery' ),
1,
$this->version,
true
);
wp_localize_script(
@ -106,6 +138,13 @@ class OnboardingAssets {
'endpoint' => home_url( \WC_AJAX::get_endpoint( LoginSellerEndpoint::ENDPOINT ) ),
'nonce' => wp_create_nonce( $this->login_seller_endpoint::nonce() ),
'paypal_js_url' => 'https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js',
'sandbox_state' => State::get_state_name( $this->state->sandbox_state() ),
'production_state' => State::get_state_name( $this->state->production_state() ),
'current_state' => State::get_state_name( $this->state->current_state() ),
'current_env' => $this->environment->current_environment(),
'error_messages' => array(
'no_credentials' => __( 'API credentials must be entered to save the settings.', 'woocommerce-paypal-payments' ),
),
);
}
@ -131,7 +170,6 @@ class OnboardingAssets {
* @return bool
*/
private function should_render_onboarding_script(): bool {
global $current_section;
return 'ppcp-gateway' === $current_section;
return PayPalGateway::ID === $this->page_id;
}
}

View file

@ -128,6 +128,7 @@ class LoginSellerEndpoint implements EndpointInterface {
$this->settings->set( 'sandbox_on', $is_sandbox );
$this->settings->set( 'products_dcc_enabled', null );
$this->settings->persist();
$endpoint = $is_sandbox ? $this->login_seller_sandbox : $this->login_seller_production;
$credentials = $endpoint->credentials_for(
$data['sharedId'],
@ -143,10 +144,30 @@ class LoginSellerEndpoint implements EndpointInterface {
}
$this->settings->set( 'client_secret', $credentials->client_secret );
$this->settings->set( 'client_id', $credentials->client_id );
$accept_cards = (bool) ( $data['acceptCards'] ?? true );
$funding_sources = array();
if ( $this->settings->get( 'disable_funding' ) ) {
$funding_sources = $this->settings->get( 'disable_funding' );
if ( ! is_array( $funding_sources ) ) {
$funding_sources = array();
}
}
if ( $accept_cards ) {
$funding_sources = array_diff( $funding_sources, array( 'card' ) );
} else {
if ( ! in_array( 'card', $funding_sources, true ) ) {
$funding_sources[] = 'card';
}
}
$this->settings->set( 'disable_funding', $funding_sources );
$this->settings->persist();
if ( $this->cache->has( PayPalBearer::CACHE_KEY ) ) {
$this->cache->delete( PayPalBearer::CACHE_KEY );
}
wp_schedule_single_event(
time() + 5,
WebhookRegistrar::EVENT_HOOK

View file

@ -65,16 +65,15 @@ class OnboardingModule implements ModuleInterface {
if ( 'ppcp_onboarding' !== $config['type'] ) {
return $field;
}
$renderer = $c->get( 'onboarding.render' );
$is_production = 'production' === $config['env'];
/**
* The OnboardingRenderer.
*
* @var OnboardingRenderer $renderer
*/
$renderer = $c->get( 'onboarding.render' );
assert( $renderer instanceof OnboardingRenderer );
$is_production = 'production' === $config['env'];
$products = $config['products'];
ob_start();
$renderer->render( $is_production );
$renderer->render( $is_production, $products );
$content = ob_get_contents();
ob_end_clean();
return $content;

View file

@ -10,7 +10,6 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Onboarding;
use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
/**
@ -138,13 +137,13 @@ class OnboardingRESTController {
return array(
'environment' => $environment->current_environment(),
'onboarded' => ( $state->current_state() >= State::STATE_ONBOARDED ),
'state' => $this->get_onboarding_state_name( $state->current_state() ),
'state' => State::get_state_name( $state->current_state() ),
'sandbox' => array(
'state' => $this->get_onboarding_state_name( $state->sandbox_state() ),
'state' => State::get_state_name( $state->sandbox_state() ),
'onboarded' => ( $state->sandbox_state() >= State::STATE_ONBOARDED ),
),
'production' => array(
'state' => $this->get_onboarding_state_name( $state->production_state() ),
'state' => State::get_state_name( $state->production_state() ),
'onboarded' => ( $state->production_state() >= State::STATE_ONBOARDED ),
),
);
@ -265,34 +264,6 @@ class OnboardingRESTController {
return add_query_arg( $this->return_url_args, $url );
}
/**
* Translates an onboarding state to a string.
*
* @param int $state An onboarding state to translate as returned by {@link State} methods.
* @return string A string representing the state: "start", "progressive" or "onboarded".
* @see State::current_state(), State::sandbox_state(), State::production_state().
*/
public function get_onboarding_state_name( $state ) {
$name = 'unknown';
switch ( absint( $state ) ) {
case State::STATE_START:
$name = 'start';
break;
case State::STATE_PROGRESSIVE:
$name = 'progressive';
break;
case State::STATE_ONBOARDED:
$name = 'onboarded';
break;
default:
break;
}
return $name;
}
/**
* Generates a signup link for onboarding for a given environment and optionally adding certain URL arguments
* to the URL users are redirected after completing the onboarding flow.

View file

@ -0,0 +1,199 @@
<?php
/**
* Renders the onboarding options.
*
* @package WooCommerce\PayPalCommerce\Onboarding\Render
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Onboarding\Render;
/**
* Class OnboardingRenderer
*/
class OnboardingOptionsRenderer {
/**
* The module url.
*
* @var string
*/
private $module_url;
/**
* OnboardingOptionsRenderer constructor.
*
* @param string $module_url The module url (for assets).
*/
public function __construct( string $module_url ) {
$this->module_url = $module_url;
}
/**
* Renders the onboarding options.
*
* @param bool $is_shop_supports_dcc Whether the shop can use DCC (country, currency).
*/
public function render( bool $is_shop_supports_dcc ): string {
return '
<ul class="ppcp-onboarding-options">
<li>
<label><input type="checkbox" disabled checked> ' .
__( 'Enable PayPal Payments — includes PayPal, Venmo, Pay Later — with fraud protection', 'woocommerce-paypal-payments' ) . '
</label>
</li>
<li>
<label><input type="checkbox" id="ppcp-onboarding-accept-cards" checked> ' .
__( 'Securely accept all major credit & debit cards on the strength of the PayPal network', 'woocommerce-paypal-payments' ) . '
</label>
</li>
<li>' . $this->render_dcc( $is_shop_supports_dcc ) . '</li>
</ul>';
}
/**
* Renders the onboarding DCC options.
*
* @param bool $is_shop_supports_dcc Whether the shop can use DCC (country, currency).
*/
private function render_dcc( bool $is_shop_supports_dcc ): string {
$items = array();
if ( $is_shop_supports_dcc ) {
$dcc_table_rows = array(
$this->render_table_row(
__( 'Credit & Debit Card form fields', 'woocommerce-paypal-payments' ),
__( 'Customizable user experience', 'woocommerce-paypal-payments' )
),
$this->render_table_row(
__( 'Credit & Debit Card pricing', 'woocommerce-paypal-payments' ),
__( '2.59% + $0.49', 'woocommerce-paypal-payments' )
),
$this->render_table_row(
__( 'Seller Protection', 'woocommerce-paypal-payments' ),
__( 'Yes', 'woocommerce-paypal-payments' ),
__( 'No matter what you sell, Seller Protection can help you avoid chargebacks, reversals, and fees on eligible PayPal payment transactions — even when a customer has filed a dispute.', 'woocommerce-paypal-payments' ),
__( 'On eligible PayPal transactions', 'woocommerce-paypal-payments' )
),
$this->render_table_row(
__( 'Advanced Fraud Protection', 'woocommerce-paypal-payments' ),
__( 'Yes', 'woocommerce-paypal-payments' ),
__( 'Included with Advanced Checkout at no extra cost, Fraud Protection gives you the insight and control you need to better balance chargebacks and declines.', 'woocommerce-paypal-payments' )
),
$this->render_table_row(
__( 'Chargeback Protection', 'woocommerce-paypal-payments' ),
__( 'Yes', 'woocommerce-paypal-payments' ),
__( 'If you choose this optional, fee-based alternative to Fraud Protection, PayPal will manage chargebacks for eligible credit and debit card transactions — so you wont have to worry about unexpected costs.', 'woocommerce-paypal-payments' ),
__( 'Extra 0.4% per transaction', 'woocommerce-paypal-payments' )
),
$this->render_table_row(
__( 'Additional Vetting and Underwriting Required', 'woocommerce-paypal-payments' ),
__( 'Yes', 'woocommerce-paypal-payments' ),
__( 'Business Ownership and other business information will be required during the application for Advanced Card Processing.', 'woocommerce-paypal-payments' )
),
$this->render_table_row(
__( 'Seller Account Type', 'woocommerce-paypal-payments' ),
__( 'Business', 'woocommerce-paypal-payments' )
),
);
$items[] = '
<li>
<label' .
' title="' . __( 'PayPal acts as the payment processor for card transactions. You can add optional features like Chargeback Protection for more security.', 'woocommerce-paypal-payments' ) . '"'
. '>
<input type="radio" id="ppcp-onboarding-dcc-acdc" name="ppcp_onboarding_dcc" value="acdc" checked ' .
'data-screen-url="' . $this->get_screen_url( 'acdc' ) . '"> ' .
__( 'Advanced Card Processing', 'woocommerce-paypal-payments' ) . '
</label>
<table>
' . implode( '', $dcc_table_rows ) . '
</table>
</li>';
}
$basic_table_rows = array(
$this->render_table_row(
__( 'Credit & Debit Card form fields', 'woocommerce-paypal-payments' ),
__( 'Prebuilt user experience', 'woocommerce-paypal-payments' )
),
$this->render_table_row(
__( 'Credit & Debit Card pricing', 'woocommerce-paypal-payments' ),
__( '3.49% + $0.49', 'woocommerce-paypal-payments' )
),
$this->render_table_row(
__( 'Seller Protection', 'woocommerce-paypal-payments' ),
__( 'Yes', 'woocommerce-paypal-payments' ),
__( 'No matter what you sell, Seller Protection can help you avoid chargebacks, reversals, and fees on eligible PayPal payment transactions — even when a customer has filed a dispute.', 'woocommerce-paypal-payments' ),
__( 'On eligible PayPal transactions', 'woocommerce-paypal-payments' )
),
$this->render_table_row(
__( 'Seller Account Type', 'woocommerce-paypal-payments' ),
__( 'Business or Personal', 'woocommerce-paypal-payments' ),
__( 'For Standard payments, Casual sellers may connect their Personal PayPal account in eligible countries to sell on WooCommerce. For Advanced payments, a Business PayPal account is required.', 'woocommerce-paypal-payments' )
),
);
$items[] = '
<li ' . ( ! $is_shop_supports_dcc ? 'style="display: none;"' : '' ) . '>
<label ' .
' title="' . __( 'Card transactions are managed by PayPal, which simplifies compliance requirements for you.', 'woocommerce-paypal-payments' ) . '"'
. '>
<input type="radio" id="ppcp-onboarding-dcc-basic" name="ppcp_onboarding_dcc" value="basic" ' .
( ! $is_shop_supports_dcc ? 'checked' : '' ) .
' data-screen-url="' . $this->get_screen_url( 'basic' ) . '"' .
'> ' .
__( 'Standard Card Processing', 'woocommerce-paypal-payments' ) . '
</label>
<table>
' . implode( $basic_table_rows ) . '
</table>
</li>';
return '
<div class="ppcp-onboarding-cards-options">
<ul id="ppcp-onboarding-dcc-options" class="ppcp-onboarding-options-sublist">' .
implode( '', $items ) .
'
</ul>
<div class="ppcp-onboarding-cards-screen">' .
( $is_shop_supports_dcc ? '<img id="ppcp-onboarding-cards-screen-img" />' : '' ) . '
</div>
</div>';
}
/**
* Returns HTML of a row for the cards options tables.
*
* @param string $header The text in the first cell.
* @param string $value The text in the second cell.
* @param string $tooltip The text shown on hover.
* @param string $note The additional description text, such as about conditions.
* @return string
*/
private function render_table_row( string $header, string $value, string $tooltip = '', string $note = '' ): string {
$value_html = $value;
if ( $note ) {
$value_html .= '<br/><span class="ppcp-muted-text">' . $note . '</span>';
}
$row_attributes_html = '';
if ( $tooltip ) {
$row_attributes_html .= 'title="' . $tooltip . '"';
}
return "
<tr $row_attributes_html>
<td>$header</td>
<td>$value_html</td>
</tr>";
}
/**
* Returns the screen image URL.
*
* @param string $key The image suffix, 'acdc' or 'basic'.
* @return string
*/
private function get_screen_url( string $key ): string {
return untrailingslashit( $this->module_url ) . "/assets/images/cards-screen-$key.png";
}
}

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Onboarding\Render;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnerReferrals;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
/**
@ -39,31 +40,50 @@ class OnboardingRenderer {
*/
private $sandbox_partner_referrals;
/**
* The default partner referrals data.
*
* @var PartnerReferralsData
*/
private $partner_referrals_data;
/**
* OnboardingRenderer constructor.
*
* @param Settings $settings The settings.
* @param PartnerReferrals $production_partner_referrals The PartnerReferrals for production.
* @param PartnerReferrals $sandbox_partner_referrals The PartnerReferrals for sandbox.
* @param PartnerReferralsData $partner_referrals_data The default partner referrals data.
*/
public function __construct( Settings $settings, PartnerReferrals $production_partner_referrals, PartnerReferrals $sandbox_partner_referrals ) {
public function __construct(
Settings $settings,
PartnerReferrals $production_partner_referrals,
PartnerReferrals $sandbox_partner_referrals,
PartnerReferralsData $partner_referrals_data
) {
$this->settings = $settings;
$this->production_partner_referrals = $production_partner_referrals;
$this->sandbox_partner_referrals = $sandbox_partner_referrals;
$this->partner_referrals_data = $partner_referrals_data;
}
/**
* Returns the action URL for the onboarding button/link.
*
* @param boolean $is_production Whether the production or sandbox button should be rendered.
* @param string[] $products The list of products ('PPCP', 'EXPRESS_CHECKOUT').
* @return string URL.
*/
public function get_signup_link( bool $is_production ) {
public function get_signup_link( bool $is_production, array $products ) {
$args = array(
'displayMode' => 'minibrowser',
);
$url = $is_production ? $this->production_partner_referrals->signup_link() : $this->sandbox_partner_referrals->signup_link();
$data = $this->partner_referrals_data
->with_products( $products )
->data();
$url = $is_production ? $this->production_partner_referrals->signup_link( $data ) : $this->sandbox_partner_referrals->signup_link( $data );
$url = add_query_arg( $args, $url );
return $url;
@ -73,13 +93,17 @@ class OnboardingRenderer {
* Renders the "Connect to PayPal" button.
*
* @param bool $is_production Whether the production or sandbox button should be rendered.
* @param string[] $products The list of products ('PPCP', 'EXPRESS_CHECKOUT').
*/
public function render( bool $is_production ) {
public function render( bool $is_production, array $products ) {
try {
$id = 'connect-to' . ( $is_production ? 'production' : 'sandbox' ) . strtolower( implode( '-', $products ) );
$this->render_button(
$this->get_signup_link( $is_production ),
$is_production ? 'connect-to-production' : 'connect-to-sandbox',
$is_production ? __( 'Connect to PayPal', 'woocommerce-paypal-payments' ) : __( 'Connect to PayPal Sandbox', 'woocommerce-paypal-payments' ),
$this->get_signup_link( $is_production, $products ),
$id,
$is_production ? __( 'Activate PayPal', 'woocommerce-paypal-payments' ) : __( 'Test payments with PayPal sandbox', 'woocommerce-paypal-payments' ),
$is_production ? 'primary' : 'secondary',
$is_production ? 'production' : 'sandbox'
);
} catch ( RuntimeException $exception ) {
@ -96,13 +120,14 @@ class OnboardingRenderer {
* @param string $url The url of the button.
* @param string $id The ID of the button.
* @param string $label The button text.
* @param string $class The CSS class for button ('primary', 'secondary').
* @param string $env The environment ('production' or 'sandbox').
*/
private function render_button( string $url, string $id, string $label, string $env ) {
private function render_button( string $url, string $id, string $label, string $class, string $env ) {
?>
<a
target="_blank"
class="button-primary"
class="button-<?php echo esc_attr( $class ); ?>"
id="<?php echo esc_attr( $id ); ?>"
data-paypal-onboard-complete="ppcp_onboarding_<?php echo esc_attr( $env ); ?>Callback"
data-paypal-onboard-button="true"

View file

@ -17,16 +17,8 @@ use Psr\Container\ContainerInterface;
class State {
const STATE_START = 0;
const STATE_PROGRESSIVE = 4;
const STATE_ONBOARDED = 8;
/**
* The Environment.
*
* @var Environment
*/
private $environment;
/**
* The Settings.
*
@ -37,18 +29,31 @@ class State {
/**
* State constructor.
*
* @param Environment $environment The Environment.
* @param ContainerInterface $settings The Settings.
*/
public function __construct(
Environment $environment,
ContainerInterface $settings
) {
$this->environment = $environment;
$this->settings = $settings;
}
/**
* Returns the state of the specified environment (or the active environment if null).
*
* @param string|null $environment 'sandbox', 'production'.
* @return int
*/
public function environment_state( ?string $environment = null ): int {
switch ( $environment ) {
case Environment::PRODUCTION:
return $this->production_state();
case Environment::SANDBOX:
return $this->sandbox_state();
}
return $this->current_state();
}
/**
* Returns the current active onboarding state.
*
@ -57,9 +62,6 @@ class State {
public function current_state(): int {
return $this->state_by_keys(
array(
'merchant_email',
),
array(
'merchant_email',
'merchant_id',
@ -77,9 +79,6 @@ class State {
public function sandbox_state() : int {
return $this->state_by_keys(
array(
'merchant_email_sandbox',
),
array(
'merchant_email_sandbox',
'merchant_id_sandbox',
@ -97,9 +96,6 @@ class State {
public function production_state() : int {
return $this->state_by_keys(
array(
'merchant_email_production',
),
array(
'merchant_email_production',
'merchant_id_production',
@ -110,36 +106,36 @@ class State {
}
/**
* Returns the state based on progressive and onboarded values being looked up in the settings.
* Translates an onboarding state to a string.
*
* @param int $state An onboarding state to translate.
* @return string A string representing the state: "start" or "onboarded".
*/
public static function get_state_name( int $state ) : string {
switch ( $state ) {
case self::STATE_START:
return 'start';
case self::STATE_ONBOARDED:
return 'onboarded';
default:
return 'unknown';
}
}
/**
* Returns the state based on onboarding settings values.
*
* @param array $progressive_keys The keys which need to be present to be at least in progressive state.
* @param array $onboarded_keys The keys which need to be present to be in onboarded state.
*
* @return int
*/
private function state_by_keys( array $progressive_keys, array $onboarded_keys ) : int {
$state = self::STATE_START;
$is_progressive = true;
foreach ( $progressive_keys as $key ) {
if ( ! $this->settings->has( $key ) || ! $this->settings->get( $key ) ) {
$is_progressive = false;
}
}
if ( $is_progressive ) {
$state = self::STATE_PROGRESSIVE;
}
$is_onboarded = true;
private function state_by_keys( array $onboarded_keys ) : int {
foreach ( $onboarded_keys as $key ) {
if ( ! $this->settings->has( $key ) || ! $this->settings->get( $key ) ) {
$is_onboarded = false;
return self::STATE_START;
}
}
if ( $is_onboarded ) {
$state = self::STATE_ONBOARDED;
}
return $state;
return self::STATE_ONBOARDED;
}
}

View file

@ -174,6 +174,9 @@ class RenewalHandler {
* @return PaymentToken|null
*/
private function get_token_for_customer( \WC_Customer $customer, \WC_Order $wc_order ) {
/**
* Returns a payment token for a customer, or null.
*/
$token = apply_filters( 'woocommerce_paypal_payments_subscriptions_get_token_for_customer', null, $customer, $wc_order );
if ( null !== $token ) {
return $token;

View file

@ -22,7 +22,8 @@ return array(
},
'vaulting.assets.myaccount-payments' => function( ContainerInterface $container ) : MyAccountPaymentsAssets {
return new MyAccountPaymentsAssets(
$container->get( 'vaulting.module-url' )
$container->get( 'vaulting.module-url' ),
$container->get( 'ppcp.asset-version' )
);
},
'vaulting.payment-tokens-renderer' => static function (): PaymentTokensRenderer {

View file

@ -23,15 +23,25 @@ class MyAccountPaymentsAssets {
*/
private $module_url;
/**
* The assets version.
*
* @var string
*/
private $version;
/**
* MyAccountPaymentsAssets constructor.
*
* @param string $module_url The URL to the module.
* @param string $version The assets version.
*/
public function __construct(
string $module_url
string $module_url,
string $version
) {
$this->module_url = untrailingslashit( $module_url );
$this->version = $version;
}
/**
@ -44,7 +54,7 @@ class MyAccountPaymentsAssets {
'ppcp-vaulting-myaccount-payments',
untrailingslashit( $this->module_url ) . '/assets/js/myaccount-payments.js',
array( 'jquery' ),
'1',
$this->version,
true
);
}

View file

@ -1,10 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="50px" height="50px" viewBox="0 0 50 50" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Amex_acceptancemark_50x50</title>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Amex_acceptancemark_50x50">
<polygon id="Shape" fill="#FFFFFF" fill-rule="nonzero" points="50 0 0 0 0 50 50 50"></polygon>
<path d="M25.0930414,18.1130368 L21.2948396,18.1130368 L23.1939405,13.5354022 L25.0930414,18.1130368 Z M27.5916246,24.0501324 L31.8892892,24.0501324 L25.7128236,10.0571358 L20.7951652,10.0571358 L14.6182767,24.0501324 L18.8161334,24.0501324 L19.9755555,21.2514908 L26.412114,21.2514908 L27.5916246,24.0501324 Z M46.2218867,24.0501324 L50,24.0501324 L50,10.0571358 L44.1229584,10.0571358 L40.9845044,18.7725731 L37.8661389,10.0571358 L31.8892892,10.0571358 L31.8892892,24.0501324 L35.6671911,24.0501324 L35.6671911,14.255204 L39.2655654,24.0501324 L42.6237239,24.0501324 L46.2218867,14.234904 L46.2218867,24.0501324 Z M23.7946916,36.8350715 L23.7946916,34.6562122 L31.6905191,34.6562122 L31.6905191,31.4978812 L23.7946916,31.4978812 L23.7946916,29.3190219 L31.8903465,29.3190219 L31.8903465,26.0807599 L19.9766128,26.0807599 L19.9766128,40.0733335 L31.8903465,40.0733335 L31.8903465,36.8350715 L23.7946916,36.8350715 Z M46.1576036,33.0427906 L50,37.1306893 L50,28.989148 L46.1576036,33.0427906 Z M44.9840138,40.0733335 L50,40.0733335 L43.3646714,33.0370812 L50,26.0807599 L45.0637333,26.0807599 L40.9661076,30.558375 L36.9078129,26.0807599 L31.8907695,26.0807599 L38.4871899,33.0770467 L31.8907695,40.0733335 L36.7682509,40.0733335 L40.8861766,35.5557529 L44.9840138,40.0733335 Z M50,50 L50,42.0773174 L43.9679599,42.0773174 L40.8622819,38.6432456 L37.7411674,42.0773174 L17.8527325,42.0773174 L17.8527325,26.072513 L11.4335135,26.072513 L19.3957387,8.05336344 L27.0746107,8.05336344 L29.8157358,14.2264457 L29.8157358,8.05336344 L39.3205444,8.05336344 L40.9709711,12.7052196 L42.6319707,8.05336344 L50,8.05336344 L50,0 L0,0 L0,50 L50,50 L50,50 Z" id="Fill-18" fill="#216EA9"></path>
<svg width="134px" height="85px" viewBox="0 0 134 85" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>AmEx Card Icon</title>
<g id="RD-4" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="LP---venmo---social---primary" transform="translate(-824.000000, -1587.000000)">
<g id="AmEx-Card-Icon" transform="translate(824.988647, 1587.578995)">
<rect id="Rectangle" fill="#216EA9" x="0" y="0" width="132.39159" height="83.7921454" rx="4.581738"></rect>
<g id="Amex" transform="translate(11.042625, 26.813487)" fill-rule="nonzero">
<polygon id="path3082" fill="#FFFFFF" points="58.1781633 28.829246 58.1781633 0.111970975 88.752584 0.111970975 92.0328881 4.36473322 95.4216632 0.111970975 111.627357 0.111970975 100.111543 14.3998649 111.627357 28.829246 95.1623158 28.829246 91.8866983 24.4852763 88.560787 28.829246"></polygon>
<polygon id="path3080" fill="#FFFFFF" points="12.9456251 0.111970975 24.8692065 0.111970975 28.7820013 9.06638213 28.7820013 0.111970975 43.6041122 0.111970975 45.933401 6.58395398 48.1915676 0.111970975 83.0100213 0.111970975 83.0100213 28.829228 23.1027999 28.829228 21.2713726 24.3023659 16.3877429 24.3023659 14.5692593 28.829228 0.216820214 28.829228"></polygon>
<path d="M15.3859151,3.6521988 L6.08653439,25.1547742 L12.140911,25.1547742 L13.8567623,20.8489817 L23.8318149,20.8489817 L25.5387763,25.1547742 L31.7265095,25.1547742 L22.436018,3.6521988 L15.3859151,3.6521988 Z M18.8265072,8.6564979 L21.8670326,16.1806509 L15.7770926,16.1806509 L18.8265072,8.6564979 L18.8265072,8.6564979 Z" id="path3046" fill="#216EA9"></path>
<polygon id="path3048" fill="#216EA9" points="32.3666185 25.1511618 32.3666185 3.64856809 40.9702248 3.68034593 45.9743744 17.543851 50.8586955 3.64856809 59.3934994 3.64856809 59.3934994 25.1511618 53.9881232 25.1511618 53.9881232 9.30714548 48.2583106 25.1511618 43.5177841 25.1511618 37.7719947 9.30714548 37.7719947 25.1511618"></polygon>
<polygon id="path3050" fill="#216EA9" points="63.091914 25.1511618 63.091914 3.64856809 80.7305103 3.64856809 80.7305103 8.45836792 68.5541888 8.45836792 68.5541888 12.1364341 80.4460167 12.1364341 80.4460167 16.6632958 68.5541888 16.6632958 68.5541888 20.482831 80.7305103 20.482831 80.7305103 25.1511618"></polygon>
<polygon id="path3066" fill="#216EA9" points="80.1997365 25.1511618 88.7878839 14.5324773 79.9952578 3.64856809 86.80532 3.64856809 92.0417773 10.3769555 97.2960166 3.64856809 103.839367 3.64856809 95.1623158 14.3998648 103.766272 25.1511618 96.9572869 25.1511618 91.8728606 18.5288349 86.9120057 25.1511618"></polygon>
</g>
</g>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="88px" height="55px" viewBox="0 0 88 55" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>iDEAL_acceptancemark_80x50</title>
<g id="RD-4" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="LP---venmo---social---primary" transform="translate(-1290.000000, -1489.000000)">
<g id="iDEAL_acceptancemark_80x50" transform="translate(1290.674250, 1489.000000)">
<rect id="Rectangle" fill="#000000" x="0" y="0" width="86.55975" height="54.78165" rx="3.55725"></rect>
<g id="iDeal" transform="translate(19.722475, 8.569431)" fill-rule="nonzero">
<g id="Group-10">
<path d="M1.31483165,0.4147596 L1.31483165,38.542788 L23.6150559,38.542788 C38.3257411,38.542788 44.7042759,30.3306152 44.7042759,19.4407953 C44.7042759,8.59428425 38.3257411,0.4147596 23.6150559,0.4147596 L1.31483165,0.4147596 Z" id="Fill-6" fill="#FFFFFF"></path>
<path d="M24.4089797,0.0145181949 C43.6643857,0.0145181949 46.5394168,12.2271201 46.5394168,19.5055435 C46.5394168,32.133495 38.680567,39.0878016 24.4089797,39.0878016 L0.807144801,39.0878016 L0.807144801,0.0145181949 L24.4089797,0.0145181949 Z M2.66510307,1.8517804 L2.66510307,37.249739 L24.4089797,37.249739 C37.5392931,37.249739 44.6818631,31.2003587 44.6818631,19.5055435 C44.6818631,7.48721161 36.9395275,1.8517804 24.4089797,1.8517804 L2.66510307,1.8517804 Z" id="Fill-8" fill="#000000"></path>
</g>
<polygon id="Fill-11" fill="#000000" points="5.58237061 34.364139 12.5430893 34.364139 12.5430893 22.1081216 5.58237061 22.1081216"></polygon>
<g id="Group-16" transform="translate(4.652482, 4.673437)">
<path d="M8.73559986,11.2615791 C8.73559986,13.6248309 6.79935854,15.5409215 4.40980375,15.5409215 C2.02146263,15.5409215 0.0834007826,13.6248309 0.0834007826,11.2615791 C0.0834007826,8.89992785 2.02146263,6.98303694 4.40980375,6.98303694 C6.79935854,6.98303694 8.73559986,8.89992785 8.73559986,11.2615791" id="Fill-12" fill="#000000"></path>
<path d="M22.3930799,13.2641209 L22.3930799,15.2470356 L17.4327257,15.2470356 L17.4327257,7.28636627 L22.233075,7.28636627 L22.233075,9.26848068 L19.4381473,9.26848068 L19.4381473,10.1914133 L22.0813635,10.1914133 L22.0813635,12.1731276 L19.4381473,12.1731276 L19.4381473,13.2641209 L22.3930799,13.2641209 Z M23.3559412,15.2496365 L25.7841318,7.28296504 L28.6367095,7.28296504 L31.0640911,15.2496365 L28.9767452,15.2496365 L28.5218135,13.708481 L25.8990278,13.708481 L25.4426801,15.2496365 L23.3559412,15.2496365 Z M26.4850382,11.7269668 L27.9356009,11.7269668 L27.2723189,9.47555532 L27.1519613,9.47555532 L26.4850382,11.7269668 Z M32.0714544,7.2831651 L34.0764715,7.2831651 L34.0764715,13.2641209 L37.0477888,13.2641209 C36.2329978,2.4118093 27.6012291,0.0671642083 19.7581572,0.0671642083 L11.3960302,0.0671642083 L11.3960302,7.28736663 L12.6337925,7.28736663 C14.8904481,7.28736663 16.2924632,8.80091216 16.2924632,11.2355897 C16.2924632,13.7476951 14.9242292,15.2470356 12.6337925,15.2470356 L11.3960302,15.2470356 L11.3960302,29.6942429 L19.7581572,29.6942429 C32.5104059,29.6942429 36.9480638,23.8371318 37.1046299,15.2470356 L32.0714544,15.2470356 L32.0714544,7.2831651 Z M11.394412,9.26988119 L11.394412,13.2641209 L12.6337925,13.2641209 C13.492681,13.2641209 14.2858279,13.0186324 14.2858279,11.2355897 C14.2858279,9.49336174 13.4030701,9.26988119 12.6337925,9.26988119 L11.394412,9.26988119 Z" id="Fill-14" fill="#CC0066"></path>
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="134px" height="84px" viewBox="0 0 134 84" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Mastercard_acceptancemark_80x50</title>
<g id="RD-4" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="LP---venmo---social---primary" transform="translate(-967.000000, -1489.000000)">
<g id="Mastercard_acceptancemark_80x50" transform="translate(967.005261, 1489.000000)">
<rect id="Rectangle" fill="#000000" x="0" y="0" width="132.39159" height="83.7921454" rx="4.581738"></rect>
<g id="mc_symbol" transform="translate(16.758429, 11.730900)" fill-rule="nonzero">
<rect id="Rectangle" fill="#FF5F00" x="34.961091" y="6.91411461" width="29.2905829" height="48.0845243"></rect>
<path d="M37.978038,30.9606238 C37.9706835,21.5790039 42.2555184,12.7149877 49.5979316,6.92260862 C37.1243267,-2.93038543 19.2117299,-1.49521164 8.44863276,10.2195284 C-2.31446439,21.9342684 -2.31446439,39.9954731 8.44863276,51.7102132 C19.2117299,63.4249532 37.1243267,64.8601271 49.5979316,55.0071329 C42.2531818,49.2129145 37.9680851,40.3452244 37.978038,30.9606238 Z" id="Path" fill="#EB001B"></path>
<path d="M95.9169404,50.3974171 L95.9169404,49.0088616 L96.3394821,49.0088616 L96.3394821,48.7215742 L95.333833,48.7215742 L95.333833,49.0088616 L95.7310222,49.0088616 L95.7310222,50.3974171 L95.9169404,50.3974171 Z M97.8690825,50.3974171 L97.8690825,48.7215742 L97.5648527,48.7215742 L97.2099177,49.9186049 L96.8549827,48.7215742 L96.5507529,48.7215742 L96.5507529,50.3974171 L96.7704745,50.3974171 L96.7704745,49.1285648 L97.1000568,50.2178626 L97.3282294,50.2178626 L97.6578119,49.1285648 L97.6578119,50.3974171 L97.8690825,50.3974171 Z" id="Shape" fill="#F79E1B"></path>
<path d="M98.8240266,30.9606238 C98.8240266,42.6682247 92.1727326,53.3479581 81.695674,58.4641002 C71.2186153,63.5802422 58.7549062,62.2345869 49.5979316,54.9986391 C56.9371412,49.2013423 61.2222985,40.3385046 61.2222985,30.9563768 C61.2222985,21.5742491 56.9371412,12.7114113 49.5979316,6.91411461 C58.7549062,-0.321833201 71.2186153,-1.66748859 81.695674,3.44865344 C92.1727326,8.56479549 98.8240266,19.2445288 98.8240266,30.9521297 L98.8240266,30.9606238 Z" id="Path" fill="#F79E1B"></path>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.4 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 16 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

Before After
Before After

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="133px" height="84px" viewBox="0 0 133 84" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Visa_acceptancemark_80x50</title>
<g id="RD-4" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="LP---venmo---social---primary" transform="translate(-824.000000, -1489.000000)">
<g id="Visa_acceptancemark_80x50" transform="translate(824.000000, 1489.000000)">
<rect id="Rectangle" fill="#1D1C45" x="0" y="0" width="132.39159" height="83.7921454" rx="4.581738"></rect>
<g id="Visa" transform="translate(15.082586, 25.137644)" fill="#FFFFFF" fill-rule="nonzero">
<path d="M51.4455687,0.590854329 L44.5028773,32.8958387 L36.1060355,32.8958387 L43.051613,0.590854329 L51.4455687,0.590854329 Z M86.768489,21.4493529 L91.1881833,9.31960182 L93.7323456,21.4493529 L86.768489,21.4493529 Z M96.1370094,32.8958387 L103.90226,32.8958387 L97.1240809,0.590854329 L89.9581922,0.590854329 C88.3462641,0.590854329 86.9873571,1.5231018 86.3841468,2.96001738 L73.7864787,32.8958387 L82.6003729,32.8958387 L84.3517993,28.0694111 L95.1225193,28.0694111 L96.1370094,32.8958387 Z M74.222772,22.3476047 C74.2602923,13.8223523 62.3788765,13.3516799 62.4606514,9.54224952 C62.486627,8.38400266 63.5949177,7.15249753 66.021709,6.83696026 C67.2228384,6.68086746 70.5404952,6.55972795 74.2987747,8.28201565 L75.7740906,1.43212747 C73.7523257,0.701938773 71.1542883,0 67.9188872,0 C59.6211374,0 53.7795214,4.39166605 53.7328615,10.6779922 C53.6775431,15.3310897 57.9014586,17.9238582 61.0839464,19.4709005 C64.3535004,21.0538539 65.4502465,22.0694147 65.4382207,23.4852625 C65.4136884,25.6538032 62.8291196,26.6095125 60.412911,26.6468598 C56.1918816,26.7124572 53.7420011,25.5111171 51.7899855,24.6056832 L50.2699339,31.6849224 C52.2296459,32.581259 55.8508322,33.3626806 59.6062254,33.4009855 C68.4268539,33.4009855 74.1953534,29.0658194 74.222772,22.3476047 L74.222772,22.3476047 Z M39.4487059,0.590854329 L25.8456873,32.8958387 L16.9711835,32.8958387 L10.2771842,7.11419256 C9.87071473,5.52692991 9.51812048,4.94421538 8.28235702,4.2767511 C6.26444044,3.18553796 2.93187165,2.16279498 0,1.52741111 L0.197702912,0.590854329 L14.4847447,0.590854329 C16.3044774,0.590854329 17.9428621,1.79602479 18.3560659,3.88412506 L21.8916291,22.578392 L30.6300016,0.590854329 L39.4487059,0.590854329 L39.4487059,0.590854329 Z" id="Fill-1"></path>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

File diff suppressed because it is too large Load diff

View file

@ -25,11 +25,11 @@ class SettingsPageAssets {
private $module_url;
/**
* The filesystem path to the module dir.
* The assets version.
*
* @var string
*/
private $module_path;
private $version;
/**
* The bearer.
@ -42,12 +42,12 @@ class SettingsPageAssets {
* Assets constructor.
*
* @param string $module_url The url of this module.
* @param string $module_path The filesystem path to this module.
* @param string $version The assets version.
* @param Bearer $bearer The bearer.
*/
public function __construct( string $module_url, string $module_path, Bearer $bearer ) {
public function __construct( string $module_url, string $version, Bearer $bearer ) {
$this->module_url = $module_url;
$this->module_path = $module_path;
$this->version = $version;
$this->bearer = $bearer;
}
@ -102,13 +102,11 @@ class SettingsPageAssets {
* @param Bearer $bearer The bearer.
*/
private function register_admin_assets( Bearer $bearer ) {
$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,
$this->version,
true
);

View file

@ -71,6 +71,6 @@ class ConnectAdminNotice {
* @return bool
*/
protected function should_display(): bool {
return $this->state->current_state() < State::STATE_PROGRESSIVE;
return $this->state->current_state() !== State::STATE_ONBOARDED;
}
}

View file

@ -146,8 +146,14 @@ class SettingsListener {
}
$this->settings->persist();
/**
* The hook fired before performing the redirect at the end of onboarding after saving the merchant ID/email.
*/
do_action( 'woocommerce_paypal_payments_onboarding_before_redirect' );
/**
* The URL opened at the end of onboarding after saving the merchant ID/email.
*/
$redirect_url = apply_filters( 'woocommerce_paypal_payments_onboarding_redirect_url', admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' ) );
if ( ! $this->settings->has( 'client_id' ) || ! $this->settings->get( 'client_id' ) ) {
$redirect_url = add_query_arg( 'ppcp-onboarding-error', '1', $redirect_url );

View file

@ -377,8 +377,18 @@ $data_rows_html
?>
<input type="hidden" name="ppcp-nonce" value="<?php echo esc_attr( $nonce ); ?>">
<?php
// Create a hidden first row with 2 cells to avoid issues with table-layout: fixed
// when the first visible row needs to have one cell.
?>
<tr style="height: 1px; padding-top: 0; padding-bottom: 0;">
<th style="padding-top: 0; padding-bottom: 0;"></th>
<td style="padding-top: 0; padding-bottom: 0;"></td>
</tr>
<?php
foreach ( $this->fields as $field => $config ) :
if ( ! in_array( $this->state->current_state(), $config['screens'], true ) ) {
if ( ! in_array( $this->state->environment_state( $config['state_from'] ?? null ), $config['screens'], true ) ) {
continue;
}
if ( ! $this->field_matches_page( $config, $this->page_id ) ) {
@ -406,14 +416,18 @@ $data_rows_html
$key = 'ppcp[' . $field . ']';
$id = 'ppcp-' . $field;
$config['id'] = $id;
$colspan = 'ppcp-heading' !== $config['type'] ? 1 : 2;
$colspan = ( 'ppcp-heading' !== $config['type'] && isset( $config['title'] ) ) ? 1 : 2;
$classes = isset( $config['classes'] ) ? $config['classes'] : array();
$classes[] = 'ppcp-settings-field';
$classes[] = sprintf( 'ppcp-settings-field-%s', str_replace( 'ppcp-', '', $config['type'] ) );
if ( 1 !== $colspan ) {
$classes[] = 'ppcp-settings-no-title-col';
}
$description = isset( $config['description'] ) ? $config['description'] : '';
unset( $config['description'] );
?>
<tr valign="top" id="<?php echo esc_attr( 'field-' . $field ); ?>" class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
<?php if ( 'ppcp-heading' !== $config['type'] ) : ?>
<?php if ( 'ppcp-heading' !== $config['type'] && isset( $config['title'] ) ) : ?>
<th scope="row">
<label
for="<?php echo esc_attr( $id ); ?>"
@ -462,7 +476,14 @@ $data_rows_html
* @param array $config The configuration array.
*/
private function render_text( array $config ) {
$raw = $config['raw'] ?? false;
if ( $raw ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $config['text'];
} else {
echo wp_kses_post( $config['text'] );
}
if ( isset( $config['hidden'] ) ) {
$value = $this->settings->has( $config['hidden'] ) ?
(string) $this->settings->get( $config['hidden'] )

View file

@ -74,7 +74,7 @@ class WCGatewayModule implements ModuleInterface {
if ( $c->has( 'wcgateway.url' ) ) {
$assets = new SettingsPageAssets(
$c->get( 'wcgateway.url' ),
$c->get( 'wcgateway.absolute-path' ),
$c->get( 'ppcp.asset-version' ),
$c->get( 'api.bearer' )
);
$assets->register_assets();

View file

@ -19,7 +19,6 @@ return array(
'title' => __( 'Subscribed webhooks', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-table',
'screens' => array(
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
),
'requirements' => array(),
@ -34,7 +33,6 @@ return array(
'type' => 'ppcp-text',
'text' => '<button type="button" class="button ppcp-webhooks-resubscribe">' . esc_html__( 'Resubscribe', 'woocommerce-paypal-payments' ) . '</button>',
'screens' => array(
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
),
'requirements' => array(),
@ -53,7 +51,6 @@ return array(
'type' => 'ppcp-text',
'text' => '<button type="button" class="button ppcp-webhooks-simulate">' . esc_html__( 'Simulate', 'woocommerce-paypal-payments' ) . '</button>',
'screens' => array(
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
),
'requirements' => array(),

View file

@ -156,7 +156,8 @@ return array(
'webhook.status.assets' => function( ContainerInterface $container ) : WebhooksStatusPageAssets {
return new WebhooksStatusPageAssets(
$container->get( 'webhook.module-url' )
$container->get( 'webhook.module-url' ),
$container->get( 'ppcp.asset-version' )
);
},

View file

@ -26,15 +26,25 @@ class WebhooksStatusPageAssets {
*/
private $module_url;
/**
* The assets version.
*
* @var string
*/
private $version;
/**
* WebhooksStatusPageAssets constructor.
*
* @param string $module_url The URL to the module.
* @param string $version The assets version.
*/
public function __construct(
string $module_url
string $module_url,
string $version
) {
$this->module_url = untrailingslashit( $module_url );
$this->version = $version;
}
/**
@ -47,14 +57,14 @@ class WebhooksStatusPageAssets {
'ppcp-webhooks-status-page-style',
untrailingslashit( $this->module_url ) . '/assets/css/status-page.css',
array(),
'1'
$this->version
);
wp_register_script(
'ppcp-webhooks-status-page',
untrailingslashit( $this->module_url ) . '/assets/js/status-page.js',
array(),
'1',
$this->version,
true
);

View file

@ -1,6 +1,6 @@
{
"name": "woocommerce-paypal-payments",
"version": "1.6.5",
"version": "1.7.0",
"description": "WooCommerce PayPal Payments",
"repository": "https://github.com/woocommerce/woocommerce-paypal-payments",
"license": "GPL-2.0",

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.11.2@6fba5eb554f9507b72932f9c75533d8af593688d">
<files psalm-version="4.20.0@f82a70e7edfc6cf2705e9374c8a0b6a974a779ed">
<file src="modules/ppcp-api-client/services.php">
<UndefinedConstant occurrences="2">
<code>PAYPAL_API_URL</code>
@ -12,9 +12,6 @@
</UndefinedMethod>
</file>
<file src="modules/ppcp-api-client/src/Endpoint/IdentityToken.php">
<InvalidOperand occurrences="1">
<code>$customer_id</code>
</InvalidOperand>
<UndefinedMethod occurrences="1">
<code>$response</code>
</UndefinedMethod>
@ -52,9 +49,6 @@
</UndefinedMethod>
</file>
<file src="modules/ppcp-api-client/src/Endpoint/PaymentTokenEndpoint.php">
<InvalidOperand occurrences="1">
<code>$id</code>
</InvalidOperand>
<UndefinedMethod occurrences="1">
<code>$response</code>
</UndefinedMethod>
@ -212,9 +206,7 @@
<RedundantCast occurrences="1">
<code>(float) $item_total</code>
</RedundantCast>
<RedundantCastGivenDocblockType occurrences="8">
<code>(float) $cart-&gt;get_cart_contents_tax()</code>
<code>(float) $cart-&gt;get_discount_tax()</code>
<RedundantCastGivenDocblockType occurrences="6">
<code>(float) $cart-&gt;get_discount_total()</code>
<code>(float) $cart-&gt;get_shipping_total()</code>
<code>(float) $cart-&gt;get_total( 'numeric' )</code>
@ -288,6 +280,9 @@
</UndefinedConstant>
</file>
<file src="modules/ppcp-button/services.php">
<PossiblyFalseArgument occurrences="1">
<code>realpath( __FILE__ )</code>
</PossiblyFalseArgument>
<UndefinedConstant occurrences="2">
<code>CONNECT_WOO_CLIENT_ID</code>
<code>CONNECT_WOO_SANDBOX_CLIENT_ID</code>
@ -297,13 +292,9 @@
<InvalidScalarArgument occurrences="1">
<code>1</code>
</InvalidScalarArgument>
<MissingClosureParamType occurrences="2">
<code>$default_fields</code>
<MissingClosureParamType occurrences="1">
<code>$id</code>
</MissingClosureParamType>
<MissingClosureReturnType occurrences="1">
<code>function ( $default_fields, $id ) {</code>
</MissingClosureReturnType>
<MissingReturnType occurrences="3">
<code>button_renderer</code>
<code>dcc_renderer</code>
@ -440,6 +431,9 @@
<MissingClosureParamType occurrences="1">
<code>$container</code>
</MissingClosureParamType>
<PossiblyFalseArgument occurrences="1">
<code>realpath( __FILE__ )</code>
</PossiblyFalseArgument>
<UndefinedConstant occurrences="10">
<code>CONNECT_WOO_MERCHANT_ID</code>
<code>CONNECT_WOO_SANDBOX_MERCHANT_ID</code>
@ -532,18 +526,13 @@
<FalsableReturnStatement occurrences="1">
<code>current( $tokens )</code>
</FalsableReturnStatement>
<MissingReturnType occurrences="3">
<code>capture_order</code>
<MissingReturnType occurrences="2">
<code>process_order</code>
<code>renew</code>
</MissingReturnType>
<RedundantCastGivenDocblockType occurrences="6">
<code>(int) $customer-&gt;get_id()</code>
<RedundantCastGivenDocblockType occurrences="2">
<code>(int) $customer-&gt;get_id()</code>
<code>(int) $wc_order-&gt;get_customer_id()</code>
<code>(int) $wc_order-&gt;get_id()</code>
<code>(int) $wc_order-&gt;get_id()</code>
<code>(int) $wc_order-&gt;get_id()</code>
</RedundantCastGivenDocblockType>
<TooManyArguments occurrences="1">
<code>apply_filters( 'woocommerce_paypal_payments_subscriptions_get_token_for_customer', null, $customer, $wc_order )</code>
@ -571,6 +560,11 @@
<code>\WC_Subscription</code>
</UndefinedClass>
</file>
<file src="modules/ppcp-vaulting/services.php">
<PossiblyFalseArgument occurrences="1">
<code>realpath( __FILE__ )</code>
</PossiblyFalseArgument>
</file>
<file src="modules/ppcp-vaulting/src/Assets/MyAccountPaymentsAssets.php">
<MissingReturnType occurrences="1">
<code>localize</code>
@ -603,6 +597,13 @@
</MissingReturnType>
</file>
<file src="modules/ppcp-wc-gateway/services.php">
<PossiblyFalseArgument occurrences="2">
<code>realpath( __FILE__ )</code>
<code>realpath( __FILE__ )</code>
</PossiblyFalseArgument>
<PossiblyFalseOperand occurrences="1">
<code>substr( $letters, 0, 6 )</code>
</PossiblyFalseOperand>
<PossiblyInvalidArgument occurrences="5">
<code>wp_unslash( $_GET[ SectionsRenderer::KEY ] )</code>
<code>wp_unslash( $_GET['page'] )</code>
@ -637,7 +638,6 @@
</file>
<file src="modules/ppcp-wc-gateway/src/Checkout/CheckoutPayPalAddressPreset.php">
<PossiblyNullReference occurrences="3">
<code>phone</code>
<code>phone</code>
<code>phone</code>
<code>purchase_units</code>
@ -764,7 +764,7 @@
</RedundantCast>
</file>
<file src="modules/ppcp-wc-gateway/src/WCGatewayModule.php">
<MissingClosureParamType occurrences="15">
<MissingClosureParamType occurrences="13">
<code>$args</code>
<code>$args</code>
<code>$column</code>
@ -774,9 +774,7 @@
<code>$methods</code>
<code>$methods</code>
<code>$notices</code>
<code>$order</code>
<code>$order_actions</code>
<code>$recipient</code>
<code>$value</code>
<code>$wc_order_id</code>
<code>$wc_order_id</code>
@ -793,6 +791,11 @@
<code>$container</code>
</MissingClosureParamType>
</file>
<file src="modules/ppcp-webhooks/services.php">
<PossiblyFalseArgument occurrences="1">
<code>realpath( __FILE__ )</code>
</PossiblyFalseArgument>
</file>
<file src="modules/ppcp-webhooks/src/Endpoint/ResubscribeEndpoint.php">
<MissingReturnType occurrences="1">
<code>handle_request</code>
@ -918,4 +921,9 @@
</PossiblyNullArgument>
<RedundantCastGivenDocblockType occurrences="1"/>
</file>
<file src="src/services.php">
<PossiblyFalseArgument occurrences="1">
<code>realpath( __FILE__ )</code>
</PossiblyFalseArgument>
</file>
</files>

View file

@ -4,12 +4,11 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
xmlns:xi="http://www.w3.org/2001/XInclude"
totallyTyped="false"
reportMixedIssues="false"
useDocblockTypes="true"
usePhpDocMethodsWithoutMagicCall="false"
strictBinaryOperands="true"
rememberPropertyAssignmentsAfterCall="true"
allowPhpStormGenerics="true"
allowStringToStandInForClass="false"
memoizeMethodCallResults="false"
hoistConstants="false"

View file

@ -4,7 +4,7 @@ Tags: woocommerce, paypal, payments, ecommerce, e-commerce, store, sales, sell,
Requires at least: 5.3
Tested up to: 5.9
Requires PHP: 7.1
Stable tag: 1.6.5
Stable tag: 1.7.0
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -81,6 +81,21 @@ Follow the steps below to connect the plugin to your PayPal account:
== Changelog ==
= 1.7.0 =
* Fix - DCC orders randomly failing #503
* Fix - Multi-currency broke #481
* Fix - Address information from PayPal shortcut flow not loaded #451
* Enhancement - Improve onboarding flow, allow no card processing #443
* Enhancement - Add Germany to supported ACDC countries #459
* Enhancement - Add filters to allow ACDC for countries #437
* Enhancement - Update 3D Secure #464
* Enhancement - Extend event, error logging & order notes #456
* Enhancement - Display API response errors in checkout page with user-friendly error message #457
* Enhancement - Pass address details to credit card fields #479
* Enhancement - Improve onboarding notice #465
* Enhancement - Add transaction ID to WC order and order note when refund is received #473
* Enhancement - Asset caching may cause bugs on upgrades #501
= 1.6.5 =
* Fix - Allow guest users to purchase subscription products from checkout page #422
* Fix - Transaction ID missing for renewal order #424

View file

@ -0,0 +1,134 @@
<?php
/**
* Extracts plugin info from plugin file path.
*
* @package WooCommerce\PayPalCommerce
*
* @phpcs:disable Squiz.Commenting.FunctionCommentThrowTag
* @phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce;
use Dhii\Package\Version\StringVersionFactoryInterface;
use Dhii\Package\Version\VersionInterface;
use Exception;
use RuntimeException;
use UnexpectedValueException;
use WpOop\WordPress\Plugin\FilePathPluginFactoryInterface;
use WpOop\WordPress\Plugin\PluginInterface;
/**
* Extracts plugin info from plugin file path.
*/
class FilePathPluginFactory implements FilePathPluginFactoryInterface {
/**
* The version factory.
*
* @var StringVersionFactoryInterface
*/
protected $version_factory;
/**
* FilePathPluginFactory constructor.
*
* @param StringVersionFactoryInterface $version_factory The version factory.
*/
public function __construct( StringVersionFactoryInterface $version_factory ) {
$this->version_factory = $version_factory;
}
/**
* Extracts plugin info from plugin file path.
*
* @param string $filePath The plugin file path.
*/
public function createPluginFromFilePath( string $filePath ): PluginInterface {
if ( ! is_readable( $filePath ) ) {
throw new RuntimeException(
sprintf(
'Plugin file "%1$s" does not exist or is not readable',
$filePath
)
);
}
$plugin_data = get_plugin_data( $filePath );
if ( empty( $plugin_data ) ) {
throw new UnexpectedValueException(
sprintf(
'Plugin file "%1$s" does not have a valid plugin header',
$filePath
)
);
}
$plugin_data = array_merge(
array(
'Name' => '',
'Version' => '0.1.0-alpha1+default',
'Title' => '',
'Description' => '',
'TextDomain' => '',
'RequiresWP' => '5.0',
'RequiresPHP' => '7.1',
),
$plugin_data
);
$base_dir = dirname( $filePath );
$base_name = plugin_basename( $filePath );
$slug = $this->get_plugin_slug( $base_name );
$text_domain = ! empty( $plugin_data['TextDomain'] ) ? $plugin_data['TextDomain'] : $slug;
return new Plugin(
$plugin_data['Name'],
$this->create_version( $plugin_data['Version'] ),
$base_dir,
$base_name,
$plugin_data['Title'],
$plugin_data['Description'],
$text_domain,
$this->create_version( $plugin_data['RequiresPHP'] ),
$this->create_version( $plugin_data['RequiresWP'] )
);
}
/**
* Creates a new version from a version string.
*
* @param string $version_string The SemVer-compliant version string.
*
* @return VersionInterface The new version.
*
* @throws Exception If version string is malformed.
*/
protected function create_version( string $version_string ): VersionInterface {
return $this->version_factory->createVersionFromString( $version_string );
}
/**
* Retrieves a plugin slug from its basename.
*
* @param string $base_name The plugin's basename.
*
* @return string The plugin's slug.
*/
protected function get_plugin_slug( string $base_name ): string {
$directory_separator = '/';
// If plugin is in a directory, use directory name.
if ( strstr( $base_name, $directory_separator ) !== false ) {
$parts = explode( $directory_separator, $base_name );
if ( $parts ) {
return $parts[0];
}
}
// If plugin is not in a directory, return plugin file basename.
return basename( $base_name );
}
}

180
src/Plugin.php Normal file
View file

@ -0,0 +1,180 @@
<?php
/**
* Plugin properties.
*
* @package WooCommerce\PayPalCommerce
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce;
use Dhii\Package\Version\VersionInterface;
use WpOop\WordPress\Plugin\PluginInterface;
/**
* Plugin properties.
*/
class Plugin implements PluginInterface {
/**
* The plugin name.
*
* @var string
*/
protected $name;
/**
* The plugin version.
*
* @var VersionInterface
*/
protected $version;
/**
* The path to the plugin base directory.
*
* @var string
*/
protected $base_dir;
/**
* The plugin base name.
*
* @var string
*/
protected $base_name;
/**
* The plugin title.
*
* @var string
*/
protected $title;
/**
* The plugin description.
*
* @var string
*/
protected $description;
/**
* The text domain of this plugin
*
* @var string
*/
protected $text_domain;
/**
* The minimal version of PHP required by this plugin.
*
* @var VersionInterface
*/
protected $min_php_version;
/**
* The minimal version of WP required by this plugin.
*
* @var VersionInterface
*/
protected $min_wp_version;
/**
* Plugin constructor.
*
* @param string $name The plugin name.
* @param VersionInterface $version The plugin version.
* @param string $base_dir The path to the plugin base directory.
* @param string $base_name The plugin base name.
* @param string $title The plugin title.
* @param string $description The plugin description.
* @param string $text_domain The text domain of this plugin.
* @param VersionInterface $min_php_version The minimal version of PHP required by this plugin.
* @param VersionInterface $min_wp_version The minimal version of WP required by this plugin.
*/
public function __construct(
string $name,
VersionInterface $version,
string $base_dir,
string $base_name,
string $title,
string $description,
string $text_domain,
VersionInterface $min_php_version,
VersionInterface $min_wp_version
) {
$this->name = $name;
$this->description = $description;
$this->version = $version;
$this->base_dir = $base_dir;
$this->base_name = $base_name;
$this->title = $title;
$this->text_domain = $text_domain;
$this->min_php_version = $min_php_version;
$this->min_wp_version = $min_wp_version;
}
/**
* The plugin name.
*/
public function getName(): string {
return $this->name;
}
/**
* The plugin description.
*/
public function getDescription(): string {
return $this->description;
}
/**
* The plugin version.
*/
public function getVersion(): VersionInterface {
return $this->version;
}
/**
* The path to the plugin base directory.
*/
public function getBaseDir(): string {
return $this->base_dir;
}
/**
* The plugin base name.
*/
public function getBaseName(): string {
return $this->base_name;
}
/**
* The text domain of this plugin.
*/
public function getTextDomain(): string {
return $this->text_domain;
}
/**
* The plugin title.
*/
public function getTitle(): string {
return $this->title;
}
/**
* The minimal version of PHP required by this plugin.
*/
public function getMinPhpVersion(): VersionInterface {
return $this->min_php_version;
}
/**
* The minimal version of WP required by this plugin.
*/
public function getMinWpVersion(): VersionInterface {
return $this->min_wp_version;
}
}

View file

@ -23,7 +23,10 @@ class PluginModule implements ModuleInterface {
* {@inheritDoc}
*/
public function setup(): ServiceProviderInterface {
return new ServiceProvider( array(), array() );
return new ServiceProvider(
require __DIR__ . '/services.php',
require __DIR__ . '/extensions.php'
);
}
/**

12
src/extensions.php Normal file
View file

@ -0,0 +1,12 @@
<?php
/**
* The plugin module extensions.
*
* @package WooCommerce\PayPalCommerce
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce;
return array();

27
src/services.php Normal file
View file

@ -0,0 +1,27 @@
<?php
/**
* The plugin module services.
*
* @package WooCommerce\PayPalCommerce
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce;
use Dhii\Versions\StringVersionFactory;
use Psr\Container\ContainerInterface;
use WpOop\WordPress\Plugin\PluginInterface;
return array(
'ppcp.plugin' => function( ContainerInterface $container ) : PluginInterface {
$factory = new FilePathPluginFactory( new StringVersionFactory() );
return $factory->createPluginFromFilePath( dirname( realpath( __FILE__ ), 2 ) . '/woocommerce-paypal-payments.php' );
},
'ppcp.asset-version' => function( ContainerInterface $container ) : string {
$plugin = $container->get( 'ppcp.plugin' );
assert( $plugin instanceof PluginInterface );
return (string) $plugin->getVersion();
},
);

View file

@ -25,6 +25,7 @@ class ModularTestCase extends TestCase
when('get_current_blog_id')->justReturn(42);
when('get_site_url')->justReturn('example.com');
when('get_bloginfo')->justReturn('My Shop');
when('get_woocommerce_currency')->justReturn('USD');
when('wc_get_base_location')->justReturn(['country' => 'US']);
when('WC')->justReturn((object) [
'session' => null,

View file

@ -28,6 +28,8 @@ class TestCase extends \PHPUnit\Framework\TestCase
when('wc_print_r')->alias(function ($value, bool $return = false) {
return print_r($value, $return);
});
when('get_plugin_data')->justReturn(['Version' => '1.0']);
when('plugin_basename')->justReturn('woocommerce-paypal-payments/woocommerce-paypal-payments.php');
setUp();
}

View file

@ -270,7 +270,6 @@ class WcGatewayTest extends TestCase
{
return [
[State::STATE_START, true],
[State::STATE_PROGRESSIVE, true],
[State::STATE_ONBOARDED, false]
];
}

View file

@ -3,13 +3,13 @@
* Plugin Name: WooCommerce PayPal Payments
* Plugin URI: https://woocommerce.com/products/woocommerce-paypal-payments/
* Description: PayPal's latest complete payments processing solution. Accept PayPal, Pay Later, credit/debit cards, alternative digital wallets local payment types and bank accounts. Turn on only PayPal options or process a full suite of payment methods. Enable global transaction with extensive currency and country coverage.
* Version: 1.6.5
* Version: 1.7.0
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* License: GPL-2.0
* Requires PHP: 7.1
* WC requires at least: 3.9
* WC tested up to: 6.1
* WC tested up to: 6.2
* Text Domain: woocommerce-paypal-payments
*
* @package WooCommerce\PayPalCommerce
@ -73,6 +73,9 @@ define( 'PPCP_FLAG_SUBSCRIPTION', true );
$app_container = $bootstrap( $root_dir );
$initialized = true;
/**
* The hook fired after the plugin bootstrap with the app services container as parameter.
*/
do_action( 'woocommerce_paypal_payments_built_container', $app_container );
}
}
@ -88,6 +91,9 @@ define( 'PPCP_FLAG_SUBSCRIPTION', true );
$plugin_data = get_plugin_data( __DIR__ . '/woocommerce-paypal-payments.php' );
$plugin_version = $plugin_data['Version'] ?? null;
if ( get_option( 'woocommerce-ppcp-version' ) !== $plugin_version ) {
/**
* The hook fired when the plugin is installed or updated.
*/
do_action( 'woocommerce_paypal_payments_gateway_migrate' );
update_option( 'woocommerce-ppcp-version', $plugin_version );
}
@ -97,6 +103,9 @@ define( 'PPCP_FLAG_SUBSCRIPTION', true );
__FILE__,
function () {
init();
/**
* The hook fired in register_activation_hook.
*/
do_action( 'woocommerce_paypal_payments_gateway_activate' );
}
);
@ -104,6 +113,9 @@ define( 'PPCP_FLAG_SUBSCRIPTION', true );
__FILE__,
function () {
init();
/**
* The hook fired in register_deactivation_hook.
*/
do_action( 'woocommerce_paypal_payments_gateway_deactivate' );
}
);