mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Fix merge conflicts
This commit is contained in:
commit
e6adf38edd
12 changed files with 243 additions and 151 deletions
|
@ -322,7 +322,13 @@ return array(
|
|||
},
|
||||
|
||||
'api.shop.currency' => static function ( ContainerInterface $container ) : string {
|
||||
return get_woocommerce_currency();
|
||||
// We use option instead of get_woocommerce_currency
|
||||
// because it will not be overridden by currency switching plugins.
|
||||
$currency = get_option( 'woocommerce_currency' );
|
||||
if ( ! $currency ) {
|
||||
return 'NO_CURRENCY'; // Unlikely to happen.
|
||||
}
|
||||
return $currency;
|
||||
},
|
||||
'api.shop.country' => static function ( ContainerInterface $container ) : string {
|
||||
$location = wc_get_base_location();
|
||||
|
@ -510,6 +516,7 @@ return array(
|
|||
'AU' => array(
|
||||
'mastercard' => array(),
|
||||
'visa' => array(),
|
||||
'amex' => array( 'AUD' ),
|
||||
),
|
||||
'ES' => array(
|
||||
'mastercard' => array(),
|
||||
|
|
|
@ -120,11 +120,17 @@ class BillingAgreementsEndpoint {
|
|||
*/
|
||||
public function reference_transaction_enabled(): bool {
|
||||
try {
|
||||
$this->create_token(
|
||||
'Checking if reference transactions are enabled',
|
||||
'https://example.com/return',
|
||||
'https://example.com/cancel'
|
||||
);
|
||||
$this->is_request_logging_enabled = false;
|
||||
|
||||
try {
|
||||
$this->create_token(
|
||||
'Checking if reference transactions are enabled',
|
||||
'https://example.com/return',
|
||||
'https://example.com/cancel'
|
||||
);
|
||||
} finally {
|
||||
$this->is_request_logging_enabled = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch ( PayPalApiException $exception ) {
|
||||
|
|
|
@ -16,6 +16,13 @@ use WP_Error;
|
|||
*/
|
||||
trait RequestTrait {
|
||||
|
||||
/**
|
||||
* Whether to log the detailed request/response info.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $is_request_logging_enabled = true;
|
||||
|
||||
/**
|
||||
* Performs a request
|
||||
*
|
||||
|
@ -39,7 +46,9 @@ trait RequestTrait {
|
|||
}
|
||||
|
||||
$response = wp_remote_get( $url, $args );
|
||||
$this->logger->debug( $this->request_response_string( $url, $args, $response ) );
|
||||
if ( $this->is_request_logging_enabled ) {
|
||||
$this->logger->debug( $this->request_response_string( $url, $args, $response ) );
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
|
|
@ -215,11 +215,12 @@ class SmartButton implements SmartButtonInterface {
|
|||
function ( array $default_fields, $id ) use ( $subscription_helper ) : array {
|
||||
if ( is_user_logged_in() && $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ) && CreditCardGateway::ID === $id ) {
|
||||
|
||||
if ( ! $subscription_helper->cart_contains_subscription() ) {
|
||||
$default_fields['card-vault'] = sprintf(
|
||||
'<p class="form-row form-row-wide"><label for="ppcp-credit-card-vault"><input class="ppcp-credit-card-vault" type="checkbox" id="ppcp-credit-card-vault" name="vault"> %s</label></p>',
|
||||
esc_html__( 'Save your Credit Card', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
$default_fields['card-vault'] = sprintf(
|
||||
'<p class="form-row form-row-wide"><label for="ppcp-credit-card-vault"><input class="ppcp-credit-card-vault" type="checkbox" id="ppcp-credit-card-vault" name="vault">%s</label></p>',
|
||||
esc_html__( 'Save your Credit Card', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
if ( $subscription_helper->cart_contains_subscription() || $subscription_helper->order_pay_contains_subscription() ) {
|
||||
$default_fields['card-vault'] = '';
|
||||
}
|
||||
|
||||
$tokens = $this->payment_token_repository->all_for_user_id( get_current_user_id() );
|
||||
|
@ -570,7 +571,8 @@ class SmartButton implements SmartButtonInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
$label = 'checkout' === $this->context() ? __( 'Place order', 'woocommerce-paypal-payments' ) : __( 'Pay for order', 'woocommerce-paypal-payments' );
|
||||
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
|
||||
$label = 'checkout' === $this->context() ? apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ) : __( 'Pay for order', 'woocommerce' );
|
||||
|
||||
printf(
|
||||
'<div id="%1$s" style="display:none;">
|
||||
|
@ -612,6 +614,10 @@ class SmartButton implements SmartButtonInterface {
|
|||
if ( is_product() ) {
|
||||
return $this->subscription_helper->current_product_is_subscription();
|
||||
}
|
||||
if ( is_wc_endpoint_url( 'order-pay' ) ) {
|
||||
return $this->subscription_helper->order_pay_contains_subscription();
|
||||
}
|
||||
|
||||
return $this->subscription_helper->cart_contains_subscription();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,14 @@ return array(
|
|||
$endpoint = $container->get( 'api.endpoint.order' );
|
||||
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
|
||||
$payer_factory = $container->get( 'api.factory.payer' );
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
return new RenewalHandler(
|
||||
$logger,
|
||||
$repository,
|
||||
$endpoint,
|
||||
$purchase_unit_factory,
|
||||
$payer_factory
|
||||
$payer_factory,
|
||||
$environment
|
||||
);
|
||||
},
|
||||
'subscription.repository.payment-token' => static function ( ContainerInterface $container ): PaymentTokenRepository {
|
||||
|
|
|
@ -55,6 +55,42 @@ class SubscriptionHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether pay for order contains subscriptions.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function order_pay_contains_subscription(): bool {
|
||||
if ( ! $this->plugin_is_active() || ! is_wc_endpoint_url( 'order-pay' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global $wp;
|
||||
$order_id = (int) $wp->query_vars['order-pay'];
|
||||
if ( 0 === $order_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = wc_get_order( $order_id );
|
||||
if ( is_a( $order, \WC_Order::class ) ) {
|
||||
foreach ( $order->get_items() as $item ) {
|
||||
if ( is_a( $item, \WC_Order_Item_Product::class ) ) {
|
||||
$product = wc_get_product( $item->get_product_id() );
|
||||
/**
|
||||
* Class already exist in subscriptions plugin.
|
||||
*
|
||||
* @psalm-suppress UndefinedClass
|
||||
*/
|
||||
if ( is_a( $product, \WC_Product_Subscription::class ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether only automatic payment gateways are accepted.
|
||||
*
|
||||
|
|
|
@ -10,21 +10,26 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\Subscription;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\PaymentsStatusHandlingTrait;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait;
|
||||
|
||||
/**
|
||||
* Class RenewalHandler
|
||||
*/
|
||||
class RenewalHandler {
|
||||
|
||||
use OrderMetaTrait;
|
||||
use TransactionIdHandlingTrait;
|
||||
use PaymentsStatusHandlingTrait;
|
||||
|
||||
/**
|
||||
* The logger.
|
||||
*
|
||||
|
@ -60,6 +65,13 @@ class RenewalHandler {
|
|||
*/
|
||||
private $payer_factory;
|
||||
|
||||
/**
|
||||
* The environment.
|
||||
*
|
||||
* @var Environment
|
||||
*/
|
||||
protected $environment;
|
||||
|
||||
/**
|
||||
* RenewalHandler constructor.
|
||||
*
|
||||
|
@ -68,13 +80,15 @@ class RenewalHandler {
|
|||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
|
||||
* @param PayerFactory $payer_factory The payer factory.
|
||||
* @param Environment $environment The environment.
|
||||
*/
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
PaymentTokenRepository $repository,
|
||||
OrderEndpoint $order_endpoint,
|
||||
PurchaseUnitFactory $purchase_unit_factory,
|
||||
PayerFactory $payer_factory
|
||||
PayerFactory $payer_factory,
|
||||
Environment $environment
|
||||
) {
|
||||
|
||||
$this->logger = $logger;
|
||||
|
@ -82,6 +96,7 @@ class RenewalHandler {
|
|||
$this->order_endpoint = $order_endpoint;
|
||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||
$this->payer_factory = $payer_factory;
|
||||
$this->environment = $environment;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,52 +105,23 @@ class RenewalHandler {
|
|||
* @param \WC_Order $wc_order The WooCommerce order.
|
||||
*/
|
||||
public function renew( \WC_Order $wc_order ) {
|
||||
|
||||
$this->logger->log(
|
||||
'info',
|
||||
sprintf(
|
||||
// translators: %d is the id of the order.
|
||||
__( 'Start moneytransfer for order %d', 'woocommerce-paypal-payments' ),
|
||||
(int) $wc_order->get_id()
|
||||
),
|
||||
array(
|
||||
'order' => $wc_order,
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
$this->process_order( $wc_order );
|
||||
} catch ( \Exception $error ) {
|
||||
$this->logger->log(
|
||||
'error',
|
||||
$this->logger->error(
|
||||
sprintf(
|
||||
// translators: %1$d is the order number, %2$s the error message.
|
||||
__(
|
||||
'An error occured while trying to renew the subscription for order %1$d: %2$s',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
(int) $wc_order->get_id(),
|
||||
'An error occurred while trying to renew the subscription for order %1$d: %2$s',
|
||||
$wc_order->get_id(),
|
||||
$error->getMessage()
|
||||
),
|
||||
array(
|
||||
'order' => $wc_order,
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
$this->logger->log(
|
||||
'info',
|
||||
$this->logger->info(
|
||||
sprintf(
|
||||
// translators: %d is the order number.
|
||||
__(
|
||||
'Moneytransfer for order %d is completed.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
(int) $wc_order->get_id()
|
||||
),
|
||||
array(
|
||||
'order' => $wc_order,
|
||||
'Renewal for order %d is completed.',
|
||||
$wc_order->get_id()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -164,7 +150,19 @@ class RenewalHandler {
|
|||
$token
|
||||
);
|
||||
|
||||
$this->capture_order( $order, $wc_order );
|
||||
$this->add_paypal_meta( $wc_order, $order, $this->environment );
|
||||
|
||||
if ( $order->intent() === 'AUTHORIZE' ) {
|
||||
$order = $this->order_endpoint->authorize( $order );
|
||||
$wc_order->update_meta_data( AuthorizedPaymentsProcessor::CAPTURED_META_KEY, 'false' );
|
||||
}
|
||||
|
||||
$transaction_id = $this->get_paypal_order_transaction_id( $order );
|
||||
if ( $transaction_id ) {
|
||||
$this->update_transaction_id( $transaction_id, $wc_order );
|
||||
}
|
||||
|
||||
$this->handle_new_order_status( $order, $wc_order );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,12 +183,8 @@ class RenewalHandler {
|
|||
if ( ! $tokens ) {
|
||||
|
||||
$error_message = sprintf(
|
||||
// translators: %d is the customer id.
|
||||
__(
|
||||
'Payment failed. No payment tokens found for customer %d.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
(int) $customer->get_id()
|
||||
'Payment failed. No payment tokens found for customer %d.',
|
||||
$customer->get_id()
|
||||
);
|
||||
|
||||
$wc_order->update_status(
|
||||
|
@ -198,14 +192,7 @@ class RenewalHandler {
|
|||
$error_message
|
||||
);
|
||||
|
||||
$this->logger->log(
|
||||
'error',
|
||||
$error_message,
|
||||
array(
|
||||
'customer' => $customer,
|
||||
'order' => $wc_order,
|
||||
)
|
||||
);
|
||||
$this->logger->error( $error_message );
|
||||
}
|
||||
|
||||
$subscription = function_exists( 'wcs_get_subscription' ) ? wcs_get_subscription( $wc_order->get_meta( '_subscription_renewal' ) ) : null;
|
||||
|
@ -223,25 +210,4 @@ class RenewalHandler {
|
|||
|
||||
return current( $tokens );
|
||||
}
|
||||
|
||||
/**
|
||||
* If the PayPal order is captured/authorized the WooCommerce order gets updated accordingly.
|
||||
*
|
||||
* @param Order $order The PayPal order.
|
||||
* @param \WC_Order $wc_order The related WooCommerce order.
|
||||
*/
|
||||
private function capture_order( Order $order, \WC_Order $wc_order ) {
|
||||
|
||||
if ( $order->intent() === 'CAPTURE' && $order->status()->is( OrderStatus::COMPLETED ) ) {
|
||||
$wc_order->update_status(
|
||||
'processing',
|
||||
__( 'Payment received.', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( $order->intent() === 'AUTHORIZE' ) {
|
||||
$this->order_endpoint->authorize( $order );
|
||||
$wc_order->update_meta_data( AuthorizedPaymentsProcessor::CAPTURED_META_KEY, 'false' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -729,7 +729,8 @@ return array(
|
|||
'title' => __( 'Logging', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
'label' => __( 'Enable logging', 'woocommerce-paypal-payments' ),
|
||||
'label' => __( 'Enable logging. ', 'woocommerce-paypal-payments' ) .
|
||||
' <a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">' . __( 'View logs', 'woocommerce-paypal-payments' ) . '</a>',
|
||||
'description' => __( 'Enable logging of unexpected behavior. This can also log private data and should only be enabled in a development or stage environment.', 'woocommerce-paypal-payments' ),
|
||||
'default' => false,
|
||||
'screens' => array(
|
||||
|
|
|
@ -538,6 +538,14 @@ $data_rows_html
|
|||
'woocommerce-paypal-payments'
|
||||
);
|
||||
?>
|
||||
<a href="https://developer.paypal.com/docs/checkout/advanced/currency-availability-advanced-cards/">
|
||||
<?php
|
||||
esc_html_e(
|
||||
'Advanced credit and debit country and currency availability.',
|
||||
'woocommerce-paypal-payments'
|
||||
);
|
||||
?>
|
||||
</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue