Merge trunk

This commit is contained in:
dinamiko 2022-07-11 11:51:04 +02:00
commit 5f90aaae20
44 changed files with 627 additions and 420 deletions

View file

@ -90,6 +90,7 @@ return array(
$page_id,
$environment,
$payment_token_repository,
$container->get( 'api.factory.shipping-preference' ),
$logger,
$payments_endpoint,
$order_endpoint,
@ -126,6 +127,7 @@ return array(
$transaction_url_provider,
$payment_token_repository,
$purchase_unit_factory,
$container->get( 'api.factory.shipping-preference' ),
$payer_factory,
$order_endpoint,
$subscription_helper,

View file

@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
@ -111,6 +112,13 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
*/
private $purchase_unit_factory;
/**
* The shipping_preference factory.
*
* @var ShippingPreferenceFactory
*/
private $shipping_preference_factory;
/**
* The payer factory.
*
@ -167,6 +175,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
* @param TransactionUrlProvider $transaction_url_provider Service able to provide view transaction url base.
* @param PaymentTokenRepository $payment_token_repository The payment token repository.
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
* @param ShippingPreferenceFactory $shipping_preference_factory The shipping_preference factory.
* @param PayerFactory $payer_factory The payer factory.
* @param OrderEndpoint $order_endpoint The order endpoint.
* @param SubscriptionHelper $subscription_helper The subscription helper.
@ -186,6 +195,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
TransactionUrlProvider $transaction_url_provider,
PaymentTokenRepository $payment_token_repository,
PurchaseUnitFactory $purchase_unit_factory,
ShippingPreferenceFactory $shipping_preference_factory,
PayerFactory $payer_factory,
OrderEndpoint $order_endpoint,
SubscriptionHelper $subscription_helper,
@ -252,16 +262,17 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
)
);
$this->module_url = $module_url;
$this->payment_token_repository = $payment_token_repository;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->payer_factory = $payer_factory;
$this->order_endpoint = $order_endpoint;
$this->transaction_url_provider = $transaction_url_provider;
$this->subscription_helper = $subscription_helper;
$this->logger = $logger;
$this->payments_endpoint = $payments_endpoint;
$this->state = $state;
$this->module_url = $module_url;
$this->payment_token_repository = $payment_token_repository;
$this->purchase_unit_factory = $purchase_unit_factory;
$this->shipping_preference_factory = $shipping_preference_factory;
$this->payer_factory = $payer_factory;
$this->order_endpoint = $order_endpoint;
$this->transaction_url_provider = $transaction_url_provider;
$this->subscription_helper = $subscription_helper;
$this->logger = $logger;
$this->payments_endpoint = $payments_endpoint;
$this->state = $state;
}
/**

View file

@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
@ -118,6 +119,13 @@ class PayPalGateway extends \WC_Payment_Gateway {
*/
protected $payment_token_repository;
/**
* The shipping_preference factory.
*
* @var ShippingPreferenceFactory
*/
private $shipping_preference_factory;
/**
* The payments endpoint
*
@ -183,6 +191,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
* @param Environment $environment The environment.
* @param PaymentTokenRepository $payment_token_repository The payment token repository.
* @param ShippingPreferenceFactory $shipping_preference_factory The shipping_preference factory.
* @param LoggerInterface $logger The logger.
* @param PaymentsEndpoint $payments_endpoint The payments endpoint.
* @param OrderEndpoint $order_endpoint The order endpoint.
@ -202,6 +211,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
string $page_id,
Environment $environment,
PaymentTokenRepository $payment_token_repository,
ShippingPreferenceFactory $shipping_preference_factory,
LoggerInterface $logger,
PaymentsEndpoint $payments_endpoint,
OrderEndpoint $order_endpoint,
@ -223,6 +233,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
$this->id = self::ID;
$this->order_processor = $order_processor;
$this->authorized_payments = $authorized_payments_processor;
$this->shipping_preference_factory = $shipping_preference_factory;
$this->settings_renderer = $settings_renderer;
$this->config = $config;
$this->session_handler = $session_handler;
@ -353,7 +364,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
return __( 'PayPal Checkout', 'woocommerce-paypal-payments' );
}
if ( $this->is_pui_tab() ) {
return __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' );
return __( 'Pay upon Invoice', 'woocommerce-paypal-payments' );
}
return __( 'PayPal', 'woocommerce-paypal-payments' );

View file

@ -31,6 +31,7 @@ class FraudNetSessionId {
return WC()->session->get( 'ppcp_fraudnet_session_id' );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
$pui_pay_for_order_session_id = filter_input( INPUT_POST, 'pui_pay_for_order_session_id', FILTER_SANITIZE_STRING );
if ( $pui_pay_for_order_session_id && '' !== $pui_pay_for_order_session_id ) {

View file

@ -12,9 +12,10 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Factory\CaptureFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
@ -115,11 +116,11 @@ class PayUponInvoice {
protected $pui_product_status;
/**
* The checkout helper.
* The capture factory.
*
* @var CheckoutHelper
* @var CaptureFactory
*/
protected $checkout_helper;
protected $capture_factory;
/**
* PayUponInvoice constructor.
@ -136,7 +137,7 @@ class PayUponInvoice {
* @param string $current_ppcp_settings_page_id Current PayPal settings page id.
* @param PayUponInvoiceProductStatus $pui_product_status The PUI product status.
* @param PayUponInvoiceHelper $pui_helper The PUI helper.
* @param CheckoutHelper $checkout_helper The checkout helper.
* @param CaptureFactory $capture_factory The capture factory.
*/
public function __construct(
string $module_url,
@ -151,7 +152,7 @@ class PayUponInvoice {
string $current_ppcp_settings_page_id,
PayUponInvoiceProductStatus $pui_product_status,
PayUponInvoiceHelper $pui_helper,
CheckoutHelper $checkout_helper
CaptureFactory $capture_factory
) {
$this->module_url = $module_url;
$this->fraud_net = $fraud_net;
@ -165,7 +166,7 @@ class PayUponInvoice {
$this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id;
$this->pui_product_status = $pui_product_status;
$this->pui_helper = $pui_helper;
$this->checkout_helper = $checkout_helper;
$this->capture_factory = $capture_factory;
}
/**
@ -216,7 +217,12 @@ class PayUponInvoice {
'ppcp_payment_capture_completed_webhook_handler',
function ( WC_Order $wc_order, string $order_id ) {
try {
$payment_instructions = $this->pui_order_endpoint->order_payment_instructions( $order_id );
$order = $this->pui_order_endpoint->order( $order_id );
$payment_instructions = array(
$order->payment_source->pay_upon_invoice->payment_reference,
$order->payment_source->pay_upon_invoice->deposit_bank_details,
);
$wc_order->update_meta_data(
'ppcp_ratepay_payment_instructions_payment_reference',
$payment_instructions
@ -224,6 +230,12 @@ class PayUponInvoice {
$wc_order->save_meta_data();
$this->logger->info( "Ratepay payment instructions added to order #{$wc_order->get_id()}." );
$capture = $this->capture_factory->from_paypal_response( $order->purchase_units[0]->payments->captures[0] );
$breakdown = $capture->seller_receivable_breakdown();
if ( $breakdown ) {
$wc_order->update_meta_data( PayPalGateway::FEES_META_KEY, $breakdown->to_array() );
$wc_order->save_meta_data();
}
} catch ( RuntimeException $exception ) {
$this->logger->error( $exception->getMessage() );
}
@ -348,7 +360,7 @@ class PayUponInvoice {
}
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
if ( ( $birth_date && ! $this->checkout_helper->validate_birth_date( $birth_date ) ) || $birth_date === '' ) {
if ( ( $birth_date && ! $this->pui_helper->validate_birth_date( $birth_date ) ) || $birth_date === '' ) {
$errors->add( 'validation', __( 'Invalid birth date.', 'woocommerce-paypal-payments' ) );
}
@ -401,7 +413,7 @@ class PayUponInvoice {
printf(
'<div class="notice notice-error"><p>%1$s</p></div>',
esc_html__( 'Could not enable gateway because the connected PayPal account is not activated for Pay upon Invoice. Reconnect your account while Onboard with Pay Upon Invoice is selected to try again.', 'woocommerce-paypal-payments' )
esc_html__( 'Could not enable gateway because the connected PayPal account is not activated for Pay upon Invoice. Reconnect your account while Onboard with Pay upon Invoice is selected to try again.', 'woocommerce-paypal-payments' )
);
}
}
@ -501,21 +513,26 @@ class PayUponInvoice {
* Registers PUI assets.
*/
public function register_assets(): void {
wp_enqueue_script(
'ppcp-pay-upon-invoice',
trailingslashit( $this->module_url ) . 'assets/js/pay-upon-invoice.js',
array(),
$this->asset_version
);
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
$gateway_enabled = $gateway_settings['enabled'] ?? '';
if ( $gateway_enabled === 'yes' && ( is_checkout() || is_checkout_pay_page() ) ) {
wp_enqueue_script(
'ppcp-pay-upon-invoice',
trailingslashit( $this->module_url ) . 'assets/js/pay-upon-invoice.js',
array(),
$this->asset_version,
true
);
wp_localize_script(
'ppcp-pay-upon-invoice',
'FraudNetConfig',
array(
'f' => $this->fraud_net->session_id(),
's' => $this->fraud_net->source_website_id(),
'sandbox' => $this->environment->current_environment_is( Environment::SANDBOX ),
)
);
wp_localize_script(
'ppcp-pay-upon-invoice',
'FraudNetConfig',
array(
'f' => $this->fraud_net->session_id(),
's' => $this->fraud_net->source_website_id(),
'sandbox' => $this->environment->current_environment_is( Environment::SANDBOX ),
)
);
}
}
}

View file

@ -111,7 +111,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
) {
$this->id = self::ID;
$this->method_title = __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' );
$this->method_title = __( 'Pay upon Invoice', 'woocommerce-paypal-payments' );
$this->method_description = __( 'Pay upon Invoice is an invoice payment method in Germany. It is a local buy now, pay later payment method that allows the buyer to place an order, receive the goods, try them, verify they are in good order, and then pay the invoice within 30 days.', 'woocommerce-paypal-payments' );
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
@ -150,7 +150,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
'default' => 'no',
'desc_tip' => true,
'description' => __( 'Enable/Disable Pay Upon Invoice payment gateway.', 'woocommerce-paypal-payments' ),
'description' => __( 'Enable/Disable Pay upon Invoice payment gateway.', 'woocommerce-paypal-payments' ),
),
'title' => array(
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
@ -215,7 +215,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
}
}
$wc_order->update_status( 'on-hold', __( 'Awaiting Pay Upon Invoice payment.', 'woocommerce-paypal-payments' ) );
$wc_order->update_status( 'on-hold', __( 'Awaiting Pay upon Invoice payment.', 'woocommerce-paypal-payments' ) );
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
$payment_source = $this->payment_source_factory->from_wc_order( $wc_order, $birth_date );

View file

@ -82,9 +82,16 @@ trait ProcessPaymentTrait {
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
$payer = $this->payer_factory->from_customer( $customer );
$shipping_preference = $this->shipping_preference_factory->from_state(
$purchase_unit,
''
);
try {
$order = $this->order_endpoint->create(
array( $purchase_unit ),
$shipping_preference,
$payer,
$selected_token
);

View file

@ -66,7 +66,7 @@ class SectionsRenderer {
$sections = array(
PayPalGateway::ID => __( 'PayPal Checkout', 'woocommerce-paypal-payments' ),
CreditCardGateway::ID => __( 'PayPal Card Processing', 'woocommerce-paypal-payments' ),
PayUponInvoiceGateway::ID => __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' ),
PayUponInvoiceGateway::ID => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
WebhooksStatusPage::ID => __( 'Webhooks Status', 'woocommerce-paypal-payments' ),
);

View file

@ -228,7 +228,7 @@ class WCGatewayModule implements ModuleInterface {
add_action(
'init',
function () use ( $c ) {
if ( 'DE' === $c->get( 'api.shop.country' ) && 'EUR' === get_woocommerce_currency() ) {
if ( 'DE' === $c->get( 'api.shop.country' ) && 'EUR' === $c->get( 'api.shop.currency' ) ) {
( $c->get( 'wcgateway.pay-upon-invoice' ) )->init();
}
@ -286,7 +286,7 @@ class WCGatewayModule implements ModuleInterface {
$methods[] = $container->get( 'wcgateway.credit-card-gateway' );
}
if ( 'DE' === $container->get( 'api.shop.country' ) ) {
if ( 'DE' === $container->get( 'api.shop.country' ) && 'EUR' === $container->get( 'api.shop.currency' ) ) {
$methods[] = $container->get( 'wcgateway.pay-upon-invoice-gateway' );
}