mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Merge branch 'refs/heads/trunk' into modularity-module-migration
# Conflicts: # modules/ppcp-applepay/src/ApplepayModule.php # modules/ppcp-compat/src/CompatModule.php
This commit is contained in:
commit
789d979c80
113 changed files with 11616 additions and 2360 deletions
58
modules/ppcp-wc-gateway/resources/js/helper/ConsoleLogger.js
Normal file
58
modules/ppcp-wc-gateway/resources/js/helper/ConsoleLogger.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Helper component to log debug details to the browser console.
|
||||
*
|
||||
* A utility class that is used by payment buttons on the front-end, like the GooglePayButton.
|
||||
*/
|
||||
export default class ConsoleLogger {
|
||||
/**
|
||||
* The prefix to display before every log output.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
#prefix = '';
|
||||
|
||||
/**
|
||||
* Whether logging is enabled, disabled by default.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
#enabled = false;
|
||||
|
||||
constructor( ...prefixes ) {
|
||||
if ( prefixes.length ) {
|
||||
this.#prefix = `[${ prefixes.join( ' | ' ) }]`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable logging. Only impacts `log()` output.
|
||||
*
|
||||
* @param {boolean} state True to enable log output.
|
||||
*/
|
||||
set enabled( state ) {
|
||||
this.#enabled = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output log-level details to the browser console, if logging is enabled.
|
||||
*
|
||||
* @param {...any} args - All provided values are output to the browser console.
|
||||
*/
|
||||
log( ...args ) {
|
||||
if ( this.#enabled ) {
|
||||
// eslint-disable-next-line
|
||||
console.log( this.#prefix, ...args );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an error message in the browser's console.
|
||||
*
|
||||
* Error messages are always output, even when logging is disabled.
|
||||
*
|
||||
* @param {...any} args - All provided values are output to the browser console.
|
||||
*/
|
||||
error( ...args ) {
|
||||
console.error( this.#prefix, ...args );
|
||||
}
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
/* global jQuery */
|
||||
|
||||
/**
|
||||
* Returns a Map with all input fields that are relevant to render the preview of the
|
||||
* given payment button.
|
||||
*
|
||||
* @param {string} apmName - Value of the custom attribute `data-ppcp-apm-name`.
|
||||
* @return {Map<string, {val:Function, el:HTMLInputElement}>}
|
||||
* @return {Map<string, {val:Function, el:HTMLInputElement}>} List of input elements found on the current admin page.
|
||||
*/
|
||||
export function getButtonFormFields( apmName ) {
|
||||
const inputFields = document.querySelectorAll(
|
||||
|
@ -28,9 +30,9 @@ export function getButtonFormFields( apmName ) {
|
|||
|
||||
/**
|
||||
* Returns a function that triggers an update of the specified preview button, when invoked.
|
||||
|
||||
*
|
||||
* @param {string} apmName
|
||||
* @return {((object) => void)}
|
||||
* @return {((object) => void)} Trigger-function; updates preview buttons when invoked.
|
||||
*/
|
||||
export function buttonRefreshTriggerFactory( apmName ) {
|
||||
const eventName = `ppcp_paypal_render_preview_${ apmName }`;
|
||||
|
@ -44,7 +46,7 @@ export function buttonRefreshTriggerFactory( apmName ) {
|
|||
* Returns a function that gets the current form values of the specified preview button.
|
||||
*
|
||||
* @param {string} apmName
|
||||
* @return {() => {button: {wrapper:string, is_enabled:boolean, style:{}}}}
|
||||
* @return {() => {button: {wrapper:string, is_enabled:boolean, style:{}}}} Getter-function; returns preview config details when invoked.
|
||||
*/
|
||||
export function buttonSettingsGetterFactory( apmName ) {
|
||||
const fields = getButtonFormFields( apmName );
|
||||
|
|
|
@ -71,6 +71,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
||||
use WooCommerce\PayPalCommerce\Applepay\ApplePayGateway;
|
||||
|
||||
return array(
|
||||
'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway {
|
||||
|
@ -198,6 +199,7 @@ return array(
|
|||
Settings::PAY_LATER_TAB_ID,
|
||||
AxoGateway::ID,
|
||||
GooglePayGateway::ID,
|
||||
ApplePayGateway::ID,
|
||||
),
|
||||
true
|
||||
);
|
||||
|
@ -220,6 +222,7 @@ return array(
|
|||
Settings::PAY_LATER_TAB_ID,
|
||||
Settings::CONNECTION_TAB_ID,
|
||||
GooglePayGateway::ID,
|
||||
ApplePayGateway::ID,
|
||||
),
|
||||
true
|
||||
);
|
||||
|
@ -1411,10 +1414,10 @@ return array(
|
|||
return $label;
|
||||
},
|
||||
'wcgateway.enable-dcc-url-sandbox' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.sandbox.paypal.com/bizsignup/entry/product/ppcp';
|
||||
return 'https://www.sandbox.paypal.com/bizsignup/entry?product=ppcp';
|
||||
},
|
||||
'wcgateway.enable-dcc-url-live' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.paypal.com/bizsignup/entry/product/ppcp';
|
||||
return 'https://www.paypal.com/bizsignup/entry?product=ppcp';
|
||||
},
|
||||
'wcgateway.enable-pui-url-sandbox' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.sandbox.paypal.com/bizsignup/entry?country.x=DE&product=payment_methods&capabilities=PAY_UPON_INVOICE';
|
||||
|
|
|
@ -426,12 +426,42 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
public function process_payment( $order_id ) {
|
||||
$wc_order = wc_get_order( $order_id );
|
||||
if ( ! is_a( $wc_order, WC_Order::class ) ) {
|
||||
WC()->session->set( 'ppcp_card_payment_token_for_free_trial', null );
|
||||
|
||||
return $this->handle_payment_failure(
|
||||
null,
|
||||
new GatewayGenericException( new Exception( 'WC order was not found.' ) )
|
||||
);
|
||||
}
|
||||
|
||||
$guest_card_payment_for_free_trial = WC()->session->get( 'ppcp_guest_payment_for_free_trial' ) ?? null;
|
||||
WC()->session->get( 'ppcp_guest_payment_for_free_trial', null );
|
||||
if ( $guest_card_payment_for_free_trial ) {
|
||||
$customer_id = $guest_card_payment_for_free_trial->customer->id ?? '';
|
||||
if ( $customer_id ) {
|
||||
update_user_meta( $wc_order->get_customer_id(), '_ppcp_target_customer_id', $customer_id );
|
||||
}
|
||||
|
||||
if ( isset( $guest_card_payment_for_free_trial->payment_source->card ) ) {
|
||||
$this->wc_payment_tokens->create_payment_token_card( $wc_order->get_customer_id(), $guest_card_payment_for_free_trial );
|
||||
|
||||
$wc_order->payment_complete();
|
||||
return $this->handle_payment_success( $wc_order );
|
||||
}
|
||||
}
|
||||
|
||||
$card_payment_token_for_free_trial = WC()->session->get( 'ppcp_card_payment_token_for_free_trial' ) ?? null;
|
||||
WC()->session->set( 'ppcp_card_payment_token_for_free_trial', null );
|
||||
if ( $card_payment_token_for_free_trial ) {
|
||||
$tokens = WC_Payment_Tokens::get_customer_tokens( get_current_user_id() );
|
||||
foreach ( $tokens as $token ) {
|
||||
if ( $token->get_id() === (int) $card_payment_token_for_free_trial ) {
|
||||
$wc_order->payment_complete();
|
||||
return $this->handle_payment_success( $wc_order );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$card_payment_token_id = wc_clean( wp_unslash( $_POST['wc-ppcp-credit-card-gateway-payment-token'] ?? '' ) );
|
||||
|
||||
|
|
|
@ -118,18 +118,15 @@ class Settings implements ContainerInterface {
|
|||
* Stores the settings to the database.
|
||||
*/
|
||||
public function persist() {
|
||||
|
||||
return update_option( self::KEY, $this->settings );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the settings.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function load(): bool {
|
||||
|
||||
if ( $this->settings ) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway;
|
|||
use Psr\Log\LoggerInterface;
|
||||
use Throwable;
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue