Skip to content

Commit

Permalink
Merge branch 'trunk' into bug/fix-project-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
XedinUnknown authored Sep 14, 2021
2 parents 5aaf685 + 079e8e6 commit ac8061a
Show file tree
Hide file tree
Showing 23 changed files with 719 additions and 352 deletions.
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

56 changes: 56 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Bootstraps the modular app.
*
* @package WooCommerce\PayPalCommerce
*/

use Dhii\Container\CachingContainer;
use Dhii\Container\CompositeCachingServiceProvider;
use Dhii\Container\CompositeContainer;
use Dhii\Container\DelegatingContainer;
use Dhii\Container\ProxyContainer;
use Dhii\Modular\Module\ModuleInterface;
use Interop\Container\ServiceProviderInterface;
use Psr\Container\ContainerInterface;

return function (
string $root_dir,
ContainerInterface ...$additional_containers
): ContainerInterface {
$modules = ( require "$root_dir/modules.php" )( $root_dir );

// Use this filter to add custom module or remove some of existing ones.
// Modules able to access container, add services and modify existing ones.
$modules = apply_filters( 'woocommerce_paypal_payments_modules', $modules );

$providers = array_map(
function ( ModuleInterface $module ): ServiceProviderInterface {
return $module->setup();
},
$modules
);

$provider = new CompositeCachingServiceProvider( $providers );
$proxy_container = new ProxyContainer();
// TODO: caching does not work currently,
// may want to consider fixing it later (pass proxy as parent to DelegatingContainer)
// for now not fixed since we were using this behavior for long time and fixing it now may break things.
$container = new DelegatingContainer( $provider );
$app_container = new CachingContainer(
new CompositeContainer(
array_merge(
$additional_containers,
array( $container )
)
)
);
$proxy_container->setInnerContainer( $app_container );

foreach ( $modules as $module ) {
/* @var $module ModuleInterface module */
$module->run( $app_container );
}

return $app_container;
};
29 changes: 29 additions & 0 deletions modules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* The list of modules.
*
* @package WooCommerce\PayPalCommerce
*/

use WooCommerce\PayPalCommerce\PluginModule;

return function ( string $root_dir ): iterable {
$modules_dir = "$root_dir/modules";

$modules = array(
new PluginModule(),
( require "$modules_dir/woocommerce-logging/module.php" )(),
( require "$modules_dir/ppcp-admin-notices/module.php" )(),
( require "$modules_dir/ppcp-api-client/module.php" )(),
( require "$modules_dir/ppcp-button/module.php" )(),
( require "$modules_dir/ppcp-compat/module.php" )(),
( require "$modules_dir/ppcp-onboarding/module.php" )(),
( require "$modules_dir/ppcp-session/module.php" )(),
( require "$modules_dir/ppcp-status-report/module.php" )(),
( require "$modules_dir/ppcp-subscription/module.php" )(),
( require "$modules_dir/ppcp-wc-gateway/module.php" )(),
( require "$modules_dir/ppcp-webhooks/module.php" )(),
);

return $modules;
};
6 changes: 3 additions & 3 deletions modules/ppcp-api-client/src/Entity/class-payee.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public function merchant_id(): string {
* @return array
*/
public function to_array(): array {
$data = array(
'email_address' => $this->email(),
);
$data = array();
if ( $this->merchant_id ) {
$data['merchant_id'] = $this->merchant_id();
} else {
$data['email_address'] = $this->email();
}
return $data;
}
Expand Down
9 changes: 2 additions & 7 deletions modules/ppcp-api-client/src/Factory/class-payeefactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ class PayeeFactory {
* @throws RuntimeException When JSON object is malformed.
*/
public function from_paypal_response( \stdClass $data ) {
if ( ! isset( $data->email_address ) ) {
throw new RuntimeException(
__( 'No email for payee given.', 'woocommerce-paypal-payments' )
);
}

$email = ( isset( $data->email_address ) ) ? $data->email_address : '';
$merchant_id = ( isset( $data->merchant_id ) ) ? $data->merchant_id : '';
return new Payee( $data->email_address, $merchant_id );
return new Payee( $email, $merchant_id );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class CreditCardRenderer {
this.spinner = spinner;
this.cardValid = false;
this.formValid = false;
this.currentHostedFieldsInstance = null;
this.formSubmissionSubscribed = false;
}

render(wrapper, contextConfig) {
Expand All @@ -31,6 +33,12 @@ class CreditCardRenderer {
return;
}

if (this.currentHostedFieldsInstance) {
this.currentHostedFieldsInstance.teardown()
.catch(err => console.error(`Hosted fields teardown error: ${err}`));
this.currentHostedFieldsInstance = null;
}

const gateWayBox = document.querySelector('.payment_box.payment_method_ppcp-credit-card-gateway');
const oldDisplayStyle = gateWayBox.style.display;
gateWayBox.style.display = 'block';
Expand Down Expand Up @@ -92,36 +100,10 @@ class CreditCardRenderer {
}
}
}).then(hostedFields => {
const submitEvent = (event) => {
this.spinner.block();
if (event) {
event.preventDefault();
}
this.errorHandler.clear();

if (this.formValid && this.cardValid) {
const save_card = this.defaultConfig.save_card ? true : false;
const vault = document.getElementById('ppcp-credit-card-vault') ?
document.getElementById('ppcp-credit-card-vault').checked : save_card;
hostedFields.submit({
contingencies: ['SCA_WHEN_REQUIRED'],
vault: vault
}).then((payload) => {
payload.orderID = payload.orderId;
this.spinner.unblock();
return contextConfig.onApprove(payload);
}).catch(() => {
this.errorHandler.genericError();
this.spinner.unblock();
});
} else {
this.spinner.unblock();
const message = ! this.cardValid ? this.defaultConfig.hosted_fields.labels.card_not_supported : this.defaultConfig.hosted_fields.labels.fields_not_valid;
this.errorHandler.message(message);
}
}
hostedFields.on('inputSubmitRequest', function () {
submitEvent(null);
this.currentHostedFieldsInstance = hostedFields;

hostedFields.on('inputSubmitRequest', () => {
this._submit(contextConfig);
});
hostedFields.on('cardTypeChange', (event) => {
if ( ! event.cards.length ) {
Expand All @@ -137,11 +119,18 @@ class CreditCardRenderer {
});
this.formValid = formValid;

})
document.querySelector(wrapper + ' button').addEventListener(
'click',
submitEvent
);
});

if (!this.formSubmissionSubscribed) {
document.querySelector(wrapper + ' button').addEventListener(
'click',
event => {
event.preventDefault();
this._submit(contextConfig);
}
);
this.formSubmissionSubscribed = true;
}
});

document.querySelector('#payment_method_ppcp-credit-card-gateway').addEventListener(
Expand All @@ -151,5 +140,36 @@ class CreditCardRenderer {
}
)
}

_submit(contextConfig) {
this.spinner.block();
this.errorHandler.clear();

if (this.formValid && this.cardValid) {
const save_card = this.defaultConfig.save_card ? true : false;
const vault = document.getElementById('ppcp-credit-card-vault') ?
document.getElementById('ppcp-credit-card-vault').checked : save_card;
const contingency = this.defaultConfig.hosted_fields.contingency;
const hostedFieldsData = {
vault: vault
};
if (contingency !== 'NO_3D_SECURE') {
hostedFieldsData.contingencies = [contingency];
}
this.currentHostedFieldsInstance.submit(hostedFieldsData).then((payload) => {
payload.orderID = payload.orderId;
this.spinner.unblock();
return contextConfig.onApprove(payload);
}).catch(err => {
console.error(err);
this.errorHandler.genericError();
this.spinner.unblock();
});
} else {
this.spinner.unblock();
const message = ! this.cardValid ? this.defaultConfig.hosted_fields.labels.card_not_supported : this.defaultConfig.hosted_fields.labels.fields_not_valid;
this.errorHandler.message(message);
}
}
}
export default CreditCardRenderer;
30 changes: 26 additions & 4 deletions modules/ppcp-button/src/Assets/class-smartbutton.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,19 @@ private function has_subscriptions(): bool {
return $this->subscription_helper->cart_contains_subscription();
}

/**
* Retrieves the 3D Secure contingency settings.
*
* @return string
*/
private function get_3ds_contingency(): string {
if ( $this->settings->has( '3d_secure_contingency' ) ) {
return $this->settings->get( '3d_secure_contingency' );
}

return 'SCA_WHEN_REQUIRED';
}

/**
* The localized data for the smart button.
*
Expand Down Expand Up @@ -677,6 +690,7 @@ private function localize_script(): array {
),
),
'valid_cards' => $this->dcc_applies->valid_cards(),
'contingency' => $this->get_3ds_contingency(),
),
'messages' => $this->message_values(),
'labels' => array(
Expand Down Expand Up @@ -729,8 +743,7 @@ private function url(): string {
'currency' => get_woocommerce_currency(),
'integration-date' => PAYPAL_INTEGRATION_DATE,
'components' => implode( ',', $this->components() ),
'vault' => $this->can_save_vault_token() ?
'true' : 'false',
'vault' => $this->can_save_vault_token() ? 'true' : 'false',
'commit' => is_checkout() ? 'true' : 'false',
'intent' => ( $this->settings->has( 'intent' ) ) ?
$this->settings->get( 'intent' ) : 'capture',
Expand All @@ -743,11 +756,20 @@ private function url(): string {
) {
$params['buyer-country'] = WC()->customer->get_billing_country();
}
$disable_funding = $this->settings->has( 'disable_funding' ) ?
$this->settings->get( 'disable_funding' ) : array();

$disable_funding = $this->settings->has( 'disable_funding' )
? $this->settings->get( 'disable_funding' )
: array();

if ( ! is_checkout() ) {
$disable_funding[] = 'card';
}
if ( is_checkout() && $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ) ) {
$key = array_search( 'card', $disable_funding, true );
if ( false !== $key ) {
unset( $disable_funding[ $key ] );
}
}

if ( count( $disable_funding ) > 0 ) {
$params['disable-funding'] = implode( ',', array_unique( $disable_funding ) );
Expand Down
Loading

0 comments on commit ac8061a

Please sign in to comment.