From 18220769a2bd9b990bd830b97756d019eddba5b6 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 7 Mar 2022 12:54:02 +0100
Subject: [PATCH 001/163] Introduce pay upon invoice gateway (WIP)
---
.../ppcp-wc-gateway/resources/js/fraudnet.js | 8 ++
modules/ppcp-wc-gateway/services.php | 17 +++
.../Gateway/PayUponInvoice/OrderEndpoint.php | 120 ++++++++++++++++++
.../PayUponInvoice/PayUponInvoiceGateway.php | 96 ++++++++++++++
.../ppcp-wc-gateway/src/WCGatewayModule.php | 22 ++++
modules/ppcp-wc-gateway/webpack.config.js | 1 +
6 files changed, 264 insertions(+)
create mode 100644 modules/ppcp-wc-gateway/resources/js/fraudnet.js
create mode 100644 modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
create mode 100644 modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
diff --git a/modules/ppcp-wc-gateway/resources/js/fraudnet.js b/modules/ppcp-wc-gateway/resources/js/fraudnet.js
new file mode 100644
index 000000000..11a74b1c5
--- /dev/null
+++ b/modules/ppcp-wc-gateway/resources/js/fraudnet.js
@@ -0,0 +1,8 @@
+document.addEventListener('DOMContentLoaded', () => {
+ const script = document.createElement('script');
+ script.setAttribute('src', 'https://c.paypal.com/da/r/fb.js');
+
+ console.log(script)
+
+ document.body.append(script);
+});
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 22bb3715f..ca52026d1 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -29,6 +29,8 @@ use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
use WooCommerce\PayPalCommerce\WcGateway\FundingSource\FundingSourceRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\OrderEndpoint;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
@@ -2118,4 +2120,19 @@ return array(
$container->get( 'wcgateway.settings' )
);
},
+ 'wcgateway.pay-upon-invoice-order-endpoint' => static function (ContainerInterface $container): OrderEndpoint {
+ return new OrderEndpoint(
+ $container->get( 'api.host' ),
+ $container->get( 'api.bearer' ),
+ $container->get( 'api.factory.order' ),
+ $container->get( 'woocommerce.logger.woocommerce' )
+ );
+ },
+ 'wcgateway.pay-upon-invoice-gateway' => static function (ContainerInterface $container): PayUponInvoiceGateway {
+ return new PayUponInvoiceGateway(
+ $container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
+ $container->get( 'api.factory.purchase-unit' ),
+ $container->get( 'woocommerce.logger.woocommerce' )
+ );
+ },
);
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
new file mode 100644
index 000000000..6ef341b6b
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -0,0 +1,120 @@
+host = $host;
+ $this->bearer = $bearer;
+ $this->order_factory = $order_factory;
+ $this->logger = $logger;
+ }
+
+ /**
+ * Creates an order.
+ *
+ * @param PurchaseUnit[] $items The purchase unit items for the order.
+ * @return Order
+ */
+ public function create( array $items ): Order {
+ $data = array(
+ 'intent' => 'CAPTURE',
+ 'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
+ 'purchase_units' => array_map(
+ static function ( PurchaseUnit $item ): array {
+ return $item->to_array();
+ },
+ $items
+ ),
+ 'payment_source' => array (
+ 'pay_upon_invoice' => array(
+ 'name' => array(
+ 'given_name' => 'John',
+ 'surname' => 'Doe',
+ ),
+ 'email' => 'buyer@example.com',
+ 'birth_date' => '1990-01-01',
+ 'phone' => array(
+ 'national_number' => '6912345678',
+ 'country_code' => '49',
+ ),
+ 'billing_address' => array(
+ 'address_line_1' => 'Schönhauser Allee 84',
+ 'admin_area_2' => 'Berlin',
+ 'postal_code' => '10439',
+ 'country_code' => 'DE',
+ ),
+ 'experience_context' => array(
+ 'locale' => 'en-DE',
+ 'brand_name' => 'EXAMPLE INC',
+ 'logo_url' => 'https://example.com/logoUrl.svg',
+ 'customer_service_instructions' => array(
+ 'Customer service phone is +49 6912345678.',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $bearer = $this->bearer->bearer();
+ $url = trailingslashit( $this->host ) . 'v2/checkout/orders';
+ $args = array(
+ 'method' => 'POST',
+ 'headers' => array(
+ 'Authorization' => 'Bearer ' . $bearer->token(),
+ 'Content-Type' => 'application/json',
+ 'Prefer' => 'return=representation',
+ 'PayPal-Client-Metadata-Id' => 'd4e0d7b9-4f75-43f9-9437-d8a57c901585',
+ 'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
+ ),
+ 'body' => wp_json_encode( $data ),
+ );
+
+ $response = $this->request( $url, $args );
+ if ( is_wp_error( $response ) ) {
+ throw new RuntimeException($response->get_error_message());
+ }
+
+ $json = json_decode( $response['body'] );
+ $status_code = (int) wp_remote_retrieve_response_code( $response );
+ if ( 201 !== $status_code ) {
+ throw new PayPalApiException($json, $status_code);
+ }
+
+ return $this->order_factory->from_paypal_response( $json );
+ }
+}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
new file mode 100644
index 000000000..a81f7f535
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -0,0 +1,96 @@
+id = self::ID;
+
+ $this->method_title = __('Pay Upon Invoice', 'woocommerce-paypal-payments');
+ $this->method_description = __('Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', 'woocommerce-paypal-payments');
+ $this->title = $this->method_title;
+ $this->description = $this->method_description;
+
+ $this->init_form_fields();
+ $this->init_settings();
+
+ add_action(
+ 'woocommerce_update_options_payment_gateways_' . $this->id,
+ array(
+ $this,
+ 'process_admin_options',
+ )
+ );
+
+ $this->order_endpoint = $order_endpoint;
+ $this->purchase_unit_factory = $purchase_unit_factory;
+ $this->logger = $logger;
+ }
+
+ /**
+ * Initialize the form fields.
+ */
+ public function init_form_fields() {
+ $this->form_fields = array(
+ 'enabled' => array(
+ 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
+ 'type' => 'checkbox',
+ 'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
+ 'default' => 'yes'
+ ),
+ );
+ }
+
+ public function process_payment($order_id)
+ {
+ $wc_order = new WC_Order( $order_id );
+ $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 );
+
+ try {
+ $this->order_endpoint->create(array( $purchase_unit ));
+ } catch (RuntimeException $exception) {
+ $error = $exception->getMessage();
+ $this->logger->error($error);
+
+ // TODO display error in the screen
+ }
+ }
+}
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 8ec2f9965..854da583d 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -205,6 +205,9 @@ class WCGatewayModule implements ModuleInterface {
if ( $dcc_applies->for_country_currency() ) {
$methods[] = $container->get( 'wcgateway.credit-card-gateway' );
}
+
+ $methods[] = $container->get('wcgateway.pay-upon-invoice-gateway');
+
return (array) $methods;
}
);
@@ -268,6 +271,25 @@ class WCGatewayModule implements ModuleInterface {
return $disabler->handler( (array) $methods );
}
);
+
+ add_action('wp_footer', function () { ?>
+
+ get('wcgateway.url');
+ wp_enqueue_script(
+ 'ppcp-fraudnet',
+ trailingslashit($gateway_module_url) . 'assets/js/fraudnet.js',
+ array(),
+ 1
+ );
+ });
}
/**
diff --git a/modules/ppcp-wc-gateway/webpack.config.js b/modules/ppcp-wc-gateway/webpack.config.js
index c9c6c2b55..fcc5648bb 100644
--- a/modules/ppcp-wc-gateway/webpack.config.js
+++ b/modules/ppcp-wc-gateway/webpack.config.js
@@ -7,6 +7,7 @@ module.exports = {
target: 'web',
entry: {
'gateway-settings': path.resolve('./resources/js/gateway-settings.js'),
+ 'fraudnet': path.resolve('./resources/js/fraudnet.js'),
},
output: {
path: path.resolve(__dirname, 'assets/'),
From da523884d63cf005fc9cc92a2766025ff56a8fb2 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 7 Mar 2022 14:49:41 +0100
Subject: [PATCH 002/163] Handle error when creating order
---
.../Gateway/PayUponInvoice/OrderEndpoint.php | 56 +++++++++----------
.../PayUponInvoice/PayUponInvoiceGateway.php | 16 +++++-
2 files changed, 41 insertions(+), 31 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 6ef341b6b..090aa72d5 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -37,11 +37,11 @@ class OrderEndpoint {
*/
protected $logger;
- public function __construct( string $host, Bearer $bearer, OrderFactory $order_factory, LoggerInterface $logger) {
- $this->host = $host;
- $this->bearer = $bearer;
+ public function __construct( string $host, Bearer $bearer, OrderFactory $order_factory, LoggerInterface $logger ) {
+ $this->host = $host;
+ $this->bearer = $bearer;
$this->order_factory = $order_factory;
- $this->logger = $logger;
+ $this->logger = $logger;
}
/**
@@ -52,36 +52,36 @@ class OrderEndpoint {
*/
public function create( array $items ): Order {
$data = array(
- 'intent' => 'CAPTURE',
+ 'intent' => 'CAPTURE',
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
- 'purchase_units' => array_map(
+ 'purchase_units' => array_map(
static function ( PurchaseUnit $item ): array {
return $item->to_array();
},
$items
),
- 'payment_source' => array (
+ 'payment_source' => array(
'pay_upon_invoice' => array(
- 'name' => array(
+ 'name' => array(
'given_name' => 'John',
- 'surname' => 'Doe',
+ 'surname' => 'Doe',
),
- 'email' => 'buyer@example.com',
- 'birth_date' => '1990-01-01',
- 'phone' => array(
+ 'email' => 'buyer@example.com',
+ 'birth_date' => '1990-01-01',
+ 'phone' => array(
'national_number' => '6912345678',
- 'country_code' => '49',
+ 'country_code' => '49',
),
- 'billing_address' => array(
+ 'billing_address' => array(
'address_line_1' => 'Schönhauser Allee 84',
- 'admin_area_2' => 'Berlin',
- 'postal_code' => '10439',
- 'country_code' => 'DE',
+ 'admin_area_2' => 'Berlin',
+ 'postal_code' => '10439',
+ 'country_code' => 'DE',
),
'experience_context' => array(
- 'locale' => 'en-DE',
- 'brand_name' => 'EXAMPLE INC',
- 'logo_url' => 'https://example.com/logoUrl.svg',
+ 'locale' => 'en-DE',
+ 'brand_name' => 'EXAMPLE INC',
+ 'logo_url' => 'https://example.com/logoUrl.svg',
'customer_service_instructions' => array(
'Customer service phone is +49 6912345678.',
),
@@ -91,28 +91,28 @@ class OrderEndpoint {
);
$bearer = $this->bearer->bearer();
- $url = trailingslashit( $this->host ) . 'v2/checkout/orders';
- $args = array(
+ $url = trailingslashit( $this->host ) . 'v2/checkout/orders';
+ $args = array(
'method' => 'POST',
'headers' => array(
- 'Authorization' => 'Bearer ' . $bearer->token(),
- 'Content-Type' => 'application/json',
- 'Prefer' => 'return=representation',
+ 'Authorization' => 'Bearer ' . $bearer->token(),
+ 'Content-Type' => 'application/json',
+ 'Prefer' => 'return=representation',
'PayPal-Client-Metadata-Id' => 'd4e0d7b9-4f75-43f9-9437-d8a57c901585',
- 'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
+ 'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
),
'body' => wp_json_encode( $data ),
);
$response = $this->request( $url, $args );
if ( is_wp_error( $response ) ) {
- throw new RuntimeException($response->get_error_message());
+ throw new RuntimeException( $response->get_error_message() );
}
$json = json_decode( $response['body'] );
$status_code = (int) wp_remote_retrieve_response_code( $response );
if ( 201 !== $status_code ) {
- throw new PayPalApiException($json, $status_code);
+ throw new PayPalApiException( $json, $status_code );
}
return $this->order_factory->from_paypal_response( $json );
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index a81f7f535..0dd36afe1 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -79,7 +79,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
public function process_payment($order_id)
{
- $wc_order = new WC_Order( $order_id );
+ $wc_order = wc_get_order( $order_id );
$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 );
@@ -88,9 +88,19 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$this->order_endpoint->create(array( $purchase_unit ));
} catch (RuntimeException $exception) {
$error = $exception->getMessage();
- $this->logger->error($error);
- // TODO display error in the screen
+ $this->logger->error($error);
+ wc_add_notice( $error, 'error' );
+
+ $wc_order->update_status(
+ 'failed',
+ $error
+ );
+
+ return array(
+ 'result' => 'failure',
+ 'redirect' => wc_get_checkout_url(),
+ );
}
}
}
From 2e9cc0b8af5e91df2e0417e1bcbfa97372b65ce1 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 8 Mar 2022 11:43:05 +0100
Subject: [PATCH 003/163] Pass hardcoded session id to test order creation
---
modules/ppcp-wc-gateway/resources/js/fraudnet.js | 3 ---
.../src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php | 1 -
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 2 +-
3 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/modules/ppcp-wc-gateway/resources/js/fraudnet.js b/modules/ppcp-wc-gateway/resources/js/fraudnet.js
index 11a74b1c5..a9b735fde 100644
--- a/modules/ppcp-wc-gateway/resources/js/fraudnet.js
+++ b/modules/ppcp-wc-gateway/resources/js/fraudnet.js
@@ -1,8 +1,5 @@
document.addEventListener('DOMContentLoaded', () => {
const script = document.createElement('script');
script.setAttribute('src', 'https://c.paypal.com/da/r/fb.js');
-
- console.log(script)
-
document.body.append(script);
});
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 0dd36afe1..864c83329 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use RuntimeException;
-use WC_Order;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 854da583d..0176e4362 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -275,7 +275,7 @@ class WCGatewayModule implements ModuleInterface {
add_action('wp_footer', function () { ?>
From 00de9de57e7661cca83cedc6a1df9bbe6ea646e7 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 8 Mar 2022 12:33:59 +0100
Subject: [PATCH 004/163] Display pay upon invoice gateway only if store
country is germany
---
.../ppcp-wc-gateway/src/WCGatewayModule.php | 37 +++++++++++++------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 0176e4362..2285a6cc7 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -206,7 +206,9 @@ class WCGatewayModule implements ModuleInterface {
$methods[] = $container->get( 'wcgateway.credit-card-gateway' );
}
- $methods[] = $container->get('wcgateway.pay-upon-invoice-gateway');
+ if ( 'DE' === $container->get( 'api.shop.country' ) ) {
+ $methods[] = $container->get( 'wcgateway.pay-upon-invoice-gateway' );
+ }
return (array) $methods;
}
@@ -272,24 +274,35 @@ class WCGatewayModule implements ModuleInterface {
}
);
- add_action('wp_footer', function () { ?>
+ add_action(
+ 'wp_footer',
+ function () use ( $container ) {
+ if ( 'DE' === $container->get( 'api.shop.country' ) ) { ?>
- get('wcgateway.url');
- wp_enqueue_script(
- 'ppcp-fraudnet',
- trailingslashit($gateway_module_url) . 'assets/js/fraudnet.js',
- array(),
- 1
- );
- });
+ add_action(
+ 'wp_enqueue_scripts',
+ function () use ( $container ) {
+ if ( 'DE' === $container->get( 'api.shop.country' ) ) {
+ $gateway_module_url = $container->get( 'wcgateway.url' );
+ wp_enqueue_script(
+ 'ppcp-fraudnet',
+ trailingslashit( $gateway_module_url ) . 'assets/js/fraudnet.js',
+ array(),
+ 1
+ );
+ }
+ }
+ );
}
/**
From 6c7eef4f58c47897b03f58d6f2e8689fd00518a0 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 9 Mar 2022 12:01:27 +0100
Subject: [PATCH 005/163] Display legal text under place order button
---
.../ppcp-wc-gateway/resources/js/fraudnet.js | 5 --
.../resources/js/pay-upon-invoice.js | 12 ++++
.../ppcp-wc-gateway/src/WCGatewayModule.php | 70 +++++++++++--------
modules/ppcp-wc-gateway/webpack.config.js | 2 +-
4 files changed, 53 insertions(+), 36 deletions(-)
delete mode 100644 modules/ppcp-wc-gateway/resources/js/fraudnet.js
create mode 100644 modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
diff --git a/modules/ppcp-wc-gateway/resources/js/fraudnet.js b/modules/ppcp-wc-gateway/resources/js/fraudnet.js
deleted file mode 100644
index a9b735fde..000000000
--- a/modules/ppcp-wc-gateway/resources/js/fraudnet.js
+++ /dev/null
@@ -1,5 +0,0 @@
-document.addEventListener('DOMContentLoaded', () => {
- const script = document.createElement('script');
- script.setAttribute('src', 'https://c.paypal.com/da/r/fb.js');
- document.body.append(script);
-});
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
new file mode 100644
index 000000000..d5671fab9
--- /dev/null
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -0,0 +1,12 @@
+document.addEventListener('DOMContentLoaded', () => {
+ const script = document.createElement('script');
+ script.setAttribute('src', 'https://c.paypal.com/da/r/fb.js');
+ document.body.append(script);
+
+ jQuery(document.body).on('updated_checkout payment_method_selected', () => {
+ jQuery('#ppcp-pui-legal-text').hide();
+ if(jQuery('input[name="payment_method"]:checked').val() === 'ppcp-pay-upon-invoice-gateway') {
+ jQuery('#ppcp-pui-legal-text').show();
+ }
+ });
+});
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 2285a6cc7..5fbaa30f6 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -182,6 +182,46 @@ class WCGatewayModule implements ModuleInterface {
}
}
);
+
+ if ( 'DE' === $c->get( 'api.shop.country' ) ) {
+ add_action(
+ 'wp_footer',
+ function () {
+ ?>
+
+ get( 'wcgateway.url' );
+ wp_enqueue_script(
+ 'ppcp-pay-upon-invoice',
+ trailingslashit( $gateway_module_url ) . 'assets/js/pay-upon-invoice.js',
+ array(),
+ 1
+ );
+ }
+ );
+
+ add_action(
+ 'woocommerce_review_order_after_submit',
+ function () {
+ // TODO show/hide via JS
+ ?>
+ By clicking on the button, you agree to the terms of payment and performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.
+ handler( (array) $methods );
}
);
-
- add_action(
- 'wp_footer',
- function () use ( $container ) {
- if ( 'DE' === $container->get( 'api.shop.country' ) ) { ?>
-
- get( 'api.shop.country' ) ) {
- $gateway_module_url = $container->get( 'wcgateway.url' );
- wp_enqueue_script(
- 'ppcp-fraudnet',
- trailingslashit( $gateway_module_url ) . 'assets/js/fraudnet.js',
- array(),
- 1
- );
- }
- }
- );
}
/**
diff --git a/modules/ppcp-wc-gateway/webpack.config.js b/modules/ppcp-wc-gateway/webpack.config.js
index fcc5648bb..5abb1f94a 100644
--- a/modules/ppcp-wc-gateway/webpack.config.js
+++ b/modules/ppcp-wc-gateway/webpack.config.js
@@ -7,7 +7,7 @@ module.exports = {
target: 'web',
entry: {
'gateway-settings': path.resolve('./resources/js/gateway-settings.js'),
- 'fraudnet': path.resolve('./resources/js/fraudnet.js'),
+ 'pay-upon-invoice': path.resolve('./resources/js/pay-upon-invoice.js'),
},
output: {
path: path.resolve(__dirname, 'assets/'),
From f8d25a9357458b655878951701d9587af734271d Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 9 Mar 2022 12:51:11 +0100
Subject: [PATCH 006/163] Display legal text from gateway settings
---
.../PayUponInvoice/PayUponInvoiceGateway.php | 5 ++
.../ppcp-wc-gateway/src/WCGatewayModule.php | 74 ++++++++++---------
2 files changed, 45 insertions(+), 34 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 864c83329..2504d8ff7 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -73,6 +73,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
'default' => 'yes'
),
+ 'legal_text' => array(
+ 'title' => __( 'Legal text', 'woocommerce-paypal-payments' ),
+ 'type' => 'textarea',
+ 'default' => 'By clicking on the button, you agree to the terms of payment and performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.',
+ ),
);
}
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 5fbaa30f6..280678937 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -183,45 +183,51 @@ class WCGatewayModule implements ModuleInterface {
}
);
- if ( 'DE' === $c->get( 'api.shop.country' ) ) {
- add_action(
- 'wp_footer',
- function () {
- ?>
-
+
- get( 'wcgateway.url' );
+ wp_enqueue_script(
+ 'ppcp-pay-upon-invoice',
+ trailingslashit( $gateway_module_url ) . 'assets/js/pay-upon-invoice.js',
+ array(),
+ 1
+ );
+ }
+ );
- add_action(
- 'wp_enqueue_scripts',
- function () use ( $c ) {
- $gateway_module_url = $c->get( 'wcgateway.url' );
- wp_enqueue_script(
- 'ppcp-pay-upon-invoice',
- trailingslashit( $gateway_module_url ) . 'assets/js/pay-upon-invoice.js',
- array(),
- 1
+ add_action(
+ 'woocommerce_review_order_after_submit',
+ function () {
+ $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
+ ?>
+
+
- By clicking on the button, you agree to the terms of payment and performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.
-
Date: Wed, 9 Mar 2022 16:23:03 +0100
Subject: [PATCH 007/163] Get fraudNet session id from WC session
---
.../resources/js/pay-upon-invoice.js | 4 --
modules/ppcp-wc-gateway/services.php | 20 ++++++
.../src/Gateway/PayUponInvoice/FraudNet.php | 38 +++++++++++
.../PayUponInvoice/FraudNetSessionId.php | 18 ++++++
.../Gateway/PayUponInvoice/OrderEndpoint.php | 15 ++++-
.../Gateway/PayUponInvoice/PayUponInvoice.php | 63 +++++++++++++++++++
.../ppcp-wc-gateway/src/WCGatewayModule.php | 43 +------------
7 files changed, 155 insertions(+), 46 deletions(-)
create mode 100644 modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php
create mode 100644 modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
create mode 100644 modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index d5671fab9..db862b962 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -1,8 +1,4 @@
document.addEventListener('DOMContentLoaded', () => {
- const script = document.createElement('script');
- script.setAttribute('src', 'https://c.paypal.com/da/r/fb.js');
- document.body.append(script);
-
jQuery(document.body).on('updated_checkout payment_method_selected', () => {
jQuery('#ppcp-pui-legal-text').hide();
if(jQuery('input[name="payment_method"]:checked').val() === 'ppcp-pay-upon-invoice-gateway') {
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index ca52026d1..9d635fab8 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -29,7 +29,10 @@ use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
use WooCommerce\PayPalCommerce\WcGateway\FundingSource\FundingSourceRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSessionId;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\OrderEndpoint;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
@@ -2125,6 +2128,7 @@ return array(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'api.factory.order' ),
+ $container->get('wcgateway.pay-upon-invoice-fraudnet'),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
@@ -2135,4 +2139,20 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' )
);
},
+ 'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function (ContainerInterface $container): FraudNetSessionId {
+ return new FraudNetSessionId();
+ },
+ 'wcgateway.pay-upon-invoice-fraudnet' => static function (ContainerInterface $container): FraudNet {
+ $session_id = $container->get('wcgateway.pay-upon-invoice-fraudnet-session-id');
+ return new FraudNet(
+ (string)$session_id(),
+ 'bar'
+ );
+ },
+ 'wcgateway.pay-upon-invoice' => static function (ContainerInterface $container): PayUponInvoice {
+ return new PayUponInvoice(
+ $container->get('wcgateway.url'),
+ $container->get('wcgateway.pay-upon-invoice-fraudnet')
+ );
+ }
);
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php
new file mode 100644
index 000000000..b6ddf43a1
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php
@@ -0,0 +1,38 @@
+session_id = $session_id;
+ $this->source_website_id = $source_website_id;
+ }
+
+ /**
+ * @return string
+ */
+ public function sessionId(): string
+ {
+ return $this->session_id;
+ }
+
+ /**
+ * @return string
+ */
+ public function sourceWebsiteId(): string
+ {
+ return $this->source_website_id;
+ }
+}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
new file mode 100644
index 000000000..7e138d13f
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
@@ -0,0 +1,18 @@
+session->get( 'ppcp_fraudnet_session_id' )) {
+ return WC()->session->get( 'ppcp_fraudnet_session_id' );
+ }
+
+ $session_id = bin2hex(random_bytes(16));
+ WC()->session->set( 'ppcp_fraudnet_session_id', $session_id);
+
+ return bin2hex($session_id);
+ }
+}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 090aa72d5..74877be59 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -36,12 +36,23 @@ class OrderEndpoint {
* @var LoggerInterface
*/
protected $logger;
+ /**
+ * @var FraudNet
+ */
+ protected $fraudNet;
- public function __construct( string $host, Bearer $bearer, OrderFactory $order_factory, LoggerInterface $logger ) {
+ public function __construct(
+ string $host,
+ Bearer $bearer,
+ OrderFactory $order_factory,
+ FraudNet $fraudNet,
+ LoggerInterface $logger
+ ) {
$this->host = $host;
$this->bearer = $bearer;
$this->order_factory = $order_factory;
$this->logger = $logger;
+ $this->fraudNet = $fraudNet;
}
/**
@@ -98,7 +109,7 @@ class OrderEndpoint {
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation',
- 'PayPal-Client-Metadata-Id' => 'd4e0d7b9-4f75-43f9-9437-d8a57c901585',
+ 'PayPal-Client-Metadata-Id' => $this->fraudNet->sessionId(),
'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
),
'body' => wp_json_encode( $data ),
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
new file mode 100644
index 000000000..1a27480e0
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -0,0 +1,63 @@
+module_url = $module_url;
+ $this->fraud_net = $fraud_net;
+ }
+
+ public function init() {
+ add_action(
+ 'wp_footer',
+ array( $this, 'add_parameter_block' )
+ );
+
+ add_action(
+ 'woocommerce_review_order_after_submit',
+ array( $this, 'add_legal_text' )
+ );
+
+ add_action(
+ 'wp_enqueue_scripts',
+ array( $this, 'register_assets' )
+ );
+ }
+
+ public function add_parameter_block() { ?>
+
+
+
+
+ module_url ) . 'assets/js/pay-upon-invoice.js',
+ array(),
+ 1
+ );
+ }
+}
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 280678937..460863398 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -185,46 +185,9 @@ class WCGatewayModule implements ModuleInterface {
add_action(
'init',
- function() use ( $c ) {
- if ( 'DE' === $c->get( 'api.shop.country' ) ) { // TODO && is_checkout() does not work, we are on admin-ajax.php
-
- add_action(
- 'wp_footer',
- function () {
- ?>
-
- get( 'wcgateway.url' );
- wp_enqueue_script(
- 'ppcp-pay-upon-invoice',
- trailingslashit( $gateway_module_url ) . 'assets/js/pay-upon-invoice.js',
- array(),
- 1
- );
- }
- );
-
- add_action(
- 'woocommerce_review_order_after_submit',
- function () {
- $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
- ?>
-
- get( 'api.shop.country' ) ) {
+ ($c->get('wcgateway.pay-upon-invoice'))->init();
}
}
);
From da3272e68762fcc1143b90945897cde2b9f87dcc Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 9 Mar 2022 17:22:17 +0100
Subject: [PATCH 008/163] Add pui payment source entity (WIP)
---
modules/ppcp-wc-gateway/services.php | 93 ++++++------
.../src/Gateway/PayUponInvoice/FraudNet.php | 15 +-
.../PayUponInvoice/FraudNetSessionId.php | 15 +-
.../Gateway/PayUponInvoice/OrderEndpoint.php | 40 ++----
.../PayUponInvoice/PayUponInvoiceGateway.php | 54 +++----
.../Gateway/PayUponInvoice/PaymentSource.php | 135 ++++++++++++++++++
.../PayUponInvoice/PaymentSourceFactory.php | 13 ++
.../ppcp-wc-gateway/src/WCGatewayModule.php | 4 +-
8 files changed, 250 insertions(+), 119 deletions(-)
create mode 100644 modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php
create mode 100644 modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 9d635fab8..816201e48 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -32,6 +32,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSessionId;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\OrderEndpoint;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSourceFactory;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
@@ -50,7 +51,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
use WooCommerce\PayPalCommerce\Webhooks\Status\WebhooksStatusPage;
return array(
- 'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway {
+ 'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway {
$order_processor = $container->get( 'wcgateway.order-processor' );
$settings_renderer = $container->get( 'wcgateway.settings.render' );
$funding_source_renderer = $container->get( 'wcgateway.funding-source.renderer' );
@@ -86,7 +87,7 @@ return array(
$order_endpoint
);
},
- 'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
+ 'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
$order_processor = $container->get( 'wcgateway.order-processor' );
$settings_renderer = $container->get( 'wcgateway.settings.render' );
$authorized_payments = $container->get( 'wcgateway.processor.authorized-payments' );
@@ -124,18 +125,18 @@ return array(
$payments_endpoint
);
},
- 'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways {
+ 'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways {
$session_handler = $container->get( 'session.handler' );
$settings = $container->get( 'wcgateway.settings' );
return new DisableGateways( $session_handler, $settings );
},
- 'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool {
+ 'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool {
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
$tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
return 'wc-settings' === $page && 'checkout' === $tab;
},
- 'wcgateway.is-ppcp-settings-page' => static function ( ContainerInterface $container ): bool {
+ 'wcgateway.is-ppcp-settings-page' => static function ( ContainerInterface $container ): bool {
if ( ! $container->get( 'wcgateway.is-wc-payments-page' ) ) {
return false;
}
@@ -144,7 +145,7 @@ return array(
return in_array( $section, array( PayPalGateway::ID, CreditCardGateway::ID, WebhooksStatusPage::ID ), true );
},
- 'wcgateway.current-ppcp-settings-page-id' => static function ( ContainerInterface $container ): string {
+ 'wcgateway.current-ppcp-settings-page-id' => static function ( ContainerInterface $container ): string {
if ( ! $container->get( 'wcgateway.is-ppcp-settings-page' ) ) {
return '';
}
@@ -155,33 +156,33 @@ return array(
return $ppcp_tab ? $ppcp_tab : $section;
},
- 'wcgateway.settings' => static function ( ContainerInterface $container ): Settings {
+ 'wcgateway.settings' => static function ( ContainerInterface $container ): Settings {
return new Settings();
},
- 'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice {
+ 'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice {
$state = $container->get( 'onboarding.state' );
$settings = $container->get( 'wcgateway.settings' );
return new ConnectAdminNotice( $state, $settings );
},
- 'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): DccWithoutPayPalAdminNotice {
+ 'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): DccWithoutPayPalAdminNotice {
$state = $container->get( 'onboarding.state' );
$settings = $container->get( 'wcgateway.settings' );
$is_payments_page = $container->get( 'wcgateway.is-wc-payments-page' );
$is_ppcp_settings_page = $container->get( 'wcgateway.is-ppcp-settings-page' );
return new DccWithoutPayPalAdminNotice( $state, $settings, $is_payments_page, $is_ppcp_settings_page );
},
- 'wcgateway.notice.authorize-order-action' =>
+ 'wcgateway.notice.authorize-order-action' =>
static function ( ContainerInterface $container ): AuthorizeOrderActionNotice {
return new AuthorizeOrderActionNotice();
},
- 'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
+ 'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
return new SectionsRenderer( $container->get( 'wcgateway.current-ppcp-settings-page-id' ) );
},
- 'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus {
+ 'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus {
$settings = $container->get( 'wcgateway.settings' );
return new SettingsStatus( $settings );
},
- 'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer {
+ 'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer {
$settings = $container->get( 'wcgateway.settings' );
$state = $container->get( 'onboarding.state' );
$fields = $container->get( 'wcgateway.settings.fields' );
@@ -201,7 +202,7 @@ return array(
$page_id
);
},
- 'wcgateway.settings.listener' => static function ( ContainerInterface $container ): SettingsListener {
+ 'wcgateway.settings.listener' => static function ( ContainerInterface $container ): SettingsListener {
$settings = $container->get( 'wcgateway.settings' );
$fields = $container->get( 'wcgateway.settings.fields' );
$webhook_registrar = $container->get( 'webhook.registrar' );
@@ -211,7 +212,7 @@ return array(
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state, $bearer, $page_id );
},
- 'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
+ 'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
$session_handler = $container->get( 'session.handler' );
$order_endpoint = $container->get( 'api.endpoint.order' );
@@ -232,36 +233,36 @@ return array(
$environment
);
},
- 'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
+ 'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
$order_endpoint = $container->get( 'api.endpoint.order' );
$payments_endpoint = $container->get( 'api.endpoint.payments' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new RefundProcessor( $order_endpoint, $payments_endpoint, $logger );
},
- 'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor {
+ 'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor {
$order_endpoint = $container->get( 'api.endpoint.order' );
$payments_endpoint = $container->get( 'api.endpoint.payments' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
$notice = $container->get( 'wcgateway.notice.authorize-order-action' );
return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint, $logger, $notice );
},
- 'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction {
+ 'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction {
$column = $container->get( 'wcgateway.admin.orders-payment-status-column' );
return new RenderAuthorizeAction( $column );
},
- 'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ): PaymentStatusOrderDetail {
+ 'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ): PaymentStatusOrderDetail {
$column = $container->get( 'wcgateway.admin.orders-payment-status-column' );
return new PaymentStatusOrderDetail( $column );
},
- 'wcgateway.admin.orders-payment-status-column' => static function ( ContainerInterface $container ): OrderTablePaymentStatusColumn {
+ 'wcgateway.admin.orders-payment-status-column' => static function ( ContainerInterface $container ): OrderTablePaymentStatusColumn {
$settings = $container->get( 'wcgateway.settings' );
return new OrderTablePaymentStatusColumn( $settings );
},
- 'wcgateway.admin.fees-renderer' => static function ( ContainerInterface $container ): FeesRenderer {
+ 'wcgateway.admin.fees-renderer' => static function ( ContainerInterface $container ): FeesRenderer {
return new FeesRenderer();
},
- 'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array {
+ 'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array {
$state = $container->get( 'onboarding.state' );
assert( $state instanceof State );
@@ -2058,28 +2059,28 @@ return array(
return $fields;
},
- 'wcgateway.checkout.address-preset' => static function( ContainerInterface $container ): CheckoutPayPalAddressPreset {
+ 'wcgateway.checkout.address-preset' => static function( ContainerInterface $container ): CheckoutPayPalAddressPreset {
return new CheckoutPayPalAddressPreset(
$container->get( 'session.handler' )
);
},
- 'wcgateway.url' => static function ( ContainerInterface $container ): string {
+ 'wcgateway.url' => static function ( ContainerInterface $container ): string {
return plugins_url(
$container->get( 'wcgateway.relative-path' ),
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
);
},
- 'wcgateway.relative-path' => static function( ContainerInterface $container ): string {
+ 'wcgateway.relative-path' => static function( ContainerInterface $container ): string {
return 'modules/ppcp-wc-gateway/';
},
- 'wcgateway.absolute-path' => static function( ContainerInterface $container ): string {
+ 'wcgateway.absolute-path' => static function( ContainerInterface $container ): string {
return plugin_dir_path(
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
) .
$container->get( 'wcgateway.relative-path' );
},
- 'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ) : ReturnUrlEndpoint {
+ 'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ) : ReturnUrlEndpoint {
$gateway = $container->get( 'wcgateway.paypal-gateway' );
$endpoint = $container->get( 'api.endpoint.order' );
$prefix = $container->get( 'api.prefix' );
@@ -2090,69 +2091,73 @@ return array(
);
},
- 'wcgateway.transaction-url-sandbox' => static function ( ContainerInterface $container ): string {
+ 'wcgateway.transaction-url-sandbox' => static function ( ContainerInterface $container ): string {
return 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s';
},
- 'wcgateway.transaction-url-live' => static function ( ContainerInterface $container ): string {
+ 'wcgateway.transaction-url-live' => static function ( ContainerInterface $container ): string {
return 'https://www.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s';
},
- 'wcgateway.transaction-url-provider' => static function ( ContainerInterface $container ): TransactionUrlProvider {
+ 'wcgateway.transaction-url-provider' => static function ( ContainerInterface $container ): TransactionUrlProvider {
$sandbox_url_base = $container->get( 'wcgateway.transaction-url-sandbox' );
$live_url_base = $container->get( 'wcgateway.transaction-url-live' );
return new TransactionUrlProvider( $sandbox_url_base, $live_url_base );
},
- 'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : DCCProductStatus {
+ 'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : DCCProductStatus {
$settings = $container->get( 'wcgateway.settings' );
$partner_endpoint = $container->get( 'api.endpoint.partners' );
return new DCCProductStatus( $settings, $partner_endpoint );
},
- 'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers {
+ 'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers {
return new MessagesDisclaimers(
$container->get( 'api.shop.country' )
);
},
- 'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer {
+ 'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer {
return new FundingSourceRenderer(
$container->get( 'wcgateway.settings' )
);
},
- 'wcgateway.pay-upon-invoice-order-endpoint' => static function (ContainerInterface $container): OrderEndpoint {
+ 'wcgateway.pay-upon-invoice-order-endpoint' => static function ( ContainerInterface $container ): OrderEndpoint {
return new OrderEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'api.factory.order' ),
- $container->get('wcgateway.pay-upon-invoice-fraudnet'),
+ $container->get( 'wcgateway.pay-upon-invoice-fraudnet' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
- 'wcgateway.pay-upon-invoice-gateway' => static function (ContainerInterface $container): PayUponInvoiceGateway {
+ 'wcgateway.pay-upon-invoice-payment-source-factory' => static function ( ContainerInterface $container ): PaymentSourceFactory {
+ return new PaymentSourceFactory();
+ },
+ 'wcgateway.pay-upon-invoice-gateway' => static function ( ContainerInterface $container ): PayUponInvoiceGateway {
return new PayUponInvoiceGateway(
$container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
$container->get( 'api.factory.purchase-unit' ),
+ $container->get( 'wcgateway.pay-upon-invoice-payment-source-factory' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
- 'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function (ContainerInterface $container): FraudNetSessionId {
+ 'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
return new FraudNetSessionId();
},
- 'wcgateway.pay-upon-invoice-fraudnet' => static function (ContainerInterface $container): FraudNet {
- $session_id = $container->get('wcgateway.pay-upon-invoice-fraudnet-session-id');
+ 'wcgateway.pay-upon-invoice-fraudnet' => static function ( ContainerInterface $container ): FraudNet {
+ $session_id = $container->get( 'wcgateway.pay-upon-invoice-fraudnet-session-id' );
return new FraudNet(
- (string)$session_id(),
+ (string) $session_id(),
'bar'
);
},
- 'wcgateway.pay-upon-invoice' => static function (ContainerInterface $container): PayUponInvoice {
+ 'wcgateway.pay-upon-invoice' => static function ( ContainerInterface $container ): PayUponInvoice {
return new PayUponInvoice(
- $container->get('wcgateway.url'),
- $container->get('wcgateway.pay-upon-invoice-fraudnet')
+ $container->get( 'wcgateway.url' ),
+ $container->get( 'wcgateway.pay-upon-invoice-fraudnet' )
);
- }
+ },
);
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php
index b6ddf43a1..5591ebf54 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php
@@ -2,8 +2,8 @@
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
-class FraudNet
-{
+class FraudNet {
+
/**
* @var string
*/
@@ -14,25 +14,22 @@ class FraudNet
*/
protected $source_website_id;
- public function __construct(string $session_id, string $source_website_id)
- {
- $this->session_id = $session_id;
+ public function __construct( string $session_id, string $source_website_id ) {
+ $this->session_id = $session_id;
$this->source_website_id = $source_website_id;
}
/**
* @return string
*/
- public function sessionId(): string
- {
+ public function sessionId(): string {
return $this->session_id;
}
/**
* @return string
*/
- public function sourceWebsiteId(): string
- {
+ public function sourceWebsiteId(): string {
return $this->source_website_id;
}
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
index 7e138d13f..9decb845f 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
@@ -2,17 +2,16 @@
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
-class FraudNetSessionId
-{
- public function __invoke()
- {
- if(WC()->session->get( 'ppcp_fraudnet_session_id' )) {
+class FraudNetSessionId {
+
+ public function __invoke() {
+ if ( WC()->session->get( 'ppcp_fraudnet_session_id' ) ) {
return WC()->session->get( 'ppcp_fraudnet_session_id' );
}
- $session_id = bin2hex(random_bytes(16));
- WC()->session->set( 'ppcp_fraudnet_session_id', $session_id);
+ $session_id = bin2hex( random_bytes( 16 ) );
+ WC()->session->set( 'ppcp_fraudnet_session_id', $session_id );
- return bin2hex($session_id);
+ return $session_id;
}
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 74877be59..338a67351 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -32,15 +32,16 @@ class OrderEndpoint {
*/
protected $order_factory;
- /**
- * @var LoggerInterface
- */
- protected $logger;
/**
* @var FraudNet
*/
protected $fraudNet;
+ /**
+ * @var LoggerInterface
+ */
+ protected $logger;
+
public function __construct(
string $host,
Bearer $bearer,
@@ -52,7 +53,7 @@ class OrderEndpoint {
$this->bearer = $bearer;
$this->order_factory = $order_factory;
$this->logger = $logger;
- $this->fraudNet = $fraudNet;
+ $this->fraudNet = $fraudNet;
}
/**
@@ -61,7 +62,7 @@ class OrderEndpoint {
* @param PurchaseUnit[] $items The purchase unit items for the order.
* @return Order
*/
- public function create( array $items ): Order {
+ public function create( array $items, PaymentSource $payment_source ): Order {
$data = array(
'intent' => 'CAPTURE',
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@@ -72,32 +73,7 @@ class OrderEndpoint {
$items
),
'payment_source' => array(
- 'pay_upon_invoice' => array(
- 'name' => array(
- 'given_name' => 'John',
- 'surname' => 'Doe',
- ),
- 'email' => 'buyer@example.com',
- 'birth_date' => '1990-01-01',
- 'phone' => array(
- 'national_number' => '6912345678',
- 'country_code' => '49',
- ),
- 'billing_address' => array(
- 'address_line_1' => 'Schönhauser Allee 84',
- 'admin_area_2' => 'Berlin',
- 'postal_code' => '10439',
- 'country_code' => 'DE',
- ),
- 'experience_context' => array(
- 'locale' => 'en-DE',
- 'brand_name' => 'EXAMPLE INC',
- 'logo_url' => 'https://example.com/logoUrl.svg',
- 'customer_service_instructions' => array(
- 'Customer service phone is +49 6912345678.',
- ),
- ),
- ),
+ 'pay_upon_invoice' => $payment_source->to_array(),
),
);
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 2504d8ff7..5037ddc9b 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -28,6 +28,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
*/
protected $purchase_unit_factory;
+ /**
+ * @var PaymentSourceFactory
+ */
+ protected $payment_source_factory;
+
/**
* @var LoggerInterface
*/
@@ -36,15 +41,15 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
public function __construct(
OrderEndpoint $order_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
+ PaymentSourceFactory $payment_source_factory,
LoggerInterface $logger
- )
- {
- $this->id = self::ID;
+ ) {
+ $this->id = self::ID;
- $this->method_title = __('Pay Upon Invoice', 'woocommerce-paypal-payments');
- $this->method_description = __('Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', 'woocommerce-paypal-payments');
- $this->title = $this->method_title;
- $this->description = $this->method_description;
+ $this->method_title = __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' );
+ $this->method_description = __( 'Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', 'woocommerce-paypal-payments' );
+ $this->title = $this->method_title;
+ $this->description = $this->method_description;
$this->init_form_fields();
$this->init_settings();
@@ -57,9 +62,10 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
)
);
- $this->order_endpoint = $order_endpoint;
- $this->purchase_unit_factory = $purchase_unit_factory;
- $this->logger = $logger;
+ $this->order_endpoint = $order_endpoint;
+ $this->purchase_unit_factory = $purchase_unit_factory;
+ $this->payment_source_factory = $payment_source_factory;
+ $this->logger = $logger;
}
/**
@@ -67,33 +73,33 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
*/
public function init_form_fields() {
$this->form_fields = array(
- 'enabled' => array(
- 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
- 'type' => 'checkbox',
- 'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
- 'default' => 'yes'
+ 'enabled' => array(
+ 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
+ 'type' => 'checkbox',
+ 'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
+ 'default' => 'yes',
),
'legal_text' => array(
- 'title' => __( 'Legal text', 'woocommerce-paypal-payments' ),
- 'type' => 'textarea',
+ 'title' => __( 'Legal text', 'woocommerce-paypal-payments' ),
+ 'type' => 'textarea',
'default' => 'By clicking on the button, you agree to the terms of payment and performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.',
),
);
}
- public function process_payment($order_id)
- {
+ public function process_payment( $order_id ) {
$wc_order = wc_get_order( $order_id );
- $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 );
+ $purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
+ $payment_source = $this->payment_source_factory->from_wc_order( $wc_order );
try {
- $this->order_endpoint->create(array( $purchase_unit ));
- } catch (RuntimeException $exception) {
+ $this->order_endpoint->create( array( $purchase_unit ), $payment_source );
+ } catch ( RuntimeException $exception ) {
$error = $exception->getMessage();
- $this->logger->error($error);
+ $this->logger->error( $error );
wc_add_notice( $error, 'error' );
$wc_order->update_status(
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php
new file mode 100644
index 000000000..8b7cf5aeb
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php
@@ -0,0 +1,135 @@
+given_name = $given_name;
+ $this->surname = $surname;
+ $this->email = $email;
+ $this->birth_date = $birth_date;
+ $this->national_number = $national_number;
+ $this->phone_country_code = $phone_country_code;
+ $this->address_line_1 = $address_line_1;
+ $this->admin_area_2 = $admin_area_2;
+ $this->postal_code = $postal_code;
+ $this->country_code = $country_code;
+ $this->locale = $locale;
+ $this->brand_name = $brand_name;
+ $this->logo_url = $logo_url;
+ $this->customer_service_instructions = $customer_service_instructions;
+ }
+
+ public function to_array(): array {
+ return array(
+ 'name' => array(
+ 'given_name' => $this->given_name,
+ 'surname' => $this->surname,
+ ),
+ 'email' => $this->email,
+ 'birth_date' => $this->birth_date,
+ 'phone' => array(
+ 'national_number' => $this->national_number,
+ 'country_code' => $this->phone_country_code,
+ ),
+ 'billing_address' => array(
+ 'address_line_1' => $this->address_line_1,
+ 'admin_area_2' => $this->admin_area_2,
+ 'postal_code' => $this->postal_code,
+ 'country_code' => $this->country_code,
+ ),
+ 'experience_context' => array(
+ 'locale' => $this->locale,
+ 'brand_name' => $this->brand_name,
+ 'logo_url' => $this->logo_url,
+ 'customer_service_instructions' => $this->customer_service_instructions,
+ ),
+ );
+ }
+}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
new file mode 100644
index 000000000..e9b05a8e6
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -0,0 +1,13 @@
+get( 'api.shop.country' ) ) {
- ($c->get('wcgateway.pay-upon-invoice'))->init();
+ ( $c->get( 'wcgateway.pay-upon-invoice' ) )->init();
}
}
);
From 19e4a6444554abd6f44ed60a9864c8b764e9436d Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 10 Mar 2022 14:41:07 +0100
Subject: [PATCH 009/163] Add birth date field to checkout form
---
.../PayUponInvoice/FraudNetSessionId.php | 4 +
.../Gateway/PayUponInvoice/PayUponInvoice.php | 12 ++
.../Gateway/PayUponInvoice/PaymentSource.php | 140 ++++++++++++++++--
.../PayUponInvoice/PaymentSourceFactory.php | 20 ++-
4 files changed, 161 insertions(+), 15 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
index 9decb845f..701ad3292 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
@@ -5,6 +5,10 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
class FraudNetSessionId {
public function __invoke() {
+ if(WC()->session === null) {
+ return '';
+ }
+
if ( WC()->session->get( 'ppcp_fraudnet_session_id' ) ) {
return WC()->session->get( 'ppcp_fraudnet_session_id' );
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 1a27480e0..d2d76241a 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -36,6 +36,18 @@ class PayUponInvoice {
'wp_enqueue_scripts',
array( $this, 'register_assets' )
);
+
+ add_filter( 'woocommerce_billing_fields', function($billing_fields) {
+ $billing_fields['billing_birth_date'] = array(
+ 'type' => 'date',
+ 'label' => __('Birth date', 'woocommerce-paypal-payments'),
+ 'class' => array('form-row-wide'),
+ 'required' => true,
+ 'clear' => true,
+ );
+
+ return $billing_fields;
+ });
}
public function add_parameter_block() { ?>
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php
index 8b7cf5aeb..bfd51ed44 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php
@@ -106,29 +106,141 @@ class PaymentSource {
$this->customer_service_instructions = $customer_service_instructions;
}
+ /**
+ * @return string
+ */
+ public function given_name(): string
+ {
+ return $this->given_name;
+ }
+
+ /**
+ * @return string
+ */
+ public function surname(): string
+ {
+ return $this->surname;
+ }
+
+ /**
+ * @return string
+ */
+ public function email(): string
+ {
+ return $this->email;
+ }
+
+ /**
+ * @return string
+ */
+ public function birth_date(): string
+ {
+ return $this->birth_date;
+ }
+
+ /**
+ * @return string
+ */
+ public function national_number(): string
+ {
+ return $this->national_number;
+ }
+
+ /**
+ * @return string
+ */
+ public function phone_country_code(): string
+ {
+ return $this->phone_country_code;
+ }
+
+ /**
+ * @return string
+ */
+ public function address_line_1(): string
+ {
+ return $this->address_line_1;
+ }
+
+ /**
+ * @return string
+ */
+ public function admin_area_2(): string
+ {
+ return $this->admin_area_2;
+ }
+
+ /**
+ * @return string
+ */
+ public function postal_code(): string
+ {
+ return $this->postal_code;
+ }
+
+ /**
+ * @return string
+ */
+ public function country_code(): string
+ {
+ return $this->country_code;
+ }
+
+ /**
+ * @return string
+ */
+ public function locale(): string
+ {
+ return $this->locale;
+ }
+
+ /**
+ * @return string
+ */
+ public function brand_name(): string
+ {
+ return $this->brand_name;
+ }
+
+ /**
+ * @return string
+ */
+ public function logo_url(): string
+ {
+ return $this->logo_url;
+ }
+
+ /**
+ * @return array
+ */
+ public function customer_service_instructions(): array
+ {
+ return $this->customer_service_instructions;
+ }
+
public function to_array(): array {
return array(
'name' => array(
- 'given_name' => $this->given_name,
- 'surname' => $this->surname,
+ 'given_name' => $this->given_name(),
+ 'surname' => $this->surname(),
),
- 'email' => $this->email,
- 'birth_date' => $this->birth_date,
+ 'email' => $this->email(),
+ 'birth_date' => $this->birth_date(),
'phone' => array(
- 'national_number' => $this->national_number,
- 'country_code' => $this->phone_country_code,
+ 'national_number' => $this->national_number(),
+ 'country_code' => $this->phone_country_code(),
),
'billing_address' => array(
- 'address_line_1' => $this->address_line_1,
- 'admin_area_2' => $this->admin_area_2,
- 'postal_code' => $this->postal_code,
- 'country_code' => $this->country_code,
+ 'address_line_1' => $this->address_line_1(),
+ 'admin_area_2' => $this->admin_area_2(),
+ 'postal_code' => $this->postal_code(),
+ 'country_code' => $this->country_code(),
),
'experience_context' => array(
- 'locale' => $this->locale,
- 'brand_name' => $this->brand_name,
- 'logo_url' => $this->logo_url,
- 'customer_service_instructions' => $this->customer_service_instructions,
+ 'locale' => $this->locale(),
+ 'brand_name' => $this->brand_name(),
+ 'logo_url' => $this->logo_url(),
+ 'customer_service_instructions' => $this->customer_service_instructions(),
),
);
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
index e9b05a8e6..81c005bd7 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -8,6 +8,24 @@ class PaymentSourceFactory {
public function from_wc_order( WC_Order $order ) {
- return new PaymentSource();
+ $address = $order->get_address();
+ $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
+
+ return new PaymentSource(
+ $address['first_name'] ?? '',
+ $address['last_name'] ?? '',
+ $address['email'] ?? '',
+ $birth_date,
+ $address['phone'] ?? '',
+ '49',
+ $address['address_1'] ?? '',
+ $address['city'] ?? '',
+ $address['postcode'] ?? '',
+ $address['country'] ?? '',
+ 'en-DE',
+ 'EXAMPLE INC',
+ 'https://example.com/logoUrl.svg',
+ array('Customer service phone is +49 6912345678.')
+ );
}
}
From 9dfa15acfc6965c7f96792a9ee70fb038739d3b7 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 11 Mar 2022 12:33:49 +0100
Subject: [PATCH 010/163] Add `PAY_UPON_INVOICE` into `capabiliies` (WIP)
---
.../src/Entity/OrderStatus.php | 8 +++----
.../src/Repository/PartnerReferralsData.php | 23 ++++++++++++++++++-
.../Gateway/PayUponInvoice/OrderEndpoint.php | 11 ++++++++-
.../PayUponInvoice/PayUponInvoiceGateway.php | 7 ++++++
.../PayUponInvoice/PaymentSourceFactory.php | 3 +--
5 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/modules/ppcp-api-client/src/Entity/OrderStatus.php b/modules/ppcp-api-client/src/Entity/OrderStatus.php
index e8e33cba8..397ae8b64 100644
--- a/modules/ppcp-api-client/src/Entity/OrderStatus.php
+++ b/modules/ppcp-api-client/src/Entity/OrderStatus.php
@@ -15,21 +15,21 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
* Class OrderStatus
*/
class OrderStatus {
-
-
const INTERNAL = 'INTERNAL';
const CREATED = 'CREATED';
const SAVED = 'SAVED';
const APPROVED = 'APPROVED';
const VOIDED = 'VOIDED';
const COMPLETED = 'COMPLETED';
- const VALID_STATI = array(
+ const PENDING_APPROVAL = 'PENDING_APPROVAL';
+ const VALID_STATUS = array(
self::INTERNAL,
self::CREATED,
self::SAVED,
self::APPROVED,
self::VOIDED,
self::COMPLETED,
+ self::PENDING_APPROVAL,
);
/**
@@ -46,7 +46,7 @@ class OrderStatus {
* @throws RuntimeException When the status is not valid.
*/
public function __construct( string $status ) {
- if ( ! in_array( $status, self::VALID_STATI, true ) ) {
+ if ( ! in_array( $status, self::VALID_STATUS, true ) ) {
throw new RuntimeException(
sprintf(
// translators: %s is the current status.
diff --git a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
index e2a13c949..307317711 100644
--- a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
+++ b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
@@ -91,7 +91,7 @@ class PartnerReferralsData {
),
'show_add_credit_card' => true,
),
- 'products' => $this->products,
+ //'products' => $this->products,
'legal_consents' => array(
array(
'type' => 'SHARE_DATA_CONSENT',
@@ -119,6 +119,27 @@ class PartnerReferralsData {
),
),
),
+ "products" => [
+ "PAYMENT_METHODS"
+ ],
+ "capabilities" => [
+ "PAY_UPON_INVOICE"
+ ],
+ "business_entity" => array(
+ "business_type" => array(
+ "type" => "INDIVIDUAL"
+ ),
+ "addresses" => array(
+ array(
+ "address_line_1" => "Parkstr. 26",
+ "admin_area_1" => "Berlin",
+ "postal_code" => "90409",
+ "country_code" => "DE",
+ "type" => "WORK",
+ ),
+ ),
+ ),
+ "tracking_id" => "testenterprices123122",
);
}
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 338a67351..2ad775049 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -77,6 +77,15 @@ class OrderEndpoint {
),
);
+ $data['purchase_units'][0]['items'][0]['tax_rate'] = '19.00';
+ $data['purchase_units'][0]['shipping']['name']['full_name'] = 'John Doe';
+ $data['purchase_units'][0]['shipping']['address'] = array(
+ 'address_line_1' => 'Taunusanlage 12',
+ 'admin_area_2' => 'FRANKFURT AM MAIN',
+ 'postal_code' => '60325',
+ 'country_code' => 'DE',
+ );
+
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v2/checkout/orders';
$args = array(
@@ -98,7 +107,7 @@ class OrderEndpoint {
$json = json_decode( $response['body'] );
$status_code = (int) wp_remote_retrieve_response_code( $response );
- if ( 201 !== $status_code ) {
+ if ( ! in_array($status_code, [200,201] ) ) {
throw new PayPalApiException( $json, $status_code );
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 5037ddc9b..5a6e147d0 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -96,6 +96,13 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
try {
$this->order_endpoint->create( array( $purchase_unit ), $payment_source );
+
+ WC()->cart->empty_cart();
+
+ return array(
+ 'result' => 'success',
+ 'redirect' => $this->get_return_url( $wc_order ),
+ );
} catch ( RuntimeException $exception ) {
$error = $exception->getMessage();
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
index 81c005bd7..378e1e618 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -7,7 +7,6 @@ use WC_Order;
class PaymentSourceFactory {
public function from_wc_order( WC_Order $order ) {
-
$address = $order->get_address();
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
@@ -15,7 +14,7 @@ class PaymentSourceFactory {
$address['first_name'] ?? '',
$address['last_name'] ?? '',
$address['email'] ?? '',
- $birth_date,
+ $birth_date ?? '',
$address['phone'] ?? '',
'49',
$address['address_1'] ?? '',
From 61973a62234daa02eafdbdbb0cf87a74d35fd40a Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 11 Mar 2022 15:21:48 +0100
Subject: [PATCH 011/163] Set pui partner referrals config through filter
---
.../src/Repository/PartnerReferralsData.php | 104 ++++++++----------
.../Gateway/PayUponInvoice/PayUponInvoice.php | 7 ++
2 files changed, 50 insertions(+), 61 deletions(-)
diff --git a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
index 307317711..d8ada8567 100644
--- a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
+++ b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
@@ -72,74 +72,56 @@ class PartnerReferralsData {
* @return array
*/
public function 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§ion=ppcp-gateway' )
+ return apply_filters(
+ 'ppcp_partner_referrals_data',
+ 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§ion=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,
),
- /**
- * 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' )
+ 'products' => $this->products,
+ 'legal_consents' => array(
+ array(
+ 'type' => 'SHARE_DATA_CONSENT',
+ 'granted' => true,
+ ),
),
- 'show_add_credit_card' => true,
- ),
- //'products' => $this->products,
- 'legal_consents' => array(
- array(
- 'type' => 'SHARE_DATA_CONSENT',
- 'granted' => true,
- ),
- ),
- 'operations' => array(
- array(
- 'operation' => 'API_INTEGRATION',
- 'api_integration_preference' => array(
- 'rest_api_integration' => array(
- 'integration_method' => 'PAYPAL',
- 'integration_type' => 'FIRST_PARTY',
- 'first_party_details' => array(
- 'features' => array(
- 'PAYMENT',
- 'FUTURE_PAYMENT',
- 'REFUND',
- 'ADVANCED_TRANSACTIONS_SEARCH',
- 'VAULT',
+ 'operations' => array(
+ array(
+ 'operation' => 'API_INTEGRATION',
+ 'api_integration_preference' => array(
+ 'rest_api_integration' => array(
+ 'integration_method' => 'PAYPAL',
+ 'integration_type' => 'FIRST_PARTY',
+ 'first_party_details' => array(
+ 'features' => array(
+ 'PAYMENT',
+ 'FUTURE_PAYMENT',
+ 'REFUND',
+ 'ADVANCED_TRANSACTIONS_SEARCH',
+ 'VAULT',
+ ),
+ 'seller_nonce' => $this->nonce(),
),
- 'seller_nonce' => $this->nonce(),
),
),
),
),
- ),
- "products" => [
- "PAYMENT_METHODS"
- ],
- "capabilities" => [
- "PAY_UPON_INVOICE"
- ],
- "business_entity" => array(
- "business_type" => array(
- "type" => "INDIVIDUAL"
- ),
- "addresses" => array(
- array(
- "address_line_1" => "Parkstr. 26",
- "admin_area_1" => "Berlin",
- "postal_code" => "90409",
- "country_code" => "DE",
- "type" => "WORK",
- ),
- ),
- ),
- "tracking_id" => "testenterprices123122",
+ )
);
}
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index d2d76241a..edcd98fcb 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -22,6 +22,13 @@ class PayUponInvoice {
}
public function init() {
+ add_filter('ppcp_partner_referrals_data', function ($data) {
+ $data['products'][] = 'PAYMENT_METHODS';
+ $data['capabilities'][] = 'PAY_UPON_INVOICE';
+
+ return $data;
+ });
+
add_action(
'wp_footer',
array( $this, 'add_parameter_block' )
From f166c1fff2353624757f3deecfe847d6165d73e9 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 11 Mar 2022 15:36:25 +0100
Subject: [PATCH 012/163] Add fraudnet source website id value
---
modules/ppcp-wc-gateway/services.php | 7 ++++++-
.../FraudNetSourceWebsiteId.php | 21 +++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
create mode 100644 modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSourceWebsiteId.php
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 816201e48..ee2955df0 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -31,6 +31,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSessionId;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSourceWebsiteId;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\OrderEndpoint;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSourceFactory;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
@@ -2147,11 +2148,15 @@ return array(
'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
return new FraudNetSessionId();
},
+ 'wcgateway.pay-upon-invoice-fraudnet-source-website-id' => static function ( ContainerInterface $container ): FraudNetSourceWebsiteId {
+ return new FraudNetSourceWebsiteId($container->get('api.merchant_id'));
+ },
'wcgateway.pay-upon-invoice-fraudnet' => static function ( ContainerInterface $container ): FraudNet {
$session_id = $container->get( 'wcgateway.pay-upon-invoice-fraudnet-session-id' );
+ $source_website_id = $container->get( 'wcgateway.pay-upon-invoice-fraudnet-source-website-id' );
return new FraudNet(
(string) $session_id(),
- 'bar'
+ (string) $source_website_id()
);
},
'wcgateway.pay-upon-invoice' => static function ( ContainerInterface $container ): PayUponInvoice {
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSourceWebsiteId.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSourceWebsiteId.php
new file mode 100644
index 000000000..8d0570cbc
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSourceWebsiteId.php
@@ -0,0 +1,21 @@
+api_merchant_id = $api_merchant_id;
+ }
+
+ public function __invoke()
+ {
+ return "{$this->api_merchant_id}_checkout-page";
+ }
+}
From 9b881e7189d9ba028ad7e901aac6c282a3f796cd Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 14 Mar 2022 11:42:51 +0100
Subject: [PATCH 013/163] Add german button legal text
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 4 ++--
.../Gateway/PayUponInvoice/PayUponInvoiceGateway.php | 11 ++++++++---
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index edcd98fcb..839489375 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -58,7 +58,7 @@ class PayUponInvoice {
}
public function add_parameter_block() { ?>
-
+
+ style="display:none;">
__( 'Enable/Disable', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
- 'default' => 'yes',
+ 'default' => 'no',
),
- 'legal_text' => array(
- 'title' => __( 'Legal text', 'woocommerce-paypal-payments' ),
+ 'button_legal_text_en' => array(
+ 'title' => __( 'Button legal text (English)', 'woocommerce-paypal-payments' ),
'type' => 'textarea',
'default' => 'By clicking on the button, you agree to the terms of payment and performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.',
),
+ 'button_legal_text_de' => array(
+ 'title' => __( 'Button legal text (German)', 'woocommerce-paypal-payments' ),
+ 'type' => 'textarea',
+ 'default' => 'Mit Klicken auf den Button akzeptieren Sie die Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.',
+ ),
);
}
From 9dc5aa43e6ec30e5acfcadae61169194c6352dcf Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 14 Mar 2022 12:24:35 +0100
Subject: [PATCH 014/163] Add error details on create order
---
.../Gateway/PayUponInvoice/PayUponInvoiceGateway.php | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index cc3e4b25c..160d3e3d9 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -111,6 +111,18 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
} catch ( RuntimeException $exception ) {
$error = $exception->getMessage();
+ if(is_array($exception->details())) {
+ $details = '';
+ foreach ($exception->details() as $detail) {
+ $issue = $detail->issue ?? '';
+ $field = $detail->field ?? '';
+ $description = $detail->description ?? '';
+ $details .= $issue . ' ' . $field . ' ' . $description . ' ';
+ }
+
+ $error = $details;
+ }
+
$this->logger->error( $error );
wc_add_notice( $error, 'error' );
From 28edfcbebc082a05b870a655238a877f6acb82d4 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 16 Mar 2022 16:29:22 +0100
Subject: [PATCH 015/163] Get tax rate from item
---
modules/ppcp-api-client/src/Entity/Item.php | 30 ++++++++++++++++---
.../src/Factory/ItemFactory.php | 9 ++++--
.../Gateway/PayUponInvoice/OrderEndpoint.php | 1 -
3 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/modules/ppcp-api-client/src/Entity/Item.php b/modules/ppcp-api-client/src/Entity/Item.php
index 218bf3fa3..dd661301e 100644
--- a/modules/ppcp-api-client/src/Entity/Item.php
+++ b/modules/ppcp-api-client/src/Entity/Item.php
@@ -14,7 +14,6 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
*/
class Item {
-
const PHYSICAL_GOODS = 'PHYSICAL_GOODS';
const DIGITAL_GOODS = 'DIGITAL_GOODS';
@@ -67,6 +66,13 @@ class Item {
*/
private $category;
+ /**
+ * The tax rate.
+ *
+ * @var float|int
+ */
+ protected $tax_rate;
+
/**
* Item constructor.
*
@@ -85,7 +91,8 @@ class Item {
string $description = '',
Money $tax = null,
string $sku = '',
- string $category = 'PHYSICAL_GOODS'
+ string $category = 'PHYSICAL_GOODS',
+ float $tax_rate = 0
) {
$this->name = $name;
@@ -94,8 +101,9 @@ class Item {
$this->description = $description;
$this->tax = $tax;
$this->sku = $sku;
- $this->category = ( self::DIGITAL_GOODS === $category ) ?
- self::DIGITAL_GOODS : self::PHYSICAL_GOODS;
+ $this->category = ( self::DIGITAL_GOODS === $category ) ? self::DIGITAL_GOODS : self::PHYSICAL_GOODS;
+ $this->category = $category;
+ $this->tax_rate = $tax_rate;
}
/**
@@ -161,6 +169,16 @@ class Item {
return $this->category;
}
+ /**
+ * Returns the tax rate.
+ *
+ * @return float
+ */
+ public function tax_rate():float
+ {
+ return round((float) $this->tax_rate, 2);
+ }
+
/**
* Returns the object as array.
*
@@ -180,6 +198,10 @@ class Item {
$item['tax'] = $this->tax()->to_array();
}
+ if ($this->tax_rate()) {
+ $item['tax_rate'] = (string) $this->tax_rate();
+ }
+
return $item;
}
}
diff --git a/modules/ppcp-api-client/src/Factory/ItemFactory.php b/modules/ppcp-api-client/src/Factory/ItemFactory.php
index 10aa40ff8..a292d90bd 100644
--- a/modules/ppcp-api-client/src/Factory/ItemFactory.php
+++ b/modules/ppcp-api-client/src/Factory/ItemFactory.php
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
+use WC_Tax;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
@@ -57,6 +58,7 @@ class ItemFactory {
$price_without_tax_rounded = round( $price_without_tax, 2 );
$tax = round( $price - $price_without_tax_rounded, 2 );
$tax = new Money( $tax, $this->currency );
+ $tax_rates = WC_Tax::get_rates($product->get_tax_class());
return new Item(
mb_substr( $product->get_name(), 0, 127 ),
new Money( $price_without_tax_rounded, $this->currency ),
@@ -64,7 +66,8 @@ class ItemFactory {
mb_substr( wp_strip_all_tags( $product->get_description() ), 0, 127 ),
$tax,
$product->get_sku(),
- ( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
+ ( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
+ reset($tax_rates)['rate'] ?? 0
);
},
$cart->get_cart_contents()
@@ -138,6 +141,7 @@ class ItemFactory {
$price_without_tax_rounded = round( $price_without_tax, 2 );
$tax = round( $price - $price_without_tax_rounded, 2 );
$tax = new Money( $tax, $currency );
+ $tax_rates = WC_Tax::get_rates($product->get_tax_class());
return new Item(
mb_substr( $product->get_name(), 0, 127 ),
new Money( $price_without_tax_rounded, $currency ),
@@ -145,7 +149,8 @@ class ItemFactory {
mb_substr( wp_strip_all_tags( $product->get_description() ), 0, 127 ),
$tax,
$product->get_sku(),
- ( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
+ ( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
+ reset($tax_rates)['rate'] ?? 0
);
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 2ad775049..1349d9f45 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -77,7 +77,6 @@ class OrderEndpoint {
),
);
- $data['purchase_units'][0]['items'][0]['tax_rate'] = '19.00';
$data['purchase_units'][0]['shipping']['name']['full_name'] = 'John Doe';
$data['purchase_units'][0]['shipping']['address'] = array(
'address_line_1' => 'Taunusanlage 12',
From 07ec6ab542d71c6898d6b386e295241b6f410653 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 18 Mar 2022 12:44:09 +0100
Subject: [PATCH 016/163] Add PayPal order id to wc order and disable email
on-hold notification for pui payment
---
modules/ppcp-wc-gateway/services.php | 1 +
.../Gateway/PayUponInvoice/PayUponInvoice.php | 8 ++++++++
.../PayUponInvoice/PayUponInvoiceGateway.php | 16 ++++++++++++++--
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index ee2955df0..c7c421ab7 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2142,6 +2142,7 @@ return array(
$container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.pay-upon-invoice-payment-source-factory' ),
+ $container->get( 'onboarding.environment' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 839489375..fe7559f0d 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -55,6 +55,14 @@ class PayUponInvoice {
return $billing_fields;
});
+
+ add_filter( 'woocommerce_email_recipient_customer_on_hold_order', function( $recipient, $order, $email) {
+ if($order->get_payment_method() === PayUponInvoiceGateway::ID) {
+ return '';
+ }
+
+ return $recipient;
+ }, 10, 3 );
}
public function add_parameter_block() { ?>
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 160d3e3d9..09b71ebdf 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -13,9 +13,13 @@ use Psr\Log\LoggerInterface;
use RuntimeException;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
+use WooCommerce\PayPalCommerce\Onboarding\Environment;
+use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait;
class PayUponInvoiceGateway extends WC_Payment_Gateway {
+ use OrderMetaTrait;
+
const ID = 'ppcp-pay-upon-invoice-gateway';
/**
@@ -33,6 +37,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
*/
protected $payment_source_factory;
+ /**
+ * @var Environment
+ */
+ protected $environment;
+
/**
* @var LoggerInterface
*/
@@ -42,6 +51,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
OrderEndpoint $order_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
PaymentSourceFactory $payment_source_factory,
+ Environment $environment,
LoggerInterface $logger
) {
$this->id = self::ID;
@@ -66,6 +76,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$this->purchase_unit_factory = $purchase_unit_factory;
$this->payment_source_factory = $payment_source_factory;
$this->logger = $logger;
+ $this->environment = $environment;
}
/**
@@ -94,13 +105,14 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
public function process_payment( $order_id ) {
$wc_order = wc_get_order( $order_id );
- $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 );
try {
- $this->order_endpoint->create( array( $purchase_unit ), $payment_source );
+ $order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source );
+ $this->add_paypal_meta( $wc_order, $order, $this->environment );
WC()->cart->empty_cart();
From e53384f460a63a08a54d9b2ce5c64b16561f3b17 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 18 Mar 2022 17:10:56 +0100
Subject: [PATCH 017/163] Remove hardcoded shipping address for testing
---
.../src/Gateway/PayUponInvoice/OrderEndpoint.php | 8 --------
1 file changed, 8 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 1349d9f45..aef5df4a2 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -77,14 +77,6 @@ class OrderEndpoint {
),
);
- $data['purchase_units'][0]['shipping']['name']['full_name'] = 'John Doe';
- $data['purchase_units'][0]['shipping']['address'] = array(
- 'address_line_1' => 'Taunusanlage 12',
- 'admin_area_2' => 'FRANKFURT AM MAIN',
- 'postal_code' => '60325',
- 'country_code' => 'DE',
- );
-
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v2/checkout/orders';
$args = array(
From 8eb320c5995644e45dfa01f41bfd608da35b16e8 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Sun, 20 Mar 2022 14:15:56 +0100
Subject: [PATCH 018/163] Get Ratepay payment instructions from order
---
modules/ppcp-wc-gateway/services.php | 4 ++-
.../Gateway/PayUponInvoice/OrderEndpoint.php | 28 +++++++++++++++++++
.../Gateway/PayUponInvoice/PayUponInvoice.php | 26 ++++++++++++++++-
.../src/Handler/PaymentCaptureCompleted.php | 3 ++
4 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index c7c421ab7..8f6e097fb 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2163,7 +2163,9 @@ return array(
'wcgateway.pay-upon-invoice' => static function ( ContainerInterface $container ): PayUponInvoice {
return new PayUponInvoice(
$container->get( 'wcgateway.url' ),
- $container->get( 'wcgateway.pay-upon-invoice-fraudnet' )
+ $container->get( 'wcgateway.pay-upon-invoice-fraudnet' ),
+ $container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
+ $container->get( 'woocommerce.logger.woocommerce' )
);
},
);
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index aef5df4a2..9e5122834 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -104,4 +104,32 @@ class OrderEndpoint {
return $this->order_factory->from_paypal_response( $json );
}
+
+ public function order_payment_instructions(string $id) {
+ $bearer = $this->bearer->bearer();
+ $url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $id;
+ $args = array(
+ 'headers' => array(
+ 'Authorization' => 'Bearer ' . $bearer->token(),
+ 'Content-Type' => 'application/json',
+ 'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
+ ),
+ );
+
+ $response = $this->request( $url, $args );
+
+ if ( is_wp_error( $response ) ) {
+ throw new RuntimeException( $response->get_error_message() );
+ }
+
+ $json = json_decode( $response['body'] );
+ $status_code = (int) wp_remote_retrieve_response_code( $response );
+ if ( 200 !== $status_code ) {
+ throw new PayPalApiException( $json, $status_code );
+ }
+
+ $this->logger->info('Payment instructions');
+ $this->logger->info($json->payment_source->pay_upon_invoice->payment_reference);
+ $this->logger->info(wc_print_r($json->payment_source->pay_upon_invoice->deposit_bank_details, true));
+ }
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index fe7559f0d..f933a0220 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -4,6 +4,9 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
+use Psr\Log\LoggerInterface;
+use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
+
class PayUponInvoice {
/**
@@ -16,9 +19,26 @@ class PayUponInvoice {
*/
protected $fraud_net;
- public function __construct( string $module_url, FraudNet $fraud_net ) {
+ /**
+ * @var OrderEndpoint
+ */
+ protected $order_endpoint;
+
+ /**
+ * @var LoggerInterface
+ */
+ protected $logger;
+
+ public function __construct(
+ string $module_url,
+ FraudNet $fraud_net,
+ OrderEndpoint $order_endpoint,
+ LoggerInterface $logger
+ ) {
$this->module_url = $module_url;
$this->fraud_net = $fraud_net;
+ $this->order_endpoint = $order_endpoint;
+ $this->logger = $logger;
}
public function init() {
@@ -63,6 +83,10 @@ class PayUponInvoice {
return $recipient;
}, 10, 3 );
+
+ add_action('ppcp_payment_capture_completed_webhook_handler', function (string $order_id) {
+ $this->order_endpoint->order_payment_instructions($order_id);
+ });
}
public function add_parameter_block() { ?>
diff --git a/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php b/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php
index 325541671..252e0d051 100644
--- a/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php
+++ b/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php
@@ -149,6 +149,9 @@ class PaymentCaptureCompleted implements RequestHandler {
if ( $transaction_id ) {
$this->update_transaction_id( $transaction_id, $wc_order, $this->logger );
}
+
+ do_action('ppcp_payment_capture_completed_webhook_handler', (string) $order_id);
+
} catch ( Exception $exception ) {
$this->logger->warning( 'Failed to get transaction ID: ' . $exception->getMessage() );
}
From 21522fb8c1c95c8663230952cc62d069b9dd0866 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 22 Mar 2022 09:19:07 +0100
Subject: [PATCH 019/163] Move capture action hook up before wc order status
update
---
.../src/Gateway/PayUponInvoice/OrderEndpoint.php | 8 ++++++--
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 15 ++++++++++++---
.../src/Handler/PaymentCaptureCompleted.php | 8 ++++----
3 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 9e5122834..3bc6a39de 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -105,7 +105,7 @@ class OrderEndpoint {
return $this->order_factory->from_paypal_response( $json );
}
- public function order_payment_instructions(string $id) {
+ public function order_payment_instructions(string $id): array {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $id;
$args = array(
@@ -117,7 +117,6 @@ class OrderEndpoint {
);
$response = $this->request( $url, $args );
-
if ( is_wp_error( $response ) ) {
throw new RuntimeException( $response->get_error_message() );
}
@@ -131,5 +130,10 @@ class OrderEndpoint {
$this->logger->info('Payment instructions');
$this->logger->info($json->payment_source->pay_upon_invoice->payment_reference);
$this->logger->info(wc_print_r($json->payment_source->pay_upon_invoice->deposit_bank_details, true));
+
+ return array(
+ $json->payment_source->pay_upon_invoice->payment_reference,
+ $json->payment_source->pay_upon_invoice->deposit_bank_details
+ );
}
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index f933a0220..3eaccfb2d 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -5,7 +5,10 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
+use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
+use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
+use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
class PayUponInvoice {
@@ -84,9 +87,15 @@ class PayUponInvoice {
return $recipient;
}, 10, 3 );
- add_action('ppcp_payment_capture_completed_webhook_handler', function (string $order_id) {
- $this->order_endpoint->order_payment_instructions($order_id);
- });
+ add_action('ppcp_payment_capture_completed_webhook_handler', function (WC_Order $wc_order, string $order_id) {
+ try {
+ $payment_instructions = $this->order_endpoint->order_payment_instructions($order_id);
+ $wc_order->update_meta_data( 'ppcp_ratepay_payment_instructions_payment_reference', $payment_instructions );
+ $this->logger->info("Ratepay payment instructions added to order #{$wc_order->get_id()}.");
+ } catch (RuntimeException $exception) {
+ $this->logger->error($exception->getMessage());
+ }
+ }, 10, 2);
}
public function add_parameter_block() { ?>
diff --git a/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php b/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php
index 252e0d051..5ed5a41aa 100644
--- a/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php
+++ b/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php
@@ -112,6 +112,10 @@ class PaymentCaptureCompleted implements RequestHandler {
return new WP_REST_Response( $response );
}
+ $order_id = $resource['supplementary_data']['related_ids']['order_id'] ?? null;
+
+ do_action('ppcp_payment_capture_completed_webhook_handler', $wc_order, $order_id);
+
if ( $wc_order->get_status() !== 'on-hold' ) {
$response['success'] = true;
return new WP_REST_Response( $response );
@@ -139,8 +143,6 @@ class PaymentCaptureCompleted implements RequestHandler {
)
);
- $order_id = $resource['supplementary_data']['related_ids']['order_id'] ?? null;
-
if ( $order_id ) {
try {
$order = $this->order_endpoint->order( (string) $order_id );
@@ -150,8 +152,6 @@ class PaymentCaptureCompleted implements RequestHandler {
$this->update_transaction_id( $transaction_id, $wc_order, $this->logger );
}
- do_action('ppcp_payment_capture_completed_webhook_handler', (string) $order_id);
-
} catch ( Exception $exception ) {
$this->logger->warning( 'Failed to get transaction ID: ' . $exception->getMessage() );
}
From 2024f2c0ab472c072edd32299c9bf1fc2c5dc52e Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 24 Mar 2022 16:27:03 +0100
Subject: [PATCH 020/163] Add button legal text inside gateway box description
---
.../resources/js/pay-upon-invoice.js | 10 ++--------
.../Gateway/PayUponInvoice/PayUponInvoice.php | 20 +++++++------------
.../PayUponInvoice/PayUponInvoiceGateway.php | 14 ++-----------
3 files changed, 11 insertions(+), 33 deletions(-)
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index db862b962..139597f9c 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -1,8 +1,2 @@
-document.addEventListener('DOMContentLoaded', () => {
- jQuery(document.body).on('updated_checkout payment_method_selected', () => {
- jQuery('#ppcp-pui-legal-text').hide();
- if(jQuery('input[name="payment_method"]:checked').val() === 'ppcp-pay-upon-invoice-gateway') {
- jQuery('#ppcp-pui-legal-text').show();
- }
- });
-});
+
+
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 3eaccfb2d..28e9ccb34 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -57,11 +57,6 @@ class PayUponInvoice {
array( $this, 'add_parameter_block' )
);
- add_action(
- 'woocommerce_review_order_after_submit',
- array( $this, 'add_legal_text' )
- );
-
add_action(
'wp_enqueue_scripts',
array( $this, 'register_assets' )
@@ -96,6 +91,13 @@ class PayUponInvoice {
$this->logger->error($exception->getMessage());
}
}, 10, 2);
+
+ add_filter( 'woocommerce_gateway_description', function($description, $id) {
+ if(PayUponInvoiceGateway::ID === $id) {
+ $description .= __( 'By clicking on the button, you agree to the terms of payment and performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant. ', 'woocommerce-paypal-payments');
+ }
+ return $description;
+ }, 10, 2);
}
public function add_parameter_block() { ?>
@@ -104,14 +106,6 @@ class PayUponInvoice {
-
- id = self::ID;
$this->method_title = __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' );
- $this->method_description = __( 'Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', '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' );;
$this->title = $this->method_title;
- $this->description = $this->method_description;
+ $this->description = __( 'Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', 'woocommerce-paypal-payments' );;
$this->init_form_fields();
$this->init_settings();
@@ -90,16 +90,6 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
'default' => 'no',
),
- 'button_legal_text_en' => array(
- 'title' => __( 'Button legal text (English)', 'woocommerce-paypal-payments' ),
- 'type' => 'textarea',
- 'default' => 'By clicking on the button, you agree to the terms of payment and performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.',
- ),
- 'button_legal_text_de' => array(
- 'title' => __( 'Button legal text (German)', 'woocommerce-paypal-payments' ),
- 'type' => 'textarea',
- 'default' => 'Mit Klicken auf den Button akzeptieren Sie die Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.',
- ),
);
}
From 5089b6335fd8a78ac470aa9947c4cab4860eaff7 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 25 Mar 2022 10:14:54 +0100
Subject: [PATCH 021/163] Add custom checkout validation (WIP)
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 28e9ccb34..dbec919d0 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -98,6 +98,14 @@ class PayUponInvoice {
}
return $description;
}, 10, 2);
+
+ add_action('woocommerce_checkout_order_processed', function($order_id, $posted_data, $order) {
+ if($order->get_billing_country() !== 'DE') {
+ wp_send_json_error(array(
+ 'result' => 'failure',
+ ));
+ }
+ }, 10, 3);
}
public function add_parameter_block() { ?>
From b6c2396e329c12378ad5358295d8e88c2b8d509a Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 25 Mar 2022 14:28:27 +0100
Subject: [PATCH 022/163] Grab fraudnet session id from form hidden field (WIP)
---
.../resources/js/pay-upon-invoice.js | 15 +++++++++++++++
.../src/Gateway/PayUponInvoice/OrderEndpoint.php | 4 ++--
.../PayUponInvoice/PayUponInvoiceGateway.php | 4 +++-
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index 139597f9c..7d1ee70b9 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -1,2 +1,17 @@
+window.addEventListener('load', function() {
+ setTimeout(() => {
+ const fncls = document.querySelector("[fncls='fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99']");
+ const fncls_params = JSON.parse(fncls.textContent);
+ const fraudnetSessionId = document.createElement('input');
+ fraudnetSessionId.setAttribute('type', 'hidden');
+ fraudnetSessionId.setAttribute('name', 'fraudnet-session-id');
+ fraudnetSessionId.setAttribute('value', fncls_params.f);
+
+ const form = document.querySelector('form.checkout');
+ form.appendChild(fraudnetSessionId);
+
+ console.log(fncls_params.f)
+ }, 3000)
+})
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 3bc6a39de..42e1d1e2b 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -62,7 +62,7 @@ class OrderEndpoint {
* @param PurchaseUnit[] $items The purchase unit items for the order.
* @return Order
*/
- public function create( array $items, PaymentSource $payment_source ): Order {
+ public function create( array $items, PaymentSource $payment_source, $fraudnet_session_id = '' ): Order {
$data = array(
'intent' => 'CAPTURE',
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@@ -85,7 +85,7 @@ class OrderEndpoint {
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation',
- 'PayPal-Client-Metadata-Id' => $this->fraudNet->sessionId(),
+ 'PayPal-Client-Metadata-Id' => $fraudnet_session_id ?: $this->fraudNet->sessionId(),
'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
),
'body' => wp_json_encode( $data ),
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 9db4987f6..495dae912 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -101,7 +101,9 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$payment_source = $this->payment_source_factory->from_wc_order( $wc_order );
try {
- $order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source );
+ $fraudnet_session_id = filter_input(INPUT_POST, 'fraudnet-session-id', FILTER_SANITIZE_STRING) ?? '';
+
+ $order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source, $fraudnet_session_id );
$this->add_paypal_meta( $wc_order, $order, $this->environment );
WC()->cart->empty_cart();
From 077203dd8efc70e21af71169b182fd8f1c7aab7e Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 25 Mar 2022 16:37:58 +0100
Subject: [PATCH 023/163] Only add pui referrals data when ppcp in products
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 125 +++++++++++-------
1 file changed, 77 insertions(+), 48 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index dbec919d0..6099d1330 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -38,19 +38,23 @@ class PayUponInvoice {
OrderEndpoint $order_endpoint,
LoggerInterface $logger
) {
- $this->module_url = $module_url;
- $this->fraud_net = $fraud_net;
+ $this->module_url = $module_url;
+ $this->fraud_net = $fraud_net;
$this->order_endpoint = $order_endpoint;
- $this->logger = $logger;
+ $this->logger = $logger;
}
public function init() {
- add_filter('ppcp_partner_referrals_data', function ($data) {
- $data['products'][] = 'PAYMENT_METHODS';
- $data['capabilities'][] = 'PAY_UPON_INVOICE';
-
- return $data;
- });
+ add_filter(
+ 'ppcp_partner_referrals_data',
+ function ( $data ) {
+ if ( in_array( 'PPCP', $data['products'] ) ) {
+ $data['products'][] = 'PAYMENT_METHODS';
+ $data['capabilities'][] = 'PAY_UPON_INVOICE';
+ }
+ return $data;
+ }
+ );
add_action(
'wp_footer',
@@ -62,54 +66,79 @@ class PayUponInvoice {
array( $this, 'register_assets' )
);
- add_filter( 'woocommerce_billing_fields', function($billing_fields) {
- $billing_fields['billing_birth_date'] = array(
- 'type' => 'date',
- 'label' => __('Birth date', 'woocommerce-paypal-payments'),
- 'class' => array('form-row-wide'),
- 'required' => true,
- 'clear' => true,
- );
+ add_filter(
+ 'woocommerce_billing_fields',
+ function( $billing_fields ) {
+ $billing_fields['billing_birth_date'] = array(
+ 'type' => 'date',
+ 'label' => __( 'Birth date', 'woocommerce-paypal-payments' ),
+ 'class' => array( 'form-row-wide' ),
+ 'required' => true,
+ 'clear' => true,
+ );
- return $billing_fields;
- });
-
- add_filter( 'woocommerce_email_recipient_customer_on_hold_order', function( $recipient, $order, $email) {
- if($order->get_payment_method() === PayUponInvoiceGateway::ID) {
- return '';
+ return $billing_fields;
}
+ );
- return $recipient;
- }, 10, 3 );
+ add_filter(
+ 'woocommerce_email_recipient_customer_on_hold_order',
+ function( $recipient, $order, $email ) {
+ if ( $order->get_payment_method() === PayUponInvoiceGateway::ID ) {
+ return '';
+ }
- add_action('ppcp_payment_capture_completed_webhook_handler', function (WC_Order $wc_order, string $order_id) {
- try {
- $payment_instructions = $this->order_endpoint->order_payment_instructions($order_id);
- $wc_order->update_meta_data( 'ppcp_ratepay_payment_instructions_payment_reference', $payment_instructions );
- $this->logger->info("Ratepay payment instructions added to order #{$wc_order->get_id()}.");
- } catch (RuntimeException $exception) {
- $this->logger->error($exception->getMessage());
- }
- }, 10, 2);
+ return $recipient;
+ },
+ 10,
+ 3
+ );
- add_filter( 'woocommerce_gateway_description', function($description, $id) {
- if(PayUponInvoiceGateway::ID === $id) {
- $description .= __( 'By clicking on the button, you agree to the terms of payment and performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant. ', 'woocommerce-paypal-payments');
- }
- return $description;
- }, 10, 2);
+ add_action(
+ 'ppcp_payment_capture_completed_webhook_handler',
+ function ( WC_Order $wc_order, string $order_id ) {
+ try {
+ $payment_instructions = $this->order_endpoint->order_payment_instructions( $order_id );
+ $wc_order->update_meta_data( 'ppcp_ratepay_payment_instructions_payment_reference', $payment_instructions );
+ $this->logger->info( "Ratepay payment instructions added to order #{$wc_order->get_id()}." );
+ } catch ( RuntimeException $exception ) {
+ $this->logger->error( $exception->getMessage() );
+ }
+ },
+ 10,
+ 2
+ );
- add_action('woocommerce_checkout_order_processed', function($order_id, $posted_data, $order) {
- if($order->get_billing_country() !== 'DE') {
- wp_send_json_error(array(
- 'result' => 'failure',
- ));
- }
- }, 10, 3);
+ add_filter(
+ 'woocommerce_gateway_description',
+ function( $description, $id ) {
+ if ( PayUponInvoiceGateway::ID === $id ) {
+ $description .= __( 'By clicking on the button, you agree to the terms of payment and performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant. ', 'woocommerce-paypal-payments' );
+ }
+ return $description;
+ },
+ 10,
+ 2
+ );
+
+ add_action(
+ 'woocommerce_checkout_order_processed',
+ function( $order_id, $posted_data, $order ) {
+ if ( $order->get_billing_country() !== 'DE' ) {
+ wp_send_json_error(
+ array(
+ 'result' => 'failure',
+ )
+ );
+ }
+ },
+ 10,
+ 3
+ );
}
public function add_parameter_block() { ?>
-
+
Date: Mon, 28 Mar 2022 10:42:11 +0200
Subject: [PATCH 024/163] Move birth date field into pui gateway box
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 36 ++++++++++---------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 6099d1330..4175cf6d5 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -66,21 +66,6 @@ class PayUponInvoice {
array( $this, 'register_assets' )
);
- add_filter(
- 'woocommerce_billing_fields',
- function( $billing_fields ) {
- $billing_fields['billing_birth_date'] = array(
- 'type' => 'date',
- 'label' => __( 'Birth date', 'woocommerce-paypal-payments' ),
- 'class' => array( 'form-row-wide' ),
- 'required' => true,
- 'clear' => true,
- );
-
- return $billing_fields;
- }
- );
-
add_filter(
'woocommerce_email_recipient_customer_on_hold_order',
function( $recipient, $order, $email ) {
@@ -113,8 +98,27 @@ class PayUponInvoice {
'woocommerce_gateway_description',
function( $description, $id ) {
if ( PayUponInvoiceGateway::ID === $id ) {
- $description .= __( 'By clicking on the button, you agree to the terms of payment and performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant. ', 'woocommerce-paypal-payments' );
+ ob_start();
+ echo '';
+
+ woocommerce_form_field(
+ 'billing_birth_date',
+ array(
+ 'type' => 'date',
+ 'label' => __('Birth date', 'woocommerce-paypal-payments'),
+ 'class' => array('form-row-wide'),
+ 'required' => true,
+ 'clear' => true,
+ )
+ );
+
+ echo '
';
+ _e( 'By clicking on the button, you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
+ echo '
';
+
+ $description .= ob_get_clean();
}
+
return $description;
},
10,
From 7f8ce720e0dd24e373dd869ede6e2c66ce840341 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 28 Mar 2022 12:31:59 +0200
Subject: [PATCH 025/163] Add title and description to pui gateway settings
---
.../PayUponInvoice/PayUponInvoiceGateway.php | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 495dae912..0a1306087 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -57,9 +57,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$this->id = self::ID;
$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' );;
- $this->title = $this->method_title;
- $this->description = __( 'Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', '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' );
+ $this->title = $gateway_settings['title'] ?? $this->method_title;
+ $this->description = $gateway_settings['description'] ?? __( 'Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', 'woocommerce-paypal-payments' );
$this->init_form_fields();
$this->init_settings();
@@ -90,6 +92,16 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
'default' => 'no',
),
+ 'title' => array(
+ 'title' => __( 'Title', 'woocommerce-paypal-payments' ),
+ 'type' => 'text',
+ 'default' => $this->title,
+ ),
+ 'description' => array(
+ 'title' => __( 'Description', 'woocommerce-paypal-payments' ),
+ 'type' => 'text',
+ 'default' => $this->description,
+ ),
);
}
From b05d15437ff45b37f0c3a8308cbb597f3bc04335 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 28 Mar 2022 12:42:49 +0200
Subject: [PATCH 026/163] Add tooltip description to gateway settings fields
---
.../src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 0a1306087..440a788ed 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -91,16 +91,22 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
'type' => 'checkbox',
'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
'default' => 'no',
+ 'desc_tip' => true,
+ 'description' => __('Enable/Disable Pay Upon Invoice payment gateway.', 'woocommerce-paypal-payments'),
),
'title' => array(
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
'type' => 'text',
'default' => $this->title,
+ 'desc_tip' => true,
+ 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments'),
),
'description' => array(
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
'type' => 'text',
'default' => $this->description,
+ 'desc_tip' => true,
+ 'description' => __('This controls the descriptiong which the user sees during checkout.', 'woocommerce-paypal-payments'),
),
);
}
From d99fdb15d35f0c111e0364f61d5ea5dadfa6b5b4 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 29 Mar 2022 11:15:36 +0200
Subject: [PATCH 027/163] Add phone country code field to pui gateway box
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 10 ++++++++++
.../Gateway/PayUponInvoice/PaymentSourceFactory.php | 3 ++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 4175cf6d5..939618881 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -111,6 +111,16 @@ class PayUponInvoice {
'clear' => true,
)
);
+ woocommerce_form_field(
+ 'phone_country_code',
+ array(
+ 'type' => 'number',
+ 'label' => __('Phone country code (ex. 49)', 'woocommerce-paypal-payments'),
+ 'class' => array('form-row-wide'),
+ 'required' => true,
+ 'clear' => true,
+ )
+ );
echo '';
_e( 'By clicking on the button, you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
index 378e1e618..e1943f977 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -9,6 +9,7 @@ class PaymentSourceFactory {
public function from_wc_order( WC_Order $order ) {
$address = $order->get_address();
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
+ $phone_country_code = filter_input( INPUT_POST, 'phone_country_code', FILTER_SANITIZE_STRING );
return new PaymentSource(
$address['first_name'] ?? '',
@@ -16,7 +17,7 @@ class PaymentSourceFactory {
$address['email'] ?? '',
$birth_date ?? '',
$address['phone'] ?? '',
- '49',
+ $phone_country_code ?? '',
$address['address_1'] ?? '',
$address['city'] ?? '',
$address['postcode'] ?? '',
From 72efcbb71dc129a0384e9a2c36e9086e7cc60f10 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 29 Mar 2022 11:37:22 +0200
Subject: [PATCH 028/163] Only init pui if gateway is enabled
---
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 30fb8061d..697d90654 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -173,7 +173,7 @@ class WCGatewayModule implements ModuleInterface {
assert( $settings instanceof Settings );
try {
- if ( $settings->get( '3d_secure_contingency' ) === '3D_SECURE' ) {
+ if ( $settings->has( '3d_secure_contingency' ) && $settings->get( '3d_secure_contingency' ) === '3D_SECURE' ) {
$settings->set( '3d_secure_contingency', 'SCA_ALWAYS' );
$settings->persist();
}
@@ -186,7 +186,10 @@ class WCGatewayModule implements ModuleInterface {
add_action(
'init',
function () use ( $c ) {
- if ( 'DE' === $c->get( 'api.shop.country' ) ) {
+ $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
+ $gateway_enabled = $gateway_settings['enabled'] ?? '';
+
+ if ( 'yes' === $gateway_enabled && 'DE' === $c->get( 'api.shop.country' ) ) {
( $c->get( 'wcgateway.pay-upon-invoice' ) )->init();
}
}
From 6c216ad7bb314f531b3419b0dc8f32931f300ff3 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 30 Mar 2022 09:54:03 +0200
Subject: [PATCH 029/163] Get phone country code from billing country code
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 32 ++++++-------------
.../PayUponInvoice/PaymentSourceFactory.php | 4 +--
2 files changed, 11 insertions(+), 25 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 939618881..cf9b525f9 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -104,21 +104,11 @@ class PayUponInvoice {
woocommerce_form_field(
'billing_birth_date',
array(
- 'type' => 'date',
- 'label' => __('Birth date', 'woocommerce-paypal-payments'),
- 'class' => array('form-row-wide'),
+ 'type' => 'date',
+ 'label' => __( 'Birth date', 'woocommerce-paypal-payments' ),
+ 'class' => array( 'form-row-wide' ),
'required' => true,
- 'clear' => true,
- )
- );
- woocommerce_form_field(
- 'phone_country_code',
- array(
- 'type' => 'number',
- 'label' => __('Phone country code (ex. 49)', 'woocommerce-paypal-payments'),
- 'class' => array('form-row-wide'),
- 'required' => true,
- 'clear' => true,
+ 'clear' => true,
)
);
@@ -136,18 +126,14 @@ class PayUponInvoice {
);
add_action(
- 'woocommerce_checkout_order_processed',
- function( $order_id, $posted_data, $order ) {
- if ( $order->get_billing_country() !== 'DE' ) {
- wp_send_json_error(
- array(
- 'result' => 'failure',
- )
- );
+ 'woocommerce_after_checkout_validation',
+ function( $fields, $errors ) {
+ if ( $fields['billing_country'] !== 'DE' ) {
+ $errors->add( 'validation', __( 'Billing country not available.', 'woocommerce-paypal-payments' ) );
}
},
10,
- 3
+ 2
);
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
index e1943f977..ccacd8a16 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -9,7 +9,7 @@ class PaymentSourceFactory {
public function from_wc_order( WC_Order $order ) {
$address = $order->get_address();
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
- $phone_country_code = filter_input( INPUT_POST, 'phone_country_code', FILTER_SANITIZE_STRING );
+ $phone_country_code = WC()->countries->get_country_calling_code( $address['country'] ?? '' );
return new PaymentSource(
$address['first_name'] ?? '',
@@ -17,7 +17,7 @@ class PaymentSourceFactory {
$address['email'] ?? '',
$birth_date ?? '',
$address['phone'] ?? '',
- $phone_country_code ?? '',
+ substr($phone_country_code, strlen('+')) ?? '',
$address['address_1'] ?? '',
$address['city'] ?? '',
$address['postcode'] ?? '',
From 3dd46c7258fa87a569bb53725386f4380e8725c1 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 31 Mar 2022 12:47:05 +0200
Subject: [PATCH 030/163] Add RatePay payment instructions into processing
order email notification (WIP)
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 42 ++++++++++++++++++-
.../PayUponInvoice/PayUponInvoiceGateway.php | 14 ++++++-
.../src/Handler/CheckoutOrderApproved.php | 5 +++
.../src/Handler/CheckoutOrderCompleted.php | 5 +++
4 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index cf9b525f9..ef6645056 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -94,6 +94,46 @@ class PayUponInvoice {
2
);
+ add_action( 'woocommerce_email_before_order_table', function(WC_Order $order, $sent_to_admin) {
+ if(! $sent_to_admin && PayUponInvoiceGateway::ID === $order->get_payment_method() && $order->has_status( 'processing' )) {
+ $this->logger->info( "Adding Ratepay payment instructions to email for order #{$order->get_id()}." );
+
+ $instructions = $order->get_meta('ppcp_ratepay_payment_instructions_payment_reference');
+
+ $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
+ $merchant_name = $gateway_settings['brand_name'] ?? '';
+
+ $order_date = $order->get_date_created();
+ $order_purchase_date = $order_date->date('d-m-Y');
+ $order_time = $order_date->date('H:i:s');
+ $order_date = $order_date->date('d-m-Y H:i:s');
+ $order_date_30d = date( 'd-m-Y', strtotime( $order_date . ' +30 days' ));
+
+ $payment_reference = $instructions[0] ?? '';
+ $bic = $instructions[1]->bic ?? '';
+ $bank_name = $instructions[1]->bank_name ?? '';
+ $iban = $instructions[1]->iban ?? '';
+ $account_holder_name = $instructions[1]->account_holder_name ?? '';
+
+ echo "Für Ihre Bestellung #{$order->get_id()} ({$order_purchase_date} $order_time) bei {$merchant_name} haben Sie die Zahlung mittels “Rechnungskauf mit Ratepay“ gewählt.";
+ echo " Bitte benutzen Sie die folgenden Informationen für Ihre Überweisung:";
+ echo "
Bitte überweisen Sie den Betrag in Höhe von {$order->get_total()} bis zum {$order_date_30d} auf das unten angegebene Konto. Wichtig: Bitte geben Sie unbedingt als Verwendungszweck {$payment_reference} an, sonst kann die Zahlung nicht zugeordnet werden.
";
+ echo "";
+ echo "Empfänger: {$account_holder_name} ";
+ echo "IBAN: {$iban} ";
+ echo "BIC: {$bic} ";
+ echo "Name der Bank: {$bank_name} ";
+ echo "Verwendungszweck: {$payment_reference} ";
+ echo " ";
+
+ echo "{$merchant_name} hat die Forderung gegen Sie an die PayPal (Europe) S.à r.l. et Cie, S.C.A. abgetreten, die wiederum die Forderung an Ratepay GmbH abgetreten hat. Zahlungen mit schuldbefreiender Wirkung können nur an die Ratepay GmbH geleistet werden.
";
+
+ echo "Mit freundlichen Grüßen";
+ echo " ";
+ echo "{$merchant_name}
";
+ }
+ }, 10, 3 );
+
add_filter(
'woocommerce_gateway_description',
function( $description, $id ) {
@@ -138,7 +178,7 @@ class PayUponInvoice {
}
public function add_parameter_block() { ?>
-
+
'text',
'default' => $this->description,
'desc_tip' => true,
- 'description' => __('This controls the descriptiong which the user sees during checkout.', 'woocommerce-paypal-payments'),
+ 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments'),
+ ),
+ 'experience_context' => array(
+ 'title' => __( 'Experience Context', 'woocommerce' ),
+ 'type' => 'title',
+ 'description' => __("Specify brand name, logo and customer service instructions to be presented on Ratepay's payment instruction email sent to the buyer.", 'woocommerce-paypal-payments'),
+ ),
+ 'brand_name' => array(
+ 'title' => __( 'Brand name', 'woocommerce-paypal-payments' ),
+ 'type' => 'text',
+ 'default' => '',
+ 'desc_tip' => true,
+ 'description' => __('Merchant name displayed in the email.', 'woocommerce-paypal-payments'),
),
);
}
diff --git a/modules/ppcp-webhooks/src/Handler/CheckoutOrderApproved.php b/modules/ppcp-webhooks/src/Handler/CheckoutOrderApproved.php
index 45d49762b..03fc21412 100644
--- a/modules/ppcp-webhooks/src/Handler/CheckoutOrderApproved.php
+++ b/modules/ppcp-webhooks/src/Handler/CheckoutOrderApproved.php
@@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\Webhooks\Handler;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use Psr\Log\LoggerInterface;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
/**
* Class CheckoutOrderApproved
@@ -188,6 +189,10 @@ class CheckoutOrderApproved implements RequestHandler {
}
foreach ( $wc_orders as $wc_order ) {
+ if(PayUponInvoiceGateway::ID === $wc_order->get_payment_method()) {
+ continue;
+ }
+
if ( ! in_array( $wc_order->get_status(), array( 'pending', 'on-hold' ), true ) ) {
continue;
}
diff --git a/modules/ppcp-webhooks/src/Handler/CheckoutOrderCompleted.php b/modules/ppcp-webhooks/src/Handler/CheckoutOrderCompleted.php
index 4b1eea7b7..44f9ca6e6 100644
--- a/modules/ppcp-webhooks/src/Handler/CheckoutOrderCompleted.php
+++ b/modules/ppcp-webhooks/src/Handler/CheckoutOrderCompleted.php
@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Webhooks\Handler;
use Psr\Log\LoggerInterface;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
/**
* Class CheckoutOrderCompleted
@@ -131,6 +132,10 @@ class CheckoutOrderCompleted implements RequestHandler {
}
foreach ( $wc_orders as $wc_order ) {
+ if(PayUponInvoiceGateway::ID === $wc_order->get_payment_method()) {
+ continue;
+ }
+
if ( ! in_array( $wc_order->get_status(), array( 'pending', 'on-hold' ), true ) ) {
continue;
}
From 2f87f90c9aa6509f7310e1b8513e5efd801e5705 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 4 Apr 2022 12:58:44 +0200
Subject: [PATCH 031/163] Add error messages for pui error codes
---
.../src/Gateway/PayUponInvoice/OrderEndpoint.php | 8 ++++++++
.../src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php | 3 ++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 42e1d1e2b..d57a85a36 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -99,6 +99,14 @@ class OrderEndpoint {
$json = json_decode( $response['body'] );
$status_code = (int) wp_remote_retrieve_response_code( $response );
if ( ! in_array($status_code, [200,201] ) ) {
+ $issue = $json->details[0]->issue ?? null;
+ if($issue === 'PAYMENT_SOURCE_INFO_CANNOT_BE_VERIFIED') {
+ throw new RuntimeException('The combination of your name and address could not be validated. Please correct your data and try again. You can find further information in the Ratepay Data Privacy Statement or you can contact Ratepay using this contact form .');
+ }
+ if($issue === 'PAYMENT_SOURCE_DECLINED_BY_PROCESSOR') {
+ throw new RuntimeException('It is not possible to use the selected payment method. This decision is based on automated data processing. You can find further information in the Ratepay Data Privacy Statement or you can contact Ratepay using this contact form .');
+ }
+
throw new PayPalApiException( $json, $status_code );
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 122f554cf..dab06489c 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use RuntimeException;
use WC_Payment_Gateway;
+use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait;
@@ -145,7 +146,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
} catch ( RuntimeException $exception ) {
$error = $exception->getMessage();
- if(is_array($exception->details())) {
+ if(is_a($exception, PayPalApiException::class) && is_array($exception->details())) {
$details = '';
foreach ($exception->details() as $detail) {
$issue = $detail->issue ?? '';
From 201b359abb53d09291a2f0111639995402d8c534 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 4 Apr 2022 16:55:04 +0200
Subject: [PATCH 032/163] Do not remove on-hold notification email
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index ef6645056..12636687d 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -66,19 +66,6 @@ class PayUponInvoice {
array( $this, 'register_assets' )
);
- add_filter(
- 'woocommerce_email_recipient_customer_on_hold_order',
- function( $recipient, $order, $email ) {
- if ( $order->get_payment_method() === PayUponInvoiceGateway::ID ) {
- return '';
- }
-
- return $recipient;
- },
- 10,
- 3
- );
-
add_action(
'ppcp_payment_capture_completed_webhook_handler',
function ( WC_Order $wc_order, string $order_id ) {
@@ -117,7 +104,7 @@ class PayUponInvoice {
echo "Für Ihre Bestellung #{$order->get_id()} ({$order_purchase_date} $order_time) bei {$merchant_name} haben Sie die Zahlung mittels “Rechnungskauf mit Ratepay“ gewählt.";
echo " Bitte benutzen Sie die folgenden Informationen für Ihre Überweisung:";
- echo "
Bitte überweisen Sie den Betrag in Höhe von {$order->get_total()} bis zum {$order_date_30d} auf das unten angegebene Konto. Wichtig: Bitte geben Sie unbedingt als Verwendungszweck {$payment_reference} an, sonst kann die Zahlung nicht zugeordnet werden.
";
+ echo "Bitte überweisen Sie den Betrag in Höhe von {$order->get_currency()}{$order->get_total()} bis zum {$order_date_30d} auf das unten angegebene Konto. Wichtig: Bitte geben Sie unbedingt als Verwendungszweck {$payment_reference} an, sonst kann die Zahlung nicht zugeordnet werden.
";
echo "";
echo "Empfänger: {$account_holder_name} ";
echo "IBAN: {$iban} ";
@@ -126,6 +113,7 @@ class PayUponInvoice {
echo "Verwendungszweck: {$payment_reference} ";
echo " ";
+
echo "{$merchant_name} hat die Forderung gegen Sie an die PayPal (Europe) S.à r.l. et Cie, S.C.A. abgetreten, die wiederum die Forderung an Ratepay GmbH abgetreten hat. Zahlungen mit schuldbefreiender Wirkung können nur an die Ratepay GmbH geleistet werden.
";
echo "Mit freundlichen Grüßen";
From 6cbcdf32ddfae187b9198c1f6eff14587161f704 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 8 Apr 2022 10:50:59 +0200
Subject: [PATCH 033/163] Do not display pui gateway if customer billing
country is not germany
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 82 +++++++++++--------
1 file changed, 49 insertions(+), 33 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 12636687d..c42c43116 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -81,46 +81,50 @@ class PayUponInvoice {
2
);
- add_action( 'woocommerce_email_before_order_table', function(WC_Order $order, $sent_to_admin) {
- if(! $sent_to_admin && PayUponInvoiceGateway::ID === $order->get_payment_method() && $order->has_status( 'processing' )) {
- $this->logger->info( "Adding Ratepay payment instructions to email for order #{$order->get_id()}." );
+ add_action(
+ 'woocommerce_email_before_order_table',
+ function( WC_Order $order, $sent_to_admin ) {
+ if ( ! $sent_to_admin && PayUponInvoiceGateway::ID === $order->get_payment_method() && $order->has_status( 'processing' ) ) {
+ $this->logger->info( "Adding Ratepay payment instructions to email for order #{$order->get_id()}." );
- $instructions = $order->get_meta('ppcp_ratepay_payment_instructions_payment_reference');
+ $instructions = $order->get_meta( 'ppcp_ratepay_payment_instructions_payment_reference' );
- $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
- $merchant_name = $gateway_settings['brand_name'] ?? '';
+ $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
+ $merchant_name = $gateway_settings['brand_name'] ?? '';
- $order_date = $order->get_date_created();
- $order_purchase_date = $order_date->date('d-m-Y');
- $order_time = $order_date->date('H:i:s');
- $order_date = $order_date->date('d-m-Y H:i:s');
- $order_date_30d = date( 'd-m-Y', strtotime( $order_date . ' +30 days' ));
+ $order_date = $order->get_date_created();
+ $order_purchase_date = $order_date->date( 'd-m-Y' );
+ $order_time = $order_date->date( 'H:i:s' );
+ $order_date = $order_date->date( 'd-m-Y H:i:s' );
+ $order_date_30d = date( 'd-m-Y', strtotime( $order_date . ' +30 days' ) );
- $payment_reference = $instructions[0] ?? '';
- $bic = $instructions[1]->bic ?? '';
- $bank_name = $instructions[1]->bank_name ?? '';
- $iban = $instructions[1]->iban ?? '';
- $account_holder_name = $instructions[1]->account_holder_name ?? '';
+ $payment_reference = $instructions[0] ?? '';
+ $bic = $instructions[1]->bic ?? '';
+ $bank_name = $instructions[1]->bank_name ?? '';
+ $iban = $instructions[1]->iban ?? '';
+ $account_holder_name = $instructions[1]->account_holder_name ?? '';
- echo "Für Ihre Bestellung #{$order->get_id()} ({$order_purchase_date} $order_time) bei {$merchant_name} haben Sie die Zahlung mittels “Rechnungskauf mit Ratepay“ gewählt.";
- echo " Bitte benutzen Sie die folgenden Informationen für Ihre Überweisung:";
- echo "
Bitte überweisen Sie den Betrag in Höhe von {$order->get_currency()}{$order->get_total()} bis zum {$order_date_30d} auf das unten angegebene Konto. Wichtig: Bitte geben Sie unbedingt als Verwendungszweck {$payment_reference} an, sonst kann die Zahlung nicht zugeordnet werden.
";
- echo "";
- echo "Empfänger: {$account_holder_name} ";
- echo "IBAN: {$iban} ";
- echo "BIC: {$bic} ";
- echo "Name der Bank: {$bank_name} ";
- echo "Verwendungszweck: {$payment_reference} ";
- echo " ";
+ echo "Für Ihre Bestellung #{$order->get_id()} ({$order_purchase_date} $order_time) bei {$merchant_name} haben Sie die Zahlung mittels “Rechnungskauf mit Ratepay“ gewählt.";
+ echo ' Bitte benutzen Sie die folgenden Informationen für Ihre Überweisung:';
+ echo "
Bitte überweisen Sie den Betrag in Höhe von {$order->get_currency()}{$order->get_total()} bis zum {$order_date_30d} auf das unten angegebene Konto. Wichtig: Bitte geben Sie unbedingt als Verwendungszweck {$payment_reference} an, sonst kann die Zahlung nicht zugeordnet werden.
";
+ echo '';
+ echo "Empfänger: {$account_holder_name} ";
+ echo "IBAN: {$iban} ";
+ echo "BIC: {$bic} ";
+ echo "Name der Bank: {$bank_name} ";
+ echo "Verwendungszweck: {$payment_reference} ";
+ echo ' ';
+ echo "{$merchant_name} hat die Forderung gegen Sie an die PayPal (Europe) S.à r.l. et Cie, S.C.A. abgetreten, die wiederum die Forderung an Ratepay GmbH abgetreten hat. Zahlungen mit schuldbefreiender Wirkung können nur an die Ratepay GmbH geleistet werden.
";
- echo "{$merchant_name} hat die Forderung gegen Sie an die PayPal (Europe) S.à r.l. et Cie, S.C.A. abgetreten, die wiederum die Forderung an Ratepay GmbH abgetreten hat. Zahlungen mit schuldbefreiender Wirkung können nur an die Ratepay GmbH geleistet werden.
";
-
- echo "Mit freundlichen Grüßen";
- echo " ";
- echo "{$merchant_name}
";
- }
- }, 10, 3 );
+ echo 'Mit freundlichen Grüßen';
+ echo ' ';
+ echo "{$merchant_name}
";
+ }
+ },
+ 10,
+ 3
+ );
add_filter(
'woocommerce_gateway_description',
@@ -163,6 +167,18 @@ class PayUponInvoice {
10,
2
);
+
+ add_filter(
+ 'woocommerce_available_payment_gateways',
+ function( $methods ) {
+ $billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
+ if ( ! is_admin() && $billing_country !== 'DE' ) {
+ unset( $methods[ PayUponInvoiceGateway::ID ] );
+ }
+
+ return $methods;
+ }
+ );
}
public function add_parameter_block() { ?>
From a1741d5575402976def1af28ca0ac78abfa0132b Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 8 Apr 2022 11:13:46 +0200
Subject: [PATCH 034/163] Do not display pui gateway if customer billing
country is not germany
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index c42c43116..d27d72d0c 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -172,7 +172,7 @@ class PayUponInvoice {
'woocommerce_available_payment_gateways',
function( $methods ) {
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
- if ( ! is_admin() && $billing_country !== 'DE' ) {
+ if ( $billing_country && $billing_country !== 'DE' ) {
unset( $methods[ PayUponInvoiceGateway::ID ] );
}
From a56c756773125972c983b3254350e740f92a0369 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 8 Apr 2022 11:23:02 +0200
Subject: [PATCH 035/163] Fix typo in item factory
---
modules/ppcp-api-client/src/Factory/ItemFactory.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/modules/ppcp-api-client/src/Factory/ItemFactory.php b/modules/ppcp-api-client/src/Factory/ItemFactory.php
index fb57f066a..91d27d3ab 100644
--- a/modules/ppcp-api-client/src/Factory/ItemFactory.php
+++ b/modules/ppcp-api-client/src/Factory/ItemFactory.php
@@ -142,7 +142,6 @@ class ItemFactory {
$tax = round( $price - $price_without_tax_rounded, 2 );
$tax = new Money( $tax, $currency );
$tax_rates = WC_Tax::get_rates($product->get_tax_class());
- $tax = new Money( $tax + $shipping_tax, $currency );
return new Item(
mb_substr( $product->get_name(), 0, 127 ),
From 6fa6d3cdc9bd1e1d7e92cfd523ed041b58bc028e Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 8 Apr 2022 12:03:24 +0200
Subject: [PATCH 036/163] Add custom translations
---
.../src/Gateway/PayUponInvoice/OrderEndpoint.php | 15 +++++++++++++--
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 7 ++++++-
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index d57a85a36..cdfb553ce 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -100,11 +100,22 @@ class OrderEndpoint {
$status_code = (int) wp_remote_retrieve_response_code( $response );
if ( ! in_array($status_code, [200,201] ) ) {
$issue = $json->details[0]->issue ?? null;
+
+ $site_country_code = explode('-', get_bloginfo("language"))[0] ?? '';
if($issue === 'PAYMENT_SOURCE_INFO_CANNOT_BE_VERIFIED') {
- throw new RuntimeException('The combination of your name and address could not be validated. Please correct your data and try again. You can find further information in the Ratepay Data Privacy Statement or you can contact Ratepay using this contact form .');
+ if($site_country_code === 'de') {
+ throw new RuntimeException('Die Kombination aus Ihrem Namen und Ihrer Anschrift konnte nicht validiert werden. Bitte korrigieren Sie Ihre Daten und versuchen Sie es erneut. Weitere Informationen finden Sie in den Ratepay Datenschutzbestimmungen oder nutzen Sie das Ratepay Kontaktformular .');
+
+ } else {
+ throw new RuntimeException('The combination of your name and address could not be validated. Please correct your data and try again. You can find further information in the Ratepay Data Privacy Statement or you can contact Ratepay using this contact form .');
+ }
}
if($issue === 'PAYMENT_SOURCE_DECLINED_BY_PROCESSOR') {
- throw new RuntimeException('It is not possible to use the selected payment method. This decision is based on automated data processing. You can find further information in the Ratepay Data Privacy Statement or you can contact Ratepay using this contact form .');
+ if($site_country_code === 'de') {
+ throw new RuntimeException('Die gewählte Zahlungsart kann nicht genutzt werden. Diese Entscheidung basiert auf einem automatisierten Datenverarbeitungsverfahren . Weitere Informationen finden Sie in den Ratepay Datenschutzbestimmungen oder nutzen Sie das Ratepay Kontaktformular .');
+ } else {
+ throw new RuntimeException('It is not possible to use the selected payment method. This decision is based on automated data processing. You can find further information in the Ratepay Data Privacy Statement or you can contact Ratepay using this contact form .');
+ }
}
throw new PayPalApiException( $json, $status_code );
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index d27d72d0c..b0bc39858 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -145,7 +145,12 @@ class PayUponInvoice {
);
echo '
';
- _e( 'By clicking on the button, you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
+ $site_country_code = explode('-', get_bloginfo("language"))[0] ?? '';
+ if($site_country_code === 'de') {
+ _e( 'Mit Klicken auf den Button akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
+ } else {
+ _e( 'By clicking on the button, you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
+ }
echo '
';
$description .= ob_get_clean();
From 2d60d93617baaa8b43c738cea15a64357c18b10c Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 8 Apr 2022 12:35:01 +0200
Subject: [PATCH 037/163] Grab button label from place order button and display
it on button legal text
---
modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js | 6 +++++-
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 4 ++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index 7d1ee70b9..31420d7b3 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -12,6 +12,10 @@ window.addEventListener('load', function() {
form.appendChild(fraudnetSessionId);
console.log(fncls_params.f)
- }, 3000)
+ }, 3000);
+
+ const buttonLabel = document.querySelector('#place_order').textContent;
+ const buttonLegalTextLabel = document.querySelector('#ppcp-legal-text-button-label');
+ buttonLegalTextLabel.textContent = '"' + buttonLabel + '"';
})
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index b0bc39858..28ebef6d2 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -147,9 +147,9 @@ class PayUponInvoice {
echo '';
$site_country_code = explode('-', get_bloginfo("language"))[0] ?? '';
if($site_country_code === 'de') {
- _e( 'Mit Klicken auf den Button akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
+ _e( 'Mit Klicken auf
den Button akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
} else {
- _e( 'By clicking on the button, you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
+ _e( 'By clicking on
the button, you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
}
echo '
';
From 1046b9d77a2738b4d537feb2795abce35886125f Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 8 Apr 2022 12:44:50 +0200
Subject: [PATCH 038/163] Grab button label from place order button and display
it on button legal text
---
.../resources/js/pay-upon-invoice.js | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index 31420d7b3..3ca9b5a78 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -14,8 +14,18 @@ window.addEventListener('load', function() {
console.log(fncls_params.f)
}, 3000);
- const buttonLabel = document.querySelector('#place_order').textContent;
- const buttonLegalTextLabel = document.querySelector('#ppcp-legal-text-button-label');
- buttonLegalTextLabel.textContent = '"' + buttonLabel + '"';
+ const replaceButtonLabel = () => {
+ const buttonLabel = document.querySelector('#place_order').textContent;
+ const buttonLegalTextLabel = document.querySelector('#ppcp-legal-text-button-label');
+ if(buttonLabel && buttonLegalTextLabel) {
+ buttonLegalTextLabel.textContent = '"' + buttonLabel + '"';
+ }
+ }
+
+ jQuery(document.body).on('payment_method_selected', () => {
+ replaceButtonLabel();
+ });
+
+ replaceButtonLabel();
})
From 317ac3f7e8c18ed671f47aae105f891489903d74 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 11 Apr 2022 12:50:05 +0200
Subject: [PATCH 039/163] Onboard pui optionally for merchants (wip)
---
.../ppcp-onboarding/assets/js/onboarding.js | 19 +++++++
modules/ppcp-onboarding/services.php | 10 +++-
.../src/Assets/OnboardingAssets.php | 2 +
.../src/Endpoint/PayUponInvoiceEndpoint.php | 56 +++++++++++++++++++
.../ppcp-onboarding/src/OnboardingModule.php | 8 +++
.../src/Render/OnboardingOptionsRenderer.php | 29 +++++++++-
modules/ppcp-wc-gateway/services.php | 3 +-
.../Gateway/PayUponInvoice/PayUponInvoice.php | 17 +++++-
8 files changed, 137 insertions(+), 7 deletions(-)
create mode 100644 modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
diff --git a/modules/ppcp-onboarding/assets/js/onboarding.js b/modules/ppcp-onboarding/assets/js/onboarding.js
index 0753ad943..e7c70c5ee 100644
--- a/modules/ppcp-onboarding/assets/js/onboarding.js
+++ b/modules/ppcp-onboarding/assets/js/onboarding.js
@@ -70,6 +70,25 @@ const ppcp_onboarding = {
},
1000
);
+
+ const onboard_pui = document.querySelector('#ppcp-onboarding-pui');
+ onboard_pui.addEventListener('click', (event) => {
+ event.preventDefault();
+
+ fetch(PayPalCommerceGatewayOnboarding.pui_endpoint, {
+ method: 'POST',
+ body: JSON.stringify({
+ nonce: PayPalCommerceGatewayOnboarding.pui_nonce,
+ checked: onboard_pui.checked
+ })
+ }).then((res)=>{
+ return res.json();
+ }).then((data)=>{
+ console.log(data)
+ });
+
+ location.reload();
+ })
},
loginSeller: function(env, authCode, sharedId) {
diff --git a/modules/ppcp-onboarding/services.php b/modules/ppcp-onboarding/services.php
index 5bbbbd6a9..29301c85e 100644
--- a/modules/ppcp-onboarding/services.php
+++ b/modules/ppcp-onboarding/services.php
@@ -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\Endpoint\PayUponInvoiceEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
use WooCommerce\PayPalCommerce\Onboarding\OnboardingRESTController;
@@ -186,6 +187,12 @@ return array(
$logger
);
},
+ 'onboarding.endpoint.pui' => static function(ContainerInterface $container) : PayUponInvoiceEndpoint {
+ return new PayUponInvoiceEndpoint(
+ $container->get( 'wcgateway.settings' ),
+ $container->get( 'button.request-data' )
+ );
+ },
'api.endpoint.partner-referrals-sandbox' => static function ( ContainerInterface $container ) : PartnerReferrals {
return new PartnerReferrals(
@@ -218,7 +225,8 @@ return array(
'onboarding.render-options' => static function ( ContainerInterface $container ) : OnboardingOptionsRenderer {
return new OnboardingOptionsRenderer(
$container->get( 'onboarding.url' ),
- $container->get( 'api.shop.country' )
+ $container->get( 'api.shop.country' ),
+ $container->get( 'wcgateway.settings' )
);
},
'onboarding.rest' => static function( $container ) : OnboardingRESTController {
diff --git a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php
index 6e73c3bac..8f669e9b4 100644
--- a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php
+++ b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php
@@ -145,6 +145,8 @@ class OnboardingAssets {
'error_messages' => array(
'no_credentials' => __( 'API credentials must be entered to save the settings.', 'woocommerce-paypal-payments' ),
),
+ 'pui_endpoint' => \WC_AJAX::get_endpoint( 'ppc-pui' ),
+ 'pui_nonce' => wp_create_nonce( 'ppc-pui' ),
);
}
diff --git a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
new file mode 100644
index 000000000..474840122
--- /dev/null
+++ b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
@@ -0,0 +1,56 @@
+settings = $settings;
+ $this->request_data = $request_data;
+ }
+
+ public static function nonce(): string
+ {
+ return 'ppc-pui';
+ }
+
+ public function handle_request(): bool
+ {
+ try {
+ $data = $this->request_data->read_request( $this->nonce() );
+ $this->settings->set('ppcp-onboarding-pui', $data['checked']);
+ $this->settings->persist();
+
+ } catch (\Exception $exception) {
+
+ }
+
+ wp_send_json_success([
+ $this->settings->get('ppcp-onboarding-pui'),
+ ]);
+ return true;
+ }
+}
+
diff --git a/modules/ppcp-onboarding/src/OnboardingModule.php b/modules/ppcp-onboarding/src/OnboardingModule.php
index 0960c7b6c..3f35cfd9e 100644
--- a/modules/ppcp-onboarding/src/OnboardingModule.php
+++ b/modules/ppcp-onboarding/src/OnboardingModule.php
@@ -96,6 +96,14 @@ class OnboardingModule implements ModuleInterface {
}
);
+ add_action(
+ 'wc_ajax_' . 'ppc-pui',
+ static function () use ( $c ) {
+ $endpoint = $c->get( 'onboarding.endpoint.pui' );
+ $endpoint->handle_request();
+ }
+ );
+
// Initialize REST routes at the appropriate time.
$rest_controller = $c->get( 'onboarding.rest' );
add_action( 'rest_api_init', array( $rest_controller, 'register_routes' ) );
diff --git a/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php b/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php
index ce0d20b3f..24c1c2340 100644
--- a/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php
+++ b/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php
@@ -9,6 +9,8 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Onboarding\Render;
+use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
+
/**
* Class OnboardingRenderer
*/
@@ -27,15 +29,21 @@ class OnboardingOptionsRenderer {
*/
private $country;
+ /**
+ * @var Settings
+ */
+ protected $settings;
+
/**
* OnboardingOptionsRenderer constructor.
*
* @param string $module_url The module url (for assets).
* @param string $country 2-letter country code of the shop.
*/
- public function __construct( string $module_url, string $country ) {
+ public function __construct( string $module_url, string $country, Settings $settings) {
$this->module_url = $module_url;
$this->country = $country;
+ $this->settings = $settings;
}
/**
@@ -56,8 +64,23 @@ class OnboardingOptionsRenderer {
__( 'Securely accept all major credit & debit cards on the strength of the PayPal network', 'woocommerce-paypal-payments' ) . '
- ' . $this->render_dcc( $is_shop_supports_dcc ) . '
-';
+ ' . $this->render_dcc( $is_shop_supports_dcc ) . ' ' .
+ $this->render_pui_option()
+. '';
+ }
+
+ private function render_pui_option(): string {
+ if($this->country === 'DE') {
+ $checked = 'checked';
+ if($this->settings->has('ppcp-onboarding-pui') && $this->settings->get('ppcp-onboarding-pui') !== '1') {
+ $checked = '';
+ }
+ return ' ' .
+ __( 'Onboard with Pay Upon Invoice', 'woocommerce-paypal-payments' ) . '
+ ';
+ }
+
+ return '';
}
/**
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index db8c84888..8eda96b2d 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2176,7 +2176,8 @@ return array(
$container->get( 'wcgateway.url' ),
$container->get( 'wcgateway.pay-upon-invoice-fraudnet' ),
$container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
- $container->get( 'woocommerce.logger.woocommerce' )
+ $container->get( 'woocommerce.logger.woocommerce' ),
+ $container->get( 'wcgateway.settings' )
);
},
);
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 28ebef6d2..c925ad444 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -9,6 +9,7 @@ use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
+use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
class PayUponInvoice {
@@ -32,26 +33,38 @@ class PayUponInvoice {
*/
protected $logger;
+ /**
+ * @var Settings
+ */
+ protected $settings;
+
public function __construct(
string $module_url,
FraudNet $fraud_net,
OrderEndpoint $order_endpoint,
- LoggerInterface $logger
+ LoggerInterface $logger,
+ Settings $settings
) {
$this->module_url = $module_url;
$this->fraud_net = $fraud_net;
$this->order_endpoint = $order_endpoint;
$this->logger = $logger;
+ $this->settings = $settings;
}
public function init() {
add_filter(
'ppcp_partner_referrals_data',
function ( $data ) {
- if ( in_array( 'PPCP', $data['products'] ) ) {
+ if($this->settings->has('ppcp-onboarding-pui') && $this->settings->get('ppcp-onboarding-pui') !== '1') {
+ return $data;
+ }
+
+ if(in_array( 'PPCP', $data['products'] )) {
$data['products'][] = 'PAYMENT_METHODS';
$data['capabilities'][] = 'PAY_UPON_INVOICE';
}
+
return $data;
}
);
From dcf1fd863c12c5bc61d1ef85e655c137d1f9d81b Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 12 Apr 2022 15:09:28 +0200
Subject: [PATCH 040/163] Remove fraudnet session id if exist before creating
it
---
.../resources/js/pay-upon-invoice.js | 31 +++++++++++++++----
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index 3ca9b5a78..2509fd762 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -1,23 +1,42 @@
window.addEventListener('load', function() {
- setTimeout(() => {
+
+ const getSessionIdFromJson = () => {
+ const form = document.querySelector('form.checkout');
+ if(!form) {
+ return;
+ }
+
const fncls = document.querySelector("[fncls='fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99']");
const fncls_params = JSON.parse(fncls.textContent);
+ if(document.querySelector("[name='fraudnet-session-id']") !== null) {
+ document.querySelector("[name='fraudnet-session-id']").remove();
+ }
+
const fraudnetSessionId = document.createElement('input');
fraudnetSessionId.setAttribute('type', 'hidden');
fraudnetSessionId.setAttribute('name', 'fraudnet-session-id');
fraudnetSessionId.setAttribute('value', fncls_params.f);
- const form = document.querySelector('form.checkout');
form.appendChild(fraudnetSessionId);
+ console.log(fncls_params)
+ }
- console.log(fncls_params.f)
- }, 3000);
+ document.addEventListener('hosted_fields_loaded', (event) => {
+ getSessionIdFromJson();
+ });
+
+ getSessionIdFromJson();
const replaceButtonLabel = () => {
- const buttonLabel = document.querySelector('#place_order').textContent;
+ const form = document.querySelector('form.checkout');
+ if(!form) {
+ return;
+ }
+
+ const buttonLabel = document.querySelector('#place_order')?.textContent;
const buttonLegalTextLabel = document.querySelector('#ppcp-legal-text-button-label');
- if(buttonLabel && buttonLegalTextLabel) {
+ if (buttonLabel && buttonLegalTextLabel) {
buttonLegalTextLabel.textContent = '"' + buttonLabel + '"';
}
}
From ae30f4346dd9f0e7c715e45bdf2d0105ab743bf5 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 13 Apr 2022 11:53:44 +0200
Subject: [PATCH 041/163] Add experience context fields
---
.../PayUponInvoice/PayUponInvoiceGateway.php | 86 +++++++++++--------
.../PayUponInvoice/PaymentSourceFactory.php | 11 ++-
2 files changed, 58 insertions(+), 39 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index dab06489c..4249042d0 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -60,8 +60,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$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' );
- $this->title = $gateway_settings['title'] ?? $this->method_title;
+ $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
+ $this->title = $gateway_settings['title'] ?? $this->method_title;
$this->description = $gateway_settings['description'] ?? __( 'Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', 'woocommerce-paypal-payments' );
$this->init_form_fields();
@@ -79,7 +79,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$this->purchase_unit_factory = $purchase_unit_factory;
$this->payment_source_factory = $payment_source_factory;
$this->logger = $logger;
- $this->environment = $environment;
+ $this->environment = $environment;
}
/**
@@ -87,39 +87,53 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
*/
public function init_form_fields() {
$this->form_fields = array(
- 'enabled' => array(
- 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
- 'type' => 'checkbox',
- 'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
- 'default' => 'no',
- 'desc_tip' => true,
- 'description' => __('Enable/Disable Pay Upon Invoice payment gateway.', 'woocommerce-paypal-payments'),
+ 'enabled' => array(
+ 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
+ 'type' => 'checkbox',
+ 'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
+ 'default' => 'no',
+ 'desc_tip' => true,
+ 'description' => __( 'Enable/Disable Pay Upon Invoice payment gateway.', 'woocommerce-paypal-payments' ),
),
- 'title' => array(
- 'title' => __( 'Title', 'woocommerce-paypal-payments' ),
- 'type' => 'text',
- 'default' => $this->title,
- 'desc_tip' => true,
- 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments'),
+ 'title' => array(
+ 'title' => __( 'Title', 'woocommerce-paypal-payments' ),
+ 'type' => 'text',
+ 'default' => $this->title,
+ 'desc_tip' => true,
+ 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ),
),
- 'description' => array(
- 'title' => __( 'Description', 'woocommerce-paypal-payments' ),
- 'type' => 'text',
- 'default' => $this->description,
- 'desc_tip' => true,
- 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments'),
+ 'description' => array(
+ 'title' => __( 'Description', 'woocommerce-paypal-payments' ),
+ 'type' => 'text',
+ 'default' => $this->description,
+ 'desc_tip' => true,
+ 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
),
- 'experience_context' => array(
+ 'experience_context' => array(
'title' => __( 'Experience Context', 'woocommerce' ),
'type' => 'title',
- 'description' => __("Specify brand name, logo and customer service instructions to be presented on Ratepay's payment instruction email sent to the buyer.", 'woocommerce-paypal-payments'),
+ 'description' => __( "Specify brand name, logo and customer service instructions to be presented on Ratepay's payment instructions.", 'woocommerce-paypal-payments' ),
),
- 'brand_name' => array(
- 'title' => __( 'Brand name', 'woocommerce-paypal-payments' ),
- 'type' => 'text',
- 'default' => '',
- 'desc_tip' => true,
- 'description' => __('Merchant name displayed in the email.', 'woocommerce-paypal-payments'),
+ 'brand_name' => array(
+ 'title' => __( 'Brand name', 'woocommerce-paypal-payments' ),
+ 'type' => 'text',
+ 'default' => get_bloginfo( 'name' ) ?? '',
+ 'desc_tip' => true,
+ 'description' => __( 'Merchant name displayed in Ratepay\'s payment instructions.', 'woocommerce-paypal-payments' ),
+ ),
+ 'logo_url' => array(
+ 'title' => __( 'Logo URL', 'woocommerce-paypal-payments' ),
+ 'type' => 'url',
+ 'default' => '',
+ 'desc_tip' => true,
+ 'description' => __( 'Logo to be presented on Ratepay\'s payment instructions.', 'woocommerce-paypal-payments' ),
+ ),
+ 'customer_service_instructions' => array(
+ 'title' => __( 'Customer service instructions', 'woocommerce-paypal-payments' ),
+ 'type' => 'text',
+ 'default' => '',
+ 'desc_tip' => true,
+ 'description' => __( 'Customer service instructions to be presented on Ratepay\'s payment instructions.', 'woocommerce-paypal-payments' ),
),
);
}
@@ -132,7 +146,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$payment_source = $this->payment_source_factory->from_wc_order( $wc_order );
try {
- $fraudnet_session_id = filter_input(INPUT_POST, 'fraudnet-session-id', FILTER_SANITIZE_STRING) ?? '';
+ $fraudnet_session_id = filter_input( INPUT_POST, 'fraudnet-session-id', FILTER_SANITIZE_STRING ) ?? '';
$order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source, $fraudnet_session_id );
$this->add_paypal_meta( $wc_order, $order, $this->environment );
@@ -146,13 +160,13 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
} catch ( RuntimeException $exception ) {
$error = $exception->getMessage();
- if(is_a($exception, PayPalApiException::class) && is_array($exception->details())) {
+ if ( is_a( $exception, PayPalApiException::class ) && is_array( $exception->details() ) ) {
$details = '';
- foreach ($exception->details() as $detail) {
- $issue = $detail->issue ?? '';
- $field = $detail->field ?? '';
+ foreach ( $exception->details() as $detail ) {
+ $issue = $detail->issue ?? '';
+ $field = $detail->field ?? '';
$description = $detail->description ?? '';
- $details .= $issue . ' ' . $field . ' ' . $description . ' ';
+ $details .= $issue . ' ' . $field . ' ' . $description . ' ';
}
$error = $details;
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
index ccacd8a16..8577c3f9b 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -11,6 +11,11 @@ class PaymentSourceFactory {
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
$phone_country_code = WC()->countries->get_country_calling_code( $address['country'] ?? '' );
+ $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
+ $merchant_name = $gateway_settings['brand_name'] ?? '';
+ $logo_url = $gateway_settings['logo_url'] ?? '';
+ $customer_service_instructions = $gateway_settings['customer_service_instructions'] ?? '';
+
return new PaymentSource(
$address['first_name'] ?? '',
$address['last_name'] ?? '',
@@ -23,9 +28,9 @@ class PaymentSourceFactory {
$address['postcode'] ?? '',
$address['country'] ?? '',
'en-DE',
- 'EXAMPLE INC',
- 'https://example.com/logoUrl.svg',
- array('Customer service phone is +49 6912345678.')
+ $merchant_name,
+ $logo_url,
+ array($customer_service_instructions)
);
}
}
From 9835421a321c3f57be23a0ddc92bffaa4bfc1681 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 13 Apr 2022 16:46:13 +0200
Subject: [PATCH 042/163] Add pui gateway settings as PayPal tab (WIP)
---
modules/ppcp-wc-gateway/services.php | 2 +-
modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php | 9 +++++++++
.../ppcp-wc-gateway/src/Settings/SectionsRenderer.php | 2 ++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index c0cf84c25..91871baef 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -143,7 +143,7 @@ return array(
}
$section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : '';
- return in_array( $section, array( PayPalGateway::ID, CreditCardGateway::ID, WebhooksStatusPage::ID ), true );
+ return in_array( $section, array( PayPalGateway::ID, CreditCardGateway::ID, WebhooksStatusPage::ID, PayUponInvoiceGateway::ID ), true );
},
'wcgateway.current-ppcp-settings-page-id' => static function ( ContainerInterface $container ): string {
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
index c0604e598..75446008d 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
@@ -19,6 +19,7 @@ use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
use WooCommerce\PayPalCommerce\WcGateway\FundingSource\FundingSourceRenderer;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@@ -340,6 +341,10 @@ class PayPalGateway extends \WC_Payment_Gateway {
if ( $this->is_paypal_tab() ) {
return __( 'PayPal Checkout', 'woocommerce-paypal-payments' );
}
+ if($this->is_pui_tab()) {
+ return __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' );
+ }
+
return __( 'PayPal', 'woocommerce-paypal-payments' );
}
@@ -388,6 +393,10 @@ class PayPalGateway extends \WC_Payment_Gateway {
}
+ private function is_pui_tab():bool {
+ return is_admin() && PayUponInvoiceGateway::ID === $this->page_id;
+ }
+
/**
* Whether we are on the Webhooks Status tab.
*
diff --git a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
index 2bddabe1b..316ff65fa 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
@@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
use WooCommerce\PayPalCommerce\Webhooks\Status\WebhooksStatusPage;
/**
@@ -56,6 +57,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' ),
WebhooksStatusPage::ID => __( 'Webhooks Status', 'woocommerce-paypal-payments' ),
);
From 0a261a0de9dec1cf1dd925cd5394085a28e5c971 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 14 Apr 2022 10:13:41 +0200
Subject: [PATCH 043/163] Add sandbox parameter to config json when in sandbox
environment
---
modules/ppcp-wc-gateway/services.php | 3 ++-
.../Gateway/PayUponInvoice/PayUponInvoice.php | 16 +++++++++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 91871baef..3086c6da0 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2192,7 +2192,8 @@ return array(
$container->get( 'wcgateway.pay-upon-invoice-fraudnet' ),
$container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
$container->get( 'woocommerce.logger.woocommerce' ),
- $container->get( 'wcgateway.settings' )
+ $container->get( 'wcgateway.settings' ),
+ $container->get( 'onboarding.environment' )
);
},
'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index c925ad444..9d2e386bd 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -9,6 +9,7 @@ use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
+use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
class PayUponInvoice {
@@ -38,18 +39,25 @@ class PayUponInvoice {
*/
protected $settings;
+ /**
+ * @var Environment
+ */
+ protected $environment;
+
public function __construct(
string $module_url,
FraudNet $fraud_net,
OrderEndpoint $order_endpoint,
LoggerInterface $logger,
- Settings $settings
+ Settings $settings,
+ Environment $environment
) {
$this->module_url = $module_url;
$this->fraud_net = $fraud_net;
$this->order_endpoint = $order_endpoint;
$this->logger = $logger;
$this->settings = $settings;
+ $this->environment = $environment;
}
public function init() {
@@ -199,8 +207,10 @@ class PayUponInvoice {
);
}
- public function add_parameter_block() { ?>
-
+ public function add_parameter_block() {
+ $sandbox = $this->environment->current_environment_is(Environment::SANDBOX) ? '"sandbox":true,': '';
+ ?>
+
Date: Thu, 14 Apr 2022 10:54:14 +0200
Subject: [PATCH 044/163] Get place order button label from filter
---
.../resources/js/pay-upon-invoice.js | 19 -------------------
.../Gateway/PayUponInvoice/PayUponInvoice.php | 4 ++--
2 files changed, 2 insertions(+), 21 deletions(-)
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index 2509fd762..50ed4d56f 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -27,24 +27,5 @@ window.addEventListener('load', function() {
});
getSessionIdFromJson();
-
- const replaceButtonLabel = () => {
- const form = document.querySelector('form.checkout');
- if(!form) {
- return;
- }
-
- const buttonLabel = document.querySelector('#place_order')?.textContent;
- const buttonLegalTextLabel = document.querySelector('#ppcp-legal-text-button-label');
- if (buttonLabel && buttonLegalTextLabel) {
- buttonLegalTextLabel.textContent = '"' + buttonLabel + '"';
- }
- }
-
- jQuery(document.body).on('payment_method_selected', () => {
- replaceButtonLabel();
- });
-
- replaceButtonLabel();
})
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 9d2e386bd..5c335dea0 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -168,9 +168,9 @@ class PayUponInvoice {
echo '';
$site_country_code = explode('-', get_bloginfo("language"))[0] ?? '';
if($site_country_code === 'de') {
- _e( 'Mit Klicken auf
den Button akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
+ _e( 'Mit Klicken auf
'.apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ).' akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
} else {
- _e( 'By clicking on
the button, you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
+ _e( 'By clicking on
'.apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ).' , you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
}
echo '
';
From 473c4026333d3ac7971bc791cb785978e294ea7b Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 14 Apr 2022 11:45:27 +0200
Subject: [PATCH 045/163] Add pui gateway settings as PayPal tab (WIP)
---
modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
index 316ff65fa..54b6eec31 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
@@ -67,6 +67,9 @@ class SectionsRenderer {
foreach ( $sections as $id => $label ) {
$url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&' . self::KEY . '=' . $id );
+ if($id === PayUponInvoiceGateway::ID) {
+ $url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway');
+ }
echo '' . esc_html( $label ) . ' ' . ( end( $array_keys ) === $id ? '' : '|' ) . ' ';
}
From b303804f813bc4421ee389b5849f3860350d5fbd Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 14 Apr 2022 12:08:13 +0200
Subject: [PATCH 046/163] Remove all phone non-numeric characters
---
.../src/Gateway/PayUponInvoice/PaymentSourceFactory.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
index 8577c3f9b..531fd7a06 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -21,7 +21,7 @@ class PaymentSourceFactory {
$address['last_name'] ?? '',
$address['email'] ?? '',
$birth_date ?? '',
- $address['phone'] ?? '',
+ preg_replace('/[^0-9]/', '', $address['phone']),
substr($phone_country_code, strlen('+')) ?? '',
$address['address_1'] ?? '',
$address['city'] ?? '',
From 42ce61de5bce99183bd5d6bade6aaa85f0e396c3 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 14 Apr 2022 15:52:22 +0200
Subject: [PATCH 047/163] Reload page inside then
---
modules/ppcp-onboarding/assets/js/onboarding.js | 9 +++++----
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 4 ++--
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/modules/ppcp-onboarding/assets/js/onboarding.js b/modules/ppcp-onboarding/assets/js/onboarding.js
index e7c70c5ee..913c86d34 100644
--- a/modules/ppcp-onboarding/assets/js/onboarding.js
+++ b/modules/ppcp-onboarding/assets/js/onboarding.js
@@ -73,7 +73,10 @@ const ppcp_onboarding = {
const onboard_pui = document.querySelector('#ppcp-onboarding-pui');
onboard_pui.addEventListener('click', (event) => {
- event.preventDefault();
+ event.preventDefault();
+ buttons.forEach((element) => {
+ element.removeAttribute('href');
+ });
fetch(PayPalCommerceGatewayOnboarding.pui_endpoint, {
method: 'POST',
@@ -84,10 +87,8 @@ const ppcp_onboarding = {
}).then((res)=>{
return res.json();
}).then((data)=>{
- console.log(data)
+ location.reload();
});
-
- location.reload();
})
},
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 5c335dea0..e51b57a13 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -168,9 +168,9 @@ class PayUponInvoice {
echo '';
$site_country_code = explode('-', get_bloginfo("language"))[0] ?? '';
if($site_country_code === 'de') {
- _e( 'Mit Klicken auf
'.apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ).' akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
+ _e( 'Mit Klicken auf '.apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ).' akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
} else {
- _e( 'By clicking on
'.apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ).' , you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
+ _e( 'By clicking on '.apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ).', you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
}
echo '
';
From e9cf8187995fb72cb31b3e11ff39e4cae8bbb2dc Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 14 Apr 2022 17:17:56 +0200
Subject: [PATCH 048/163] Fix phpcd (WIP)
---
modules/ppcp-api-client/src/Entity/Item.php | 12 +-
.../src/Entity/OrderStatus.php | 16 +--
.../src/Factory/ItemFactory.php | 8 +-
.../src/Repository/PartnerReferralsData.php | 3 +
modules/ppcp-onboarding/services.php | 5 +-
.../src/Assets/OnboardingAssets.php | 4 +-
.../src/Endpoint/PayUponInvoiceEndpoint.php | 62 +++++++--
.../ppcp-onboarding/src/OnboardingModule.php | 2 +-
.../src/Render/OnboardingOptionsRenderer.php | 26 ++--
modules/ppcp-wc-gateway/services.php | 74 +++++-----
.../src/Gateway/PayPalGateway.php | 7 +-
.../src/Gateway/PayUponInvoice/FraudNet.php | 28 +++-
.../PayUponInvoice/FraudNetSessionId.php | 20 ++-
.../FraudNetSourceWebsiteId.php | 32 ++++-
.../Gateway/PayUponInvoice/OrderEndpoint.php | 78 ++++++++---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 66 +++++++--
.../PayUponInvoice/PayUponInvoiceGateway.php | 32 ++++-
.../Gateway/PayUponInvoice/PaymentSource.php | 131 ++++++++++++++----
.../PayUponInvoice/PaymentSourceFactory.php | 34 +++--
.../src/Settings/SectionsRenderer.php | 10 +-
.../ppcp-wc-gateway/src/WCGatewayModule.php | 2 +-
.../src/Handler/CheckoutOrderApproved.php | 2 +-
.../src/Handler/CheckoutOrderCompleted.php | 2 +-
.../src/Handler/PaymentCaptureCompleted.php | 6 +-
24 files changed, 487 insertions(+), 175 deletions(-)
diff --git a/modules/ppcp-api-client/src/Entity/Item.php b/modules/ppcp-api-client/src/Entity/Item.php
index dd661301e..93576e86a 100644
--- a/modules/ppcp-api-client/src/Entity/Item.php
+++ b/modules/ppcp-api-client/src/Entity/Item.php
@@ -83,6 +83,7 @@ class Item {
* @param Money|null $tax The tax.
* @param string $sku The SKU.
* @param string $category The category.
+ * @param float $tax_rate The tax rate.
*/
public function __construct(
string $name,
@@ -102,8 +103,8 @@ class Item {
$this->tax = $tax;
$this->sku = $sku;
$this->category = ( self::DIGITAL_GOODS === $category ) ? self::DIGITAL_GOODS : self::PHYSICAL_GOODS;
- $this->category = $category;
- $this->tax_rate = $tax_rate;
+ $this->category = $category;
+ $this->tax_rate = $tax_rate;
}
/**
@@ -174,9 +175,8 @@ class Item {
*
* @return float
*/
- public function tax_rate():float
- {
- return round((float) $this->tax_rate, 2);
+ public function tax_rate():float {
+ return round( (float) $this->tax_rate, 2 );
}
/**
@@ -198,7 +198,7 @@ class Item {
$item['tax'] = $this->tax()->to_array();
}
- if ($this->tax_rate()) {
+ if ( $this->tax_rate() ) {
$item['tax_rate'] = (string) $this->tax_rate();
}
diff --git a/modules/ppcp-api-client/src/Entity/OrderStatus.php b/modules/ppcp-api-client/src/Entity/OrderStatus.php
index 397ae8b64..e2dec053b 100644
--- a/modules/ppcp-api-client/src/Entity/OrderStatus.php
+++ b/modules/ppcp-api-client/src/Entity/OrderStatus.php
@@ -15,14 +15,14 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
* Class OrderStatus
*/
class OrderStatus {
- const INTERNAL = 'INTERNAL';
- const CREATED = 'CREATED';
- const SAVED = 'SAVED';
- const APPROVED = 'APPROVED';
- const VOIDED = 'VOIDED';
- const COMPLETED = 'COMPLETED';
- const PENDING_APPROVAL = 'PENDING_APPROVAL';
- const VALID_STATUS = array(
+ const INTERNAL = 'INTERNAL';
+ const CREATED = 'CREATED';
+ const SAVED = 'SAVED';
+ const APPROVED = 'APPROVED';
+ const VOIDED = 'VOIDED';
+ const COMPLETED = 'COMPLETED';
+ const PENDING_APPROVAL = 'PENDING_APPROVAL';
+ const VALID_STATUS = array(
self::INTERNAL,
self::CREATED,
self::SAVED,
diff --git a/modules/ppcp-api-client/src/Factory/ItemFactory.php b/modules/ppcp-api-client/src/Factory/ItemFactory.php
index aa8be50c4..3bd277807 100644
--- a/modules/ppcp-api-client/src/Factory/ItemFactory.php
+++ b/modules/ppcp-api-client/src/Factory/ItemFactory.php
@@ -58,7 +58,7 @@ class ItemFactory {
$price_without_tax = (float) wc_get_price_excluding_tax( $product );
$price_without_tax_rounded = round( $price_without_tax, 2 );
$tax = round( $price - $price_without_tax_rounded, 2 );
- $tax_rates = WC_Tax::get_rates($product->get_tax_class());
+ $tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
$tax = new Money( $tax + $shipping_tax, $this->currency );
$tax = new Money( $tax, $this->currency );
return new Item(
@@ -69,7 +69,7 @@ class ItemFactory {
$tax,
$product->get_sku(),
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
- reset($tax_rates)['rate'] ?? 0
+ reset( $tax_rates )['rate'] ?? 0
);
},
$cart->get_cart_contents()
@@ -141,7 +141,7 @@ class ItemFactory {
$price_without_tax_rounded = round( $price_without_tax, 2 );
$tax = round( $price - $price_without_tax_rounded, 2 );
$tax = new Money( $tax, $currency );
- $tax_rates = WC_Tax::get_rates($product->get_tax_class());
+ $tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
return new Item(
mb_substr( $product->get_name(), 0, 127 ),
@@ -151,7 +151,7 @@ class ItemFactory {
$tax,
$product->get_sku(),
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
- reset($tax_rates)['rate'] ?? 0
+ reset( $tax_rates )['rate'] ?? 0
);
}
diff --git a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
index d8ada8567..7bf902dcb 100644
--- a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
+++ b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
@@ -72,6 +72,9 @@ class PartnerReferralsData {
* @return array
*/
public function data(): array {
+ /**
+ * Returns the partners referrals data.
+ */
return apply_filters(
'ppcp_partner_referrals_data',
array(
diff --git a/modules/ppcp-onboarding/services.php b/modules/ppcp-onboarding/services.php
index 29301c85e..d92446054 100644
--- a/modules/ppcp-onboarding/services.php
+++ b/modules/ppcp-onboarding/services.php
@@ -187,10 +187,11 @@ return array(
$logger
);
},
- 'onboarding.endpoint.pui' => static function(ContainerInterface $container) : PayUponInvoiceEndpoint {
+ 'onboarding.endpoint.pui' => static function( ContainerInterface $container ) : PayUponInvoiceEndpoint {
return new PayUponInvoiceEndpoint(
$container->get( 'wcgateway.settings' ),
- $container->get( 'button.request-data' )
+ $container->get( 'button.request-data' ),
+ $container->get( 'woocommerce.logger.woocommerce' )
);
},
'api.endpoint.partner-referrals-sandbox' => static function ( ContainerInterface $container ) : PartnerReferrals {
diff --git a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php
index 8f669e9b4..8c65cc803 100644
--- a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php
+++ b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php
@@ -145,8 +145,8 @@ class OnboardingAssets {
'error_messages' => array(
'no_credentials' => __( 'API credentials must be entered to save the settings.', 'woocommerce-paypal-payments' ),
),
- 'pui_endpoint' => \WC_AJAX::get_endpoint( 'ppc-pui' ),
- 'pui_nonce' => wp_create_nonce( 'ppc-pui' ),
+ 'pui_endpoint' => \WC_AJAX::get_endpoint( 'ppc-pui' ),
+ 'pui_nonce' => wp_create_nonce( 'ppc-pui' ),
);
}
diff --git a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
index 474840122..6700236df 100644
--- a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
+++ b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
@@ -9,47 +9,83 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Onboarding\Endpoint;
+use Exception;
+use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\Button\Endpoint\EndpointInterface;
use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
+use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
+/**
+ * Class PayUponInvoiceEndpoint
+ */
class PayUponInvoiceEndpoint implements EndpointInterface {
/**
+ * The settings.
+ *
* @var Settings
*/
protected $settings;
/**
+ * The request data.
+ *
* @var RequestData
*/
protected $request_data;
- public function __construct(Settings $settings, RequestData $request_data)
- {
- $this->settings = $settings;
+ /**
+ * The logger.
+ *
+ * @var LoggerInterface
+ */
+ protected $logger;
+
+ /**
+ * PayUponInvoiceEndpoint constructor.
+ *
+ * @param Settings $settings The settings.
+ * @param RequestData $request_data The request data.
+ * @param LoggerInterface $logger The logger.
+ */
+ public function __construct( Settings $settings, RequestData $request_data, LoggerInterface $logger ) {
+ $this->settings = $settings;
$this->request_data = $request_data;
+ $this->logger = $logger;
}
- public static function nonce(): string
- {
+ /**
+ * The nonce.
+ *
+ * @return string
+ */
+ public static function nonce(): string {
return 'ppc-pui';
}
- public function handle_request(): bool
- {
+ /**
+ * * Handles the request.
+ *
+ * @return bool
+ * @throws NotFoundException When order not found or handling failed.
+ */
+ public function handle_request(): bool {
try {
$data = $this->request_data->read_request( $this->nonce() );
- $this->settings->set('ppcp-onboarding-pui', $data['checked']);
+ $this->settings->set( 'ppcp-onboarding-pui', $data['checked'] );
$this->settings->persist();
- } catch (\Exception $exception) {
-
+ } catch ( Exception $exception ) {
+ $this->logger->error( $exception->getMessage() );
}
- wp_send_json_success([
- $this->settings->get('ppcp-onboarding-pui'),
- ]);
+ wp_send_json_success(
+ array(
+ $this->settings->get( 'ppcp-onboarding-pui' ),
+ )
+ );
+
return true;
}
}
diff --git a/modules/ppcp-onboarding/src/OnboardingModule.php b/modules/ppcp-onboarding/src/OnboardingModule.php
index 3f35cfd9e..767d47839 100644
--- a/modules/ppcp-onboarding/src/OnboardingModule.php
+++ b/modules/ppcp-onboarding/src/OnboardingModule.php
@@ -97,7 +97,7 @@ class OnboardingModule implements ModuleInterface {
);
add_action(
- 'wc_ajax_' . 'ppc-pui',
+ 'wc_ajax_ppc-pui',
static function () use ( $c ) {
$endpoint = $c->get( 'onboarding.endpoint.pui' );
$endpoint->handle_request();
diff --git a/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php b/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php
index 24c1c2340..dc02c0d9d 100644
--- a/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php
+++ b/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php
@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Onboarding\Render;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
+use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
/**
* Class OnboardingRenderer
@@ -30,6 +31,8 @@ class OnboardingOptionsRenderer {
private $country;
/**
+ * The settings.
+ *
* @var Settings
*/
protected $settings;
@@ -37,13 +40,14 @@ class OnboardingOptionsRenderer {
/**
* OnboardingOptionsRenderer constructor.
*
- * @param string $module_url The module url (for assets).
- * @param string $country 2-letter country code of the shop.
+ * @param string $module_url The module url (for assets).
+ * @param string $country 2-letter country code of the shop.
+ * @param Settings $settings The settings.
*/
- public function __construct( string $module_url, string $country, Settings $settings) {
+ public function __construct( string $module_url, string $country, Settings $settings ) {
$this->module_url = $module_url;
$this->country = $country;
- $this->settings = $settings;
+ $this->settings = $settings;
}
/**
@@ -66,16 +70,22 @@ class OnboardingOptionsRenderer {
' . $this->render_dcc( $is_shop_supports_dcc ) . ' ' .
$this->render_pui_option()
-. '';
+ . '';
}
+ /**
+ * Renders pui option.
+ *
+ * @return string
+ * @throws NotFoundException When setting is not found.
+ */
private function render_pui_option(): string {
- if($this->country === 'DE') {
+ if ( 'DE' === $this->country ) {
$checked = 'checked';
- if($this->settings->has('ppcp-onboarding-pui') && $this->settings->get('ppcp-onboarding-pui') !== '1') {
+ if ( $this->settings->has( 'ppcp-onboarding-pui' ) && $this->settings->get( 'ppcp-onboarding-pui' ) !== '1' ) {
$checked = '';
}
- return ' ' .
+ return ' ' .
__( 'Onboard with Pay Upon Invoice', 'woocommerce-paypal-payments' ) . '
';
}
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 3086c6da0..241058a3e 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -52,7 +52,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
use WooCommerce\PayPalCommerce\Webhooks\Status\WebhooksStatusPage;
return array(
- 'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway {
+ 'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway {
$order_processor = $container->get( 'wcgateway.order-processor' );
$settings_renderer = $container->get( 'wcgateway.settings.render' );
$funding_source_renderer = $container->get( 'wcgateway.funding-source.renderer' );
@@ -88,7 +88,7 @@ return array(
$order_endpoint
);
},
- 'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
+ 'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
$order_processor = $container->get( 'wcgateway.order-processor' );
$settings_renderer = $container->get( 'wcgateway.settings.render' );
$authorized_payments = $container->get( 'wcgateway.processor.authorized-payments' );
@@ -126,18 +126,18 @@ return array(
$payments_endpoint
);
},
- 'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways {
+ 'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways {
$session_handler = $container->get( 'session.handler' );
$settings = $container->get( 'wcgateway.settings' );
return new DisableGateways( $session_handler, $settings );
},
- 'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool {
+ 'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool {
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
$tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
return 'wc-settings' === $page && 'checkout' === $tab;
},
- 'wcgateway.is-ppcp-settings-page' => static function ( ContainerInterface $container ): bool {
+ 'wcgateway.is-ppcp-settings-page' => static function ( ContainerInterface $container ): bool {
if ( ! $container->get( 'wcgateway.is-wc-payments-page' ) ) {
return false;
}
@@ -146,7 +146,7 @@ return array(
return in_array( $section, array( PayPalGateway::ID, CreditCardGateway::ID, WebhooksStatusPage::ID, PayUponInvoiceGateway::ID ), true );
},
- 'wcgateway.current-ppcp-settings-page-id' => static function ( ContainerInterface $container ): string {
+ 'wcgateway.current-ppcp-settings-page-id' => static function ( ContainerInterface $container ): string {
if ( ! $container->get( 'wcgateway.is-ppcp-settings-page' ) ) {
return '';
}
@@ -157,33 +157,33 @@ return array(
return $ppcp_tab ? $ppcp_tab : $section;
},
- 'wcgateway.settings' => static function ( ContainerInterface $container ): Settings {
+ 'wcgateway.settings' => static function ( ContainerInterface $container ): Settings {
return new Settings();
},
- 'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice {
+ 'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice {
$state = $container->get( 'onboarding.state' );
$settings = $container->get( 'wcgateway.settings' );
return new ConnectAdminNotice( $state, $settings );
},
- 'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): DccWithoutPayPalAdminNotice {
+ 'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): DccWithoutPayPalAdminNotice {
$state = $container->get( 'onboarding.state' );
$settings = $container->get( 'wcgateway.settings' );
$is_payments_page = $container->get( 'wcgateway.is-wc-payments-page' );
$is_ppcp_settings_page = $container->get( 'wcgateway.is-ppcp-settings-page' );
return new DccWithoutPayPalAdminNotice( $state, $settings, $is_payments_page, $is_ppcp_settings_page );
},
- 'wcgateway.notice.authorize-order-action' =>
+ 'wcgateway.notice.authorize-order-action' =>
static function ( ContainerInterface $container ): AuthorizeOrderActionNotice {
return new AuthorizeOrderActionNotice();
},
- 'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
+ 'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
return new SectionsRenderer( $container->get( 'wcgateway.current-ppcp-settings-page-id' ) );
},
- 'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus {
+ 'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus {
$settings = $container->get( 'wcgateway.settings' );
return new SettingsStatus( $settings );
},
- 'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer {
+ 'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer {
$settings = $container->get( 'wcgateway.settings' );
$state = $container->get( 'onboarding.state' );
$fields = $container->get( 'wcgateway.settings.fields' );
@@ -203,7 +203,7 @@ return array(
$page_id
);
},
- 'wcgateway.settings.listener' => static function ( ContainerInterface $container ): SettingsListener {
+ 'wcgateway.settings.listener' => static function ( ContainerInterface $container ): SettingsListener {
$settings = $container->get( 'wcgateway.settings' );
$fields = $container->get( 'wcgateway.settings.fields' );
$webhook_registrar = $container->get( 'webhook.registrar' );
@@ -213,7 +213,7 @@ return array(
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state, $bearer, $page_id );
},
- 'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
+ 'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
$session_handler = $container->get( 'session.handler' );
$order_endpoint = $container->get( 'api.endpoint.order' );
@@ -236,13 +236,13 @@ return array(
$subscription_helper
);
},
- 'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
+ 'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
$order_endpoint = $container->get( 'api.endpoint.order' );
$payments_endpoint = $container->get( 'api.endpoint.payments' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new RefundProcessor( $order_endpoint, $payments_endpoint, $logger );
},
- 'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor {
+ 'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor {
$order_endpoint = $container->get( 'api.endpoint.order' );
$payments_endpoint = $container->get( 'api.endpoint.payments' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
@@ -258,23 +258,23 @@ return array(
$subscription_helper
);
},
- 'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction {
+ 'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction {
$column = $container->get( 'wcgateway.admin.orders-payment-status-column' );
return new RenderAuthorizeAction( $column );
},
- 'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ): PaymentStatusOrderDetail {
+ 'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ): PaymentStatusOrderDetail {
$column = $container->get( 'wcgateway.admin.orders-payment-status-column' );
return new PaymentStatusOrderDetail( $column );
},
- 'wcgateway.admin.orders-payment-status-column' => static function ( ContainerInterface $container ): OrderTablePaymentStatusColumn {
+ 'wcgateway.admin.orders-payment-status-column' => static function ( ContainerInterface $container ): OrderTablePaymentStatusColumn {
$settings = $container->get( 'wcgateway.settings' );
return new OrderTablePaymentStatusColumn( $settings );
},
- 'wcgateway.admin.fees-renderer' => static function ( ContainerInterface $container ): FeesRenderer {
+ 'wcgateway.admin.fees-renderer' => static function ( ContainerInterface $container ): FeesRenderer {
return new FeesRenderer();
},
- 'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array {
+ 'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array {
$state = $container->get( 'onboarding.state' );
assert( $state instanceof State );
@@ -2068,7 +2068,7 @@ return array(
return $fields;
},
- 'wcgateway.all-funding-sources' => static function( ContainerInterface $container ): array {
+ 'wcgateway.all-funding-sources' => static function( ContainerInterface $container ): array {
return array(
'card' => _x( 'Credit or debit cards', 'Name of payment method', 'woocommerce-paypal-payments' ),
'credit' => _x( 'Pay Later', 'Name of payment method', 'woocommerce-paypal-payments' ),
@@ -2086,28 +2086,28 @@ return array(
);
},
- 'wcgateway.checkout.address-preset' => static function( ContainerInterface $container ): CheckoutPayPalAddressPreset {
+ 'wcgateway.checkout.address-preset' => static function( ContainerInterface $container ): CheckoutPayPalAddressPreset {
return new CheckoutPayPalAddressPreset(
$container->get( 'session.handler' )
);
},
- 'wcgateway.url' => static function ( ContainerInterface $container ): string {
+ 'wcgateway.url' => static function ( ContainerInterface $container ): string {
return plugins_url(
$container->get( 'wcgateway.relative-path' ),
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
);
},
- 'wcgateway.relative-path' => static function( ContainerInterface $container ): string {
+ 'wcgateway.relative-path' => static function( ContainerInterface $container ): string {
return 'modules/ppcp-wc-gateway/';
},
- 'wcgateway.absolute-path' => static function( ContainerInterface $container ): string {
+ 'wcgateway.absolute-path' => static function( ContainerInterface $container ): string {
return plugin_dir_path(
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
) .
$container->get( 'wcgateway.relative-path' );
},
- 'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ) : ReturnUrlEndpoint {
+ 'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ) : ReturnUrlEndpoint {
$gateway = $container->get( 'wcgateway.paypal-gateway' );
$endpoint = $container->get( 'api.endpoint.order' );
$prefix = $container->get( 'api.prefix' );
@@ -2118,35 +2118,35 @@ return array(
);
},
- 'wcgateway.transaction-url-sandbox' => static function ( ContainerInterface $container ): string {
+ 'wcgateway.transaction-url-sandbox' => static function ( ContainerInterface $container ): string {
return 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s';
},
- 'wcgateway.transaction-url-live' => static function ( ContainerInterface $container ): string {
+ 'wcgateway.transaction-url-live' => static function ( ContainerInterface $container ): string {
return 'https://www.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s';
},
- 'wcgateway.transaction-url-provider' => static function ( ContainerInterface $container ): TransactionUrlProvider {
+ 'wcgateway.transaction-url-provider' => static function ( ContainerInterface $container ): TransactionUrlProvider {
$sandbox_url_base = $container->get( 'wcgateway.transaction-url-sandbox' );
$live_url_base = $container->get( 'wcgateway.transaction-url-live' );
return new TransactionUrlProvider( $sandbox_url_base, $live_url_base );
},
- 'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : DCCProductStatus {
+ 'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : DCCProductStatus {
$settings = $container->get( 'wcgateway.settings' );
$partner_endpoint = $container->get( 'api.endpoint.partners' );
return new DCCProductStatus( $settings, $partner_endpoint );
},
- 'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers {
+ 'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers {
return new MessagesDisclaimers(
$container->get( 'api.shop.country' )
);
},
- 'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer {
+ 'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer {
return new FundingSourceRenderer(
$container->get( 'wcgateway.settings' )
);
@@ -2175,8 +2175,8 @@ return array(
'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
return new FraudNetSessionId();
},
- 'wcgateway.pay-upon-invoice-fraudnet-source-website-id' => static function ( ContainerInterface $container ): FraudNetSourceWebsiteId {
- return new FraudNetSourceWebsiteId($container->get('api.merchant_id'));
+ 'wcgateway.pay-upon-invoice-fraudnet-source-website-id' => static function ( ContainerInterface $container ): FraudNetSourceWebsiteId {
+ return new FraudNetSourceWebsiteId( $container->get( 'api.merchant_id' ) );
},
'wcgateway.pay-upon-invoice-fraudnet' => static function ( ContainerInterface $container ): FraudNet {
$session_id = $container->get( 'wcgateway.pay-upon-invoice-fraudnet-session-id' );
@@ -2196,7 +2196,7 @@ return array(
$container->get( 'onboarding.environment' )
);
},
- 'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
+ 'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
$settings = $container->get( 'wcgateway.settings' );
/**
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
index 75446008d..fe28aeafc 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
@@ -341,7 +341,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
if ( $this->is_paypal_tab() ) {
return __( 'PayPal Checkout', 'woocommerce-paypal-payments' );
}
- if($this->is_pui_tab()) {
+ if ( $this->is_pui_tab() ) {
return __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' );
}
@@ -393,6 +393,11 @@ class PayPalGateway extends \WC_Payment_Gateway {
}
+ /**
+ * Whether we are on the PUI tab.
+ *
+ * @return bool
+ */
private function is_pui_tab():bool {
return is_admin() && PayUponInvoiceGateway::ID === $this->page_id;
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php
index 5591ebf54..49fa9aad8 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNet.php
@@ -1,35 +1,59 @@
session_id = $session_id;
$this->source_website_id = $source_website_id;
}
/**
+ * Returns the session ID.
+ *
* @return string
*/
- public function sessionId(): string {
+ public function session_id(): string {
return $this->session_id;
}
/**
+ * Returns the source website id.
+ *
* @return string
*/
- public function sourceWebsiteId(): string {
+ public function source_website_id(): string {
return $this->source_website_id;
}
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
index 701ad3292..7a1359560 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
@@ -1,11 +1,29 @@
session === null) {
+ if ( WC()->session === null ) {
return '';
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSourceWebsiteId.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSourceWebsiteId.php
index 8d0570cbc..6ce1453f3 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSourceWebsiteId.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSourceWebsiteId.php
@@ -1,21 +1,41 @@
api_merchant_id = $api_merchant_id;
}
- public function __invoke()
- {
+ /**
+ * Returns the source website ID.
+ *
+ * @return string
+ */
+ public function __invoke() {
return "{$this->api_merchant_id}_checkout-page";
}
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index cdfb553ce..97bc4ae6d 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -1,4 +1,9 @@
host = $host;
$this->bearer = $bearer;
$this->order_factory = $order_factory;
$this->logger = $logger;
- $this->fraudNet = $fraudNet;
+ $this->fraudnet = $fraudnet;
}
/**
* Creates an order.
*
* @param PurchaseUnit[] $items The purchase unit items for the order.
+ * @param PaymentSource $payment_source The payment source.
+ * @param string $fraudnet_session_id The FrauNet session ID.
* @return Order
+ * @throws RuntimeException When there is a problem with the payment source.
+ * @throws PayPalApiException When there is a problem creating the order.
*/
public function create( array $items, PaymentSource $payment_source, $fraudnet_session_id = '' ): Order {
$data = array(
@@ -85,7 +116,7 @@ class OrderEndpoint {
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation',
- 'PayPal-Client-Metadata-Id' => $fraudnet_session_id ?: $this->fraudNet->sessionId(),
+ 'PayPal-Client-Metadata-Id' => $fraudnet_session_id ?: $this->fraudnet->session_id(),
'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
),
'body' => wp_json_encode( $data ),
@@ -98,23 +129,22 @@ class OrderEndpoint {
$json = json_decode( $response['body'] );
$status_code = (int) wp_remote_retrieve_response_code( $response );
- if ( ! in_array($status_code, [200,201] ) ) {
+ if ( ! in_array( $status_code, array( 200, 201 ), true ) ) {
$issue = $json->details[0]->issue ?? null;
- $site_country_code = explode('-', get_bloginfo("language"))[0] ?? '';
- if($issue === 'PAYMENT_SOURCE_INFO_CANNOT_BE_VERIFIED') {
- if($site_country_code === 'de') {
- throw new RuntimeException('Die Kombination aus Ihrem Namen und Ihrer Anschrift konnte nicht validiert werden. Bitte korrigieren Sie Ihre Daten und versuchen Sie es erneut. Weitere Informationen finden Sie in den Ratepay Datenschutzbestimmungen oder nutzen Sie das Ratepay Kontaktformular .');
-
+ $site_country_code = explode( '-', get_bloginfo( 'language' ) )[0] ?? '';
+ if ( 'PAYMENT_SOURCE_INFO_CANNOT_BE_VERIFIED' === $issue ) {
+ if ( 'de' === $site_country_code ) {
+ throw new RuntimeException( 'Die Kombination aus Ihrem Namen und Ihrer Anschrift konnte nicht validiert werden. Bitte korrigieren Sie Ihre Daten und versuchen Sie es erneut. Weitere Informationen finden Sie in den Ratepay Datenschutzbestimmungen oder nutzen Sie das Ratepay Kontaktformular .' );
} else {
- throw new RuntimeException('The combination of your name and address could not be validated. Please correct your data and try again. You can find further information in the Ratepay Data Privacy Statement or you can contact Ratepay using this contact form .');
+ throw new RuntimeException( 'The combination of your name and address could not be validated. Please correct your data and try again. You can find further information in the Ratepay Data Privacy Statement or you can contact Ratepay using this contact form .' );
}
}
- if($issue === 'PAYMENT_SOURCE_DECLINED_BY_PROCESSOR') {
- if($site_country_code === 'de') {
- throw new RuntimeException('Die gewählte Zahlungsart kann nicht genutzt werden. Diese Entscheidung basiert auf einem automatisierten Datenverarbeitungsverfahren . Weitere Informationen finden Sie in den Ratepay Datenschutzbestimmungen oder nutzen Sie das Ratepay Kontaktformular .');
+ if ( 'PAYMENT_SOURCE_DECLINED_BY_PROCESSOR' === $issue ) {
+ if ( 'de' === $site_country_code ) {
+ throw new RuntimeException( 'Die gewählte Zahlungsart kann nicht genutzt werden. Diese Entscheidung basiert auf einem automatisierten Datenverarbeitungsverfahren . Weitere Informationen finden Sie in den Ratepay Datenschutzbestimmungen oder nutzen Sie das Ratepay Kontaktformular .' );
} else {
- throw new RuntimeException('It is not possible to use the selected payment method. This decision is based on automated data processing. You can find further information in the Ratepay Data Privacy Statement or you can contact Ratepay using this contact form .');
+ throw new RuntimeException( 'It is not possible to use the selected payment method. This decision is based on automated data processing. You can find further information in the Ratepay Data Privacy Statement or you can contact Ratepay using this contact form .' );
}
}
@@ -124,14 +154,22 @@ class OrderEndpoint {
return $this->order_factory->from_paypal_response( $json );
}
- public function order_payment_instructions(string $id): array {
+ /**
+ * Get Ratepay payment instructions from PayPal order.
+ *
+ * @param string $id The PayPal order ID.
+ * @return array
+ * @throws RuntimeException When there is a problem getting the order.
+ * @throws PayPalApiException When there is a problem getting the order.
+ */
+ public function order_payment_instructions( string $id ): array {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $id;
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
- 'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
+ 'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
),
);
@@ -146,13 +184,9 @@ class OrderEndpoint {
throw new PayPalApiException( $json, $status_code );
}
- $this->logger->info('Payment instructions');
- $this->logger->info($json->payment_source->pay_upon_invoice->payment_reference);
- $this->logger->info(wc_print_r($json->payment_source->pay_upon_invoice->deposit_bank_details, true));
-
return array(
$json->payment_source->pay_upon_invoice->payment_reference,
- $json->payment_source->pay_upon_invoice->deposit_bank_details
+ $json->payment_source->pay_upon_invoice->deposit_bank_details,
);
}
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index e51b57a13..780bd7c00 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -1,4 +1,9 @@
fraud_net = $fraud_net;
$this->order_endpoint = $order_endpoint;
$this->logger = $logger;
- $this->settings = $settings;
- $this->environment = $environment;
+ $this->settings = $settings;
+ $this->environment = $environment;
}
+ /**
+ * Initializes PUI integration.
+ *
+ * @throws NotFoundException When setting is not found.
+ */
public function init() {
add_filter(
'ppcp_partner_referrals_data',
function ( $data ) {
- if($this->settings->has('ppcp-onboarding-pui') && $this->settings->get('ppcp-onboarding-pui') !== '1') {
+ if ( $this->settings->has( 'ppcp-onboarding-pui' ) && $this->settings->get( 'ppcp-onboarding-pui' ) !== '1' ) {
return $data;
}
- if(in_array( 'PPCP', $data['products'] )) {
+ if ( in_array( 'PPCP', $data['products'], true ) ) {
$data['products'][] = 'PAYMENT_METHODS';
$data['capabilities'][] = 'PAY_UPON_INVOICE';
}
@@ -117,7 +151,7 @@ class PayUponInvoice {
$order_purchase_date = $order_date->date( 'd-m-Y' );
$order_time = $order_date->date( 'H:i:s' );
$order_date = $order_date->date( 'd-m-Y H:i:s' );
- $order_date_30d = date( 'd-m-Y', strtotime( $order_date . ' +30 days' ) );
+ $order_date_30d = gmdate( 'd-m-Y', strtotime( $order_date . ' +30 days' ) );
$payment_reference = $instructions[0] ?? '';
$bic = $instructions[1]->bic ?? '';
@@ -166,11 +200,11 @@ class PayUponInvoice {
);
echo '';
- $site_country_code = explode('-', get_bloginfo("language"))[0] ?? '';
- if($site_country_code === 'de') {
- _e( 'Mit Klicken auf '.apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ).' akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
+ $site_country_code = explode( '-', get_bloginfo( 'language' ) )[0] ?? '';
+ if ( $site_country_code === 'de' ) {
+ _e( 'Mit Klicken auf ' . apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ) . ' akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
} else {
- _e( 'By clicking on '.apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ).', you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
+ _e( 'By clicking on ' . apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ) . ', you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
}
echo '
';
@@ -207,14 +241,20 @@ class PayUponInvoice {
);
}
+ /**
+ * Set configuration JSON for FraudNet integration.
+ */
public function add_parameter_block() {
- $sandbox = $this->environment->current_environment_is(Environment::SANDBOX) ? '"sandbox":true,': '';
+ $sandbox = $this->environment->current_environment_is( Environment::SANDBOX ) ? '"sandbox":true,' : '';
?>
-
+
id = self::ID;
+ $this->id = self::ID;
$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' );
@@ -110,7 +132,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
),
'experience_context' => array(
- 'title' => __( 'Experience Context', 'woocommerce' ),
+ 'title' => __( 'Experience Context', 'woocommerce-paypal-payments' ),
'type' => 'title',
'description' => __( "Specify brand name, logo and customer service instructions to be presented on Ratepay's payment instructions.", 'woocommerce-paypal-payments' ),
),
@@ -138,6 +160,12 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
);
}
+ /**
+ * Processes the order.
+ *
+ * @param int $order_id The WC order ID.
+ * @return array
+ */
public function process_payment( $order_id ) {
$wc_order = wc_get_order( $order_id );
$wc_order->update_status( 'on-hold', __( 'Awaiting Pay Upon Invoice payment.', 'woocommerce-paypal-payments' ) );
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php
index bfd51ed44..bac9791cb 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSource.php
@@ -1,79 +1,135 @@
given_name;
}
/**
+ * Returns the surname.
+ *
* @return string
*/
- public function surname(): string
- {
+ public function surname(): string {
return $this->surname;
}
/**
+ * Returns the email.
+ *
* @return string
*/
- public function email(): string
- {
+ public function email(): string {
return $this->email;
}
/**
+ * Returns the birth date.
+ *
* @return string
*/
- public function birth_date(): string
- {
+ public function birth_date(): string {
return $this->birth_date;
}
/**
+ * Returns the national number.
+ *
* @return string
*/
- public function national_number(): string
- {
+ public function national_number(): string {
return $this->national_number;
}
/**
+ * Returns the phone country code.
+ *
* @return string
*/
- public function phone_country_code(): string
- {
+ public function phone_country_code(): string {
return $this->phone_country_code;
}
/**
+ * Returns the address line 1.
+ *
* @return string
*/
- public function address_line_1(): string
- {
+ public function address_line_1(): string {
return $this->address_line_1;
}
/**
+ * Returns the admin area 2.
+ *
* @return string
*/
- public function admin_area_2(): string
- {
+ public function admin_area_2(): string {
return $this->admin_area_2;
}
/**
+ * Returns the postal code.
+ *
* @return string
*/
- public function postal_code(): string
- {
+ public function postal_code(): string {
return $this->postal_code;
}
/**
+ * Returns the country code.
+ *
* @return string
*/
- public function country_code(): string
- {
+ public function country_code(): string {
return $this->country_code;
}
/**
+ * Returns the locale.
+ *
* @return string
*/
- public function locale(): string
- {
+ public function locale(): string {
return $this->locale;
}
/**
+ * Returns the brand name.
+ *
* @return string
*/
- public function brand_name(): string
- {
+ public function brand_name(): string {
return $this->brand_name;
}
/**
+ * The logo URL.
+ *
* @return string
*/
- public function logo_url(): string
- {
+ public function logo_url(): string {
return $this->logo_url;
}
/**
+ * Returns the customer service instructions.
+ *
* @return array
*/
- public function customer_service_instructions(): array
- {
+ public function customer_service_instructions(): array {
return $this->customer_service_instructions;
}
+ /**
+ * Returns payment source as array.
+ *
+ * @return array
+ */
public function to_array(): array {
return array(
'name' => array(
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
index 531fd7a06..88b23eef3 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -1,28 +1,44 @@
get_address();
- $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
+ $address = $order->get_address();
+ $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
$phone_country_code = WC()->countries->get_country_calling_code( $address['country'] ?? '' );
- $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
- $merchant_name = $gateway_settings['brand_name'] ?? '';
- $logo_url = $gateway_settings['logo_url'] ?? '';
- $customer_service_instructions = $gateway_settings['customer_service_instructions'] ?? '';
+ $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
+ $merchant_name = $gateway_settings['brand_name'] ?? '';
+ $logo_url = $gateway_settings['logo_url'] ?? '';
+ $customer_service_instructions = $gateway_settings['customer_service_instructions'] ?? '';
return new PaymentSource(
$address['first_name'] ?? '',
$address['last_name'] ?? '',
$address['email'] ?? '',
$birth_date ?? '',
- preg_replace('/[^0-9]/', '', $address['phone']),
- substr($phone_country_code, strlen('+')) ?? '',
+ preg_replace( '/[^0-9]/', '', $address['phone'] ),
+ substr( $phone_country_code, strlen( '+' ) ) ?? '',
$address['address_1'] ?? '',
$address['city'] ?? '',
$address['postcode'] ?? '',
@@ -30,7 +46,7 @@ class PaymentSourceFactory {
'en-DE',
$merchant_name,
$logo_url,
- array($customer_service_instructions)
+ array( $customer_service_instructions )
);
}
}
diff --git a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
index 54b6eec31..72d70a7f0 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
@@ -55,10 +55,10 @@ class SectionsRenderer {
}
$sections = array(
- PayPalGateway::ID => __( 'PayPal Checkout', 'woocommerce-paypal-payments' ),
- CreditCardGateway::ID => __( 'PayPal Card Processing', 'woocommerce-paypal-payments' ),
+ PayPalGateway::ID => __( 'PayPal Checkout', 'woocommerce-paypal-payments' ),
+ CreditCardGateway::ID => __( 'PayPal Card Processing', 'woocommerce-paypal-payments' ),
PayUponInvoiceGateway::ID => __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' ),
- WebhooksStatusPage::ID => __( 'Webhooks Status', 'woocommerce-paypal-payments' ),
+ WebhooksStatusPage::ID => __( 'Webhooks Status', 'woocommerce-paypal-payments' ),
);
echo '';
@@ -67,8 +67,8 @@ class SectionsRenderer {
foreach ( $sections as $id => $label ) {
$url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&' . self::KEY . '=' . $id );
- if($id === PayUponInvoiceGateway::ID) {
- $url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway');
+ if ( PayUponInvoiceGateway::ID === $id ) {
+ $url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' );
}
echo '' . esc_html( $label ) . ' ' . ( end( $array_keys ) === $id ? '' : '|' ) . ' ';
}
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 697d90654..4fe5a43ca 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -187,7 +187,7 @@ class WCGatewayModule implements ModuleInterface {
'init',
function () use ( $c ) {
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
- $gateway_enabled = $gateway_settings['enabled'] ?? '';
+ $gateway_enabled = $gateway_settings['enabled'] ?? '';
if ( 'yes' === $gateway_enabled && 'DE' === $c->get( 'api.shop.country' ) ) {
( $c->get( 'wcgateway.pay-upon-invoice' ) )->init();
diff --git a/modules/ppcp-webhooks/src/Handler/CheckoutOrderApproved.php b/modules/ppcp-webhooks/src/Handler/CheckoutOrderApproved.php
index 03fc21412..fdbdf8abc 100644
--- a/modules/ppcp-webhooks/src/Handler/CheckoutOrderApproved.php
+++ b/modules/ppcp-webhooks/src/Handler/CheckoutOrderApproved.php
@@ -189,7 +189,7 @@ class CheckoutOrderApproved implements RequestHandler {
}
foreach ( $wc_orders as $wc_order ) {
- if(PayUponInvoiceGateway::ID === $wc_order->get_payment_method()) {
+ if ( PayUponInvoiceGateway::ID === $wc_order->get_payment_method() ) {
continue;
}
diff --git a/modules/ppcp-webhooks/src/Handler/CheckoutOrderCompleted.php b/modules/ppcp-webhooks/src/Handler/CheckoutOrderCompleted.php
index 44f9ca6e6..3159c9cb1 100644
--- a/modules/ppcp-webhooks/src/Handler/CheckoutOrderCompleted.php
+++ b/modules/ppcp-webhooks/src/Handler/CheckoutOrderCompleted.php
@@ -132,7 +132,7 @@ class CheckoutOrderCompleted implements RequestHandler {
}
foreach ( $wc_orders as $wc_order ) {
- if(PayUponInvoiceGateway::ID === $wc_order->get_payment_method()) {
+ if ( PayUponInvoiceGateway::ID === $wc_order->get_payment_method() ) {
continue;
}
diff --git a/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php b/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php
index 5ed5a41aa..eda546118 100644
--- a/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php
+++ b/modules/ppcp-webhooks/src/Handler/PaymentCaptureCompleted.php
@@ -114,7 +114,10 @@ class PaymentCaptureCompleted implements RequestHandler {
$order_id = $resource['supplementary_data']['related_ids']['order_id'] ?? null;
- do_action('ppcp_payment_capture_completed_webhook_handler', $wc_order, $order_id);
+ /**
+ * Allow access to the webhook logic before updating the WC order.
+ */
+ do_action( 'ppcp_payment_capture_completed_webhook_handler', $wc_order, $order_id );
if ( $wc_order->get_status() !== 'on-hold' ) {
$response['success'] = true;
@@ -151,7 +154,6 @@ class PaymentCaptureCompleted implements RequestHandler {
if ( $transaction_id ) {
$this->update_transaction_id( $transaction_id, $wc_order, $this->logger );
}
-
} catch ( Exception $exception ) {
$this->logger->warning( 'Failed to get transaction ID: ' . $exception->getMessage() );
}
From 372884ce16172891bc642159121399f7520b7c8e Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 19 Apr 2022 10:37:33 +0200
Subject: [PATCH 049/163] Fix phpunit
---
.../src/Factory/ItemFactory.php | 1 -
.../ApiClient/Factory/ItemFactoryTest.php | 33 +++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-api-client/src/Factory/ItemFactory.php b/modules/ppcp-api-client/src/Factory/ItemFactory.php
index 3bd277807..cdd8692e0 100644
--- a/modules/ppcp-api-client/src/Factory/ItemFactory.php
+++ b/modules/ppcp-api-client/src/Factory/ItemFactory.php
@@ -59,7 +59,6 @@ class ItemFactory {
$price_without_tax_rounded = round( $price_without_tax, 2 );
$tax = round( $price - $price_without_tax_rounded, 2 );
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
- $tax = new Money( $tax + $shipping_tax, $this->currency );
$tax = new Money( $tax, $this->currency );
return new Item(
mb_substr( $product->get_name(), 0, 127 ),
diff --git a/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php b/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php
index ee89d6f5c..c323c62ab 100644
--- a/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php
+++ b/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php
@@ -31,6 +31,9 @@ class ItemFactoryTest extends TestCase
$product
->expects('is_virtual')
->andReturn(false);
+ $product
+ ->expects('get_tax_class')
+ ->andReturn('');
$items = [
[
'data' => $product,
@@ -58,6 +61,9 @@ class ItemFactoryTest extends TestCase
$woocommerce->session = $session;
$session->shouldReceive('get')->andReturn([]);
+ $tax = Mockery::mock('alias:WC_Tax');
+ $tax->expects('get_rates')->andReturn([]);
+
$result = $testee->from_wc_cart($cart);
$this->assertCount(1, $result);
@@ -92,6 +98,10 @@ class ItemFactoryTest extends TestCase
$product
->expects('is_virtual')
->andReturn(true);
+ $product
+ ->expects('get_tax_class')
+ ->andReturn('');
+
$items = [
[
'data' => $product,
@@ -119,6 +129,9 @@ class ItemFactoryTest extends TestCase
$woocommerce->session = $session;
$session->shouldReceive('get')->andReturn([]);
+ $tax = Mockery::mock('alias:WC_Tax');
+ $tax->expects('get_rates')->andReturn([]);
+
$result = $testee->from_wc_cart($cart);
$item = current($result);
@@ -139,6 +152,9 @@ class ItemFactoryTest extends TestCase
$product
->expects('get_sku')
->andReturn('sku');
+ $product
+ ->expects('get_tax_class')
+ ->andReturn('foo');
$product
->expects('is_virtual')
->andReturn(false);
@@ -173,6 +189,9 @@ class ItemFactoryTest extends TestCase
->expects('get_fees')
->andReturn([]);
+ $tax = Mockery::mock('alias:WC_Tax');
+ $tax->expects('get_rates')->andReturn([]);
+
$result = $testee->from_wc_order($order);
$this->assertCount(1, $result);
$item = current($result);
@@ -205,6 +224,10 @@ class ItemFactoryTest extends TestCase
$product
->expects('is_virtual')
->andReturn(true);
+ $product
+ ->expects('get_tax_class')
+ ->andReturn('foo');
+
expect('wp_strip_all_tags')
->with('description')
->andReturn('description');
@@ -236,6 +259,9 @@ class ItemFactoryTest extends TestCase
->expects('get_fees')
->andReturn([]);
+ $tax = Mockery::mock('alias:WC_Tax');
+ $tax->expects('get_rates')->andReturn([]);
+
$result = $testee->from_wc_order($order);
$item = current($result);
/**
@@ -263,6 +289,10 @@ class ItemFactoryTest extends TestCase
$product
->expects('is_virtual')
->andReturn(true);
+ $product
+ ->expects('get_tax_class')
+ ->andReturn('foo');
+
expect('wp_strip_all_tags')
->with($description)
->andReturn(mb_substr( $description, 0, 127 ));
@@ -294,6 +324,9 @@ class ItemFactoryTest extends TestCase
->expects('get_fees')
->andReturn([]);
+ $tax = Mockery::mock('alias:WC_Tax');
+ $tax->expects('get_rates')->andReturn([]);
+
$result = $testee->from_wc_order($order);
$item = current($result);
/**
From e2cb2ad922ec789d6cc5bf77717bbccc9e247e66 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 19 Apr 2022 11:31:47 +0200
Subject: [PATCH 050/163] Fix psalm
---
.../Gateway/PayUponInvoice/OrderEndpoint.php | 5 +--
.../Gateway/PayUponInvoice/PayUponInvoice.php | 36 ++++++++++++-------
2 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 97bc4ae6d..4d0ce2e23 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
+use WP_Error;
/**
* Class OrderEndpoint.
@@ -123,7 +124,7 @@ class OrderEndpoint {
);
$response = $this->request( $url, $args );
- if ( is_wp_error( $response ) ) {
+ if ( $response instanceof WP_Error ) {
throw new RuntimeException( $response->get_error_message() );
}
@@ -174,7 +175,7 @@ class OrderEndpoint {
);
$response = $this->request( $url, $args );
- if ( is_wp_error( $response ) ) {
+ if ( $response instanceof WP_Error ) {
throw new RuntimeException( $response->get_error_message() );
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 780bd7c00..9ff3ad62f 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -15,6 +15,7 @@ use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
+use WP_Error;
/**
* Class PayUponInvoice.
@@ -94,10 +95,10 @@ class PayUponInvoice {
*
* @throws NotFoundException When setting is not found.
*/
- public function init() {
+ public function init(): void {
add_filter(
'ppcp_partner_referrals_data',
- function ( $data ) {
+ function ( array $data ): array {
if ( $this->settings->has( 'ppcp-onboarding-pui' ) && $this->settings->get( 'ppcp-onboarding-pui' ) !== '1' ) {
return $data;
}
@@ -138,7 +139,7 @@ class PayUponInvoice {
add_action(
'woocommerce_email_before_order_table',
- function( WC_Order $order, $sent_to_admin ) {
+ function( WC_Order $order, bool $sent_to_admin ) {
if ( ! $sent_to_admin && PayUponInvoiceGateway::ID === $order->get_payment_method() && $order->has_status( 'processing' ) ) {
$this->logger->info( "Adding Ratepay payment instructions to email for order #{$order->get_id()}." );
@@ -147,11 +148,22 @@ class PayUponInvoice {
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
$merchant_name = $gateway_settings['brand_name'] ?? '';
- $order_date = $order->get_date_created();
+ $order_date = $order->get_date_created();
+ if ( null === $order_date ) {
+ $this->logger->error( 'Could not get WC order date for Ratepay payment instructions.' );
+ return;
+ }
+
$order_purchase_date = $order_date->date( 'd-m-Y' );
$order_time = $order_date->date( 'H:i:s' );
$order_date = $order_date->date( 'd-m-Y H:i:s' );
- $order_date_30d = gmdate( 'd-m-Y', strtotime( $order_date . ' +30 days' ) );
+
+ $thirty_days_date = strtotime( $order_date . ' +30 days' );
+ if ( false === $thirty_days_date ) {
+ $this->logger->error( 'Could not create +30 days date from WC order date.' );
+ return;
+ }
+ $order_date_30d = gmdate( 'd-m-Y', $thirty_days_date );
$payment_reference = $instructions[0] ?? '';
$bic = $instructions[1]->bic ?? '';
@@ -183,7 +195,7 @@ class PayUponInvoice {
add_filter(
'woocommerce_gateway_description',
- function( $description, $id ) {
+ function( string $description, string $id ): string {
if ( PayUponInvoiceGateway::ID === $id ) {
ob_start();
echo '';
@@ -208,7 +220,7 @@ class PayUponInvoice {
}
echo '
';
- $description .= ob_get_clean();
+ $description .= ob_get_clean() ?: '';
}
return $description;
@@ -219,7 +231,7 @@ class PayUponInvoice {
add_action(
'woocommerce_after_checkout_validation',
- function( $fields, $errors ) {
+ function( array $fields, WP_Error $errors ) {
if ( $fields['billing_country'] !== 'DE' ) {
$errors->add( 'validation', __( 'Billing country not available.', 'woocommerce-paypal-payments' ) );
}
@@ -230,7 +242,7 @@ class PayUponInvoice {
add_filter(
'woocommerce_available_payment_gateways',
- function( $methods ) {
+ function( array $methods ): array {
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
if ( $billing_country && $billing_country !== 'DE' ) {
unset( $methods[ PayUponInvoiceGateway::ID ] );
@@ -244,7 +256,7 @@ class PayUponInvoice {
/**
* Set configuration JSON for FraudNet integration.
*/
- public function add_parameter_block() {
+ public function add_parameter_block(): void {
$sandbox = $this->environment->current_environment_is( Environment::SANDBOX ) ? '"sandbox":true,' : '';
?>
@@ -255,12 +267,12 @@ class PayUponInvoice {
/**
* Registers PUI assets.
*/
- public function register_assets() {
+ public function register_assets(): void {
wp_enqueue_script(
'ppcp-pay-upon-invoice',
trailingslashit( $this->module_url ) . 'assets/js/pay-upon-invoice.js',
array(),
- 1
+ '1'
);
}
}
From 90340b95c9b371a52508a57dc77eb9a015fc1764 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 19 Apr 2022 11:54:49 +0200
Subject: [PATCH 051/163] Fix phpcs
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 34 +++++++++++--------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 9ff3ad62f..1abef13e8 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -171,22 +171,23 @@ class PayUponInvoice {
$iban = $instructions[1]->iban ?? '';
$account_holder_name = $instructions[1]->account_holder_name ?? '';
- echo "Für Ihre Bestellung #{$order->get_id()} ({$order_purchase_date} $order_time) bei {$merchant_name} haben Sie die Zahlung mittels “Rechnungskauf mit Ratepay“ gewählt.";
+ echo wp_kses_post( "
Für Ihre Bestellung #{$order->get_id()} ({$order_purchase_date} $order_time) bei {$merchant_name} haben Sie die Zahlung mittels “Rechnungskauf mit Ratepay“ gewählt." );
echo ' Bitte benutzen Sie die folgenden Informationen für Ihre Überweisung:';
- echo "
Bitte überweisen Sie den Betrag in Höhe von {$order->get_currency()}{$order->get_total()} bis zum {$order_date_30d} auf das unten angegebene Konto. Wichtig: Bitte geben Sie unbedingt als Verwendungszweck {$payment_reference} an, sonst kann die Zahlung nicht zugeordnet werden.
";
+ echo wp_kses_post( "Bitte überweisen Sie den Betrag in Höhe von {$order->get_currency()}{$order->get_total()} bis zum {$order_date_30d} auf das unten angegebene Konto. Wichtig: Bitte geben Sie unbedingt als Verwendungszweck {$payment_reference} an, sonst kann die Zahlung nicht zugeordnet werden.
" );
+
echo '';
- echo "Empfänger: {$account_holder_name} ";
- echo "IBAN: {$iban} ";
- echo "BIC: {$bic} ";
- echo "Name der Bank: {$bank_name} ";
- echo "Verwendungszweck: {$payment_reference} ";
+ echo wp_kses_post( "Empfänger: {$account_holder_name} " );
+ echo wp_kses_post( "IBAN: {$iban} " );
+ echo wp_kses_post( "BIC: {$bic} " );
+ echo wp_kses_post( "Name der Bank: {$bank_name} " );
+ echo wp_kses_post( "Verwendungszweck: {$payment_reference} " );
echo ' ';
- echo "{$merchant_name} hat die Forderung gegen Sie an die PayPal (Europe) S.à r.l. et Cie, S.C.A. abgetreten, die wiederum die Forderung an Ratepay GmbH abgetreten hat. Zahlungen mit schuldbefreiender Wirkung können nur an die Ratepay GmbH geleistet werden.
";
+ echo wp_kses_post( "{$merchant_name} hat die Forderung gegen Sie an die PayPal (Europe) S.à r.l. et Cie, S.C.A. abgetreten, die wiederum die Forderung an Ratepay GmbH abgetreten hat. Zahlungen mit schuldbefreiender Wirkung können nur an die Ratepay GmbH geleistet werden.
" );
echo 'Mit freundlichen Grüßen';
echo ' ';
- echo "{$merchant_name}
";
+ echo wp_kses_post( "{$merchant_name}" );
}
},
10,
@@ -213,10 +214,12 @@ class PayUponInvoice {
echo '';
$site_country_code = explode( '-', get_bloginfo( 'language' ) )[0] ?? '';
- if ( $site_country_code === 'de' ) {
- _e( 'Mit Klicken auf ' . apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ) . ' akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
+ if ( 'de' === $site_country_code ) {
+ // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
+ echo wp_kses_post( 'Mit Klicken auf ' . apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ) . ' akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
} else {
- _e( 'By clicking on ' . apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ) . ', you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
+ // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
+ echo wp_kses_post( 'By clicking on ' . apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ) . ', you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
}
echo '
';
@@ -232,7 +235,7 @@ class PayUponInvoice {
add_action(
'woocommerce_after_checkout_validation',
function( array $fields, WP_Error $errors ) {
- if ( $fields['billing_country'] !== 'DE' ) {
+ if ( 'DE' !== $fields['billing_country'] ) {
$errors->add( 'validation', __( 'Billing country not available.', 'woocommerce-paypal-payments' ) );
}
},
@@ -244,7 +247,7 @@ class PayUponInvoice {
'woocommerce_available_payment_gateways',
function( array $methods ): array {
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
- if ( $billing_country && $billing_country !== 'DE' ) {
+ if ( $billing_country && 'DE' !== $billing_country ) {
unset( $methods[ PayUponInvoiceGateway::ID ] );
}
@@ -259,7 +262,8 @@ class PayUponInvoice {
public function add_parameter_block(): void {
$sandbox = $this->environment->current_environment_is( Environment::SANDBOX ) ? '"sandbox":true,' : '';
?>
-
+
+
Date: Tue, 19 Apr 2022 12:37:25 +0200
Subject: [PATCH 052/163] Fix psalm
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 14 ++++++++++----
.../PayUponInvoice/PaymentSourceFactory.php | 19 +++++++++++++------
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 1abef13e8..39d3401e2 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -214,12 +214,18 @@ class PayUponInvoice {
echo '';
$site_country_code = explode( '-', get_bloginfo( 'language' ) )[0] ?? '';
+
+ // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
+ $button_text = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) );
+
if ( 'de' === $site_country_code ) {
- // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
- echo wp_kses_post( 'Mit Klicken auf ' . apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ) . ' akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.', 'woocommerce-paypal-payments' );
+ echo wp_kses_post(
+ 'Mit Klicken auf ' . $button_text . ' akzeptieren Sie die
Ratepay Zahlungsbedingungen und erklären sich mit der Durchführung einer
Risikoprüfung durch Ratepay , unseren Partner, einverstanden. Sie akzeptieren auch PayPals
Datenschutzerklärung . Falls Ihre Transaktion per Kauf auf Rechnung erfolgreich abgewickelt werden kann, wird der Kaufpreis an Ratepay abgetreten und Sie dürfen nur an Ratepay überweisen, nicht an den Händler.'
+ );
} else {
- // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
- echo wp_kses_post( 'By clicking on ' . apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ) . ', you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.', 'woocommerce-paypal-payments' );
+ echo wp_kses_post(
+ 'By clicking on ' . $button_text . ', you agree to the
terms of payment and
performance of a risk check from the payment partner, Ratepay. You also agree to PayPal’s
privacy statement . If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.'
+ );
}
echo '
';
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
index 88b23eef3..3581d61b3 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -23,9 +23,16 @@ class PaymentSourceFactory {
* @return PaymentSource
*/
public function from_wc_order( WC_Order $order ) {
- $address = $order->get_address();
- $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
- $phone_country_code = WC()->countries->get_country_calling_code( $address['country'] ?? '' );
+ $address = $order->get_address();
+ $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING ) ?? '';
+
+ $phone_country_code = WC()->countries->get_country_calling_code( $address['country'] );
+ $phone_country_code = is_array( $phone_country_code ) && ! empty( $phone_country_code ) ? $phone_country_code[0] : $phone_country_code;
+ if ( is_string( $phone_country_code ) && '' !== $phone_country_code ) {
+ $phone_country_code = substr( $phone_country_code, strlen( '+' ) ) ?: '';
+ } else {
+ $phone_country_code = '';
+ }
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
$merchant_name = $gateway_settings['brand_name'] ?? '';
@@ -36,9 +43,9 @@ class PaymentSourceFactory {
$address['first_name'] ?? '',
$address['last_name'] ?? '',
$address['email'] ?? '',
- $birth_date ?? '',
- preg_replace( '/[^0-9]/', '', $address['phone'] ),
- substr( $phone_country_code, strlen( '+' ) ) ?? '',
+ (string) $birth_date,
+ preg_replace( '/[^0-9]/', '', $address['phone'] ) ?? '',
+ $phone_country_code,
$address['address_1'] ?? '',
$address['city'] ?? '',
$address['postcode'] ?? '',
From e8468332029147146a39c694c9e79159b008f051 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 19 Apr 2022 12:41:13 +0200
Subject: [PATCH 053/163] Fix phpcs
---
.../src/Gateway/PayUponInvoice/OrderEndpoint.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
index 4d0ce2e23..36f91615c 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
@@ -124,7 +124,7 @@ class OrderEndpoint {
);
$response = $this->request( $url, $args );
- if ( $response instanceof WP_Error ) {
+ if ( $response instanceof WP_Error ) {
throw new RuntimeException( $response->get_error_message() );
}
From a2fad9da529e8b456c15a12cbbada007a46872e0 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 19 Apr 2022 14:54:07 +0200
Subject: [PATCH 054/163] Refactor fraudnet config json generation
---
.../src/Endpoint/PayUponInvoiceEndpoint.php | 2 +-
.../Gateway/PayUponInvoice/PayUponInvoice.php | 27 +++++++++++++++++--
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
index 6700236df..1793f84c8 100644
--- a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
+++ b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
@@ -65,7 +65,7 @@ class PayUponInvoiceEndpoint implements EndpointInterface {
}
/**
- * * Handles the request.
+ * Handles the request.
*
* @return bool
* @throws NotFoundException When order not found or handling failed.
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 39d3401e2..437d54ec7 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -266,9 +266,8 @@ class PayUponInvoice {
* Set configuration JSON for FraudNet integration.
*/
public function add_parameter_block(): void {
- $sandbox = $this->environment->current_environment_is( Environment::SANDBOX ) ? '"sandbox":true,' : '';
?>
-
+
true,
+ 'f' => $this->fraud_net->session_id(),
+ 's' => $this->fraud_net->source_website_id(),
+ );
+
+ if ( ! $this->environment->current_environment_is( Environment::SANDBOX ) ) {
+ unset( $config['sandbox'] );
+ }
+
+ $encoded = wp_json_encode( $config );
+ if ( false === $encoded ) {
+ return '';
+ }
+
+ return $encoded;
+ }
}
From 4dd322d6c57a8d48e9047ee49dc76fa82d03bf09 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 20 Apr 2022 12:07:31 +0200
Subject: [PATCH 055/163] Update version
---
readme.txt | 2 +-
woocommerce-paypal-payments.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/readme.txt b/readme.txt
index 11bc282df..5f8133d4e 100644
--- a/readme.txt
+++ b/readme.txt
@@ -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.8.0
+Stable tag: 1.9.0-test1
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php
index 366a441a0..548a5b726 100644
--- a/woocommerce-paypal-payments.php
+++ b/woocommerce-paypal-payments.php
@@ -3,7 +3,7 @@
* 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.8.0
+ * Version: 1.9.0-test1
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* License: GPL-2.0
From bd779531614e64ae56d48ee35e5a7d89becf64b2 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 21 Apr 2022 16:51:17 +0200
Subject: [PATCH 056/163] Refactoring
---
modules/ppcp-api-client/src/Entity/Item.php | 2 +-
modules/ppcp-onboarding/assets/js/onboarding.js | 2 +-
.../src/Render/OnboardingOptionsRenderer.php | 4 ++--
.../resources/js/pay-upon-invoice.js | 3 +++
modules/ppcp-wc-gateway/services.php | 3 ++-
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 14 ++++++++++++--
.../PayUponInvoice/PayUponInvoiceGateway.php | 6 ++++--
.../PayUponInvoice/PaymentSourceFactory.php | 6 +++---
8 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/modules/ppcp-api-client/src/Entity/Item.php b/modules/ppcp-api-client/src/Entity/Item.php
index 93576e86a..374c2efcb 100644
--- a/modules/ppcp-api-client/src/Entity/Item.php
+++ b/modules/ppcp-api-client/src/Entity/Item.php
@@ -69,7 +69,7 @@ class Item {
/**
* The tax rate.
*
- * @var float|int
+ * @var float
*/
protected $tax_rate;
diff --git a/modules/ppcp-onboarding/assets/js/onboarding.js b/modules/ppcp-onboarding/assets/js/onboarding.js
index 913c86d34..31dfe9745 100644
--- a/modules/ppcp-onboarding/assets/js/onboarding.js
+++ b/modules/ppcp-onboarding/assets/js/onboarding.js
@@ -72,7 +72,7 @@ const ppcp_onboarding = {
);
const onboard_pui = document.querySelector('#ppcp-onboarding-pui');
- onboard_pui.addEventListener('click', (event) => {
+ onboard_pui?.addEventListener('click', (event) => {
event.preventDefault();
buttons.forEach((element) => {
element.removeAttribute('href');
diff --git a/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php b/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php
index dc02c0d9d..0f970722f 100644
--- a/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php
+++ b/modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php
@@ -85,9 +85,9 @@ class OnboardingOptionsRenderer {
if ( $this->settings->has( 'ppcp-onboarding-pui' ) && $this->settings->get( 'ppcp-onboarding-pui' ) !== '1' ) {
$checked = '';
}
- return ' ' .
+ return ' ' .
__( 'Onboard with Pay Upon Invoice', 'woocommerce-paypal-payments' ) . '
- ';
+ ';
}
return '';
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index 50ed4d56f..d92151366 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -7,6 +7,9 @@ window.addEventListener('load', function() {
}
const fncls = document.querySelector("[fncls='fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99']");
+ if(!fncls) {
+ return;
+ }
const fncls_params = JSON.parse(fncls.textContent);
if(document.querySelector("[name='fraudnet-session-id']") !== null) {
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 241058a3e..f201d8964 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2193,7 +2193,8 @@ return array(
$container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
$container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'wcgateway.settings' ),
- $container->get( 'onboarding.environment' )
+ $container->get( 'onboarding.environment' ),
+ $container->get( 'ppcp.asset-version' )
);
},
'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 437d54ec7..673cbc095 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -64,6 +64,13 @@ class PayUponInvoice {
*/
protected $environment;
+ /**
+ * The asset version.
+ *
+ * @var string
+ */
+ protected $asset_version;
+
/**
* PayUponInvoice constructor.
*
@@ -73,6 +80,7 @@ class PayUponInvoice {
* @param LoggerInterface $logger The logger.
* @param Settings $settings The settings.
* @param Environment $environment The environment.
+ * @param string $asset_version The asset version.
*/
public function __construct(
string $module_url,
@@ -80,7 +88,8 @@ class PayUponInvoice {
OrderEndpoint $order_endpoint,
LoggerInterface $logger,
Settings $settings,
- Environment $environment
+ Environment $environment,
+ string $asset_version
) {
$this->module_url = $module_url;
$this->fraud_net = $fraud_net;
@@ -88,6 +97,7 @@ class PayUponInvoice {
$this->logger = $logger;
$this->settings = $settings;
$this->environment = $environment;
+ $this->asset_version = $asset_version;
}
/**
@@ -281,7 +291,7 @@ class PayUponInvoice {
'ppcp-pay-upon-invoice',
trailingslashit( $this->module_url ) . 'assets/js/pay-upon-invoice.js',
array(),
- '1'
+ $this->asset_version
);
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 375ddbf46..0f69765b7 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -170,8 +170,10 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$wc_order = wc_get_order( $order_id );
$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 );
+ $purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
+
+ $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING ) ?? '';
+ $payment_source = $this->payment_source_factory->from_wc_order( $wc_order, $birth_date );
try {
$fraudnet_session_id = filter_input( INPUT_POST, 'fraudnet-session-id', FILTER_SANITIZE_STRING ) ?? '';
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
index 3581d61b3..5fd42e99d 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -20,11 +20,11 @@ class PaymentSourceFactory {
* Create a PUI payment source from a WC order.
*
* @param WC_Order $order The WC order.
+ * @param string $birth_date The birth date.
* @return PaymentSource
*/
- public function from_wc_order( WC_Order $order ) {
- $address = $order->get_address();
- $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING ) ?? '';
+ public function from_wc_order( WC_Order $order, string $birth_date ) {
+ $address = $order->get_address();
$phone_country_code = WC()->countries->get_country_calling_code( $address['country'] );
$phone_country_code = is_array( $phone_country_code ) && ! empty( $phone_country_code ) ? $phone_country_code[0] : $phone_country_code;
From 1082094e37288f7485343148d6f3149c726aab0d Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 21 Apr 2022 17:02:19 +0200
Subject: [PATCH 057/163] Fix psalm
---
.../src/Gateway/PayUponInvoice/PaymentSourceFactory.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
index 5fd42e99d..d4dc82562 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php
@@ -43,7 +43,7 @@ class PaymentSourceFactory {
$address['first_name'] ?? '',
$address['last_name'] ?? '',
$address['email'] ?? '',
- (string) $birth_date,
+ $birth_date,
preg_replace( '/[^0-9]/', '', $address['phone'] ) ?? '',
$phone_country_code,
$address['address_1'] ?? '',
From c7cf9bc3e9aaf52b3286c99c3428fd1106d5b077 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 22 Apr 2022 11:49:30 +0200
Subject: [PATCH 058/163] Add unit tests
---
.../Endpoint/PayUponInvoiceOrderEndpoint.php} | 2 +-
.../ppcp-compat/src/PPEC/DeactivateNote.php | 2 +-
modules/ppcp-wc-gateway/services.php | 6 +-
.../Gateway/PayUponInvoice/PayUponInvoice.php | 6 +-
.../PayUponInvoice/PayUponInvoiceGateway.php | 6 +-
.../PayUponInvoiceGatewayTest.php | 122 ++++++++++++++++++
6 files changed, 133 insertions(+), 11 deletions(-)
rename modules/{ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php => ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php} (99%)
create mode 100644 tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
similarity index 99%
rename from modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
rename to modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
index 36f91615c..c6784530a 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/OrderEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
@@ -22,7 +22,7 @@ use WP_Error;
/**
* Class OrderEndpoint.
*/
-class OrderEndpoint {
+class PayUponInvoiceOrderEndpoint {
use RequestTrait;
diff --git a/modules/ppcp-compat/src/PPEC/DeactivateNote.php b/modules/ppcp-compat/src/PPEC/DeactivateNote.php
index 07e0dbe1b..9ced83d22 100644
--- a/modules/ppcp-compat/src/PPEC/DeactivateNote.php
+++ b/modules/ppcp-compat/src/PPEC/DeactivateNote.php
@@ -18,7 +18,7 @@ use Automattic\WooCommerce\Admin\Notes\NoteTraits;
*/
class DeactivateNote {
- use NoteTraits;
+ //use NoteTraits;
/**
* Name of the note for use in the database.
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index f201d8964..df6c13ac9 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -32,7 +32,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSessionId;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSourceWebsiteId;
-use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\OrderEndpoint;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSourceFactory;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
@@ -2151,8 +2151,8 @@ return array(
$container->get( 'wcgateway.settings' )
);
},
- 'wcgateway.pay-upon-invoice-order-endpoint' => static function ( ContainerInterface $container ): OrderEndpoint {
- return new OrderEndpoint(
+ 'wcgateway.pay-upon-invoice-order-endpoint' => static function ( ContainerInterface $container ): PayUponInvoiceOrderEndpoint {
+ return new PayUponInvoiceOrderEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'api.factory.order' ),
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 673cbc095..7f5275827 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -39,7 +39,7 @@ class PayUponInvoice {
/**
* The order endpoint.
*
- * @var OrderEndpoint
+ * @var PayUponInvoiceOrderEndpoint
*/
protected $order_endpoint;
@@ -76,7 +76,7 @@ class PayUponInvoice {
*
* @param string $module_url The module URL.
* @param FraudNet $fraud_net The FraudNet entity.
- * @param OrderEndpoint $order_endpoint The order endpoint.
+ * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint.
* @param LoggerInterface $logger The logger.
* @param Settings $settings The settings.
* @param Environment $environment The environment.
@@ -85,7 +85,7 @@ class PayUponInvoice {
public function __construct(
string $module_url,
FraudNet $fraud_net,
- OrderEndpoint $order_endpoint,
+ PayUponInvoiceOrderEndpoint $order_endpoint,
LoggerInterface $logger,
Settings $settings,
Environment $environment,
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 0f69765b7..926e45dcc 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -29,7 +29,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
/**
* The order endpoint.
*
- * @var OrderEndpoint
+ * @var PayUponInvoiceOrderEndpoint
*/
protected $order_endpoint;
@@ -64,14 +64,14 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
/**
* PayUponInvoiceGateway constructor.
*
- * @param OrderEndpoint $order_endpoint The order endpoint.
+ * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint.
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
* @param PaymentSourceFactory $payment_source_factory The payment source factory.
* @param Environment $environment The environment.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
- OrderEndpoint $order_endpoint,
+ PayUponInvoiceOrderEndpoint $order_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
PaymentSourceFactory $payment_source_factory,
Environment $environment,
diff --git a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
new file mode 100644
index 000000000..00ad76c5e
--- /dev/null
+++ b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
@@ -0,0 +1,122 @@
+order_endpoint = Mockery::mock(PayUponInvoiceOrderEndpoint::class);
+ $this->purchase_unit_factory = Mockery::mock(PurchaseUnitFactory::class);
+ $this->payment_source_factory = Mockery::mock(PaymentSourceFactory::class);
+ $this->environment = Mockery::mock(Environment::class);
+ $this->logger = Mockery::mock(LoggerInterface::class);
+
+ $this->setInitStubs();
+
+ $this->testee = new PayUponInvoiceGateway(
+ $this->order_endpoint,
+ $this->purchase_unit_factory,
+ $this->payment_source_factory,
+ $this->environment,
+ $this->logger
+ );
+ }
+
+ public function testProcessPayment()
+ {
+ list($order, $purchase_unit, $payment_source) = $this->setTestStubs();
+
+ $this->order_endpoint->shouldReceive('create')->with(
+ [$purchase_unit],
+ $payment_source,
+ ''
+ )->andReturn($order);
+
+ $result = $this->testee->process_payment(1);
+ $this->assertEquals('success', $result['result']);
+ }
+
+ public function testProcessPaymentError()
+ {
+ list($order, $purchase_unit, $payment_source) = $this->setTestStubs();
+
+ $this->logger->shouldReceive('error');
+ when('wc_add_notice')->justReturn();
+ when('wc_get_checkout_url')->justReturn();
+
+ $this->order_endpoint->shouldReceive('create')->with(
+ [$purchase_unit],
+ $payment_source,
+ ''
+ )->andThrows(\RuntimeException::class);
+
+ $result = $this->testee->process_payment(1);
+ $this->assertEquals('failure', $result['result']);
+ }
+
+ private function setInitStubs(): void
+ {
+ when('get_option')->justReturn([
+ 'title' => 'foo',
+ 'description' => 'bar',
+ ]);
+ when('get_bloginfo')->justReturn('Foo');
+
+ $woocommerce = Mockery::mock(\WooCommerce::class);
+ $cart = Mockery::mock(\WC_Cart::class);
+ when('WC')->justReturn($woocommerce);
+ $woocommerce->cart = $cart;
+ $cart->shouldReceive('empty_cart');
+ }
+
+ /**
+ * @return array
+ */
+ private function setTestStubs(): array
+ {
+ $wcOrder = Mockery::mock(WC_Order::class);
+ $wcOrder->shouldReceive('update_meta_data');
+ $wcOrder->shouldReceive('update_status');
+ when('wc_get_order')->justReturn($wcOrder);
+
+ $order = Mockery::mock(Order::class);
+ $order->shouldReceive('id')->andReturn('1');
+ $order->shouldReceive('intent')->andReturn('CAPTURE');
+
+ $purchase_unit = Mockery::mock(PurchaseUnit::class);
+ $payment_source = Mockery::mock(PaymentSource::class);
+
+ $this->payment_source_factory->shouldReceive('from_wc_order')
+ ->with($wcOrder, '')
+ ->andReturn($payment_source);
+
+ $this->purchase_unit_factory->shouldReceive('from_wc_order')
+ ->with($wcOrder)
+ ->andReturn($purchase_unit);
+
+ $this->environment->shouldReceive('current_environment_is')->andReturn(true);
+
+ return array($order, $purchase_unit, $payment_source);
+ }
+}
From 63c3c095bbb95eaa9ebd1a72c84d9ce92cededb2 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 22 Apr 2022 11:50:33 +0200
Subject: [PATCH 059/163] Remove comment for testing
---
modules/ppcp-compat/src/PPEC/DeactivateNote.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-compat/src/PPEC/DeactivateNote.php b/modules/ppcp-compat/src/PPEC/DeactivateNote.php
index 9ced83d22..07e0dbe1b 100644
--- a/modules/ppcp-compat/src/PPEC/DeactivateNote.php
+++ b/modules/ppcp-compat/src/PPEC/DeactivateNote.php
@@ -18,7 +18,7 @@ use Automattic\WooCommerce\Admin\Notes\NoteTraits;
*/
class DeactivateNote {
- //use NoteTraits;
+ use NoteTraits;
/**
* Name of the note for use in the database.
From 0f93759c9c0cb6037e9f0f3bf07c83c0f52a471c Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 22 Apr 2022 12:19:55 +0200
Subject: [PATCH 060/163] Do not display pui tab if wc store is not is germany
---
.../Endpoint/PayUponInvoiceOrderEndpoint.php | 3 ++-
modules/ppcp-wc-gateway/services.php | 11 ++++++++---
.../src/Gateway/PayPalGateway.php | 17 +++++++++++++++--
.../Gateway/PayUponInvoice/PayUponInvoice.php | 15 ++++++++-------
.../PayUponInvoice/PayUponInvoiceGateway.php | 11 ++++++-----
.../src/Settings/SectionsRenderer.php | 17 +++++++++++++++--
6 files changed, 54 insertions(+), 20 deletions(-)
diff --git a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
index c6784530a..44da8ce85 100644
--- a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
@@ -7,7 +7,7 @@
declare(strict_types=1);
-namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
+namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
use Psr\Log\LoggerInterface;
use RuntimeException;
@@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet;
use WP_Error;
/**
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index df6c13ac9..8255510e6 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway;
use Psr\Container\ContainerInterface;
+use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
@@ -32,7 +33,6 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSessionId;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSourceWebsiteId;
-use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSourceFactory;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
@@ -69,6 +69,7 @@ return array(
$order_endpoint = $container->get( 'api.endpoint.order' );
$environment = $container->get( 'onboarding.environment' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
+ $api_shop_country = $container->get( 'api.shop.country' );
return new PayPalGateway(
$settings_renderer,
$funding_source_renderer,
@@ -85,7 +86,8 @@ return array(
$payment_token_repository,
$logger,
$payments_endpoint,
- $order_endpoint
+ $order_endpoint,
+ $api_shop_country
);
},
'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
@@ -177,7 +179,10 @@ return array(
return new AuthorizeOrderActionNotice();
},
'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
- return new SectionsRenderer( $container->get( 'wcgateway.current-ppcp-settings-page-id' ) );
+ return new SectionsRenderer(
+ $container->get( 'wcgateway.current-ppcp-settings-page-id' ),
+ $container->get( 'api.shop.country' )
+ );
},
'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus {
$settings = $container->get( 'wcgateway.settings' );
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
index fe28aeafc..ccae4d6ed 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
@@ -12,7 +12,6 @@ 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\Entity\CaptureStatus;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
@@ -159,6 +158,13 @@ class PayPalGateway extends \WC_Payment_Gateway {
*/
private $logger;
+ /**
+ * The api shop country.
+ *
+ * @var string
+ */
+ protected $api_shop_country;
+
/**
* PayPalGateway constructor.
*
@@ -178,6 +184,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
* @param LoggerInterface $logger The logger.
* @param PaymentsEndpoint $payments_endpoint The payments endpoint.
* @param OrderEndpoint $order_endpoint The order endpoint.
+ * @param string $api_shop_country The api shop country.
*/
public function __construct(
SettingsRenderer $settings_renderer,
@@ -195,7 +202,8 @@ class PayPalGateway extends \WC_Payment_Gateway {
PaymentTokenRepository $payment_token_repository,
LoggerInterface $logger,
PaymentsEndpoint $payments_endpoint,
- OrderEndpoint $order_endpoint
+ OrderEndpoint $order_endpoint,
+ string $api_shop_country
) {
$this->id = self::ID;
@@ -276,6 +284,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
$this->payments_endpoint = $payments_endpoint;
$this->order_endpoint = $order_endpoint;
$this->state = $state;
+ $this->api_shop_country = $api_shop_country;
}
/**
@@ -399,6 +408,10 @@ class PayPalGateway extends \WC_Payment_Gateway {
* @return bool
*/
private function is_pui_tab():bool {
+ if ( 'DE' !== $this->api_shop_country ) {
+ return false;
+ }
+
return is_admin() && PayUponInvoiceGateway::ID === $this->page_id;
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 7f5275827..7cb86acf9 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use WC_Order;
+use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
@@ -74,13 +75,13 @@ class PayUponInvoice {
/**
* PayUponInvoice constructor.
*
- * @param string $module_url The module URL.
- * @param FraudNet $fraud_net The FraudNet entity.
- * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint.
- * @param LoggerInterface $logger The logger.
- * @param Settings $settings The settings.
- * @param Environment $environment The environment.
- * @param string $asset_version The asset version.
+ * @param string $module_url The module URL.
+ * @param FraudNet $fraud_net The FraudNet entity.
+ * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint.
+ * @param LoggerInterface $logger The logger.
+ * @param Settings $settings The settings.
+ * @param Environment $environment The environment.
+ * @param string $asset_version The asset version.
*/
public function __construct(
string $module_url,
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 926e45dcc..8acc0a358 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use RuntimeException;
use WC_Payment_Gateway;
+use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
@@ -64,11 +65,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
/**
* PayUponInvoiceGateway constructor.
*
- * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint.
- * @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
- * @param PaymentSourceFactory $payment_source_factory The payment source factory.
- * @param Environment $environment The environment.
- * @param LoggerInterface $logger The logger.
+ * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint.
+ * @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
+ * @param PaymentSourceFactory $payment_source_factory The payment source factory.
+ * @param Environment $environment The environment.
+ * @param LoggerInterface $logger The logger.
*/
public function __construct(
PayUponInvoiceOrderEndpoint $order_endpoint,
diff --git a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
index 72d70a7f0..049038e48 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
@@ -28,13 +28,22 @@ class SectionsRenderer {
*/
protected $page_id;
+ /**
+ * The api shop country.
+ *
+ * @var string
+ */
+ protected $api_shop_country;
+
/**
* SectionsRenderer constructor.
*
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
+ * @param string $api_shop_country The api shop country.
*/
- public function __construct( string $page_id ) {
- $this->page_id = $page_id;
+ public function __construct( string $page_id, string $api_shop_country ) {
+ $this->page_id = $page_id;
+ $this->api_shop_country = $api_shop_country;
}
/**
@@ -61,6 +70,10 @@ class SectionsRenderer {
WebhooksStatusPage::ID => __( 'Webhooks Status', 'woocommerce-paypal-payments' ),
);
+ if ( 'DE' !== $this->api_shop_country ) {
+ unset( $sections[ PayUponInvoiceGateway::ID ] );
+ }
+
echo '';
$array_keys = array_keys( $sections );
From cf0d7858fdfe1ad172dc56d44d820d07dcda0399 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 22 Apr 2022 15:21:00 +0200
Subject: [PATCH 061/163] Add unit tests
---
.../Endpoint/PayUponInvoiceOrderEndpoint.php | 1 +
.../PayUponInvoiceOrderEndpointTest.php | 143 ++++++++++++++++++
2 files changed, 144 insertions(+)
create mode 100644 tests/PHPUnit/ApiClient/Endpoint/PayUponInvoiceOrderEndpointTest.php
diff --git a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
index 44da8ce85..125430f8e 100644
--- a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
@@ -18,6 +18,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSource;
use WP_Error;
/**
diff --git a/tests/PHPUnit/ApiClient/Endpoint/PayUponInvoiceOrderEndpointTest.php b/tests/PHPUnit/ApiClient/Endpoint/PayUponInvoiceOrderEndpointTest.php
new file mode 100644
index 000000000..83b2dd362
--- /dev/null
+++ b/tests/PHPUnit/ApiClient/Endpoint/PayUponInvoiceOrderEndpointTest.php
@@ -0,0 +1,143 @@
+bearer = Mockery::mock(Bearer::class);
+ $token = Mockery::mock(Token::class);
+ $token->shouldReceive('token')->andReturn('');
+ $this->bearer->shouldReceive('bearer')->andReturn($token);
+
+ $this->orderFactory = Mockery::mock(OrderFactory::class);
+ $this->fraudnet = Mockery::mock(FraudNet::class);
+ $this->logger = Mockery::mock(LoggerInterface::class);
+
+ $this->testee = new PayUponInvoiceOrderEndpoint(
+ '',
+ $this->bearer,
+ $this->orderFactory,
+ $this->fraudnet,
+ $this->logger
+ );
+ }
+
+ public function testCreateOrder()
+ {
+ list($items, $paymentSource, $headers) = $this->setStubs();
+
+ $response = [
+ 'body' => '{"is_correct":true}',
+ 'headers' => $headers,
+ ];
+ expect('wp_remote_get')->andReturn($response);
+ expect('wp_remote_retrieve_response_code')->with($response)->andReturn(200);
+
+ $this->logger->shouldReceive('debug');
+
+ $result = $this->testee->create($items, $paymentSource, '');
+ $this->assertInstanceOf(Order::class, $result);
+ }
+
+ public function testCreateOrderWpError()
+ {
+ list($items, $paymentSource) = $this->setStubsForError();
+
+ $wpError = Mockery::mock(\WP_Error::class);
+ $wpError->shouldReceive('get_error_messages')->andReturn(['foo']);
+ $wpError->shouldReceive('get_error_message')->andReturn('foo');
+ expect('wp_remote_get')->andReturn($wpError);
+
+ $this->logger->shouldReceive('debug');
+
+ $this->expectException(\RuntimeException::class);
+ $this->testee->create($items, $paymentSource, '');
+ }
+
+ public function testCreateOrderApiError()
+ {
+ list($items, $paymentSource) = $this->setStubsForError();
+
+ $headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
+ $headers->shouldReceive('getAll');
+ $response = [
+ 'body' => '{"is_correct":true}',
+ 'headers' => $headers,
+ ];
+
+ when('get_bloginfo')->justReturn('de-DE');
+ expect('wp_remote_get')->andReturn($response);
+ expect('wp_remote_retrieve_response_code')->with($response)->andReturn(500);
+
+ $this->logger->shouldReceive('debug');
+
+ $this->expectException(PayPalApiException::class);
+ $this->testee->create($items, $paymentSource, '');
+ }
+
+ /**
+ * @return array
+ */
+ private function setStubs(): array
+ {
+ $order = Mockery::mock(Order::class);
+ $this->orderFactory
+ ->expects('from_paypal_response')
+ ->andReturnUsing(function (\stdClass $object) use ($order): ?Order {
+ return ($object->is_correct) ? $order : null;
+ });
+
+ $this->fraudnet->shouldReceive('session_id')->andReturn('');
+
+ $purchaseUnit = Mockery::mock(PurchaseUnit::class);
+ $purchaseUnit->shouldReceive('to_array')->andReturn([]);
+ $items = [$purchaseUnit];
+
+ $paymentSource = Mockery::mock(PaymentSource::class);
+ $paymentSource->shouldReceive('to_array')->andReturn([]);
+
+ $headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
+ $headers->shouldReceive('getAll');
+ return array($items, $paymentSource, $headers);
+ }
+
+ /**
+ * @return array
+ */
+ private function setStubsForError(): array
+ {
+ $this->fraudnet->shouldReceive('session_id')->andReturn('');
+ $purchaseUnit = Mockery::mock(PurchaseUnit::class);
+ $purchaseUnit->shouldReceive('to_array')->andReturn([]);
+ $items = [$purchaseUnit];
+ $paymentSource = Mockery::mock(PaymentSource::class);
+ $paymentSource->shouldReceive('to_array')->andReturn([]);
+ return array($items, $paymentSource);
+ }
+}
From 56f12ed853cb39ca54149519ab702fea7901c34e Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 22 Apr 2022 15:26:44 +0200
Subject: [PATCH 062/163] Fix unit tests
---
.../Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php | 1 +
tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php | 6 ++++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
index 00ad76c5e..faf1fbb6f 100644
--- a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
+++ b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
@@ -6,6 +6,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Mockery;
use Psr\Log\LoggerInterface;
use WC_Order;
+use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
diff --git a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php
index c55220ba3..f410e0b16 100644
--- a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php
+++ b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php
@@ -47,6 +47,7 @@ class WcGatewayTest extends TestCase
private $logger;
private $paymentsEndpoint;
private $orderEndpoint;
+ private $apiShopCountry;
public function setUp(): void {
parent::setUp();
@@ -70,6 +71,7 @@ class WcGatewayTest extends TestCase
$this->paymentsEndpoint = Mockery::mock(PaymentsEndpoint::class);
$this->orderEndpoint = Mockery::mock(OrderEndpoint::class);
$this->funding_source_renderer = new FundingSourceRenderer($this->settings);
+ $this->apiShopCountry = 'DE';
$this->onboardingState->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
@@ -102,7 +104,8 @@ class WcGatewayTest extends TestCase
$this->paymentTokenRepository,
$this->logger,
$this->paymentsEndpoint,
- $this->orderEndpoint
+ $this->orderEndpoint,
+ $this->apiShopCountry
);
}
@@ -135,7 +138,6 @@ class WcGatewayTest extends TestCase
->with($orderId)
->andReturn($wcOrder);
-
when('wc_get_checkout_url')
->justReturn('test');
From b5f63b9f47e0b46e58876a242155ff7eb7e17a53 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 25 Apr 2022 14:31:43 +0200
Subject: [PATCH 063/163] Inject json config and retrigger fraudnet
---
.../Endpoint/PayUponInvoiceOrderEndpoint.php | 5 +-
.../resources/js/pay-upon-invoice.js | 49 +++++++++++--------
.../Gateway/PayUponInvoice/PayUponInvoice.php | 47 ++++--------------
.../PayUponInvoice/PayUponInvoiceGateway.php | 4 +-
4 files changed, 41 insertions(+), 64 deletions(-)
diff --git a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
index 125430f8e..c7961b147 100644
--- a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
@@ -91,12 +91,11 @@ class PayUponInvoiceOrderEndpoint {
*
* @param PurchaseUnit[] $items The purchase unit items for the order.
* @param PaymentSource $payment_source The payment source.
- * @param string $fraudnet_session_id The FrauNet session ID.
* @return Order
* @throws RuntimeException When there is a problem with the payment source.
* @throws PayPalApiException When there is a problem creating the order.
*/
- public function create( array $items, PaymentSource $payment_source, $fraudnet_session_id = '' ): Order {
+ public function create( array $items, PaymentSource $payment_source ): Order {
$data = array(
'intent' => 'CAPTURE',
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@@ -119,7 +118,7 @@ class PayUponInvoiceOrderEndpoint {
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation',
- 'PayPal-Client-Metadata-Id' => $fraudnet_session_id ?: $this->fraudnet->session_id(),
+ 'PayPal-Client-Metadata-Id' => $this->fraudnet->session_id(),
'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
),
'body' => wp_json_encode( $data ),
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index d92151366..4efb00cb1 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -1,34 +1,43 @@
window.addEventListener('load', function() {
- const getSessionIdFromJson = () => {
- const form = document.querySelector('form.checkout');
- if(!form) {
- return;
+ function _loadBeaconJS(options) {
+ var script = document.createElement('script');
+ script.src = options.fnUrl;
+ document.body.appendChild(script);
+ }
+
+ function _injectConfig() {
+ var script = document.querySelector("[fncls='fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99']");
+ if (script) {
+ if (script.parentNode) {
+ script.parentNode.removeChild(script);
+ }
}
- const fncls = document.querySelector("[fncls='fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99']");
- if(!fncls) {
- return;
- }
- const fncls_params = JSON.parse(fncls.textContent);
+ script = document.createElement('script');
+ script.id = 'fconfig';
+ script.type = 'application/json';
+ script.setAttribute('fncls', 'fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99');
- if(document.querySelector("[name='fraudnet-session-id']") !== null) {
- document.querySelector("[name='fraudnet-session-id']").remove();
- }
+ var configuration = {
+ 'f': FraudNetConfig.f,
+ 's': FraudNetConfig.s
+ };
- const fraudnetSessionId = document.createElement('input');
- fraudnetSessionId.setAttribute('type', 'hidden');
- fraudnetSessionId.setAttribute('name', 'fraudnet-session-id');
- fraudnetSessionId.setAttribute('value', fncls_params.f);
+ script.text = JSON.stringify(configuration);
+ document.body.appendChild(script);
- form.appendChild(fraudnetSessionId);
- console.log(fncls_params)
+ _loadBeaconJS({fnUrl: "https://c.paypal.com/da/r/fb.js"})
}
document.addEventListener('hosted_fields_loaded', (event) => {
- getSessionIdFromJson();
+ if (PAYPAL.asyncData && typeof PAYPAL.asyncData.initAndCollect === 'function') {
+ PAYPAL.asyncData.initAndCollect()
+ }
+
+ _injectConfig();
});
- getSessionIdFromJson();
+ _injectConfig();
})
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 7cb86acf9..0efa289b6 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -123,11 +123,6 @@ class PayUponInvoice {
}
);
- add_action(
- 'wp_footer',
- array( $this, 'add_parameter_block' )
- );
-
add_action(
'wp_enqueue_scripts',
array( $this, 'register_assets' )
@@ -273,17 +268,6 @@ class PayUponInvoice {
);
}
- /**
- * Set configuration JSON for FraudNet integration.
- */
- public function add_parameter_block(): void {
- ?>
-
-
-
- asset_version
);
- }
- /**
- * Returns a configuration JSON string.
- *
- * @return string
- */
- private function fraudnet_configuration(): string {
- $config = array(
- 'sandbox' => true,
- 'f' => $this->fraud_net->session_id(),
- 's' => $this->fraud_net->source_website_id(),
+ wp_localize_script(
+ 'ppcp-pay-upon-invoice',
+ 'FraudNetConfig',
+ array(
+ 'f' => $this->fraud_net->session_id(),
+ 's' => $this->fraud_net->source_website_id(),
+ )
);
-
- if ( ! $this->environment->current_environment_is( Environment::SANDBOX ) ) {
- unset( $config['sandbox'] );
- }
-
- $encoded = wp_json_encode( $config );
- if ( false === $encoded ) {
- return '';
- }
-
- return $encoded;
}
+
+
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 8acc0a358..076caa260 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -177,9 +177,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$payment_source = $this->payment_source_factory->from_wc_order( $wc_order, $birth_date );
try {
- $fraudnet_session_id = filter_input( INPUT_POST, 'fraudnet-session-id', FILTER_SANITIZE_STRING ) ?? '';
-
- $order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source, $fraudnet_session_id );
+ $order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source );
$this->add_paypal_meta( $wc_order, $order, $this->environment );
WC()->cart->empty_cart();
From 6ad27c82b7243edf7a7faa8aa357bd8b87e2a9d6 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 25 Apr 2022 14:34:36 +0200
Subject: [PATCH 064/163] Fix phpunit test
---
.../Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
index faf1fbb6f..743308f22 100644
--- a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
+++ b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
@@ -50,8 +50,7 @@ class PayUponInvoiceGatewayTest extends TestCase
$this->order_endpoint->shouldReceive('create')->with(
[$purchase_unit],
- $payment_source,
- ''
+ $payment_source
)->andReturn($order);
$result = $this->testee->process_payment(1);
From acf7fa6d00fa809915ae89026c6673ad5237f325 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 25 Apr 2022 15:58:30 +0200
Subject: [PATCH 065/163] Add sandbox parameter to fraudnet json config
---
modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js | 3 +++
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 5 +++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index 4efb00cb1..1e73653b9 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -23,6 +23,9 @@ window.addEventListener('load', function() {
'f': FraudNetConfig.f,
's': FraudNetConfig.s
};
+ if(FraudNetConfig.sandbox === '1') {
+ configuration.sandbox = true;
+ }
script.text = JSON.stringify(configuration);
document.body.appendChild(script);
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 0efa289b6..92d4ea974 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -283,8 +283,9 @@ class PayUponInvoice {
'ppcp-pay-upon-invoice',
'FraudNetConfig',
array(
- 'f' => $this->fraud_net->session_id(),
- 's' => $this->fraud_net->source_website_id(),
+ 'f' => $this->fraud_net->session_id(),
+ 's' => $this->fraud_net->source_website_id(),
+ 'sandbox' => $this->environment->current_environment_is( Environment::SANDBOX ),
)
);
}
From ea3c13b59c8d135afebb106bd9935d6ea93509af Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 26 Apr 2022 12:36:41 +0200
Subject: [PATCH 066/163] Translate birth date manually
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 92d4ea974..9a5bb771a 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -205,13 +205,16 @@ class PayUponInvoice {
function( string $description, string $id ): string {
if ( PayUponInvoiceGateway::ID === $id ) {
ob_start();
+
+ $site_country_code = explode( '-', get_bloginfo( 'language' ) )[0] ?? '';
+
echo '';
woocommerce_form_field(
'billing_birth_date',
array(
'type' => 'date',
- 'label' => __( 'Birth date', 'woocommerce-paypal-payments' ),
+ 'label' => $site_country_code === 'de' ? 'Geburtsdatum' : 'Birth date',
'class' => array( 'form-row-wide' ),
'required' => true,
'clear' => true,
@@ -219,7 +222,6 @@ class PayUponInvoice {
);
echo '
';
- $site_country_code = explode( '-', get_bloginfo( 'language' ) )[0] ?? '';
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
$button_text = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) );
From 49781075545776c9b1344e5d7ba4d8f2d673954f Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 28 Apr 2022 11:02:00 +0200
Subject: [PATCH 067/163] Ensure purchase units contains tax rate and shipping
when creating the order
---
.../Endpoint/PayUponInvoiceOrderEndpoint.php | 48 +++++++++++++++++++
.../Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
.../PayUponInvoiceOrderEndpointTest.php | 8 +++-
.../PayUponInvoiceGatewayTest.php | 1 +
4 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
index c7961b147..833204602 100644
--- a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
@@ -96,6 +96,9 @@ class PayUponInvoiceOrderEndpoint {
* @throws PayPalApiException When there is a problem creating the order.
*/
public function create( array $items, PaymentSource $payment_source ): Order {
+
+ $a = 1;
+
$data = array(
'intent' => 'CAPTURE',
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@@ -110,6 +113,11 @@ class PayUponInvoiceOrderEndpoint {
),
);
+ $a = 1;
+
+ $data = $this->ensure_tax_rate( $data );
+ $data = $this->ensure_shipping( $data, $payment_source->to_array() );
+
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v2/checkout/orders';
$args = array(
@@ -191,4 +199,44 @@ class PayUponInvoiceOrderEndpoint {
$json->payment_source->pay_upon_invoice->deposit_bank_details,
);
}
+
+ /**
+ * Ensures items contains tax rate.
+ *
+ * @param array $data The data.
+ * @return array
+ */
+ private function ensure_tax_rate( array $data ): array {
+ $items_count = count( $data['purchase_units'][0]['items'] );
+
+ for ( $i = 0; $i < $items_count; $i++ ) {
+ if ( ! isset( $data['purchase_units'][0]['items'][ $i ]['tax_rate'] ) ) {
+ $data['purchase_units'][0]['items'][ $i ]['tax_rate'] = '0.00';
+ }
+ }
+
+ return $data;
+ }
+
+ /**
+ * Ensures purchase units contains shipping by using payment source data.
+ *
+ * @param array $data The data.
+ * @param array $payment_source The payment source.
+ * @return array
+ */
+ private function ensure_shipping( array $data, array $payment_source ): array {
+ if ( isset( $data['purchase_units'][0]['shipping'] ) ) {
+ return $data;
+ }
+
+ $given_name = $payment_source['name']['given_name'] ?? '';
+ $surname = $payment_source['name']['surname'] ?? '';
+ $address = $payment_source['billing_address'] ?? array();
+
+ $data['purchase_units'][0]['shipping']['name']['full_name'] = $given_name . ' ' . $surname;
+ $data['purchase_units'][0]['shipping']['address'] = $address;
+
+ return $data;
+ }
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 9a5bb771a..19fcaf9f7 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -214,7 +214,7 @@ class PayUponInvoice {
'billing_birth_date',
array(
'type' => 'date',
- 'label' => $site_country_code === 'de' ? 'Geburtsdatum' : 'Birth date',
+ 'label' => 'de' === $site_country_code ? 'Geburtsdatum' : 'Birth date',
'class' => array( 'form-row-wide' ),
'required' => true,
'clear' => true,
diff --git a/tests/PHPUnit/ApiClient/Endpoint/PayUponInvoiceOrderEndpointTest.php b/tests/PHPUnit/ApiClient/Endpoint/PayUponInvoiceOrderEndpointTest.php
index 83b2dd362..45c5f3ff3 100644
--- a/tests/PHPUnit/ApiClient/Endpoint/PayUponInvoiceOrderEndpointTest.php
+++ b/tests/PHPUnit/ApiClient/Endpoint/PayUponInvoiceOrderEndpointTest.php
@@ -116,7 +116,9 @@ class PayUponInvoiceOrderEndpointTest extends TestCase
$this->fraudnet->shouldReceive('session_id')->andReturn('');
$purchaseUnit = Mockery::mock(PurchaseUnit::class);
- $purchaseUnit->shouldReceive('to_array')->andReturn([]);
+ $purchaseUnit->shouldReceive('to_array')->andReturn([
+ 'items' => [],
+ ]);
$items = [$purchaseUnit];
$paymentSource = Mockery::mock(PaymentSource::class);
@@ -134,7 +136,9 @@ class PayUponInvoiceOrderEndpointTest extends TestCase
{
$this->fraudnet->shouldReceive('session_id')->andReturn('');
$purchaseUnit = Mockery::mock(PurchaseUnit::class);
- $purchaseUnit->shouldReceive('to_array')->andReturn([]);
+ $purchaseUnit->shouldReceive('to_array')->andReturn([
+ 'items' => [],
+ ]);
$items = [$purchaseUnit];
$paymentSource = Mockery::mock(PaymentSource::class);
$paymentSource->shouldReceive('to_array')->andReturn([]);
diff --git a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
index 743308f22..5b7db8899 100644
--- a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
+++ b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
@@ -103,6 +103,7 @@ class PayUponInvoiceGatewayTest extends TestCase
$order = Mockery::mock(Order::class);
$order->shouldReceive('id')->andReturn('1');
$order->shouldReceive('intent')->andReturn('CAPTURE');
+ $order->shouldReceive('payment_source')->andReturn('');
$purchase_unit = Mockery::mock(PurchaseUnit::class);
$payment_source = Mockery::mock(PaymentSource::class);
From 7dbb0e32c18d87ba014a0da7fb28ffff8142cbf2 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 28 Apr 2022 11:26:25 +0200
Subject: [PATCH 068/163] Fix psalm
---
.../src/Endpoint/PayUponInvoiceOrderEndpoint.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
index 833204602..6f5115669 100644
--- a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
@@ -234,8 +234,8 @@ class PayUponInvoiceOrderEndpoint {
$surname = $payment_source['name']['surname'] ?? '';
$address = $payment_source['billing_address'] ?? array();
- $data['purchase_units'][0]['shipping']['name']['full_name'] = $given_name . ' ' . $surname;
- $data['purchase_units'][0]['shipping']['address'] = $address;
+ $data['purchase_units'][0]['shipping']['name'] = array( 'full_name' => $given_name . ' ' . $surname );
+ $data['purchase_units'][0]['shipping']['address'] = $address;
return $data;
}
From df549b6dffa85c1b658df34ecd9d7339772d276e Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 3 May 2022 11:21:50 +0200
Subject: [PATCH 069/163] Remove testing variables
---
.../src/Endpoint/PayUponInvoiceOrderEndpoint.php | 4 ----
1 file changed, 4 deletions(-)
diff --git a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
index 6f5115669..23a330a67 100644
--- a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
@@ -97,8 +97,6 @@ class PayUponInvoiceOrderEndpoint {
*/
public function create( array $items, PaymentSource $payment_source ): Order {
- $a = 1;
-
$data = array(
'intent' => 'CAPTURE',
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
@@ -113,8 +111,6 @@ class PayUponInvoiceOrderEndpoint {
),
);
- $a = 1;
-
$data = $this->ensure_tax_rate( $data );
$data = $this->ensure_shipping( $data, $payment_source->to_array() );
From d064c257db576f5284899505e6e63212c7104c59 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 4 May 2022 09:44:15 +0200
Subject: [PATCH 070/163] Add scheduled action for checking payment captured
---
.../PayUponInvoice/PayUponInvoiceGateway.php | 8 ++++++++
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 16 ++++++++++++++++
.../PayUponInvoice/PayUponInvoiceGatewayTest.php | 3 +++
3 files changed, 27 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 076caa260..b153da161 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -180,6 +180,14 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source );
$this->add_paypal_meta( $wc_order, $order, $this->environment );
+ as_schedule_single_action(
+ time() + ( 5 * MINUTE_IN_SECONDS ),
+ 'woocommerce_paypal_payments_check_pui_payment_captured',
+ array(
+ 'order_id' => $order_id,
+ )
+ );
+
WC()->cart->empty_cart();
return array(
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 4fe5a43ca..f7f3ebbaf 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -194,6 +194,22 @@ class WCGatewayModule implements ModuleInterface {
}
}
);
+
+ add_action(
+ 'woocommerce_paypal_payments_check_pui_payment_captured',
+ function ( int $order_id ) {
+ $wc_order = wc_get_order( $order_id );
+ if ( ! is_a( $wc_order, WC_Order::class ) || $wc_order->get_status() !== 'on-hold' ) {
+ return;
+ }
+
+ $message = __(
+ 'Could not process order because PAYMENT.CAPTURE.COMPLETED webhook not received.',
+ 'woocommerce-paypal-payments'
+ );
+ $wc_order->update_status( 'failed', $message );
+ }
+ );
}
/**
diff --git a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
index 5b7db8899..4faabb68b 100644
--- a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
+++ b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
@@ -53,6 +53,9 @@ class PayUponInvoiceGatewayTest extends TestCase
$payment_source
)->andReturn($order);
+ define( 'MINUTE_IN_SECONDS', 60 );
+ when('as_schedule_single_action')->justReturn();
+
$result = $this->testee->process_payment(1);
$this->assertEquals('success', $result['result']);
}
From b9f56bba33d3a7fa47e3afa3b50c0ff0fd706f45 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 4 May 2022 11:17:56 +0200
Subject: [PATCH 071/163] Check if checkout is ready for pui
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 29 +++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 19fcaf9f7..6730bf322 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -260,8 +260,7 @@ class PayUponInvoice {
add_filter(
'woocommerce_available_payment_gateways',
function( array $methods ): array {
- $billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
- if ( $billing_country && 'DE' !== $billing_country ) {
+ if ( ! $this->is_checkout_ready_for_pui() ) {
unset( $methods[ PayUponInvoiceGateway::ID ] );
}
@@ -270,6 +269,32 @@ class PayUponInvoice {
);
}
+ /**
+ * Checks whether checkout is ready for PUI.
+ *
+ * @return bool
+ */
+ private function is_checkout_ready_for_pui(): bool {
+ $billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
+ if ( $billing_country && 'DE' !== $billing_country ) {
+ return false;
+ }
+
+ if ( 'EUR' !== get_woocommerce_currency() ) {
+ return false;
+ }
+
+ $cart = WC()->cart ?? null;
+ if ( $cart ) {
+ $cart_total = (int) WC()->cart->get_totals()['total'] ?? 0;
+ if ( $cart_total < 5 || $cart_total > 2500 ) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
/**
* Registers PUI assets.
*/
From a17a5566174caddbe71788bcb35d685f7a318829 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 4 May 2022 11:22:54 +0200
Subject: [PATCH 072/163] Fix psalm
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 6730bf322..3d8095862 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -286,7 +286,7 @@ class PayUponInvoice {
$cart = WC()->cart ?? null;
if ( $cart ) {
- $cart_total = (int) WC()->cart->get_totals()['total'] ?? 0;
+ $cart_total = (int) WC()->cart->get_totals()['total'];
if ( $cart_total < 5 || $cart_total > 2500 ) {
return false;
}
From eb2eb58a1ca2766ecafff2fc79036c41c8310ddc Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 4 May 2022 15:06:17 +0200
Subject: [PATCH 073/163] Update transaction id
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 52 ++++++++++++++-----
.../PayUponInvoice/PayUponInvoiceGateway.php | 34 ++++++++++--
2 files changed, 67 insertions(+), 19 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 19fcaf9f7..2faf5df38 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -11,9 +11,11 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use WC_Order;
+use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
+use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WP_Error;
@@ -23,6 +25,8 @@ use WP_Error;
*/
class PayUponInvoice {
+ use TransactionIdHandlingTrait;
+
/**
* The module URL.
*
@@ -38,11 +42,11 @@ class PayUponInvoice {
protected $fraud_net;
/**
- * The order endpoint.
+ * The pui order endpoint.
*
* @var PayUponInvoiceOrderEndpoint
*/
- protected $order_endpoint;
+ protected $pui_order_endpoint;
/**
* The logger.
@@ -72,33 +76,43 @@ class PayUponInvoice {
*/
protected $asset_version;
+ /**
+ * The order endpoint.
+ *
+ * @var OrderEndpoint
+ */
+ protected $order_endpoint;
+
/**
* PayUponInvoice constructor.
*
* @param string $module_url The module URL.
* @param FraudNet $fraud_net The FraudNet entity.
- * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint.
+ * @param PayUponInvoiceOrderEndpoint $pui_order_endpoint The PUI order endpoint.
* @param LoggerInterface $logger The logger.
* @param Settings $settings The settings.
* @param Environment $environment The environment.
* @param string $asset_version The asset version.
+ * @param OrderEndpoint $order_endpoint The order endpoint.
*/
public function __construct(
string $module_url,
FraudNet $fraud_net,
- PayUponInvoiceOrderEndpoint $order_endpoint,
+ PayUponInvoiceOrderEndpoint $pui_order_endpoint,
LoggerInterface $logger,
Settings $settings,
Environment $environment,
- string $asset_version
+ string $asset_version,
+ OrderEndpoint $order_endpoint
) {
- $this->module_url = $module_url;
- $this->fraud_net = $fraud_net;
- $this->order_endpoint = $order_endpoint;
- $this->logger = $logger;
- $this->settings = $settings;
- $this->environment = $environment;
- $this->asset_version = $asset_version;
+ $this->module_url = $module_url;
+ $this->fraud_net = $fraud_net;
+ $this->pui_order_endpoint = $pui_order_endpoint;
+ $this->logger = $logger;
+ $this->settings = $settings;
+ $this->environment = $environment;
+ $this->asset_version = $asset_version;
+ $this->order_endpoint = $order_endpoint;
}
/**
@@ -132,9 +146,19 @@ class PayUponInvoice {
'ppcp_payment_capture_completed_webhook_handler',
function ( WC_Order $wc_order, string $order_id ) {
try {
- $payment_instructions = $this->order_endpoint->order_payment_instructions( $order_id );
- $wc_order->update_meta_data( 'ppcp_ratepay_payment_instructions_payment_reference', $payment_instructions );
+ $order = $this->order_endpoint->order( $order_id );
+ $transaction_id = $this->get_paypal_order_transaction_id( $order );
+ if ( $transaction_id ) {
+ $this->update_transaction_id( $transaction_id, $wc_order );
+ }
+
+ $payment_instructions = $this->pui_order_endpoint->order_payment_instructions( $order_id );
+ $wc_order->update_meta_data(
+ 'ppcp_ratepay_payment_instructions_payment_reference',
+ $payment_instructions
+ );
$this->logger->info( "Ratepay payment instructions added to order #{$wc_order->get_id()}." );
+
} catch ( RuntimeException $exception ) {
$this->logger->error( $exception->getMessage() );
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index b153da161..f26deaece 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -11,11 +11,13 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use RuntimeException;
+use WC_Order;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait;
/**
@@ -55,6 +57,13 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
*/
protected $environment;
+ /**
+ * The transaction url provider.
+ *
+ * @var TransactionUrlProvider
+ */
+ protected $transaction_url_provider;
+
/**
* The logger interface.
*
@@ -76,6 +85,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
PurchaseUnitFactory $purchase_unit_factory,
PaymentSourceFactory $payment_source_factory,
Environment $environment,
+ TransactionUrlProvider $transaction_url_provider,
LoggerInterface $logger
) {
$this->id = self::ID;
@@ -98,11 +108,12 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
)
);
- $this->order_endpoint = $order_endpoint;
- $this->purchase_unit_factory = $purchase_unit_factory;
- $this->payment_source_factory = $payment_source_factory;
- $this->logger = $logger;
- $this->environment = $environment;
+ $this->order_endpoint = $order_endpoint;
+ $this->purchase_unit_factory = $purchase_unit_factory;
+ $this->payment_source_factory = $payment_source_factory;
+ $this->logger = $logger;
+ $this->environment = $environment;
+ $this->transaction_url_provider = $transaction_url_provider;
}
/**
@@ -223,4 +234,17 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
);
}
}
+
+ /**
+ * Return transaction url for this gateway and given order.
+ *
+ * @param WC_Order $order WC order to get transaction url by.
+ *
+ * @return string
+ */
+ public function get_transaction_url( $order ): string {
+ $this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base( $order );
+
+ return parent::get_transaction_url( $order );
+ }
}
From 0cedfffe7302ca2d579ea6185c9668cff7b2b387 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 4 May 2022 15:24:24 +0200
Subject: [PATCH 074/163] Fix phpunit
---
.../Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
index 4faabb68b..22e39ea66 100644
--- a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
+++ b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
@@ -12,6 +12,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\TestCase;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use function Brain\Monkey\Functions\when;
class PayUponInvoiceGatewayTest extends TestCase
@@ -20,6 +21,7 @@ class PayUponInvoiceGatewayTest extends TestCase
private $purchase_unit_factory;
private $payment_source_factory;
private $environment;
+ private $transaction_url_provider;
private $logger;
private $testee;
@@ -32,6 +34,7 @@ class PayUponInvoiceGatewayTest extends TestCase
$this->payment_source_factory = Mockery::mock(PaymentSourceFactory::class);
$this->environment = Mockery::mock(Environment::class);
$this->logger = Mockery::mock(LoggerInterface::class);
+ $this->transaction_url_provider = Mockery::mock(TransactionUrlProvider::class);
$this->setInitStubs();
@@ -40,6 +43,7 @@ class PayUponInvoiceGatewayTest extends TestCase
$this->purchase_unit_factory,
$this->payment_source_factory,
$this->environment,
+ $this->transaction_url_provider,
$this->logger
);
}
From 7e57c2ccc35689624799a5262f4ab7971d93c7a1 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 4 May 2022 16:04:02 +0200
Subject: [PATCH 075/163] Update transaction id
---
modules/ppcp-wc-gateway/services.php | 1 +
.../Gateway/PayUponInvoice/PayUponInvoice.php | 19 +------------------
.../src/Processor/OrderMetaTrait.php | 2 ++
3 files changed, 4 insertions(+), 18 deletions(-)
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 8255510e6..dffca2df2 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2174,6 +2174,7 @@ return array(
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.pay-upon-invoice-payment-source-factory' ),
$container->get( 'onboarding.environment' ),
+ $container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 2faf5df38..e4dafb9b4 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use WC_Order;
-use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
@@ -76,13 +75,6 @@ class PayUponInvoice {
*/
protected $asset_version;
- /**
- * The order endpoint.
- *
- * @var OrderEndpoint
- */
- protected $order_endpoint;
-
/**
* PayUponInvoice constructor.
*
@@ -93,7 +85,6 @@ class PayUponInvoice {
* @param Settings $settings The settings.
* @param Environment $environment The environment.
* @param string $asset_version The asset version.
- * @param OrderEndpoint $order_endpoint The order endpoint.
*/
public function __construct(
string $module_url,
@@ -102,8 +93,7 @@ class PayUponInvoice {
LoggerInterface $logger,
Settings $settings,
Environment $environment,
- string $asset_version,
- OrderEndpoint $order_endpoint
+ string $asset_version
) {
$this->module_url = $module_url;
$this->fraud_net = $fraud_net;
@@ -112,7 +102,6 @@ class PayUponInvoice {
$this->settings = $settings;
$this->environment = $environment;
$this->asset_version = $asset_version;
- $this->order_endpoint = $order_endpoint;
}
/**
@@ -146,12 +135,6 @@ class PayUponInvoice {
'ppcp_payment_capture_completed_webhook_handler',
function ( WC_Order $wc_order, string $order_id ) {
try {
- $order = $this->order_endpoint->order( $order_id );
- $transaction_id = $this->get_paypal_order_transaction_id( $order );
- if ( $transaction_id ) {
- $this->update_transaction_id( $transaction_id, $wc_order );
- }
-
$payment_instructions = $this->pui_order_endpoint->order_payment_instructions( $order_id );
$wc_order->update_meta_data(
'ppcp_ratepay_payment_instructions_payment_reference',
diff --git a/modules/ppcp-wc-gateway/src/Processor/OrderMetaTrait.php b/modules/ppcp-wc-gateway/src/Processor/OrderMetaTrait.php
index 4aad635a4..1992e60bb 100644
--- a/modules/ppcp-wc-gateway/src/Processor/OrderMetaTrait.php
+++ b/modules/ppcp-wc-gateway/src/Processor/OrderMetaTrait.php
@@ -41,6 +41,8 @@ trait OrderMetaTrait {
if ( $payment_source ) {
$wc_order->update_meta_data( PayPalGateway::ORDER_PAYMENT_SOURCE, $payment_source );
}
+
+ $wc_order->save();
}
/**
From 8e17e35987a0ec841ea9a808ebd6ad3f16a7e048 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 4 May 2022 16:27:56 +0200
Subject: [PATCH 076/163] Fix phpunit
---
tests/PHPUnit/Subscription/RenewalHandlerTest.php | 1 +
.../Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php | 1 +
tests/PHPUnit/WcGateway/Processor/OrderProcessorTest.php | 4 ++++
3 files changed, 6 insertions(+)
diff --git a/tests/PHPUnit/Subscription/RenewalHandlerTest.php b/tests/PHPUnit/Subscription/RenewalHandlerTest.php
index 9fa160612..036e8fd85 100644
--- a/tests/PHPUnit/Subscription/RenewalHandlerTest.php
+++ b/tests/PHPUnit/Subscription/RenewalHandlerTest.php
@@ -138,6 +138,7 @@ class RenewalHandlerTest extends TestCase
->andReturn($order);
$wcOrder->shouldReceive('update_status');
+ $wcOrder->shouldReceive('save');
$this->sut->renew($wcOrder);
}
diff --git a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
index 22e39ea66..5f22441f5 100644
--- a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
+++ b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
@@ -105,6 +105,7 @@ class PayUponInvoiceGatewayTest extends TestCase
$wcOrder = Mockery::mock(WC_Order::class);
$wcOrder->shouldReceive('update_meta_data');
$wcOrder->shouldReceive('update_status');
+ $wcOrder->shouldReceive('save');
when('wc_get_order')->justReturn($wcOrder);
$order = Mockery::mock(Order::class);
diff --git a/tests/PHPUnit/WcGateway/Processor/OrderProcessorTest.php b/tests/PHPUnit/WcGateway/Processor/OrderProcessorTest.php
index e379a4fc1..7555de565 100644
--- a/tests/PHPUnit/WcGateway/Processor/OrderProcessorTest.php
+++ b/tests/PHPUnit/WcGateway/Processor/OrderProcessorTest.php
@@ -159,6 +159,7 @@ class OrderProcessorTest extends TestCase
->with('on-hold', 'Awaiting payment.');
$wcOrder->expects('set_transaction_id')
->with($transactionId);
+ $wcOrder->shouldReceive('save');
$this->assertTrue($testee->process($wcOrder));
}
@@ -266,6 +267,8 @@ class OrderProcessorTest extends TestCase
->with($transactionId);
$wcOrder
->expects('payment_complete');
+ $wcOrder->shouldReceive('save');
+
$this->assertTrue($testee->process($wcOrder));
}
@@ -350,6 +353,7 @@ class OrderProcessorTest extends TestCase
PayPalGateway::INTENT_META_KEY,
$orderIntent
);
+ $wcOrder->shouldReceive('save');
$this->assertFalse($testee->process($wcOrder));
$this->assertNotEmpty($testee->last_error());
From 59551701e7a872aa322e6cf4d801601957c13566 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 4 May 2022 16:35:23 +0200
Subject: [PATCH 077/163] Use cart `get_total` and cast it as float
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 3d8095862..c873ae10a 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -286,7 +286,7 @@ class PayUponInvoice {
$cart = WC()->cart ?? null;
if ( $cart ) {
- $cart_total = (int) WC()->cart->get_totals()['total'];
+ $cart_total = (float) $cart->get_total( 'numeric' );
if ( $cart_total < 5 || $cart_total > 2500 ) {
return false;
}
From bc612dbb127b507e7011b06ca569fcc9f1e2df94 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 4 May 2022 16:59:20 +0200
Subject: [PATCH 078/163] Add product type check for pui checkout
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 6c2cb81d7..e2fbdc59e 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -297,6 +297,14 @@ class PayUponInvoice {
if ( $cart_total < 5 || $cart_total > 2500 ) {
return false;
}
+
+ $items = $cart->get_cart_contents();
+ foreach ( $items as $item ) {
+ $product = wc_get_product( $item['product_id'] );
+ if ( $product && ( $product->is_downloadable() || $product->is_virtual() ) ) {
+ return false;
+ }
+ }
}
return true;
From 49bc0f255c1f9eb90a3a5b1d6dcbd319ba2e1880 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 6 May 2022 17:03:10 +0200
Subject: [PATCH 079/163] Check seller product status for pui (WIP)
---
.../src/Endpoint/LoginSellerEndpoint.php | 1 +
.../src/OnboardingRESTController.php | 1 +
modules/ppcp-wc-gateway/services.php | 18 ++-
.../Gateway/PayUponInvoice/PayUponInvoice.php | 83 ++++++++++++--
.../Helper/PayUponInvoiceProductStatus.php | 106 ++++++++++++++++++
.../src/Settings/SettingsListener.php | 1 +
.../src/Settings/SettingsRenderer.php | 8 +-
.../ppcp-wc-gateway/src/WCGatewayModule.php | 5 +-
8 files changed, 201 insertions(+), 22 deletions(-)
create mode 100644 modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php
diff --git a/modules/ppcp-onboarding/src/Endpoint/LoginSellerEndpoint.php b/modules/ppcp-onboarding/src/Endpoint/LoginSellerEndpoint.php
index b254d6947..f01dbb99b 100644
--- a/modules/ppcp-onboarding/src/Endpoint/LoginSellerEndpoint.php
+++ b/modules/ppcp-onboarding/src/Endpoint/LoginSellerEndpoint.php
@@ -127,6 +127,7 @@ class LoginSellerEndpoint implements EndpointInterface {
$is_sandbox = isset( $data['env'] ) && 'sandbox' === $data['env'];
$this->settings->set( 'sandbox_on', $is_sandbox );
$this->settings->set( 'products_dcc_enabled', null );
+ $this->settings->set( 'products_pui_enabled', null );
$this->settings->persist();
$endpoint = $is_sandbox ? $this->login_seller_sandbox : $this->login_seller_production;
diff --git a/modules/ppcp-onboarding/src/OnboardingRESTController.php b/modules/ppcp-onboarding/src/OnboardingRESTController.php
index 58d506315..9fd59e473 100644
--- a/modules/ppcp-onboarding/src/OnboardingRESTController.php
+++ b/modules/ppcp-onboarding/src/OnboardingRESTController.php
@@ -236,6 +236,7 @@ class OnboardingRESTController {
}
$settings->set( 'products_dcc_enabled', null );
+ $settings->set( 'products_pui_enabled', null );
if ( ! $settings->persist() ) {
return new \WP_Error(
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index dffca2df2..515b018d9 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -37,7 +37,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSourceFac
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
-use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
@@ -2138,11 +2138,11 @@ return array(
return new TransactionUrlProvider( $sandbox_url_base, $live_url_base );
},
- 'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : DCCProductStatus {
+ 'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : PayUponInvoiceProductStatus {
$settings = $container->get( 'wcgateway.settings' );
$partner_endpoint = $container->get( 'api.endpoint.partners' );
- return new DCCProductStatus( $settings, $partner_endpoint );
+ return new PayUponInvoiceProductStatus( $settings, $partner_endpoint );
},
'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers {
@@ -2192,6 +2192,12 @@ return array(
(string) $source_website_id()
);
},
+ 'wcgateway.pay-upon-invoice-product-status' => static function(ContainerInterface $container): PayUponInvoiceProductStatus {
+ return new PayUponInvoiceProductStatus(
+ $container->get( 'wcgateway.settings' ),
+ $container->get( 'api.endpoint.partners' )
+ );
+ },
'wcgateway.pay-upon-invoice' => static function ( ContainerInterface $container ): PayUponInvoice {
return new PayUponInvoice(
$container->get( 'wcgateway.url' ),
@@ -2200,7 +2206,11 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'wcgateway.settings' ),
$container->get( 'onboarding.environment' ),
- $container->get( 'ppcp.asset-version' )
+ $container->get( 'ppcp.asset-version' ),
+ $container->get( 'onboarding.state' ),
+ $container->get('wcgateway.is-ppcp-settings-page'),
+ $container->get( 'wcgateway.current-ppcp-settings-page-id' ),
+ $container->get('wcgateway.pay-upon-invoice-product-status')
);
},
'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index e2fbdc59e..1146b37cd 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -14,6 +14,8 @@ use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
+use WooCommerce\PayPalCommerce\Onboarding\State;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
@@ -75,6 +77,34 @@ class PayUponInvoice {
*/
protected $asset_version;
+ /**
+ * The onboarding state.
+ *
+ * @var State
+ */
+ protected $state;
+
+ /**
+ * The is ppcp settings page.
+ *
+ * @var bool
+ */
+ protected $is_ppcp_settings_page;
+
+ /**
+ * Current PayPal settings page id.
+ *
+ * @var string
+ */
+ protected $current_ppcp_settings_page_id;
+
+ /**
+ * PUI seller product status.
+ *
+ * @var PayUponInvoiceProductStatus
+ */
+ protected $pui_product_status;
+
/**
* PayUponInvoice constructor.
*
@@ -85,6 +115,10 @@ class PayUponInvoice {
* @param Settings $settings The settings.
* @param Environment $environment The environment.
* @param string $asset_version The asset version.
+ * @param State $state The onboarding state.
+ * @param bool $is_ppcp_settings_page The is ppcp settings page.
+ * @param string $current_ppcp_settings_page_id Current PayPal settings page id.
+ * @param PayUponInvoiceProductStatus $pui_product_status PUI seller product status.
*/
public function __construct(
string $module_url,
@@ -93,15 +127,23 @@ class PayUponInvoice {
LoggerInterface $logger,
Settings $settings,
Environment $environment,
- string $asset_version
+ string $asset_version,
+ State $state,
+ bool $is_ppcp_settings_page,
+ string $current_ppcp_settings_page_id,
+ PayUponInvoiceProductStatus $pui_product_status
) {
- $this->module_url = $module_url;
- $this->fraud_net = $fraud_net;
- $this->pui_order_endpoint = $pui_order_endpoint;
- $this->logger = $logger;
- $this->settings = $settings;
- $this->environment = $environment;
- $this->asset_version = $asset_version;
+ $this->module_url = $module_url;
+ $this->fraud_net = $fraud_net;
+ $this->pui_order_endpoint = $pui_order_endpoint;
+ $this->logger = $logger;
+ $this->settings = $settings;
+ $this->environment = $environment;
+ $this->asset_version = $asset_version;
+ $this->state = $state;
+ $this->is_ppcp_settings_page = $is_ppcp_settings_page;
+ $this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id;
+ $this->pui_product_status = $pui_product_status;
}
/**
@@ -140,6 +182,7 @@ class PayUponInvoice {
'ppcp_ratepay_payment_instructions_payment_reference',
$payment_instructions
);
+ $wc_order->save_meta_data();
$this->logger->info( "Ratepay payment instructions added to order #{$wc_order->get_id()}." );
} catch ( RuntimeException $exception ) {
@@ -274,6 +317,28 @@ class PayUponInvoice {
return $methods;
}
);
+
+ add_action(
+ 'woocommerce_settings_checkout',
+ function () {
+ if (
+ $this->current_ppcp_settings_page_id === PayUponInvoiceGateway::ID
+ && ! $this->pui_product_status->pui_is_active()
+ ) {
+ $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
+ $gateway_enabled = $gateway_settings['enabled'] ?? '';
+ if($gateway_enabled === 'yes') {
+ $gateway_settings['enabled'] = 'no';
+ update_option('woocommerce_ppcp-pay-upon-invoice-gateway_settings', $gateway_settings);
+ $redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' );
+ wp_safe_redirect( $redirect_url);
+ exit;
+ }
+
+ echo 'Could not enable gateway because Pay upon invoice is not active on PayPal.
';
+ }
+ }
+ );
}
/**
@@ -331,6 +396,4 @@ class PayUponInvoice {
)
);
}
-
-
}
diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php
new file mode 100644
index 000000000..841c17a1a
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php
@@ -0,0 +1,106 @@
+settings = $settings;
+ $this->partners_endpoint = $partners_endpoint;
+ }
+
+ /**
+ * Whether the active/subscribed products support PUI.
+ *
+ * @return bool
+ * @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException Should a setting not be found.
+ */
+ public function pui_is_active() : bool {
+ if ( is_bool( $this->current_status_cache ) ) {
+ return $this->current_status_cache;
+ }
+ if ( $this->settings->has( 'products_pui_enabled' ) && $this->settings->get( 'products_pui_enabled' ) ) {
+ $this->current_status_cache = true;
+ return true;
+ }
+
+ try {
+ $seller_status = $this->partners_endpoint->seller_status();
+ } catch ( RuntimeException $error ) {
+ $this->current_status_cache = false;
+ return false;
+ }
+
+ foreach ( $seller_status->products() as $product ) {
+ if($product->name() !== 'PAYMENT_METHODS') {
+ continue;
+ }
+
+ if ( ! in_array(
+ $product->vetting_status(),
+ array(
+ SellerStatusProduct::VETTING_STATUS_APPROVED,
+ SellerStatusProduct::VETTING_STATUS_SUBSCRIBED,
+ ),
+ true
+ )
+ ) {
+ continue;
+ }
+
+ if ( in_array( 'PAY_UPON_INVOICE', $product->capabilities(), true ) ) {
+ $this->settings->set( 'products_pui_enabled', true );
+ $this->settings->persist();
+ $this->current_status_cache = true;
+ return true;
+ }
+ }
+
+ $this->current_status_cache = false;
+ return false;
+ }
+}
diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
index 6ddf945d4..c803a7b22 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
@@ -255,6 +255,7 @@ class SettingsListener {
if ( $credentials_change_status ) {
if ( self::CREDENTIALS_UNCHANGED !== $credentials_change_status ) {
$this->settings->set( 'products_dcc_enabled', null );
+ $this->settings->set( 'products_pui_enabled', null );
}
if ( in_array(
diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php
index 3deef7f48..f6fa12e35 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php
@@ -15,7 +15,7 @@ use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use Psr\Container\ContainerInterface;
-use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
@@ -71,7 +71,7 @@ class SettingsRenderer {
/**
* The DCC Product Status.
*
- * @var DCCProductStatus
+ * @var PayUponInvoiceProductStatus
*/
private $dcc_product_status;
@@ -90,7 +90,7 @@ class SettingsRenderer {
* @param array $fields The setting fields.
* @param DccApplies $dcc_applies Whether DCC gateway can be shown.
* @param MessagesApply $messages_apply Whether messages can be shown.
- * @param DCCProductStatus $dcc_product_status The product status.
+ * @param PayUponInvoiceProductStatus $dcc_product_status The product status.
* @param SettingsStatus $settings_status The Settings status helper.
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
*/
@@ -100,7 +100,7 @@ class SettingsRenderer {
array $fields,
DccApplies $dcc_applies,
MessagesApply $messages_apply,
- DCCProductStatus $dcc_product_status,
+ PayUponInvoiceProductStatus $dcc_product_status,
SettingsStatus $settings_status,
string $page_id
) {
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index f7f3ebbaf..d914dffcd 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -186,10 +186,7 @@ class WCGatewayModule implements ModuleInterface {
add_action(
'init',
function () use ( $c ) {
- $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
- $gateway_enabled = $gateway_settings['enabled'] ?? '';
-
- if ( 'yes' === $gateway_enabled && 'DE' === $c->get( 'api.shop.country' ) ) {
+ if ('DE' === $c->get( 'api.shop.country' ) && 'EUR' === get_woocommerce_currency() ) {
( $c->get( 'wcgateway.pay-upon-invoice' ) )->init();
}
}
From f2284d49f510010208c974b3d32b55bc00bdea41 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 9 May 2022 10:36:38 +0200
Subject: [PATCH 080/163] Fix psalm
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 20 +++++++++++--------
.../Helper/PayUponInvoiceProductStatus.php | 7 ++++---
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 1146b37cd..0f2daa17a 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -116,8 +116,8 @@ class PayUponInvoice {
* @param Environment $environment The environment.
* @param string $asset_version The asset version.
* @param State $state The onboarding state.
- * @param bool $is_ppcp_settings_page The is ppcp settings page.
- * @param string $current_ppcp_settings_page_id Current PayPal settings page id.
+ * @param bool $is_ppcp_settings_page The is ppcp settings page.
+ * @param string $current_ppcp_settings_page_id Current PayPal settings page id.
* @param PayUponInvoiceProductStatus $pui_product_status PUI seller product status.
*/
public function __construct(
@@ -143,7 +143,7 @@ class PayUponInvoice {
$this->state = $state;
$this->is_ppcp_settings_page = $is_ppcp_settings_page;
$this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id;
- $this->pui_product_status = $pui_product_status;
+ $this->pui_product_status = $pui_product_status;
}
/**
@@ -322,16 +322,16 @@ class PayUponInvoice {
'woocommerce_settings_checkout',
function () {
if (
- $this->current_ppcp_settings_page_id === PayUponInvoiceGateway::ID
+ PayUponInvoiceGateway::ID === $this->current_ppcp_settings_page_id
&& ! $this->pui_product_status->pui_is_active()
) {
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
- $gateway_enabled = $gateway_settings['enabled'] ?? '';
- if($gateway_enabled === 'yes') {
+ $gateway_enabled = $gateway_settings['enabled'] ?? '';
+ if ( 'yes' === $gateway_enabled ) {
$gateway_settings['enabled'] = 'no';
- update_option('woocommerce_ppcp-pay-upon-invoice-gateway_settings', $gateway_settings);
+ update_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings', $gateway_settings );
$redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' );
- wp_safe_redirect( $redirect_url);
+ wp_safe_redirect( $redirect_url );
exit;
}
@@ -347,6 +347,10 @@ class PayUponInvoice {
* @return bool
*/
private function is_checkout_ready_for_pui(): bool {
+ if ( ! $this->pui_product_status->pui_is_active() ) {
+ return false;
+ }
+
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
if ( $billing_country && 'DE' !== $billing_country ) {
return false;
diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php
index 841c17a1a..3358605e8 100644
--- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php
+++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php
@@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
+use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
/**
* Class DccProductStatus
@@ -22,7 +23,7 @@ class PayUponInvoiceProductStatus {
/**
* Caches the status for the current load.
*
- * @var string|null
+ * @var bool|null
*/
private $current_status_cache;
/**
@@ -57,7 +58,7 @@ class PayUponInvoiceProductStatus {
* Whether the active/subscribed products support PUI.
*
* @return bool
- * @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException Should a setting not be found.
+ * @throws NotFoundException Should a setting not be found.
*/
public function pui_is_active() : bool {
if ( is_bool( $this->current_status_cache ) ) {
@@ -76,7 +77,7 @@ class PayUponInvoiceProductStatus {
}
foreach ( $seller_status->products() as $product ) {
- if($product->name() !== 'PAYMENT_METHODS') {
+ if ( $product->name() !== 'PAYMENT_METHODS' ) {
continue;
}
From 5c3881a247bfe510bd0e95403c7e484e33861e1c Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 9 May 2022 10:48:19 +0200
Subject: [PATCH 081/163] Fix error requiring dcc product status
---
modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php
index f6fa12e35..3deef7f48 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php
@@ -15,7 +15,7 @@ use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use Psr\Container\ContainerInterface;
-use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
@@ -71,7 +71,7 @@ class SettingsRenderer {
/**
* The DCC Product Status.
*
- * @var PayUponInvoiceProductStatus
+ * @var DCCProductStatus
*/
private $dcc_product_status;
@@ -90,7 +90,7 @@ class SettingsRenderer {
* @param array $fields The setting fields.
* @param DccApplies $dcc_applies Whether DCC gateway can be shown.
* @param MessagesApply $messages_apply Whether messages can be shown.
- * @param PayUponInvoiceProductStatus $dcc_product_status The product status.
+ * @param DCCProductStatus $dcc_product_status The product status.
* @param SettingsStatus $settings_status The Settings status helper.
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
*/
@@ -100,7 +100,7 @@ class SettingsRenderer {
array $fields,
DccApplies $dcc_applies,
MessagesApply $messages_apply,
- PayUponInvoiceProductStatus $dcc_product_status,
+ DCCProductStatus $dcc_product_status,
SettingsStatus $settings_status,
string $page_id
) {
From 723206ff70c6a42e1bc115792b8e15b50488f25d Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 9 May 2022 10:51:50 +0200
Subject: [PATCH 082/163] Fix error requiring dcc product status
---
modules/ppcp-wc-gateway/services.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 515b018d9..0ad0b3137 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -37,6 +37,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSourceFac
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
@@ -2138,11 +2139,11 @@ return array(
return new TransactionUrlProvider( $sandbox_url_base, $live_url_base );
},
- 'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : PayUponInvoiceProductStatus {
+ 'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : DCCProductStatus {
$settings = $container->get( 'wcgateway.settings' );
$partner_endpoint = $container->get( 'api.endpoint.partners' );
- return new PayUponInvoiceProductStatus( $settings, $partner_endpoint );
+ return new DCCProductStatus( $settings, $partner_endpoint );
},
'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers {
From ac6361e2cef9721f196f990fc033c3114a8e4806 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 9 May 2022 11:46:22 +0200
Subject: [PATCH 083/163] Fix phpcs
---
modules/ppcp-wc-gateway/services.php | 6 +++---
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 0ad0b3137..9aae83b14 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2193,7 +2193,7 @@ return array(
(string) $source_website_id()
);
},
- 'wcgateway.pay-upon-invoice-product-status' => static function(ContainerInterface $container): PayUponInvoiceProductStatus {
+ 'wcgateway.pay-upon-invoice-product-status' => static function( ContainerInterface $container ): PayUponInvoiceProductStatus {
return new PayUponInvoiceProductStatus(
$container->get( 'wcgateway.settings' ),
$container->get( 'api.endpoint.partners' )
@@ -2209,9 +2209,9 @@ return array(
$container->get( 'onboarding.environment' ),
$container->get( 'ppcp.asset-version' ),
$container->get( 'onboarding.state' ),
- $container->get('wcgateway.is-ppcp-settings-page'),
+ $container->get( 'wcgateway.is-ppcp-settings-page' ),
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
- $container->get('wcgateway.pay-upon-invoice-product-status')
+ $container->get( 'wcgateway.pay-upon-invoice-product-status' )
);
},
'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index d914dffcd..1e8dc49bb 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -186,7 +186,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' === get_woocommerce_currency() ) {
( $c->get( 'wcgateway.pay-upon-invoice' ) )->init();
}
}
From e5008603c978ba64247340e99f1ca56fd8db2cfd Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 9 May 2022 11:53:30 +0200
Subject: [PATCH 084/163] Fix phpcs
---
.../src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index f26deaece..7bff8b02a 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -78,6 +78,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
* @param PaymentSourceFactory $payment_source_factory The payment source factory.
* @param Environment $environment The environment.
+ * @param TransactionUrlProvider $transaction_url_provider The transaction url provider.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
From 5911e093108df35cd2ddb4f6763befda8eb42cc2 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 10 May 2022 10:25:06 +0200
Subject: [PATCH 085/163] validate birth date (WIP)
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 71 ++++++++++++++-----
.../src/Helper/PayUponInvoiceHelper.php | 15 ++++
2 files changed, 67 insertions(+), 19 deletions(-)
create mode 100644 modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index e2fbdc59e..6a3f556c5 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
+use DateTime;
use Psr\Log\LoggerInterface;
use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
@@ -259,6 +260,11 @@ class PayUponInvoice {
if ( 'DE' !== $fields['billing_country'] ) {
$errors->add( 'validation', __( 'Billing country not available.', 'woocommerce-paypal-payments' ) );
}
+
+ $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
+ if(! $this->validate_birth_date($birth_date)) {
+ $errors->add( 'validation', __( 'Invalid birth date.', 'woocommerce-paypal-payments' ) );
+ }
},
10,
2
@@ -276,6 +282,28 @@ 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
+ );
+
+ 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 ),
+ )
+ );
+ }
+
/**
* Checks whether checkout is ready for PUI.
*
@@ -311,26 +339,31 @@ class PayUponInvoice {
}
/**
- * Registers PUI assets.
+ * Ensures date is valid, at least 18 years back and in the last 100 years timeframe.
+ *
+ * @param string $date
+ * @param string $format
+ * @return bool
*/
- 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
- );
+ private function validate_birth_date(string $date, string $format = 'Y-m-d'): bool
+ {
+ $d = DateTime::createFromFormat($format, $date);
+ if($d === false) {
+ return false;
+ }
- 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 ),
- )
- );
+ if($date !== $d->format($format)) {
+ return false;
+ }
+
+ if (time() < strtotime('+18 years', strtotime($date))) {
+ return false;
+ }
+
+// if (time() > strtotime('-100 years', strtotime($date))) {
+// return false;
+// }
+
+ return true;
}
-
-
}
diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
new file mode 100644
index 000000000..6d5029322
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
@@ -0,0 +1,15 @@
+
Date: Tue, 10 May 2022 11:59:24 +0200
Subject: [PATCH 086/163] Validate birth date
---
modules/ppcp-wc-gateway/services.php | 7 ++-
.../Gateway/PayUponInvoice/PayUponInvoice.php | 45 ++++++-------------
.../PayUponInvoice/PayUponInvoiceGateway.php | 1 +
.../src/Helper/PayUponInvoiceHelper.php | 31 ++++++++++++-
.../Helper/PayUponInvoiceHelperTest.php | 32 +++++++++++++
5 files changed, 81 insertions(+), 35 deletions(-)
create mode 100644 tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index dffca2df2..08d3fb69a 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -38,6 +38,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
@@ -2192,6 +2193,9 @@ return array(
(string) $source_website_id()
);
},
+ 'wcgateway.pay-upon-invoice-helper' => static function( ContainerInterface $container ): PayUponInvoiceHelper {
+ return new PayUponInvoiceHelper();
+ },
'wcgateway.pay-upon-invoice' => static function ( ContainerInterface $container ): PayUponInvoice {
return new PayUponInvoice(
$container->get( 'wcgateway.url' ),
@@ -2200,7 +2204,8 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'wcgateway.settings' ),
$container->get( 'onboarding.environment' ),
- $container->get( 'ppcp.asset-version' )
+ $container->get( 'ppcp.asset-version' ),
+ $container->get( 'wcgateway.pay-upon-invoice-helper' )
);
},
'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 6a3f556c5..355ef3f3b 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -9,12 +9,12 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
-use DateTime;
use Psr\Log\LoggerInterface;
use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
@@ -76,6 +76,13 @@ class PayUponInvoice {
*/
protected $asset_version;
+ /**
+ * The PUI helper.
+ *
+ * @var PayUponInvoiceHelper
+ */
+ protected $pui_helper;
+
/**
* PayUponInvoice constructor.
*
@@ -86,6 +93,7 @@ class PayUponInvoice {
* @param Settings $settings The settings.
* @param Environment $environment The environment.
* @param string $asset_version The asset version.
+ * @param PayUponInvoiceHelper $pui_helper The PUI helper.
*/
public function __construct(
string $module_url,
@@ -94,7 +102,8 @@ class PayUponInvoice {
LoggerInterface $logger,
Settings $settings,
Environment $environment,
- string $asset_version
+ string $asset_version,
+ PayUponInvoiceHelper $pui_helper
) {
$this->module_url = $module_url;
$this->fraud_net = $fraud_net;
@@ -103,6 +112,7 @@ class PayUponInvoice {
$this->settings = $settings;
$this->environment = $environment;
$this->asset_version = $asset_version;
+ $this->pui_helper = $pui_helper;
}
/**
@@ -262,7 +272,7 @@ class PayUponInvoice {
}
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
- if(! $this->validate_birth_date($birth_date)) {
+ if ( ! $this->pui_helper->validate_birth_date( $birth_date ) ) {
$errors->add( 'validation', __( 'Invalid birth date.', 'woocommerce-paypal-payments' ) );
}
},
@@ -337,33 +347,4 @@ class PayUponInvoice {
return true;
}
-
- /**
- * Ensures date is valid, at least 18 years back and in the last 100 years timeframe.
- *
- * @param string $date
- * @param string $format
- * @return bool
- */
- private function validate_birth_date(string $date, string $format = 'Y-m-d'): bool
- {
- $d = DateTime::createFromFormat($format, $date);
- if($d === false) {
- return false;
- }
-
- if($date !== $d->format($format)) {
- return false;
- }
-
- if (time() < strtotime('+18 years', strtotime($date))) {
- return false;
- }
-
-// if (time() > strtotime('-100 years', strtotime($date))) {
-// return false;
-// }
-
- return true;
- }
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index f26deaece..8afea94a1 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -78,6 +78,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
* @param PaymentSourceFactory $payment_source_factory The payment source factory.
* @param Environment $environment The environment.
+ * @param TransactionUrlProvider $transaction_url_provider The transaction URL provider.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
index 6d5029322..cd7c6c491 100644
--- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
+++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
@@ -9,7 +9,34 @@ declare( strict_types=1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Helper;
-class PayUponInvoiceHelper
-{
+use DateTime;
+/**
+ * Class PayUponInvoiceHelper
+ */
+class PayUponInvoiceHelper {
+
+ /**
+ * Ensures date is valid and at least 18 years back.
+ *
+ * @param string $date The date.
+ * @param string $format The date format.
+ * @return bool
+ */
+ public function validate_birth_date( string $date, string $format = 'Y-m-d' ): bool {
+ $d = DateTime::createFromFormat( $format, $date );
+ if ( false === $d ) {
+ return false;
+ }
+
+ if ( $date !== $d->format( $format ) ) {
+ return false;
+ }
+
+ if ( time() < strtotime( '+18 years', strtotime( $date ) ) ) {
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php b/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php
new file mode 100644
index 000000000..5a073c95a
--- /dev/null
+++ b/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php
@@ -0,0 +1,32 @@
+assertSame((new PayUponInvoiceHelper())->validate_birth_date($input), $output);
+ }
+
+ public function datesProvider(): array{
+ $format = 'Y-m-d';
+
+ return [
+ ['', false],
+ [(new DateTime())->format($format), false],
+ [(new DateTime('-17 years'))->format($format), false],
+ ['31-02-1942', false],
+ ['01-01-1942', false],
+ ['1942-01-01', true],
+ ];
+ }
+
+}
From 235c9c8281c0b1474d9d0c318e717aca9e62e803 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 10 May 2022 12:18:18 +0200
Subject: [PATCH 087/163] Fix psalm
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php | 3 ++-
tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 355ef3f3b..1bc41c257 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -272,7 +272,7 @@ class PayUponInvoice {
}
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
- if ( ! $this->pui_helper->validate_birth_date( $birth_date ) ) {
+ if ( $birth_date && ! $this->pui_helper->validate_birth_date( $birth_date ) ) {
$errors->add( 'validation', __( 'Invalid birth date.', 'woocommerce-paypal-payments' ) );
}
},
diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
index cd7c6c491..ce2dc1b8c 100644
--- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
+++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
@@ -33,7 +33,8 @@ class PayUponInvoiceHelper {
return false;
}
- if ( time() < strtotime( '+18 years', strtotime( $date ) ) ) {
+ $date_time = strtotime( $date );
+ if ( $date_time && time() < strtotime( '+18 years', $date_time ) ) {
return false;
}
diff --git a/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php b/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php
index 5a073c95a..3a1d9bdc0 100644
--- a/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php
+++ b/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php
@@ -23,7 +23,7 @@ class PayUponInvoiceHelperTest extends TestCase
['', false],
[(new DateTime())->format($format), false],
[(new DateTime('-17 years'))->format($format), false],
- ['31-02-1942', false],
+ ['1942-02-31', false],
['01-01-1942', false],
['1942-01-01', true],
];
From b7413b9adfab6168ec40f7d584e15e98e862e5a3 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 10 May 2022 12:33:50 +0200
Subject: [PATCH 088/163] Remove unnecesary throw docblock
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
.../src/Helper/PayUponInvoiceProductStatus.php | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 0f2daa17a..351db02a6 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -85,7 +85,7 @@ class PayUponInvoice {
protected $state;
/**
- * The is ppcp settings page.
+ * Whether the current page is the PPCP settings page.
*
* @var bool
*/
diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php
index 3358605e8..60b72dc7f 100644
--- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php
+++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php
@@ -16,7 +16,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
/**
- * Class DccProductStatus
+ * Class PayUponInvoiceProductStatus
*/
class PayUponInvoiceProductStatus {
@@ -41,7 +41,7 @@ class PayUponInvoiceProductStatus {
private $partners_endpoint;
/**
- * DccProductStatus constructor.
+ * PayUponInvoiceProductStatus constructor.
*
* @param Settings $settings The Settings.
* @param PartnersEndpoint $partners_endpoint The Partner Endpoint.
@@ -58,7 +58,6 @@ class PayUponInvoiceProductStatus {
* Whether the active/subscribed products support PUI.
*
* @return bool
- * @throws NotFoundException Should a setting not be found.
*/
public function pui_is_active() : bool {
if ( is_bool( $this->current_status_cache ) ) {
From b9dc98eefc9d5ad0d9f024dc8c22c6e7d15e12dc Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 10 May 2022 12:42:41 +0200
Subject: [PATCH 089/163] Make pui error translatable
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 351db02a6..d10c5b92e 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -335,7 +335,10 @@ class PayUponInvoice {
exit;
}
- echo 'Could not enable gateway because Pay upon invoice is not active on PayPal.
';
+ printf(
+ '',
+ esc_html__( 'Could not enable gateway because Pay upon invoice is not active on PayPal.', 'woocommerce-paypal-payments' )
+ );
}
}
);
From 995cd438399f3324134674e7a72154d0278b50b8 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 11 May 2022 10:11:13 +0200
Subject: [PATCH 090/163] Do not enable pui gateway if customer service
instructions is empty
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 37 +++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index d10c5b92e..a5daacfd9 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -342,6 +342,43 @@ class PayUponInvoice {
}
}
);
+
+ add_action(
+ 'woocommerce_update_options_checkout_ppcp-pay-upon-invoice-gateway',
+ function () {
+ $customer_service_instructions = filter_input( INPUT_POST, 'woocommerce_ppcp-pay-upon-invoice-gateway_customer_service_instructions', FILTER_SANITIZE_STRING );
+ if ( '' === $customer_service_instructions ) {
+ $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
+ $gateway_enabled = $gateway_settings['enabled'] ?? '';
+ if ( 'yes' === $gateway_enabled ) {
+ $gateway_settings['enabled'] = 'no';
+ update_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings', $gateway_settings );
+
+ $redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' );
+ wp_safe_redirect( $redirect_url );
+ exit;
+ }
+ }
+ }
+ );
+
+ add_action(
+ 'woocommerce_settings_checkout',
+ function() {
+ if (
+ PayUponInvoiceGateway::ID === $this->current_ppcp_settings_page_id
+ && $this->pui_product_status->pui_is_active()
+ ) {
+ $pui_gateway = WC()->payment_gateways->payment_gateways()[ PayUponInvoiceGateway::ID ];
+ if ( $pui_gateway->get_option( 'customer_service_instructions' ) === '' ) {
+ printf(
+ '',
+ esc_html__( 'Could not enable gateway because "Customer service instructions" field is empty.', 'woocommerce-paypal-payments' )
+ );
+ }
+ }
+ }
+ );
}
/**
From ff2ff8d31f1231a3cf64ed1b09979be92aad6d7f Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 11 May 2022 10:37:16 +0200
Subject: [PATCH 091/163] Update pui error notice
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index d10c5b92e..bd4317cf0 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -337,7 +337,7 @@ class PayUponInvoice {
printf(
'',
- esc_html__( 'Could not enable gateway because Pay upon invoice is not active on PayPal.', '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' )
);
}
}
From 00b40dc6deff6086abef465256ebeb64190ff990 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 11 May 2022 11:31:27 +0200
Subject: [PATCH 092/163] Do not hide pui gateway on pay for order page
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index bd4317cf0..cd73a1c02 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -364,7 +364,7 @@ class PayUponInvoice {
}
$cart = WC()->cart ?? null;
- if ( $cart ) {
+ if ( $cart && ! is_checkout_pay_page() ) {
$cart_total = (float) $cart->get_total( 'numeric' );
if ( $cart_total < 5 || $cart_total > 2500 ) {
return false;
From 30d17b2a0afc66b6c4dc0c12dadcd486dfcc04c2 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 11 May 2022 12:07:11 +0200
Subject: [PATCH 093/163] Check if product contains virtual or downloable
variation
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index cd73a1c02..1ed219c68 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -11,6 +11,8 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use WC_Order;
+use WC_Product_Variable;
+use WC_Product_Variation;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
@@ -376,6 +378,16 @@ class PayUponInvoice {
if ( $product && ( $product->is_downloadable() || $product->is_virtual() ) ) {
return false;
}
+
+ if ( is_a( $product, WC_Product_Variable::class ) ) {
+ foreach ( $product->get_available_variations( 'object' ) as $variation ) {
+ if ( is_a( $variation, WC_Product_Variation::class ) ) {
+ if ( true === $variation->is_downloadable() || true === $variation->is_virtual() ) {
+ return false;
+ }
+ }
+ }
+ }
}
}
From 5bf95fbca335d5dcbf94a0f0fc98ada6e2f632d0 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 11 May 2022 16:11:05 +0200
Subject: [PATCH 094/163] Get session id from request when page is pay for
order
---
modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js | 9 +++++++++
.../src/Gateway/PayUponInvoice/FraudNetSessionId.php | 7 +++++++
2 files changed, 16 insertions(+)
diff --git a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
index 1e73653b9..dcf30dc03 100644
--- a/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
+++ b/modules/ppcp-wc-gateway/resources/js/pay-upon-invoice.js
@@ -30,6 +30,15 @@ window.addEventListener('load', function() {
script.text = JSON.stringify(configuration);
document.body.appendChild(script);
+ const payForOrderForm = document.forms.order_review;
+ if(payForOrderForm) {
+ const puiPayForOrderSessionId = document.createElement('input');
+ puiPayForOrderSessionId.setAttribute('type', 'hidden');
+ puiPayForOrderSessionId.setAttribute('name', 'pui_pay_for_order_session_id');
+ puiPayForOrderSessionId.setAttribute('value', FraudNetConfig.f);
+ payForOrderForm.appendChild(puiPayForOrderSessionId);
+ }
+
_loadBeaconJS({fnUrl: "https://c.paypal.com/da/r/fb.js"})
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
index 7a1359560..966b5733f 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
@@ -31,6 +31,13 @@ class FraudNetSessionId {
return WC()->session->get( 'ppcp_fraudnet_session_id' );
}
+ 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 ) {
+ return $pui_pay_for_order_session_id;
+ }
+ }
+
$session_id = bin2hex( random_bytes( 16 ) );
WC()->session->set( 'ppcp_fraudnet_session_id', $session_id );
From 957e7bf84d34f64c007756f37ce81df53b79ae6e Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 12 May 2022 15:16:11 +0200
Subject: [PATCH 095/163] Check if pay for order products are ready for pui
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 59 ++++++++++++++++---
1 file changed, 50 insertions(+), 9 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 61455b533..da280bd5b 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -11,6 +11,9 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use WC_Order;
+use WC_Order_Item;
+use WC_Order_Item_Product;
+use WC_Product;
use WC_Product_Variable;
use WC_Product_Variation;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
@@ -125,11 +128,11 @@ class PayUponInvoice {
* @param Settings $settings The settings.
* @param Environment $environment The environment.
* @param string $asset_version The asset version.
- * @param PayUponInvoiceHelper $pui_helper The PUI helper.
* @param State $state The onboarding state.
- * @param bool $is_ppcp_settings_page The is ppcp settings page.
+ * @param bool $is_ppcp_settings_page Whether page is PayPal settings poge.
* @param string $current_ppcp_settings_page_id Current PayPal settings page id.
- * @param PayUponInvoiceProductStatus $pui_product_status PUI seller product status.
+ * @param PayUponInvoiceProductStatus $pui_product_status The PUI product status.
+ * @param PayUponInvoiceHelper $pui_helper The PUI helper.
*/
public function __construct(
string $module_url,
@@ -156,7 +159,7 @@ class PayUponInvoice {
$this->is_ppcp_settings_page = $is_ppcp_settings_page;
$this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id;
$this->pui_product_status = $pui_product_status;
- $this->pui_helper = $pui_helper;
+ $this->pui_helper = $pui_helper;
}
/**
@@ -450,14 +453,28 @@ class PayUponInvoice {
$items = $cart->get_cart_contents();
foreach ( $items as $item ) {
$product = wc_get_product( $item['product_id'] );
- if ( $product && ( $product->is_downloadable() || $product->is_virtual() ) ) {
+ if ( is_a( $product, WC_Product::class ) && ! $this->product_ready_for_pui( $product ) ) {
return false;
}
+ }
+ }
- if ( is_a( $product, WC_Product_Variable::class ) ) {
- foreach ( $product->get_available_variations( 'object' ) as $variation ) {
- if ( is_a( $variation, WC_Product_Variation::class ) ) {
- if ( true === $variation->is_downloadable() || true === $variation->is_virtual() ) {
+ if ( is_wc_endpoint_url( 'order-pay' ) ) {
+ /**
+ * Needed for WordPress `query_vars`.
+ *
+ * @psalm-suppress InvalidGlobal
+ */
+ global $wp;
+
+ if ( isset( $wp->query_vars['order-pay'] ) && absint( $wp->query_vars['order-pay'] ) > 0 ) {
+ $order_id = absint( $wp->query_vars['order-pay'] );
+ $order = wc_get_order( $order_id );
+ if ( is_a( $order, WC_Order::class ) ) {
+ foreach ( $order->get_items() as $item_id => $item ) {
+ if ( is_a( $item, WC_Order_Item_Product::class ) ) {
+ $product = wc_get_product( $item->get_product_id() );
+ if ( is_a( $product, WC_Product::class ) && ! $this->product_ready_for_pui( $product ) ) {
return false;
}
}
@@ -468,4 +485,28 @@ class PayUponInvoice {
return true;
}
+
+ /**
+ * Ensures product is ready for PUI.
+ *
+ * @param WC_Product $product WC product.
+ * @return bool
+ */
+ private function product_ready_for_pui( WC_Product $product ):bool {
+ if ( $product->is_downloadable() || $product->is_virtual() ) {
+ return false;
+ }
+
+ if ( is_a( $product, WC_Product_Variable::class ) ) {
+ foreach ( $product->get_available_variations( 'object' ) as $variation ) {
+ if ( is_a( $variation, WC_Product_Variation::class ) ) {
+ if ( true === $variation->is_downloadable() || true === $variation->is_virtual() ) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
}
From baef2d54080676e9c046bdb5726bc8c13d675693 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 12 May 2022 16:36:44 +0200
Subject: [PATCH 096/163] Replace `EXPRESS_CHECKOUT` with `PAYMENT_METHODS` to
make it work with pui
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index da280bd5b..2253fd690 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -176,9 +176,11 @@ class PayUponInvoice {
}
if ( in_array( 'PPCP', $data['products'], true ) ) {
- $data['products'][] = 'PAYMENT_METHODS';
- $data['capabilities'][] = 'PAY_UPON_INVOICE';
+ $data['products'][] = 'PAYMENT_METHODS';
+ } elseif ( in_array( 'EXPRESS_CHECKOUT', $data['products'], true ) ) {
+ $data['products'][0] = 'PAYMENT_METHODS';
}
+ $data['capabilities'][] = 'PAY_UPON_INVOICE';
return $data;
}
From a58e971cad671a060f119e3be8968a47a322dfba Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 12 May 2022 16:46:45 +0200
Subject: [PATCH 097/163] Display all body responses in the logs
---
modules/ppcp-api-client/src/Endpoint/RequestTrait.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-api-client/src/Endpoint/RequestTrait.php b/modules/ppcp-api-client/src/Endpoint/RequestTrait.php
index c4cbb2a45..f9db8101e 100644
--- a/modules/ppcp-api-client/src/Endpoint/RequestTrait.php
+++ b/modules/ppcp-api-client/src/Endpoint/RequestTrait.php
@@ -87,9 +87,10 @@ trait RequestTrait {
if ( isset( $response['response'] ) ) {
$output .= 'Response: ' . wc_print_r( $response['response'], true ) . "\n";
- if ( isset( $response['body'] )
+ if (
+ isset( $response['body'] )
&& isset( $response['response']['code'] )
- && ! in_array( $response['response']['code'], array( 200, 201, 202, 204 ), true ) ) {
+ ) {
$output .= 'Response Body: ' . wc_print_r( $response['body'], true ) . "\n";
}
}
From de12327f6cf3fbf53d5610136f3dda46dab88fd4 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 13 May 2022 09:38:45 +0200
Subject: [PATCH 098/163] Bump 1.9.0-test2 version
---
readme.txt | 2 +-
woocommerce-paypal-payments.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/readme.txt b/readme.txt
index 13a933c15..fe4cf49a1 100644
--- a/readme.txt
+++ b/readme.txt
@@ -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.9.0-test1
+Stable tag: 1.9.0-test2
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php
index 548a5b726..beccc18a0 100644
--- a/woocommerce-paypal-payments.php
+++ b/woocommerce-paypal-payments.php
@@ -3,7 +3,7 @@
* 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.9.0-test1
+ * Version: 1.9.0-test2
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* License: GPL-2.0
From be22a60b9329dbb0f9ccd7962b8f8e5581b1a649 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 16 May 2022 16:51:29 +0200
Subject: [PATCH 099/163] Add birth date validation for pay for order
---
modules/ppcp-wc-gateway/services.php | 3 +-
.../Gateway/PayUponInvoice/PayUponInvoice.php | 93 +------------------
.../PayUponInvoice/PayUponInvoiceGateway.php | 34 +++++--
.../src/Helper/PayUponInvoiceHelper.php | 87 +++++++++++++++++
.../PayUponInvoiceGatewayTest.php | 6 +-
5 files changed, 127 insertions(+), 96 deletions(-)
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index a04dc1580..b954fc7b7 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2177,7 +2177,8 @@ return array(
$container->get( 'wcgateway.pay-upon-invoice-payment-source-factory' ),
$container->get( 'onboarding.environment' ),
$container->get( 'wcgateway.transaction-url-provider' ),
- $container->get( 'woocommerce.logger.woocommerce' )
+ $container->get( 'woocommerce.logger.woocommerce' ),
+ $container->get( 'wcgateway.pay-upon-invoice-helper' )
);
},
'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 2253fd690..34b756020 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -332,8 +332,11 @@ class PayUponInvoice {
add_filter(
'woocommerce_available_payment_gateways',
- function( array $methods ): array {
- if ( ! $this->is_checkout_ready_for_pui() ) {
+ function ( array $methods ): array {
+ if (
+ ! $this->pui_product_status->pui_is_active()
+ || ! $this->pui_helper->is_checkout_ready_for_pui()
+ ) {
unset( $methods[ PayUponInvoiceGateway::ID ] );
}
@@ -425,90 +428,4 @@ class PayUponInvoice {
)
);
}
-
- /**
- * Checks whether checkout is ready for PUI.
- *
- * @return bool
- */
- private function is_checkout_ready_for_pui(): bool {
- if ( ! $this->pui_product_status->pui_is_active() ) {
- return false;
- }
-
- $billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
- if ( $billing_country && 'DE' !== $billing_country ) {
- return false;
- }
-
- if ( 'EUR' !== get_woocommerce_currency() ) {
- return false;
- }
-
- $cart = WC()->cart ?? null;
- if ( $cart && ! is_checkout_pay_page() ) {
- $cart_total = (float) $cart->get_total( 'numeric' );
- if ( $cart_total < 5 || $cart_total > 2500 ) {
- return false;
- }
-
- $items = $cart->get_cart_contents();
- foreach ( $items as $item ) {
- $product = wc_get_product( $item['product_id'] );
- if ( is_a( $product, WC_Product::class ) && ! $this->product_ready_for_pui( $product ) ) {
- return false;
- }
- }
- }
-
- if ( is_wc_endpoint_url( 'order-pay' ) ) {
- /**
- * Needed for WordPress `query_vars`.
- *
- * @psalm-suppress InvalidGlobal
- */
- global $wp;
-
- if ( isset( $wp->query_vars['order-pay'] ) && absint( $wp->query_vars['order-pay'] ) > 0 ) {
- $order_id = absint( $wp->query_vars['order-pay'] );
- $order = wc_get_order( $order_id );
- if ( is_a( $order, WC_Order::class ) ) {
- foreach ( $order->get_items() as $item_id => $item ) {
- if ( is_a( $item, WC_Order_Item_Product::class ) ) {
- $product = wc_get_product( $item->get_product_id() );
- if ( is_a( $product, WC_Product::class ) && ! $this->product_ready_for_pui( $product ) ) {
- return false;
- }
- }
- }
- }
- }
- }
-
- return true;
- }
-
- /**
- * Ensures product is ready for PUI.
- *
- * @param WC_Product $product WC product.
- * @return bool
- */
- private function product_ready_for_pui( WC_Product $product ):bool {
- if ( $product->is_downloadable() || $product->is_virtual() ) {
- return false;
- }
-
- if ( is_a( $product, WC_Product_Variable::class ) ) {
- foreach ( $product->get_available_variations( 'object' ) as $variation ) {
- if ( is_a( $variation, WC_Product_Variation::class ) ) {
- if ( true === $variation->is_downloadable() || true === $variation->is_virtual() ) {
- return false;
- }
- }
- }
- }
-
- return true;
- }
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 8afea94a1..9da546f9e 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -12,12 +12,15 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use RuntimeException;
use WC_Order;
+use WC_Order_Item_Product;
use WC_Payment_Gateway;
+use WC_Product;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait;
/**
@@ -71,6 +74,13 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
*/
protected $logger;
+ /**
+ * The PUI helper.
+ *
+ * @var PayUponInvoiceHelper
+ */
+ protected $pui_helper;
+
/**
* PayUponInvoiceGateway constructor.
*
@@ -80,6 +90,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
* @param Environment $environment The environment.
* @param TransactionUrlProvider $transaction_url_provider The transaction URL provider.
* @param LoggerInterface $logger The logger.
+ * @param PayUponInvoiceHelper $pui_helper The PUI helper.
*/
public function __construct(
PayUponInvoiceOrderEndpoint $order_endpoint,
@@ -87,7 +98,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
PaymentSourceFactory $payment_source_factory,
Environment $environment,
TransactionUrlProvider $transaction_url_provider,
- LoggerInterface $logger
+ LoggerInterface $logger,
+ PayUponInvoiceHelper $pui_helper
) {
$this->id = self::ID;
@@ -115,6 +127,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$this->logger = $logger;
$this->environment = $environment;
$this->transaction_url_provider = $transaction_url_provider;
+ $this->pui_helper = $pui_helper;
}
/**
@@ -180,12 +193,21 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
* @return array
*/
public function process_payment( $order_id ) {
- $wc_order = wc_get_order( $order_id );
+ $wc_order = wc_get_order( $order_id );
+ $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING ) ?? '';
+
+ $pay_for_order = filter_input( INPUT_GET, 'pay_for_order', FILTER_SANITIZE_STRING );
+ if ( 'true' === $pay_for_order ) {
+ if ( ! $this->pui_helper->validate_birth_date( $birth_date ) ) {
+ wc_add_notice( 'Invalid birth date.', 'error' );
+ return array(
+ 'result' => 'failure',
+ );
+ }
+ }
+
$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 );
-
- $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING ) ?? '';
+ $purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
$payment_source = $this->payment_source_factory->from_wc_order( $wc_order, $birth_date );
try {
diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
index ce2dc1b8c..576989c5b 100644
--- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
+++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
@@ -10,6 +10,11 @@ declare( strict_types=1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Helper;
use DateTime;
+use WC_Order;
+use WC_Order_Item_Product;
+use WC_Product;
+use WC_Product_Variable;
+use WC_Product_Variation;
/**
* Class PayUponInvoiceHelper
@@ -40,4 +45,86 @@ class PayUponInvoiceHelper {
return true;
}
+
+ /**
+ * Ensures product is ready for PUI.
+ *
+ * @param WC_Product $product WC product.
+ * @return bool
+ */
+ public function product_ready_for_pui( WC_Product $product ):bool {
+ if ( $product->is_downloadable() || $product->is_virtual() ) {
+ return false;
+ }
+
+ if ( is_a( $product, WC_Product_Variable::class ) ) {
+ foreach ( $product->get_available_variations( 'object' ) as $variation ) {
+ if ( is_a( $variation, WC_Product_Variation::class ) ) {
+ if ( true === $variation->is_downloadable() || true === $variation->is_virtual() ) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Checks whether checkout is ready for PUI.
+ *
+ * @return bool
+ */
+ public function is_checkout_ready_for_pui(): bool {
+ $billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
+ if ( $billing_country && 'DE' !== $billing_country ) {
+ return false;
+ }
+
+ if ( 'EUR' !== get_woocommerce_currency() ) {
+ return false;
+ }
+
+ $cart = WC()->cart ?? null;
+ if ( $cart && ! is_checkout_pay_page() ) {
+ $cart_total = (float) $cart->get_total( 'numeric' );
+ if ( $cart_total < 5 || $cart_total > 2500 ) {
+ return false;
+ }
+
+ $items = $cart->get_cart_contents();
+ foreach ( $items as $item ) {
+ $product = wc_get_product( $item['product_id'] );
+ if ( is_a( $product, WC_Product::class ) && ! $this->product_ready_for_pui( $product ) ) {
+ return false;
+ }
+ }
+ }
+
+ if ( is_wc_endpoint_url( 'order-pay' ) ) {
+ /**
+ * Needed for WordPress `query_vars`.
+ *
+ * @psalm-suppress InvalidGlobal
+ */
+ global $wp;
+
+ if ( isset( $wp->query_vars['order-pay'] ) && absint( $wp->query_vars['order-pay'] ) > 0 ) {
+ $order_id = absint( $wp->query_vars['order-pay'] );
+ $order = wc_get_order( $order_id );
+ if ( is_a( $order, WC_Order::class ) ) {
+ foreach ( $order->get_items() as $item_id => $item ) {
+ if ( is_a( $item, WC_Order_Item_Product::class ) ) {
+ $product = wc_get_product( $item->get_product_id() );
+ if ( is_a( $product, WC_Product::class ) && ! $this->product_ready_for_pui( $product ) ) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return true;
+ }
}
diff --git a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
index 5f22441f5..ca9fe38c5 100644
--- a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
+++ b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php
@@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\TestCase;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
use function Brain\Monkey\Functions\when;
class PayUponInvoiceGatewayTest extends TestCase
@@ -24,6 +25,7 @@ class PayUponInvoiceGatewayTest extends TestCase
private $transaction_url_provider;
private $logger;
private $testee;
+ private $pui_helper;
public function setUp(): void
{
@@ -35,6 +37,7 @@ class PayUponInvoiceGatewayTest extends TestCase
$this->environment = Mockery::mock(Environment::class);
$this->logger = Mockery::mock(LoggerInterface::class);
$this->transaction_url_provider = Mockery::mock(TransactionUrlProvider::class);
+ $this->pui_helper = Mockery::mock(PayUponInvoiceHelper::class);
$this->setInitStubs();
@@ -44,7 +47,8 @@ class PayUponInvoiceGatewayTest extends TestCase
$this->payment_source_factory,
$this->environment,
$this->transaction_url_provider,
- $this->logger
+ $this->logger,
+ $this->pui_helper
);
}
From 7d6146bfe9a352fb937003f3dd5843b48109b7b4 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 16 May 2022 16:54:05 +0200
Subject: [PATCH 100/163] Add tracking scope to referral api
---
modules/ppcp-api-client/src/Repository/PartnerReferralsData.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
index 7bf902dcb..d1ea64f64 100644
--- a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
+++ b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
@@ -117,6 +117,7 @@ class PartnerReferralsData {
'REFUND',
'ADVANCED_TRANSACTIONS_SEARCH',
'VAULT',
+ 'TRACKING_SHIPMENT_READWRITE',
),
'seller_nonce' => $this->nonce(),
),
From 676f4a7a108511a8ce017c784dae038b197ee9e9 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 17 May 2022 12:30:50 +0200
Subject: [PATCH 101/163] Ensure pay for order total is valid for pui
---
modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
index 576989c5b..4ec129327 100644
--- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
+++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
@@ -113,6 +113,11 @@ class PayUponInvoiceHelper {
$order_id = absint( $wp->query_vars['order-pay'] );
$order = wc_get_order( $order_id );
if ( is_a( $order, WC_Order::class ) ) {
+ $order_total = (float) $order->get_total();
+ if ( $order_total < 5 || $order_total > 2500 ) {
+ return false;
+ }
+
foreach ( $order->get_items() as $item_id => $item ) {
if ( is_a( $item, WC_Order_Item_Product::class ) ) {
$product = wc_get_product( $item->get_product_id() );
From 58a53af41ef1ffc0e08d60d3fe0655186073a4f4 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 18 May 2022 15:14:04 +0200
Subject: [PATCH 102/163] Do not display pui gateway if customer service
instructions field is empty
---
modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
index 4ec129327..32391bb0a 100644
--- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
+++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php
@@ -76,6 +76,11 @@ class PayUponInvoiceHelper {
* @return bool
*/
public function is_checkout_ready_for_pui(): bool {
+ $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
+ if ( $gateway_settings && '' === $gateway_settings['customer_service_instructions'] ) {
+ return false;
+ }
+
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
if ( $billing_country && 'DE' !== $billing_country ) {
return false;
From 98e356da1702841109821af272d38f907afb23e0 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 20 May 2022 12:08:33 +0200
Subject: [PATCH 103/163] Ensure is pui payment method before custom checkout
validation
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 34b756020..cc9b53ab2 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -317,6 +317,11 @@ class PayUponInvoice {
add_action(
'woocommerce_after_checkout_validation',
function( array $fields, WP_Error $errors ) {
+ $payment_method = filter_input( INPUT_POST, 'payment_method', FILTER_SANITIZE_STRING );
+ if ( PayUponInvoiceGateway::ID !== $payment_method ) {
+ return;
+ }
+
if ( 'DE' !== $fields['billing_country'] ) {
$errors->add( 'validation', __( 'Billing country not available.', 'woocommerce-paypal-payments' ) );
}
From a0e431e07cb9e7d87669cc92d6f90b467ffc86b4 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 23 May 2022 11:48:33 +0200
Subject: [PATCH 104/163] Do not call seller status if current state is not
onboarded
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index cc9b53ab2..929c074c0 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -338,6 +338,10 @@ class PayUponInvoice {
add_filter(
'woocommerce_available_payment_gateways',
function ( array $methods ): array {
+ if ( State::STATE_ONBOARDED !== $this->state->current_state() ) {
+ return $methods;
+ }
+
if (
! $this->pui_product_status->pui_is_active()
|| ! $this->pui_helper->is_checkout_ready_for_pui()
From 4b674adad26f1e0c6110d173f8b09d232a2f7e7a Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 23 May 2022 15:11:36 +0200
Subject: [PATCH 105/163] Add business entity to partner referrals data for pui
onboarding
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 929c074c0..9b4417155 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -175,6 +175,21 @@ class PayUponInvoice {
return $data;
}
+ $data['business_entity'] = array(
+ 'business_type' => array(
+ 'type' => 'PRIVATE_CORPORATION',
+ ),
+ 'addresses' => array(
+ array(
+ 'address_line_1' => WC()->countries->get_base_address(),
+ 'admin_area_1' => WC()->countries->get_base_city(),
+ 'postal_code' => WC()->countries->get_base_postcode(),
+ 'country_code' => WC()->countries->get_base_country(),
+ 'type' => 'WORK',
+ ),
+ ),
+ );
+
if ( in_array( 'PPCP', $data['products'], true ) ) {
$data['products'][] = 'PAYMENT_METHODS';
} elseif ( in_array( 'EXPRESS_CHECKOUT', $data['products'], true ) ) {
From 12a859626187340258d6fe60de33916343100ba2 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 24 May 2022 09:36:56 +0200
Subject: [PATCH 106/163] Bump `1.9.0-test3` version
---
readme.txt | 2 +-
woocommerce-paypal-payments.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/readme.txt b/readme.txt
index 1f2698d0d..67d823422 100644
--- a/readme.txt
+++ b/readme.txt
@@ -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.9.0-test2
+Stable tag: 1.9.0-test3
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php
index b3ad780c7..b549fab65 100644
--- a/woocommerce-paypal-payments.php
+++ b/woocommerce-paypal-payments.php
@@ -3,7 +3,7 @@
* 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.9.0-test2
+ * Version: 1.9.0-test3
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* License: GPL-2.0
From f813cf451abc6585cbd2f45a30a23a5989749e4a Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 25 May 2022 09:42:37 +0200
Subject: [PATCH 107/163] Cache partner referrals signup links
---
modules/ppcp-onboarding/services.php | 5 ++--
.../src/Render/OnboardingRenderer.php | 21 +++++++++++++++-
modules/ppcp-wc-gateway/services.php | 9 +++----
.../src/Settings/SettingsListener.php | 24 ++++++++++++++++++-
.../Settings/SettingsListenerTest.php | 8 ++++---
5 files changed, 56 insertions(+), 11 deletions(-)
diff --git a/modules/ppcp-onboarding/services.php b/modules/ppcp-onboarding/services.php
index d92446054..bb57eb27d 100644
--- a/modules/ppcp-onboarding/services.php
+++ b/modules/ppcp-onboarding/services.php
@@ -211,16 +211,17 @@ return array(
);
},
'onboarding.render' => static function ( ContainerInterface $container ) : OnboardingRenderer {
-
$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' );
+ $cache = new Cache( 'ppcp-paypal-signup-link' );
return new OnboardingRenderer(
$settings,
$partner_referrals,
$partner_referrals_sandbox,
- $partner_referrals_data
+ $partner_referrals_data,
+ $cache
);
},
'onboarding.render-options' => static function ( ContainerInterface $container ) : OnboardingOptionsRenderer {
diff --git a/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php b/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
index 95c0c46a4..ad795673d 100644
--- a/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
+++ b/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
@@ -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\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
@@ -47,6 +48,13 @@ class OnboardingRenderer {
*/
private $partner_referrals_data;
+ /**
+ * The cache
+ *
+ * @var Cache
+ */
+ protected $cache;
+
/**
* OnboardingRenderer constructor.
*
@@ -54,17 +62,20 @@ class OnboardingRenderer {
* @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.
+ * @param Cache $cache The cache.
*/
public function __construct(
Settings $settings,
PartnerReferrals $production_partner_referrals,
PartnerReferrals $sandbox_partner_referrals,
- PartnerReferralsData $partner_referrals_data
+ PartnerReferralsData $partner_referrals_data,
+ Cache $cache
) {
$this->settings = $settings;
$this->production_partner_referrals = $production_partner_referrals;
$this->sandbox_partner_referrals = $sandbox_partner_referrals;
$this->partner_referrals_data = $partner_referrals_data;
+ $this->cache = $cache;
}
/**
@@ -83,9 +94,17 @@ class OnboardingRenderer {
->with_products( $products )
->data();
+ $environment = $is_production ? 'production' : 'sandbox';
+ $product = isset( $data['products']['PPCP'] ) ? 'ppcp' : 'express-checkout';
+ if ( $this->cache->has( $environment . '-' . $product ) ) {
+ return $this->cache->get( $environment . '-' . $product );
+ }
+
$url = $is_production ? $this->production_partner_referrals->signup_link( $data ) : $this->sandbox_partner_referrals->signup_link( $data );
$url = add_query_arg( $args, $url );
+ $this->cache->set( $environment . '-' . $product, $url );
+
return $url;
}
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index fae3111c3..7d5361e7f 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -219,7 +219,8 @@ return array(
$cache = new Cache( 'ppcp-paypal-bearer' );
$bearer = $container->get( 'api.bearer' );
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
- return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state, $bearer, $page_id );
+ $signup_link_cache = new Cache( 'ppcp-paypal-signup-link' );
+ return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state, $bearer, $page_id, $signup_link_cache );
},
'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
@@ -2215,7 +2216,7 @@ return array(
);
},
- 'wcgateway.helper.vaulting-scope' => static function ( ContainerInterface $container ): bool {
+ 'wcgateway.helper.vaulting-scope' => static function ( ContainerInterface $container ): bool {
try {
$token = $container->get( 'api.bearer' )->bearer();
return $token->vaulting_available();
@@ -2224,7 +2225,7 @@ return array(
}
},
- 'button.helper.vaulting-label' => static function ( ContainerInterface $container ): string {
+ 'button.helper.vaulting-label' => static function ( ContainerInterface $container ): string {
$vaulting_label = __( 'Enable saved cards and subscription features on your store.', 'woocommerce-paypal-payments' );
if ( ! $container->get( 'wcgateway.helper.vaulting-scope' ) ) {
@@ -2246,7 +2247,7 @@ return array(
return $vaulting_label;
},
- 'wcgateway.settings.fields.pay-later-label' => static function ( ContainerInterface $container ): string {
+ 'wcgateway.settings.fields.pay-later-label' => static function ( ContainerInterface $container ): string {
$pay_later_label = '%s ';
$pay_later_label .= '';
$pay_later_label .= __( "You have PayPal vaulting enabled, that's why Pay Later Messaging options are unavailable now. You cannot use both features at the same time.", 'woocommerce-paypal-payments' );
diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
index 4bd403378..42af0b00d 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
@@ -81,6 +81,13 @@ class SettingsListener {
*/
protected $page_id;
+ /**
+ * The signup link cache.
+ *
+ * @var Cache
+ */
+ protected $signup_link_cache;
+
/**
* SettingsListener constructor.
*
@@ -91,6 +98,7 @@ class SettingsListener {
* @param State $state The state.
* @param Bearer $bearer The bearer.
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
+ * @param Cache $signup_link_cache The signup link cache.
*/
public function __construct(
Settings $settings,
@@ -99,7 +107,8 @@ class SettingsListener {
Cache $cache,
State $state,
Bearer $bearer,
- string $page_id
+ string $page_id,
+ Cache $signup_link_cache
) {
$this->settings = $settings;
@@ -109,6 +118,7 @@ class SettingsListener {
$this->state = $state;
$this->bearer = $bearer;
$this->page_id = $page_id;
+ $this->signup_link_cache = $signup_link_cache;
}
/**
@@ -260,6 +270,18 @@ class SettingsListener {
true
) ) {
$this->webhook_registrar->unregister();
+
+ $keys = array(
+ 'production-ppcp',
+ 'production-express-checkout',
+ 'sandbox-ppcp',
+ 'sandbox-express-checkout',
+ );
+ foreach ( $keys as $key ) {
+ if ( $this->signup_link_cache->has( $key ) ) {
+ $this->signup_link_cache->delete( $key );
+ }
+ }
}
}
diff --git a/tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php b/tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php
index 050b87e40..99a665b9f 100644
--- a/tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php
+++ b/tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php
@@ -32,12 +32,11 @@ class SettingsListenerTest extends ModularTestCase
$webhook_registrar = Mockery::mock(WebhookRegistrar::class);
$webhook_registrar->shouldReceive('unregister')->andReturnTrue();
$webhook_registrar->shouldReceive('register')->andReturnTrue();
-
$cache = Mockery::mock(Cache::class);
-
$state = Mockery::mock(State::class);
$state->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
$bearer = Mockery::mock(Bearer::class);
+ $signup_link_cache = Mockery::mock(Cache::class);
$testee = new SettingsListener(
$settings,
@@ -46,7 +45,8 @@ class SettingsListenerTest extends ModularTestCase
$cache,
$state,
$bearer,
- PayPalGateway::ID
+ PayPalGateway::ID,
+ $signup_link_cache
);
$_GET['section'] = PayPalGateway::ID;
@@ -74,6 +74,8 @@ class SettingsListenerTest extends ModularTestCase
$settings->shouldReceive('persist');
$cache->shouldReceive('has')
->andReturn(false);
+ $signup_link_cache->shouldReceive('has')
+ ->andReturn(false);
$testee->listen();
}
From 0c5dfbc3e8a60bd3bddf20b1c0aeda8cb7b27e69 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 26 May 2022 11:05:30 +0200
Subject: [PATCH 108/163] Add signup link cache expiration for 3 months
---
modules/ppcp-api-client/src/Helper/Cache.php | 5 +++--
modules/ppcp-onboarding/src/Render/OnboardingRenderer.php | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-api-client/src/Helper/Cache.php b/modules/ppcp-api-client/src/Helper/Cache.php
index e31dd14a3..c5b79dc5c 100644
--- a/modules/ppcp-api-client/src/Helper/Cache.php
+++ b/modules/ppcp-api-client/src/Helper/Cache.php
@@ -67,10 +67,11 @@ class Cache {
*
* @param string $key The key under which the value should be cached.
* @param mixed $value The value to cache.
+ * @param int $expiration Time until expiration in seconds.
*
* @return bool
*/
- public function set( string $key, $value ): bool {
- return (bool) set_transient( $this->prefix . $key, $value );
+ public function set( string $key, $value, int $expiration = 0 ): bool {
+ return (bool) set_transient( $this->prefix . $key, $value, $expiration );
}
}
diff --git a/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php b/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
index ad795673d..88091d606 100644
--- a/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
+++ b/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
@@ -103,7 +103,7 @@ class OnboardingRenderer {
$url = $is_production ? $this->production_partner_referrals->signup_link( $data ) : $this->sandbox_partner_referrals->signup_link( $data );
$url = add_query_arg( $args, $url );
- $this->cache->set( $environment . '-' . $product, $url );
+ $this->cache->set( $environment . '-' . $product, $url, 3 * MONTH_IN_SECONDS );
return $url;
}
From 9b88d1a4aee006eb67b504073288455bf48d747d Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 26 May 2022 11:29:09 +0200
Subject: [PATCH 109/163] Move signup link cache into a service
---
modules/ppcp-onboarding/services.php | 7 +++++--
modules/ppcp-wc-gateway/services.php | 2 +-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-onboarding/services.php b/modules/ppcp-onboarding/services.php
index bb57eb27d..f200d97d1 100644
--- a/modules/ppcp-onboarding/services.php
+++ b/modules/ppcp-onboarding/services.php
@@ -210,18 +210,21 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' )
);
},
+ 'onboarding.signup-link-cache' => static function( ContainerInterface $container ): Cache {
+ return new Cache( 'ppcp-paypal-signup-link' );
+ },
'onboarding.render' => static function ( ContainerInterface $container ) : OnboardingRenderer {
$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' );
- $cache = new Cache( 'ppcp-paypal-signup-link' );
+ $signup_link_cache = $container->get( 'onboarding.signup-link-cache' );
return new OnboardingRenderer(
$settings,
$partner_referrals,
$partner_referrals_sandbox,
$partner_referrals_data,
- $cache
+ $signup_link_cache
);
},
'onboarding.render-options' => static function ( ContainerInterface $container ) : OnboardingOptionsRenderer {
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 7d5361e7f..f0f890cbb 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -219,7 +219,7 @@ return array(
$cache = new Cache( 'ppcp-paypal-bearer' );
$bearer = $container->get( 'api.bearer' );
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
- $signup_link_cache = new Cache( 'ppcp-paypal-signup-link' );
+ $signup_link_cache = $container->get( 'onboarding.signup-link-cache' );
return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state, $bearer, $page_id, $signup_link_cache );
},
'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
From aa156a17b26408b56d148dbcb4f08bb7e3e76137 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 26 May 2022 14:23:17 +0200
Subject: [PATCH 110/163] Add month in seconds constant to psalm stubs
---
.psalm/stubs.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/.psalm/stubs.php b/.psalm/stubs.php
index 9f0cdaf55..00ece2e4e 100644
--- a/.psalm/stubs.php
+++ b/.psalm/stubs.php
@@ -2,3 +2,6 @@
if (!defined('EP_PAGES')) {
define('EP_PAGES', 4096);
}
+if (!defined('MONTH_IN_SECONDS')) {
+ define('MONTH_IN_SECONDS', 30 * DAY_IN_SECONDS);
+}
From f1e54ced4f5e79e9caa13cc3df6d2ec00a40db55 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 27 May 2022 14:53:55 +0200
Subject: [PATCH 111/163] Get signup links without reloading the page (WIP)
---
.../ppcp-onboarding/assets/js/onboarding.js | 9 ++-
modules/ppcp-onboarding/services.php | 11 +++
.../src/Endpoint/PayUponInvoiceEndpoint.php | 67 ++++++++++++++++---
modules/ppcp-wc-gateway/services.php | 13 +++-
.../src/Settings/SettingsListener.php | 20 +++---
5 files changed, 102 insertions(+), 18 deletions(-)
diff --git a/modules/ppcp-onboarding/assets/js/onboarding.js b/modules/ppcp-onboarding/assets/js/onboarding.js
index 31dfe9745..05db30d32 100644
--- a/modules/ppcp-onboarding/assets/js/onboarding.js
+++ b/modules/ppcp-onboarding/assets/js/onboarding.js
@@ -87,7 +87,14 @@ const ppcp_onboarding = {
}).then((res)=>{
return res.json();
}).then((data)=>{
- location.reload();
+ buttons.forEach((element) => {
+ for (let [key, value] of Object.entries(data.data.signup_links)) {
+ key = 'connect-to' + key.replace(/-/g, '');
+ if(key === element.id) {
+ element.setAttribute('href', value);
+ }
+ }
+ });
});
})
},
diff --git a/modules/ppcp-onboarding/services.php b/modules/ppcp-onboarding/services.php
index f200d97d1..82f26e26c 100644
--- a/modules/ppcp-onboarding/services.php
+++ b/modules/ppcp-onboarding/services.php
@@ -191,6 +191,9 @@ return array(
return new PayUponInvoiceEndpoint(
$container->get( 'wcgateway.settings' ),
$container->get( 'button.request-data' ),
+ $container->get( 'onboarding.signup-link-cache' ),
+ $container->get( 'onboarding.render' ),
+ $container->get( 'onboarding.signup-link-ids' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
@@ -213,6 +216,14 @@ return array(
'onboarding.signup-link-cache' => static function( ContainerInterface $container ): Cache {
return new Cache( 'ppcp-paypal-signup-link' );
},
+ 'onboarding.signup-link-ids' => static function ( ContainerInterface $container ): array {
+ return array(
+ 'production-ppcp',
+ 'production-express_checkout',
+ 'sandbox-ppcp',
+ 'sandbox-express_checkout',
+ );
+ },
'onboarding.render' => static function ( ContainerInterface $container ) : OnboardingRenderer {
$partner_referrals = $container->get( 'api.endpoint.partner-referrals-production' );
$partner_referrals_sandbox = $container->get( 'api.endpoint.partner-referrals-sandbox' );
diff --git a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
index 1793f84c8..5f81ca8a7 100644
--- a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
+++ b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
@@ -11,8 +11,10 @@ namespace WooCommerce\PayPalCommerce\Onboarding\Endpoint;
use Exception;
use Psr\Log\LoggerInterface;
+use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\Button\Endpoint\EndpointInterface;
use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData;
+use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
@@ -35,6 +37,27 @@ class PayUponInvoiceEndpoint implements EndpointInterface {
*/
protected $request_data;
+ /**
+ * The signup link cache.
+ *
+ * @var Cache
+ */
+ protected $signup_link_cache;
+
+ /**
+ * The onboarding renderer.
+ *
+ * @var OnboardingRenderer
+ */
+ protected $onboarding_renderer;
+
+ /**
+ * Signup link ids.
+ *
+ * @var array
+ */
+ protected $signup_link_ids;
+
/**
* The logger.
*
@@ -45,14 +68,27 @@ class PayUponInvoiceEndpoint implements EndpointInterface {
/**
* PayUponInvoiceEndpoint constructor.
*
- * @param Settings $settings The settings.
- * @param RequestData $request_data The request data.
- * @param LoggerInterface $logger The logger.
+ * @param Settings $settings The settings.
+ * @param RequestData $request_data The request data.
+ * @param Cache $signup_link_cache The signup link cache.
+ * @param OnboardingRenderer $onboarding_renderer The onboarding renderer.
+ * @param array $signup_link_ids Signup link ids.
+ * @param LoggerInterface $logger The logger.
*/
- public function __construct( Settings $settings, RequestData $request_data, LoggerInterface $logger ) {
- $this->settings = $settings;
- $this->request_data = $request_data;
- $this->logger = $logger;
+ public function __construct(
+ Settings $settings,
+ RequestData $request_data,
+ Cache $signup_link_cache,
+ OnboardingRenderer $onboarding_renderer,
+ array $signup_link_ids,
+ LoggerInterface $logger
+ ) {
+ $this->settings = $settings;
+ $this->request_data = $request_data;
+ $this->signup_link_cache = $signup_link_cache;
+ $this->onboarding_renderer = $onboarding_renderer;
+ $this->logger = $logger;
+ $this->signup_link_ids = $signup_link_ids;
}
/**
@@ -71,18 +107,33 @@ class PayUponInvoiceEndpoint implements EndpointInterface {
* @throws NotFoundException When order not found or handling failed.
*/
public function handle_request(): bool {
+ $signup_links = array();
+
try {
$data = $this->request_data->read_request( $this->nonce() );
$this->settings->set( 'ppcp-onboarding-pui', $data['checked'] );
$this->settings->persist();
+ foreach ( $this->signup_link_ids as $key ) {
+ if ( $this->signup_link_cache->has( $key ) ) {
+ $this->signup_link_cache->delete( $key );
+ }
+ }
+
+ foreach ( $this->signup_link_ids as $key ) {
+ $parts = explode( '-', $key );
+ $is_production = 'production' === $parts[0];
+ $products = 'ppcp' === $parts[1] ? array( 'PPCP' ) : array( 'EXPRESS_CHECKOUT' );
+ $signup_links[ $key ] = $this->onboarding_renderer->get_signup_link( $is_production, $products );
+ }
} catch ( Exception $exception ) {
$this->logger->error( $exception->getMessage() );
}
wp_send_json_success(
array(
- $this->settings->get( 'ppcp-onboarding-pui' ),
+ 'onboarding_pui' => $this->settings->get( 'ppcp-onboarding-pui' ),
+ 'signup_links' => $signup_links,
)
);
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index f0f890cbb..bdb3f8460 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -220,7 +220,18 @@ return array(
$bearer = $container->get( 'api.bearer' );
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
$signup_link_cache = $container->get( 'onboarding.signup-link-cache' );
- return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state, $bearer, $page_id, $signup_link_cache );
+ $signup_link_ids = $container->get( 'onboarding.signup-link-ids' );
+ return new SettingsListener(
+ $settings,
+ $fields,
+ $webhook_registrar,
+ $cache,
+ $state,
+ $bearer,
+ $page_id,
+ $signup_link_cache,
+ $signup_link_ids
+ );
},
'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
index 42af0b00d..d93b05504 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
@@ -88,6 +88,13 @@ class SettingsListener {
*/
protected $signup_link_cache;
+ /**
+ * Signup link ids
+ *
+ * @var array
+ */
+ protected $signup_link_ids;
+
/**
* SettingsListener constructor.
*
@@ -99,6 +106,7 @@ class SettingsListener {
* @param Bearer $bearer The bearer.
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
* @param Cache $signup_link_cache The signup link cache.
+ * @param array $signup_link_ids Signup link ids.
*/
public function __construct(
Settings $settings,
@@ -108,7 +116,8 @@ class SettingsListener {
State $state,
Bearer $bearer,
string $page_id,
- Cache $signup_link_cache
+ Cache $signup_link_cache,
+ array $signup_link_ids
) {
$this->settings = $settings;
@@ -119,6 +128,7 @@ class SettingsListener {
$this->bearer = $bearer;
$this->page_id = $page_id;
$this->signup_link_cache = $signup_link_cache;
+ $this->signup_link_ids = $signup_link_ids;
}
/**
@@ -271,13 +281,7 @@ class SettingsListener {
) ) {
$this->webhook_registrar->unregister();
- $keys = array(
- 'production-ppcp',
- 'production-express-checkout',
- 'sandbox-ppcp',
- 'sandbox-express-checkout',
- );
- foreach ( $keys as $key ) {
+ foreach ( $this->signup_link_ids as $key ) {
if ( $this->signup_link_cache->has( $key ) ) {
$this->signup_link_cache->delete( $key );
}
From af25aeead0734276f11ecfcfc47dcfa0b6be7ae1 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 27 May 2022 14:58:38 +0200
Subject: [PATCH 112/163] Fix phpunit
---
tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php b/tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php
index 99a665b9f..d4499e874 100644
--- a/tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php
+++ b/tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php
@@ -37,6 +37,7 @@ class SettingsListenerTest extends ModularTestCase
$state->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
$bearer = Mockery::mock(Bearer::class);
$signup_link_cache = Mockery::mock(Cache::class);
+ $signup_link_ids = array();
$testee = new SettingsListener(
$settings,
@@ -46,7 +47,8 @@ class SettingsListenerTest extends ModularTestCase
$state,
$bearer,
PayPalGateway::ID,
- $signup_link_cache
+ $signup_link_cache,
+ $signup_link_ids
);
$_GET['section'] = PayPalGateway::ID;
From 24280dda3ad1a157d7eb7946ef89df81aee304b0 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 27 May 2022 16:07:52 +0200
Subject: [PATCH 113/163] Fix wrong cache key product assigment
---
modules/ppcp-onboarding/src/Render/OnboardingRenderer.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php b/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
index 88091d606..8bbbc238a 100644
--- a/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
+++ b/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
@@ -95,7 +95,7 @@ class OnboardingRenderer {
->data();
$environment = $is_production ? 'production' : 'sandbox';
- $product = isset( $data['products']['PPCP'] ) ? 'ppcp' : 'express-checkout';
+ $product = 'PPCP' === $data['products'][0] ? 'ppcp' : 'express_checkout';
if ( $this->cache->has( $environment . '-' . $product ) ) {
return $this->cache->get( $environment . '-' . $product );
}
From 4b85831f52521eb5d57acfd2f6e0c25fa475fc04 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 31 May 2022 09:35:50 +0200
Subject: [PATCH 114/163] Do not update button links if response is not
successful
---
modules/ppcp-onboarding/assets/js/onboarding.js | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/modules/ppcp-onboarding/assets/js/onboarding.js b/modules/ppcp-onboarding/assets/js/onboarding.js
index 05db30d32..483d87a0c 100644
--- a/modules/ppcp-onboarding/assets/js/onboarding.js
+++ b/modules/ppcp-onboarding/assets/js/onboarding.js
@@ -87,6 +87,11 @@ const ppcp_onboarding = {
}).then((res)=>{
return res.json();
}).then((data)=>{
+ if (!data.success) {
+ console.error(data);
+ return;
+ }
+
buttons.forEach((element) => {
for (let [key, value] of Object.entries(data.data.signup_links)) {
key = 'connect-to' + key.replace(/-/g, '');
From 8cffaf9826b1e8e7f451152ccade047f9858f9a6 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 31 May 2022 15:11:56 +0200
Subject: [PATCH 115/163] Alert instead of console error when response is not
successful
---
modules/ppcp-onboarding/assets/js/onboarding.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-onboarding/assets/js/onboarding.js b/modules/ppcp-onboarding/assets/js/onboarding.js
index 483d87a0c..8eb05970f 100644
--- a/modules/ppcp-onboarding/assets/js/onboarding.js
+++ b/modules/ppcp-onboarding/assets/js/onboarding.js
@@ -88,7 +88,7 @@ const ppcp_onboarding = {
return res.json();
}).then((data)=>{
if (!data.success) {
- console.error(data);
+ alert('Could not update signup buttons: ' + data);
return;
}
From e0a94bf2ed24bb0d0467d7e853ee630130394b5c Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 31 May 2022 15:42:40 +0200
Subject: [PATCH 116/163] Persist client credentials as soon as they are
recived
---
modules/ppcp-onboarding/src/Endpoint/LoginSellerEndpoint.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/modules/ppcp-onboarding/src/Endpoint/LoginSellerEndpoint.php b/modules/ppcp-onboarding/src/Endpoint/LoginSellerEndpoint.php
index f01dbb99b..b7a6cdddb 100644
--- a/modules/ppcp-onboarding/src/Endpoint/LoginSellerEndpoint.php
+++ b/modules/ppcp-onboarding/src/Endpoint/LoginSellerEndpoint.php
@@ -145,6 +145,7 @@ class LoginSellerEndpoint implements EndpointInterface {
}
$this->settings->set( 'client_secret', $credentials->client_secret );
$this->settings->set( 'client_id', $credentials->client_id );
+ $this->settings->persist();
$accept_cards = (bool) ( $data['acceptCards'] ?? true );
$funding_sources = array();
From 5ccc49a4a8d9b8346bb530b2e09fd8b3fb69edbf Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 31 May 2022 15:53:39 +0200
Subject: [PATCH 117/163] Fix json error display
---
modules/ppcp-onboarding/assets/js/onboarding.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-onboarding/assets/js/onboarding.js b/modules/ppcp-onboarding/assets/js/onboarding.js
index 8eb05970f..5671938e4 100644
--- a/modules/ppcp-onboarding/assets/js/onboarding.js
+++ b/modules/ppcp-onboarding/assets/js/onboarding.js
@@ -88,7 +88,7 @@ const ppcp_onboarding = {
return res.json();
}).then((data)=>{
if (!data.success) {
- alert('Could not update signup buttons: ' + data);
+ alert('Could not update signup buttons: ' + JSON.stringify(data));
return;
}
From 4639a385d6ff609559cac05b61b6d8622a27537b Mon Sep 17 00:00:00 2001
From: Narek Zakarian
Date: Fri, 17 Jun 2022 17:19:03 +0400
Subject: [PATCH 118/163] Fix credit card detection.
---
.../js/modules/Helper/DccInputFactory.js | 7 ++++--
.../js/modules/Renderer/CreditCardRenderer.js | 22 +++++++++++++++++++
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-button/resources/js/modules/Helper/DccInputFactory.js b/modules/ppcp-button/resources/js/modules/Helper/DccInputFactory.js
index c01969269..c5a2034fc 100644
--- a/modules/ppcp-button/resources/js/modules/Helper/DccInputFactory.js
+++ b/modules/ppcp-button/resources/js/modules/Helper/DccInputFactory.js
@@ -1,9 +1,12 @@
const dccInputFactory = (original) => {
const styles = window.getComputedStyle(original);
const newElement = document.createElement('span');
+
newElement.setAttribute('id', original.id);
+ newElement.setAttribute('class', original.className);
+
Object.values(styles).forEach( (prop) => {
- if (! styles[prop] || ! isNaN(prop) ) {
+ if (! styles[prop] || ! isNaN(prop) || prop === 'background-image' ) {
return;
}
newElement.style.setProperty(prop,'' + styles[prop]);
@@ -11,4 +14,4 @@ const dccInputFactory = (original) => {
return newElement;
}
-export default dccInputFactory;
\ No newline at end of file
+export default dccInputFactory;
diff --git a/modules/ppcp-button/resources/js/modules/Renderer/CreditCardRenderer.js b/modules/ppcp-button/resources/js/modules/Renderer/CreditCardRenderer.js
index e2c08a483..7e0b5a235 100644
--- a/modules/ppcp-button/resources/js/modules/Renderer/CreditCardRenderer.js
+++ b/modules/ppcp-button/resources/js/modules/Renderer/CreditCardRenderer.js
@@ -1,5 +1,6 @@
import dccInputFactory from "../Helper/DccInputFactory";
import {show} from "../Helper/Hiding";
+import Product from "../Entity/Product";
class CreditCardRenderer {
@@ -117,11 +118,23 @@ class CreditCardRenderer {
}
const validCards = this.defaultConfig.hosted_fields.valid_cards;
this.cardValid = validCards.indexOf(event.cards[0].type) !== -1;
+
+ const className = this._cardNumberFiledCLassNameByCardType(event.cards[0].type);
+ this._recreateElementClassAttribute(cardNumber, cardNumberField.className);
+ if (event.fields.number.isValid) {
+ cardNumber.classList.add(className);
+ }
})
hostedFields.on('validityChange', (event) => {
const formValid = Object.keys(event.fields).every(function (key) {
return event.fields[key].isValid;
});
+
+ const className = this._cardNumberFiledCLassNameByCardType(event.cards[0].type);
+ event.fields.number.isValid
+ ? cardNumber.classList.add(className)
+ : this._recreateElementClassAttribute(cardNumber, cardNumberField.className);
+
this.formValid = formValid;
});
@@ -230,5 +243,14 @@ class CreditCardRenderer {
this.errorHandler.message(message);
}
}
+
+ _cardNumberFiledCLassNameByCardType(cardType) {
+ return cardType === 'american-express' ? 'amex' : cardType.replace('-', '');
+ }
+
+ _recreateElementClassAttribute(element, newClassName) {
+ element.removeAttribute('class')
+ element.setAttribute('class', newClassName);
+ }
}
export default CreditCardRenderer;
From b362f295f83637756656e6f09bf24e1032211c12 Mon Sep 17 00:00:00 2001
From: emilicastells
Date: Fri, 17 Jun 2022 16:04:57 +0200
Subject: [PATCH 119/163] Add custom validation for phone number
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 9b4417155..eb9658aea 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -345,6 +345,11 @@ class PayUponInvoice {
if ( $birth_date && ! $this->pui_helper->validate_birth_date( $birth_date ) ) {
$errors->add( 'validation', __( 'Invalid birth date.', 'woocommerce-paypal-payments' ) );
}
+
+ $national_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING );
+ if ( ! preg_match( '/^[0-9]{1,14}?$/', $national_number ) ) {
+ $errors->add( 'validation', __( 'Phone number size must be between 1 and 14', 'woocommerce-paypal-payments' ) );
+ }
},
10,
2
From d6bd02c9c161f2d4083a630491126081217af6fd Mon Sep 17 00:00:00 2001
From: emilicastells
Date: Fri, 17 Jun 2022 16:59:49 +0200
Subject: [PATCH 120/163] Make logo url mandatory field
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 28 +++++++++++++++----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index eb9658aea..0b056b7fb 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -424,12 +424,30 @@ class PayUponInvoice {
PayUponInvoiceGateway::ID === $this->current_ppcp_settings_page_id
&& $this->pui_product_status->pui_is_active()
) {
- $pui_gateway = WC()->payment_gateways->payment_gateways()[ PayUponInvoiceGateway::ID ];
+ $error_messages = array();
+ $pui_gateway = WC()->payment_gateways->payment_gateways()[ PayUponInvoiceGateway::ID ];
+ if ( $pui_gateway->get_option( 'logo_url' ) === '' ) {
+ $error_messages[] = esc_html__( 'Could not enable gateway because "Logo URL" field is empty.', 'woocommerce-paypal-payments' );
+ }
if ( $pui_gateway->get_option( 'customer_service_instructions' ) === '' ) {
- printf(
- '',
- esc_html__( 'Could not enable gateway because "Customer service instructions" field is empty.', 'woocommerce-paypal-payments' )
- );
+ $error_messages[] = esc_html__( 'Could not enable gateway because "Customer service instructions" field is empty.', 'woocommerce-paypal-payments' );
+ }
+ if ( count( $error_messages ) > 0 ) { ?>
+
+ ' . $message . '';
+ },
+ $error_messages
+ )
+ ?>
+
+
Date: Mon, 20 Jun 2022 10:31:39 +0200
Subject: [PATCH 121/163] Enable logging by default for now
---
modules/ppcp-wc-gateway/services.php | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 63a5a4814..433e97931 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2218,15 +2218,7 @@ return array(
);
},
'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
- $settings = $container->get( 'wcgateway.settings' );
-
- /**
- * Whether the logging of the plugin errors/events is enabled.
- */
- return apply_filters(
- 'woocommerce_paypal_payments_is_logging_enabled',
- $settings->has( 'logging_enabled' ) && $settings->get( 'logging_enabled' )
- );
+ return true;
},
'wcgateway.helper.vaulting-scope' => static function ( ContainerInterface $container ): bool {
From 3973bd4a3ba7df9dce02ab91185691a70be565c7 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 20 Jun 2022 10:39:18 +0200
Subject: [PATCH 122/163] Fix psalm
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 0b056b7fb..469a1f62f 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -347,7 +347,7 @@ class PayUponInvoice {
}
$national_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING );
- if ( ! preg_match( '/^[0-9]{1,14}?$/', $national_number ) ) {
+ if ( $national_number && ! preg_match( '/^[0-9]{1,14}?$/', $national_number ) ) {
$errors->add( 'validation', __( 'Phone number size must be between 1 and 14', 'woocommerce-paypal-payments' ) );
}
},
From d9ad48cc6ec11dedb32195708a4459794d151d84 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 20 Jun 2022 10:41:06 +0200
Subject: [PATCH 123/163] Bump 1.9.0-test4 version
---
readme.txt | 2 +-
woocommerce-paypal-payments.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/readme.txt b/readme.txt
index d4352f2ca..4e3e3f9b6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Tags: woocommerce, paypal, payments, ecommerce, e-commerce, store, sales, sell,
Requires at least: 5.3
Tested up to: 6.0
Requires PHP: 7.1
-Stable tag: 1.9.0-test3
+Stable tag: 1.9.0-test4
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php
index b549fab65..4def799b8 100644
--- a/woocommerce-paypal-payments.php
+++ b/woocommerce-paypal-payments.php
@@ -3,7 +3,7 @@
* 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.9.0-test3
+ * Version: 1.9.0-test4
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* License: GPL-2.0
From 9da3f112bc9708719e8b835e6f2a337c10ebc4c4 Mon Sep 17 00:00:00 2001
From: Narek Zakarian
Date: Mon, 20 Jun 2022 15:28:07 +0400
Subject: [PATCH 124/163] Add the hiding messages callback to single product
handler
---
.../ContextBootstrap/SingleProductBootstap.js | 20 ++++++++-----------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js b/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js
index 927b36d84..301b03cd9 100644
--- a/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js
+++ b/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js
@@ -41,7 +41,7 @@ class SingleProductBootstap {
}
- priceAmountIsZero() {
+ priceAmount() {
let priceText = "0";
if (document.querySelector('form.cart ins .woocommerce-Price-amount')) {
@@ -53,9 +53,12 @@ class SingleProductBootstap {
else if (document.querySelector('.product .woocommerce-Price-amount')) {
priceText = document.querySelector('.product .woocommerce-Price-amount').innerText;
}
- const amount = parseFloat(priceText.replace(/([^\d,\.\s]*)/g, ''));
- return amount === 0;
+ return parseFloat(priceText.replace(/([^\d,\.\s]*)/g, ''));
+ }
+
+ priceAmountIsZero() {
+ return this.priceAmount() === 0;
}
render() {
@@ -68,19 +71,12 @@ class SingleProductBootstap {
() => {
this.renderer.showButtons(this.gateway.button.wrapper);
this.renderer.showButtons(this.gateway.hosted_fields.wrapper);
- let priceText = "0";
- if (document.querySelector('form.cart ins .woocommerce-Price-amount')) {
- priceText = document.querySelector('form.cart ins .woocommerce-Price-amount').innerText;
- }
- else if (document.querySelector('form.cart .woocommerce-Price-amount')) {
- priceText = document.querySelector('form.cart .woocommerce-Price-amount').innerText;
- }
- const amount = parseInt(priceText.replace(/([^\d,\.\s]*)/g, ''));
- this.messages.renderWithAmount(amount)
+ this.messages.renderWithAmount(this.priceAmount())
},
() => {
this.renderer.hideButtons(this.gateway.button.wrapper);
this.renderer.hideButtons(this.gateway.hosted_fields.wrapper);
+ this.messages.hideMessages();
},
document.querySelector('form.cart'),
new ErrorHandler(this.gateway.labels.error.generic),
From 20c3c6e34556e6c49ccab8b5193ba3d579f5c2a1 Mon Sep 17 00:00:00 2001
From: Narek Zakarian
Date: Mon, 20 Jun 2022 17:12:58 +0400
Subject: [PATCH 125/163] Fix messaging display when the buttons are disabled.
---
modules/ppcp-button/src/Assets/SmartButton.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php
index bdb6522e6..20af30ef4 100644
--- a/modules/ppcp-button/src/Assets/SmartButton.php
+++ b/modules/ppcp-button/src/Assets/SmartButton.php
@@ -840,7 +840,7 @@ class SmartButton implements SmartButtonInterface {
'messages' => $this->message_values(),
'labels' => array(
'error' => array(
- 'generic' => __(
+ 'generic' => __(
'Something went wrong. Please try again or choose another payment source.',
'woocommerce-paypal-payments'
),
@@ -1037,6 +1037,7 @@ class SmartButton implements SmartButtonInterface {
$this->context() === 'product'
&& $this->settings->has( 'button_product_enabled' )
&& $this->settings->get( 'button_product_enabled' )
+ || $this->settings->has( 'message_product_enabled' )
) {
$load_buttons = true;
}
@@ -1050,6 +1051,7 @@ class SmartButton implements SmartButtonInterface {
$this->context() === 'cart'
&& $this->settings->has( 'button_cart_enabled' )
&& $this->settings->get( 'button_cart_enabled' )
+ || $this->settings->has( 'message_product_enabled' )
) {
$load_buttons = true;
}
From 500487f5f92917b0e49cfa16b38dac7bdb7845c1 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 20 Jun 2022 17:22:28 +0200
Subject: [PATCH 126/163] Check if WC invalid class is visible
---
modules/ppcp-button/resources/js/button.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js
index c416521a0..8038c936e 100644
--- a/modules/ppcp-button/resources/js/button.js
+++ b/modules/ppcp-button/resources/js/button.js
@@ -37,7 +37,7 @@ const bootstrap = () => {
requiredFields.each((i, input) => {
jQuery(input).trigger('validate');
});
- if (jQuery('form.woocommerce-checkout .woocommerce-invalid').length) {
+ if (jQuery('form.woocommerce-checkout .woocommerce-invalid:visible').length) {
errorHandler.clear();
errorHandler.message(PayPalCommerceGateway.labels.error.js_validation);
From d7363a0d4456aa9bd4c66336d9a9eced92493316 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Tue, 21 Jun 2022 09:19:21 +0200
Subject: [PATCH 127/163] Fix phpcs
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 469a1f62f..2986a3be3 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -437,10 +437,7 @@ class PayUponInvoice {
' . $message . '';
},
$error_messages
From fcf9b6b19eb1fd4ec369426d4faca27a38068fe6 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 22 Jun 2022 10:48:56 +0200
Subject: [PATCH 128/163] Add phone number validation for non-numeric
characters
---
composer.lock | 311 +++++++++++-------
.../Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
2 files changed, 198 insertions(+), 115 deletions(-)
diff --git a/composer.lock b/composer.lock
index 1ff2571e2..ddc32c00c 100644
--- a/composer.lock
+++ b/composer.lock
@@ -515,16 +515,16 @@
},
{
"name": "symfony/polyfill-php80",
- "version": "v1.24.0",
+ "version": "v1.26.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
- "reference": "57b712b08eddb97c762a8caa32c84e037892d2e9"
+ "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/57b712b08eddb97c762a8caa32c84e037892d2e9",
- "reference": "57b712b08eddb97c762a8caa32c84e037892d2e9",
+ "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/cfa0ae98841b9e461207c13ab093d76b0fa7bace",
+ "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace",
"shasum": ""
},
"require": {
@@ -533,7 +533,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "1.23-dev"
+ "dev-main": "1.26-dev"
},
"thanks": {
"name": "symfony/polyfill",
@@ -591,7 +591,7 @@
"type": "tidelift"
}
],
- "time": "2021-09-13T13:58:33+00:00"
+ "time": "2022-05-10T07:21:04+00:00"
},
{
"name": "wikimedia/composer-merge-plugin",
@@ -809,12 +809,12 @@
}
},
"autoload": {
- "psr-4": {
- "Amp\\ByteStream\\": "lib"
- },
"files": [
"lib/functions.php"
- ]
+ ],
+ "psr-4": {
+ "Amp\\ByteStream\\": "lib"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -1096,16 +1096,16 @@
},
{
"name": "composer/semver",
- "version": "3.2.9",
+ "version": "3.3.2",
"source": {
"type": "git",
"url": "https://github.com/composer/semver.git",
- "reference": "a951f614bd64dcd26137bc9b7b2637ddcfc57649"
+ "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/composer/semver/zipball/a951f614bd64dcd26137bc9b7b2637ddcfc57649",
- "reference": "a951f614bd64dcd26137bc9b7b2637ddcfc57649",
+ "url": "https://api.github.com/repos/composer/semver/zipball/3953f23262f2bff1919fc82183ad9acb13ff62c9",
+ "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9",
"shasum": ""
},
"require": {
@@ -1168,20 +1168,20 @@
"type": "tidelift"
}
],
- "time": "2022-02-04T13:58:43+00:00"
+ "time": "2022-04-01T19:23:25+00:00"
},
{
"name": "composer/xdebug-handler",
- "version": "2.0.4",
+ "version": "2.0.5",
"source": {
"type": "git",
"url": "https://github.com/composer/xdebug-handler.git",
- "reference": "0c1a3925ec58a4ec98e992b9c7d171e9e184be0a"
+ "reference": "9e36aeed4616366d2b690bdce11f71e9178c579a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/0c1a3925ec58a4ec98e992b9c7d171e9e184be0a",
- "reference": "0c1a3925ec58a4ec98e992b9c7d171e9e184be0a",
+ "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/9e36aeed4616366d2b690bdce11f71e9178c579a",
+ "reference": "9e36aeed4616366d2b690bdce11f71e9178c579a",
"shasum": ""
},
"require": {
@@ -1229,7 +1229,7 @@
"type": "tidelift"
}
],
- "time": "2022-01-04T17:06:45+00:00"
+ "time": "2022-02-24T20:20:32+00:00"
},
{
"name": "dealerdirect/phpcodesniffer-composer-installer",
@@ -1337,29 +1337,30 @@
},
{
"name": "doctrine/instantiator",
- "version": "1.4.0",
+ "version": "1.4.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
- "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b"
+ "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d56bf6102915de5702778fe20f2de3b2fe570b5b",
- "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b",
+ "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc",
+ "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"require-dev": {
- "doctrine/coding-standard": "^8.0",
+ "doctrine/coding-standard": "^9",
"ext-pdo": "*",
"ext-phar": "*",
- "phpbench/phpbench": "^0.13 || 1.0.0-alpha2",
- "phpstan/phpstan": "^0.12",
- "phpstan/phpstan-phpunit": "^0.12",
- "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
+ "phpbench/phpbench": "^0.16 || ^1",
+ "phpstan/phpstan": "^1.4",
+ "phpstan/phpstan-phpunit": "^1",
+ "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
+ "vimeo/psalm": "^4.22"
},
"type": "library",
"autoload": {
@@ -1384,7 +1385,21 @@
"constructor",
"instantiate"
],
- "time": "2020-11-10T18:47:58+00:00"
+ "funding": [
+ {
+ "url": "https://www.doctrine-project.org/sponsorship.html",
+ "type": "custom"
+ },
+ {
+ "url": "https://www.patreon.com/phpdoctrine",
+ "type": "patreon"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2022-03-03T08:28:38+00:00"
},
{
"name": "felixfbecker/advanced-json-rpc",
@@ -1429,16 +1444,16 @@
},
{
"name": "felixfbecker/language-server-protocol",
- "version": "1.5.1",
+ "version": "v1.5.2",
"source": {
"type": "git",
"url": "https://github.com/felixfbecker/php-language-server-protocol.git",
- "reference": "9d846d1f5cf101deee7a61c8ba7caa0a975cd730"
+ "reference": "6e82196ffd7c62f7794d778ca52b69feec9f2842"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/9d846d1f5cf101deee7a61c8ba7caa0a975cd730",
- "reference": "9d846d1f5cf101deee7a61c8ba7caa0a975cd730",
+ "url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/6e82196ffd7c62f7794d778ca52b69feec9f2842",
+ "reference": "6e82196ffd7c62f7794d778ca52b69feec9f2842",
"shasum": ""
},
"require": {
@@ -1477,7 +1492,7 @@
"php",
"server"
],
- "time": "2021-02-22T14:02:09+00:00"
+ "time": "2022-03-02T22:36:06+00:00"
},
{
"name": "hamcrest/hamcrest-php",
@@ -1593,37 +1608,38 @@
},
{
"name": "myclabs/deep-copy",
- "version": "1.10.2",
+ "version": "1.11.0",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
- "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220"
+ "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220",
- "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220",
+ "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614",
+ "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
- "replace": {
- "myclabs/deep-copy": "self.version"
+ "conflict": {
+ "doctrine/collections": "<1.6.8",
+ "doctrine/common": "<2.13.3 || >=3,<3.2.2"
},
"require-dev": {
- "doctrine/collections": "^1.0",
- "doctrine/common": "^2.6",
- "phpunit/phpunit": "^7.1"
+ "doctrine/collections": "^1.6.8",
+ "doctrine/common": "^2.13.3 || ^3.2.2",
+ "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
},
"type": "library",
"autoload": {
- "psr-4": {
- "DeepCopy\\": "src/DeepCopy/"
- },
"files": [
"src/DeepCopy/deep_copy.php"
- ]
+ ],
+ "psr-4": {
+ "DeepCopy\\": "src/DeepCopy/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -1637,7 +1653,13 @@
"object",
"object graph"
],
- "time": "2020-11-13T09:40:50+00:00"
+ "funding": [
+ {
+ "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2022-03-03T13:19:32+00:00"
},
{
"name": "netresearch/jsonmapper",
@@ -1687,16 +1709,16 @@
},
{
"name": "nikic/php-parser",
- "version": "v4.13.2",
+ "version": "v4.14.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
- "reference": "210577fe3cf7badcc5814d99455df46564f3c077"
+ "reference": "34bea19b6e03d8153165d8f30bba4c3be86184c1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/210577fe3cf7badcc5814d99455df46564f3c077",
- "reference": "210577fe3cf7badcc5814d99455df46564f3c077",
+ "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/34bea19b6e03d8153165d8f30bba4c3be86184c1",
+ "reference": "34bea19b6e03d8153165d8f30bba4c3be86184c1",
"shasum": ""
},
"require": {
@@ -1735,7 +1757,7 @@
"parser",
"php"
],
- "time": "2021-11-30T19:35:32+00:00"
+ "time": "2022-05-31T20:59:12+00:00"
},
{
"name": "openlss/lib-array2xml",
@@ -1890,24 +1912,24 @@
},
{
"name": "php-stubs/woocommerce-stubs",
- "version": "v5.9.0",
+ "version": "v5.9.1",
"source": {
"type": "git",
"url": "https://github.com/php-stubs/woocommerce-stubs.git",
- "reference": "a7204cfbb5fa90720773122cb68530087de5bc78"
+ "reference": "486ccff117badfab94c404065d37a77d632d7db5"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/a7204cfbb5fa90720773122cb68530087de5bc78",
- "reference": "a7204cfbb5fa90720773122cb68530087de5bc78",
+ "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/486ccff117badfab94c404065d37a77d632d7db5",
+ "reference": "486ccff117badfab94c404065d37a77d632d7db5",
"shasum": ""
},
"require": {
"php-stubs/wordpress-stubs": "^5.3.0"
},
"require-dev": {
- "giacocorsiglia/stubs-generator": "^0.5.0",
- "php": "~7.1"
+ "php": "~7.1",
+ "php-stubs/generator": "^0.8.0"
},
"suggest": {
"symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions",
@@ -1926,20 +1948,20 @@
"woocommerce",
"wordpress"
],
- "time": "2021-11-05T10:02:27+00:00"
+ "time": "2022-04-30T06:35:48+00:00"
},
{
"name": "php-stubs/wordpress-stubs",
- "version": "v5.9.0",
+ "version": "v5.9.3",
"source": {
"type": "git",
"url": "https://github.com/php-stubs/wordpress-stubs.git",
- "reference": "0fa8dd9a1bd2a1b60e85afc6c798fca1f599cc1b"
+ "reference": "18d56875e5078a50b8ea4bc4b20b735ca61edeee"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/0fa8dd9a1bd2a1b60e85afc6c798fca1f599cc1b",
- "reference": "0fa8dd9a1bd2a1b60e85afc6c798fca1f599cc1b",
+ "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/18d56875e5078a50b8ea4bc4b20b735ca61edeee",
+ "reference": "18d56875e5078a50b8ea4bc4b20b735ca61edeee",
"shasum": ""
},
"replace": {
@@ -1948,7 +1970,7 @@
"require-dev": {
"nikic/php-parser": "< 4.12.0",
"php": "~7.3 || ~8.0",
- "php-stubs/generator": "^0.8.0",
+ "php-stubs/generator": "^0.8.1",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpstan": "^1.2"
},
@@ -1969,7 +1991,7 @@
"static analysis",
"wordpress"
],
- "time": "2022-01-26T00:27:45+00:00"
+ "time": "2022-04-06T15:33:59+00:00"
},
{
"name": "phpcompatibility/php-compatibility",
@@ -2549,6 +2571,12 @@
"keywords": [
"timer"
],
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
"time": "2020-11-30T08:20:02+00:00"
},
{
@@ -2598,6 +2626,12 @@
"keywords": [
"tokenizer"
],
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
"abandoned": true,
"time": "2021-07-26T12:15:06+00:00"
},
@@ -2728,6 +2762,12 @@
],
"description": "Looks up which function or method a line of code belongs to",
"homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/",
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
"time": "2020-11-30T08:15:22+00:00"
},
{
@@ -2792,6 +2832,12 @@
"compare",
"equality"
],
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
"time": "2020-11-30T08:04:30+00:00"
},
{
@@ -2848,6 +2894,12 @@
"unidiff",
"unified diff"
],
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
"time": "2020-11-30T07:59:04+00:00"
},
{
@@ -2901,6 +2953,12 @@
"environment",
"hhvm"
],
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
"time": "2020-11-30T07:53:42+00:00"
},
{
@@ -3072,6 +3130,12 @@
],
"description": "Traverses array structures and object graphs to enumerate all referenced objects",
"homepage": "https://github.com/sebastianbergmann/object-enumerator/",
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
"time": "2020-11-30T07:40:27+00:00"
},
{
@@ -3117,6 +3181,12 @@
],
"description": "Allows reflection of object attributes, including inherited and non-public ones",
"homepage": "https://github.com/sebastianbergmann/object-reflector/",
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
"time": "2020-11-30T07:37:18+00:00"
},
{
@@ -3170,6 +3240,12 @@
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
"time": "2020-11-30T07:34:24+00:00"
},
{
@@ -3212,6 +3288,12 @@
],
"description": "Provides a list of PHP built-in functions that operate on resources",
"homepage": "https://www.github.com/sebastianbergmann/resource-operations",
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
"time": "2020-11-30T07:30:19+00:00"
},
{
@@ -3259,16 +3341,16 @@
},
{
"name": "squizlabs/php_codesniffer",
- "version": "3.6.2",
+ "version": "3.7.1",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
- "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a"
+ "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a",
- "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a",
+ "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619",
+ "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619",
"shasum": ""
},
"require": {
@@ -3306,20 +3388,20 @@
"phpcs",
"standards"
],
- "time": "2021-12-12T21:44:58+00:00"
+ "time": "2022-06-18T07:21:10+00:00"
},
{
"name": "symfony/console",
- "version": "v4.4.37",
+ "version": "v4.4.42",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
- "reference": "0259f01dbf9d77badddbbf4c2abb681f24c9cac6"
+ "reference": "cce7a9f99e22937a71a16b23afa762558808d587"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/console/zipball/0259f01dbf9d77badddbbf4c2abb681f24c9cac6",
- "reference": "0259f01dbf9d77badddbbf4c2abb681f24c9cac6",
+ "url": "https://api.github.com/repos/symfony/console/zipball/cce7a9f99e22937a71a16b23afa762558808d587",
+ "reference": "cce7a9f99e22937a71a16b23afa762558808d587",
"shasum": ""
},
"require": {
@@ -3393,20 +3475,20 @@
"type": "tidelift"
}
],
- "time": "2022-01-26T16:15:26+00:00"
+ "time": "2022-05-14T12:35:33+00:00"
},
{
"name": "symfony/polyfill-ctype",
- "version": "v1.24.0",
+ "version": "v1.26.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
- "reference": "30885182c981ab175d4d034db0f6f469898070ab"
+ "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab",
- "reference": "30885182c981ab175d4d034db0f6f469898070ab",
+ "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4",
+ "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4",
"shasum": ""
},
"require": {
@@ -3421,7 +3503,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "1.23-dev"
+ "dev-main": "1.26-dev"
},
"thanks": {
"name": "symfony/polyfill",
@@ -3429,12 +3511,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Ctype\\": ""
- },
"files": [
"bootstrap.php"
- ]
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Ctype\\": ""
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -3472,20 +3554,20 @@
"type": "tidelift"
}
],
- "time": "2021-10-20T20:35:02+00:00"
+ "time": "2022-05-24T11:49:31+00:00"
},
{
"name": "symfony/polyfill-mbstring",
- "version": "v1.24.0",
+ "version": "v1.26.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
- "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825"
+ "reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825",
- "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825",
+ "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e",
+ "reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e",
"shasum": ""
},
"require": {
@@ -3500,7 +3582,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "1.23-dev"
+ "dev-main": "1.26-dev"
},
"thanks": {
"name": "symfony/polyfill",
@@ -3552,20 +3634,20 @@
"type": "tidelift"
}
],
- "time": "2021-11-30T18:21:41+00:00"
+ "time": "2022-05-24T11:49:31+00:00"
},
{
"name": "symfony/polyfill-php73",
- "version": "v1.24.0",
+ "version": "v1.26.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php73.git",
- "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5"
+ "reference": "e440d35fa0286f77fb45b79a03fedbeda9307e85"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/cc5db0e22b3cb4111010e48785a97f670b350ca5",
- "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5",
+ "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/e440d35fa0286f77fb45b79a03fedbeda9307e85",
+ "reference": "e440d35fa0286f77fb45b79a03fedbeda9307e85",
"shasum": ""
},
"require": {
@@ -3574,7 +3656,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "1.23-dev"
+ "dev-main": "1.26-dev"
},
"thanks": {
"name": "symfony/polyfill",
@@ -3628,20 +3710,20 @@
"type": "tidelift"
}
],
- "time": "2021-06-05T21:20:04+00:00"
+ "time": "2022-05-24T11:49:31+00:00"
},
{
"name": "symfony/service-contracts",
- "version": "v1.1.11",
+ "version": "v1.1.12",
"source": {
"type": "git",
"url": "https://github.com/symfony/service-contracts.git",
- "reference": "633df678bec3452e04a7b0337c9bcfe7354124b3"
+ "reference": "eedb374f02031714a48848758a27812f3eca317a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/service-contracts/zipball/633df678bec3452e04a7b0337c9bcfe7354124b3",
- "reference": "633df678bec3452e04a7b0337c9bcfe7354124b3",
+ "url": "https://api.github.com/repos/symfony/service-contracts/zipball/eedb374f02031714a48848758a27812f3eca317a",
+ "reference": "eedb374f02031714a48848758a27812f3eca317a",
"shasum": ""
},
"require": {
@@ -3704,7 +3786,7 @@
"type": "tidelift"
}
],
- "time": "2021-11-04T13:32:43+00:00"
+ "time": "2022-03-09T13:39:03+00:00"
},
{
"name": "theseer/tokenizer",
@@ -3748,16 +3830,16 @@
},
{
"name": "vimeo/psalm",
- "version": "4.21.0",
+ "version": "4.23.0",
"source": {
"type": "git",
"url": "https://github.com/vimeo/psalm.git",
- "reference": "d8bec4c7aaee111a532daec32fb09de5687053d1"
+ "reference": "f1fe6ff483bf325c803df9f510d09a03fd796f88"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/vimeo/psalm/zipball/d8bec4c7aaee111a532daec32fb09de5687053d1",
- "reference": "d8bec4c7aaee111a532daec32fb09de5687053d1",
+ "url": "https://api.github.com/repos/vimeo/psalm/zipball/f1fe6ff483bf325c803df9f510d09a03fd796f88",
+ "reference": "f1fe6ff483bf325c803df9f510d09a03fd796f88",
"shasum": ""
},
"require": {
@@ -3782,6 +3864,7 @@
"php": "^7.1|^8",
"sebastian/diff": "^3.0 || ^4.0",
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0 || ^6.0",
+ "symfony/polyfill-php80": "^1.25",
"webmozart/path-util": "^2.3"
},
"provide": {
@@ -3846,7 +3929,7 @@
"inspection",
"php"
],
- "time": "2022-02-18T04:34:15+00:00"
+ "time": "2022-04-28T17:35:49+00:00"
},
{
"name": "webmozart/assert",
@@ -3946,16 +4029,16 @@
},
{
"name": "woocommerce/woocommerce-sniffs",
- "version": "0.1.2",
+ "version": "0.1.3",
"source": {
"type": "git",
"url": "https://github.com/woocommerce/woocommerce-sniffs.git",
- "reference": "5566270d280a300bc24bd0cb055a8b9325afdd6b"
+ "reference": "4576d54595614d689bc4436acff8baaece3c5bb0"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/woocommerce/woocommerce-sniffs/zipball/5566270d280a300bc24bd0cb055a8b9325afdd6b",
- "reference": "5566270d280a300bc24bd0cb055a8b9325afdd6b",
+ "url": "https://api.github.com/repos/woocommerce/woocommerce-sniffs/zipball/4576d54595614d689bc4436acff8baaece3c5bb0",
+ "reference": "4576d54595614d689bc4436acff8baaece3c5bb0",
"shasum": ""
},
"require": {
@@ -3982,7 +4065,7 @@
"woocommerce",
"wordpress"
],
- "time": "2022-01-21T20:13:23+00:00"
+ "time": "2022-02-17T15:34:51+00:00"
},
{
"name": "wp-coding-standards/wpcs",
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 2986a3be3..6d6189f12 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -347,7 +347,7 @@ class PayUponInvoice {
}
$national_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING );
- if ( $national_number && ! preg_match( '/^[0-9]{1,14}?$/', $national_number ) ) {
+ if ( $national_number && ! preg_match( '/^[0-9]{1,14}?$/', preg_replace( '/[^0-9]/', '', $national_number ) ) ) {
$errors->add( 'validation', __( 'Phone number size must be between 1 and 14', 'woocommerce-paypal-payments' ) );
}
},
From fff6c84e915ee25fefd452de06d883865ece7497 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 22 Jun 2022 11:11:16 +0200
Subject: [PATCH 129/163] Log order status in payment captured webhook checker
---
.../src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php | 3 ++-
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 9 +++++++--
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index 9da546f9e..b6923942d 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -218,7 +218,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
time() + ( 5 * MINUTE_IN_SECONDS ),
'woocommerce_paypal_payments_check_pui_payment_captured',
array(
- 'order_id' => $order_id,
+ 'wc_order_id' => $order_id,
+ 'order_id' => $order->id(),
)
);
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index f633c585f..ad77e5df7 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -235,8 +235,13 @@ class WCGatewayModule implements ModuleInterface {
add_action(
'woocommerce_paypal_payments_check_pui_payment_captured',
- function ( int $order_id ) {
- $wc_order = wc_get_order( $order_id );
+ function ( int $wc_order_id, string $order_id ) use ( $c ) {
+ $order_endpoint = $c->get( 'api.endpoint.order' );
+ $logger = $c->get( 'woocommerce.logger.woocommerce' );
+ $order = $order_endpoint->order( $order_id );
+ $logger->info( 'Checking payment captured webhook, order status: ' . $order->status() );
+
+ $wc_order = wc_get_order( $wc_order_id );
if ( ! is_a( $wc_order, WC_Order::class ) || $wc_order->get_status() !== 'on-hold' ) {
return;
}
From 977cd2f71390a25e3a0377ddc5d04b7c56e96165 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 22 Jun 2022 11:33:39 +0200
Subject: [PATCH 130/163] Add priority and number of arguments to
`woocommerce_paypal_payments_check_pui_payment_captured` action
---
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index ad77e5df7..b57b8ab42 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -251,7 +251,7 @@ class WCGatewayModule implements ModuleInterface {
'woocommerce-paypal-payments'
);
$wc_order->update_status( 'failed', $message );
- }
+ }, 10, 2
);
}
From 644604595e5b56e1b09bf1b05840ce6cad04da81 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 22 Jun 2022 11:44:28 +0200
Subject: [PATCH 131/163] Print order status in log
---
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index b57b8ab42..b37ab714b 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -239,7 +239,7 @@ class WCGatewayModule implements ModuleInterface {
$order_endpoint = $c->get( 'api.endpoint.order' );
$logger = $c->get( 'woocommerce.logger.woocommerce' );
$order = $order_endpoint->order( $order_id );
- $logger->info( 'Checking payment captured webhook, order status: ' . $order->status() );
+ $logger->info( 'Checking payment captured webhook, order status: ' . wc_print_r($order->status(), true) );
$wc_order = wc_get_order( $wc_order_id );
if ( ! is_a( $wc_order, WC_Order::class ) || $wc_order->get_status() !== 'on-hold' ) {
From 5fbe7580d0e7205b4b303c1c4634a4eade6c9182 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Wed, 22 Jun 2022 11:47:35 +0200
Subject: [PATCH 132/163] Log order status
---
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index b37ab714b..aa5ea4279 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -239,7 +239,8 @@ class WCGatewayModule implements ModuleInterface {
$order_endpoint = $c->get( 'api.endpoint.order' );
$logger = $c->get( 'woocommerce.logger.woocommerce' );
$order = $order_endpoint->order( $order_id );
- $logger->info( 'Checking payment captured webhook, order status: ' . wc_print_r($order->status(), true) );
+ $order_status = $order->status();
+ $logger->info( 'Checking payment captured webhook, order status: ' . $order_status->name());
$wc_order = wc_get_order( $wc_order_id );
if ( ! is_a( $wc_order, WC_Order::class ) || $wc_order->get_status() !== 'on-hold' ) {
From 035ff32d5952b133ba00d90469742142bf2be350 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 23 Jun 2022 11:13:41 +0200
Subject: [PATCH 133/163] Fail WC order only if PayPal order status is not
completed
---
.../ppcp-wc-gateway/src/WCGatewayModule.php | 23 ++++++++++++-------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index aa5ea4279..5cd25d7e0 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -14,6 +14,7 @@ use Dhii\Modular\Module\ModuleInterface;
use WC_Order;
use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
+use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
use WooCommerce\PayPalCommerce\WcGateway\Admin\FeesRenderer;
@@ -239,20 +240,26 @@ class WCGatewayModule implements ModuleInterface {
$order_endpoint = $c->get( 'api.endpoint.order' );
$logger = $c->get( 'woocommerce.logger.woocommerce' );
$order = $order_endpoint->order( $order_id );
- $order_status = $order->status();
- $logger->info( 'Checking payment captured webhook, order status: ' . $order_status->name());
+ $order_status = $order->status();
+ $logger->info( "Checking payment captured webhook for WC order #{$wc_order_id}, PayPal order status: " . $order_status->name() );
$wc_order = wc_get_order( $wc_order_id );
if ( ! is_a( $wc_order, WC_Order::class ) || $wc_order->get_status() !== 'on-hold' ) {
return;
}
- $message = __(
- 'Could not process order because PAYMENT.CAPTURE.COMPLETED webhook not received.',
- 'woocommerce-paypal-payments'
- );
- $wc_order->update_status( 'failed', $message );
- }, 10, 2
+ if ( $order_status->name() !== OrderStatus::COMPLETED ) {
+ $message = __(
+ 'Could not process WC order because PAYMENT.CAPTURE.COMPLETED webhook not received.',
+ 'woocommerce-paypal-payments'
+ );
+ $logger->error( $message );
+ $wc_order->update_status( 'failed', $message );
+ }
+
+ },
+ 10,
+ 2
);
}
From 2b4f77818b350fcdae9617fed7b335a257a72e69 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 23 Jun 2022 11:50:08 +0200
Subject: [PATCH 134/163] Fix psalm
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 7 +++++--
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 1 -
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 6d6189f12..7243d84c4 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -347,8 +347,11 @@ class PayUponInvoice {
}
$national_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING );
- if ( $national_number && ! preg_match( '/^[0-9]{1,14}?$/', preg_replace( '/[^0-9]/', '', $national_number ) ) ) {
- $errors->add( 'validation', __( 'Phone number size must be between 1 and 14', 'woocommerce-paypal-payments' ) );
+ if ( $national_number ) {
+ $numeric_phone_number = preg_replace( '/[^0-9]/', '', $national_number );
+ if ( $numeric_phone_number && ! preg_match( '/^[0-9]{1,14}?$/', $numeric_phone_number ) ) {
+ $errors->add( 'validation', __( 'Phone number size must be between 1 and 14', 'woocommerce-paypal-payments' ) );
+ }
}
},
10,
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 5cd25d7e0..5d85638f1 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -256,7 +256,6 @@ class WCGatewayModule implements ModuleInterface {
$logger->error( $message );
$wc_order->update_status( 'failed', $message );
}
-
},
10,
2
From c35baea61717534897325a023f4817ccc7ea1d9c Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 23 Jun 2022 12:04:44 +0200
Subject: [PATCH 135/163] Exclude phpcs comment hook rule for now
---
phpcs.xml.dist | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index f0fdaf9f9..72bb3fb08 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -25,6 +25,11 @@
+
+
+
+
+
From c880815e342ecea90ce4b328012a1f210c971092 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 23 Jun 2022 12:42:53 +0200
Subject: [PATCH 136/163] Display pui payment instructions in order metabox
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 37 +++++++++++++++++++
phpcs.xml.dist | 1 +
2 files changed, 38 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 7243d84c4..314d29e26 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -452,6 +452,43 @@ class PayUponInvoice {
}
}
);
+
+ add_action(
+ 'add_meta_boxes',
+ function( $post_type ) {
+ if ( $post_type === 'shop_order' ) {
+ $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_STRING );
+ $order = wc_get_order( $post_id );
+ if ( $order->get_payment_method() === 'ppcp-pay-upon-invoice-gateway' ) {
+ $instructions = $order->get_meta( 'ppcp_ratepay_payment_instructions_payment_reference' );
+ if ( $instructions ) {
+ add_meta_box(
+ 'ppcp_pui_ratepay_payment_instructions',
+ __( 'RatePay payment instructions', 'woocommerce-paypal-payments' ),
+ function() {
+ $payment_reference = $instructions[0] ?? '';
+ $bic = $instructions[1]->bic ?? '';
+ $bank_name = $instructions[1]->bank_name ?? '';
+ $iban = $instructions[1]->iban ?? '';
+ $account_holder_name = $instructions[1]->account_holder_name ?? '';
+
+ echo '';
+ echo wp_kses_post( "Empfänger: {$account_holder_name} " );
+ echo wp_kses_post( "IBAN: {$iban} " );
+ echo wp_kses_post( "BIC: {$bic} " );
+ echo wp_kses_post( "Name der Bank: {$bank_name} " );
+ echo wp_kses_post( "Verwendungszweck: {$payment_reference} " );
+ echo ' ';
+ },
+ $post_type,
+ 'side',
+ 'high'
+ );
+ }
+ }
+ }
+ }
+ );
}
/**
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 72bb3fb08..64e16f16c 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -23,6 +23,7 @@
+
From 63cb0bad56f7c23634523dbc3a7cdd0bda24304c Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 23 Jun 2022 14:15:11 +0200
Subject: [PATCH 137/163] Log pui payment instructions in order
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 314d29e26..df72722e5 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -462,6 +462,8 @@ class PayUponInvoice {
if ( $order->get_payment_method() === 'ppcp-pay-upon-invoice-gateway' ) {
$instructions = $order->get_meta( 'ppcp_ratepay_payment_instructions_payment_reference' );
if ( $instructions ) {
+ $this->logger->info("Displaying payment instructions for WC order #{$order->get_id()}");
+ $this->logger->info(wc_print_r($instructions, true));
add_meta_box(
'ppcp_pui_ratepay_payment_instructions',
__( 'RatePay payment instructions', 'woocommerce-paypal-payments' ),
From 67ff58251142fdd4028e74c98c98c396bdfffe2d Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 23 Jun 2022 14:55:16 +0200
Subject: [PATCH 138/163] Fix psalm
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index df72722e5..acb8ec8cd 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -455,19 +455,17 @@ class PayUponInvoice {
add_action(
'add_meta_boxes',
- function( $post_type ) {
+ function( string $post_type ) {
if ( $post_type === 'shop_order' ) {
$post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_STRING );
$order = wc_get_order( $post_id );
- if ( $order->get_payment_method() === 'ppcp-pay-upon-invoice-gateway' ) {
+ if ( is_a( $order, WC_Order::class ) && $order->get_payment_method() === 'ppcp-pay-upon-invoice-gateway' ) {
$instructions = $order->get_meta( 'ppcp_ratepay_payment_instructions_payment_reference' );
if ( $instructions ) {
- $this->logger->info("Displaying payment instructions for WC order #{$order->get_id()}");
- $this->logger->info(wc_print_r($instructions, true));
add_meta_box(
'ppcp_pui_ratepay_payment_instructions',
__( 'RatePay payment instructions', 'woocommerce-paypal-payments' ),
- function() {
+ function() use ( $instructions ) {
$payment_reference = $instructions[0] ?? '';
$bic = $instructions[1]->bic ?? '';
$bank_name = $instructions[1]->bank_name ?? '';
From 70189f192862908d48484da268156bfbfa0c56d8 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 23 Jun 2022 15:03:26 +0200
Subject: [PATCH 139/163] Ensure birth date is not empty
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index acb8ec8cd..0ebec8c17 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -342,7 +342,7 @@ class PayUponInvoice {
}
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
- if ( $birth_date && ! $this->pui_helper->validate_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' ) );
}
From 6c3f9f4dfdebca9d03bc797b64347df94f8a62d2 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Thu, 23 Jun 2022 15:08:19 +0200
Subject: [PATCH 140/163] Bump 1.9.0-test5 version
---
readme.txt | 2 +-
woocommerce-paypal-payments.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/readme.txt b/readme.txt
index 4e3e3f9b6..ea9181349 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Tags: woocommerce, paypal, payments, ecommerce, e-commerce, store, sales, sell,
Requires at least: 5.3
Tested up to: 6.0
Requires PHP: 7.1
-Stable tag: 1.9.0-test4
+Stable tag: 1.9.0-test5
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php
index 4def799b8..6beaf9613 100644
--- a/woocommerce-paypal-payments.php
+++ b/woocommerce-paypal-payments.php
@@ -3,7 +3,7 @@
* 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.9.0-test4
+ * Version: 1.9.0-test5
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* License: GPL-2.0
From 1d9af879efa4654e53c264b6d3dcf3e79c584c85 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 27 Jun 2022 12:33:51 +0200
Subject: [PATCH 141/163] Fix phpunit
---
.../ApiClient/Factory/ItemFactoryTest.php | 28 -------------------
1 file changed, 28 deletions(-)
diff --git a/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php b/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php
index 502491337..640dffcdf 100644
--- a/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php
+++ b/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php
@@ -31,9 +31,6 @@ class ItemFactoryTest extends TestCase
$product
->expects('is_virtual')
->andReturn(false);
- $product
- ->expects('get_tax_class')
- ->andReturn('');
$items = [
[
'data' => $product,
@@ -56,9 +53,6 @@ class ItemFactoryTest extends TestCase
$woocommerce->session = $session;
$session->shouldReceive('get')->andReturn([]);
- $tax = Mockery::mock('alias:WC_Tax');
- $tax->expects('get_rates')->andReturn([]);
-
$result = $testee->from_wc_cart($cart);
$this->assertCount(1, $result);
@@ -92,9 +86,6 @@ class ItemFactoryTest extends TestCase
$product
->expects('is_virtual')
->andReturn(true);
- $product
- ->expects('get_tax_class')
- ->andReturn('');
$items = [
[
@@ -118,8 +109,6 @@ class ItemFactoryTest extends TestCase
$woocommerce->session = $session;
$session->shouldReceive('get')->andReturn([]);
- $tax = Mockery::mock('alias:WC_Tax');
- $tax->expects('get_rates')->andReturn([]);
$result = $testee->from_wc_cart($cart);
@@ -138,9 +127,6 @@ class ItemFactoryTest extends TestCase
$product
->expects('get_sku')
->andReturn('sku');
- $product
- ->expects('get_tax_class')
- ->andReturn('foo');
$product
->expects('is_virtual')
->andReturn(false);
@@ -174,8 +160,6 @@ class ItemFactoryTest extends TestCase
->expects('get_fees')
->andReturn([]);
- $tax = Mockery::mock('alias:WC_Tax');
- $tax->expects('get_rates')->andReturn([]);
$result = $testee->from_wc_order($order);
$this->assertCount(1, $result);
@@ -205,9 +189,6 @@ class ItemFactoryTest extends TestCase
$product
->expects('is_virtual')
->andReturn(true);
- $product
- ->expects('get_tax_class')
- ->andReturn('foo');
expect('wp_strip_all_tags')
->with('description')
@@ -239,9 +220,6 @@ class ItemFactoryTest extends TestCase
->expects('get_fees')
->andReturn([]);
- $tax = Mockery::mock('alias:WC_Tax');
- $tax->expects('get_rates')->andReturn([]);
-
$result = $testee->from_wc_order($order);
$item = current($result);
/**
@@ -266,9 +244,6 @@ class ItemFactoryTest extends TestCase
$product
->expects('is_virtual')
->andReturn(true);
- $product
- ->expects('get_tax_class')
- ->andReturn('foo');
expect('wp_strip_all_tags')
->with($description)
@@ -300,9 +275,6 @@ class ItemFactoryTest extends TestCase
->expects('get_fees')
->andReturn([]);
- $tax = Mockery::mock('alias:WC_Tax');
- $tax->expects('get_rates')->andReturn([]);
-
$result = $testee->from_wc_order($order);
$item = current($result);
/**
From e8166247db377cd11c96e60aba785df963a96bbb Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 27 Jun 2022 12:40:31 +0200
Subject: [PATCH 142/163] Bump 1.9.0
---
changelog.txt | 3 ++-
readme.txt | 5 +++--
woocommerce-paypal-payments.php | 2 +-
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/changelog.txt b/changelog.txt
index d96d61df3..820f8999b 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,6 +1,7 @@
*** Changelog ***
-= 1.8.2 - TBD =
+= 1.9.0 - TBD =
+* Add - New Feature - Pay Upon Invoice (Germany only) #608
* Fix - Order not approved: payment via vaulted PayPal account fails #677
* Fix - Cant' refund : "ERROR Refund failed: No country given for address." #639
* Fix - Something went wrong error in Virtual products when using vaulted payment #673
diff --git a/readme.txt b/readme.txt
index e7a05d500..63e9e8361 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Tags: woocommerce, paypal, payments, ecommerce, e-commerce, store, sales, sell,
Requires at least: 5.3
Tested up to: 6.0
Requires PHP: 7.1
-Stable tag: 1.9.0-test5
+Stable tag: 1.9.0
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -81,7 +81,8 @@ Follow the steps below to connect the plugin to your PayPal account:
== Changelog ==
-= 1.8.2 =
+= 1.9.0 =
+* Add - New Feature - Pay Upon Invoice (Germany only) #608
* Fix - Order not approved: payment via vaulted PayPal account fails #677
* Fix - Cant' refund : "ERROR Refund failed: No country given for address." #639
* Fix - Something went wrong error in Virtual products when using vaulted payment #673
diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php
index 397f04a29..4aa932a36 100644
--- a/woocommerce-paypal-payments.php
+++ b/woocommerce-paypal-payments.php
@@ -3,7 +3,7 @@
* 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.9.0-test5
+ * Version: 1.9.0
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* License: GPL-2.0
From 6fab64e6586298c8e5d72e0391bfabf3e1229738 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 27 Jun 2022 14:25:02 +0200
Subject: [PATCH 143/163] Revert logging default behavior
---
modules/ppcp-api-client/src/Endpoint/RequestTrait.php | 1 +
modules/ppcp-wc-gateway/services.php | 10 +++++++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-api-client/src/Endpoint/RequestTrait.php b/modules/ppcp-api-client/src/Endpoint/RequestTrait.php
index f9db8101e..369dc9c1e 100644
--- a/modules/ppcp-api-client/src/Endpoint/RequestTrait.php
+++ b/modules/ppcp-api-client/src/Endpoint/RequestTrait.php
@@ -90,6 +90,7 @@ trait RequestTrait {
if (
isset( $response['body'] )
&& isset( $response['response']['code'] )
+ && ! in_array( $response['response']['code'], array( 200, 201, 202, 204 ), true )
) {
$output .= 'Response Body: ' . wc_print_r( $response['body'], true ) . "\n";
}
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 433e97931..63a5a4814 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2218,7 +2218,15 @@ return array(
);
},
'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
- return true;
+ $settings = $container->get( 'wcgateway.settings' );
+
+ /**
+ * Whether the logging of the plugin errors/events is enabled.
+ */
+ return apply_filters(
+ 'woocommerce_paypal_payments_is_logging_enabled',
+ $settings->has( 'logging_enabled' ) && $settings->get( 'logging_enabled' )
+ );
},
'wcgateway.helper.vaulting-scope' => static function ( ContainerInterface $container ): bool {
From eb1fafbc61206dc53c013574d10f1b5e53bf6093 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 27 Jun 2022 16:00:08 +0200
Subject: [PATCH 144/163] Ensure items contains tax
---
.../Endpoint/PayUponInvoiceOrderEndpoint.php | 22 +++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
index 23a330a67..91d1ba79a 100644
--- a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
@@ -111,6 +111,7 @@ class PayUponInvoiceOrderEndpoint {
),
);
+ $data = $this->ensure_tax( $data );
$data = $this->ensure_tax_rate( $data );
$data = $this->ensure_shipping( $data, $payment_source->to_array() );
@@ -196,6 +197,27 @@ class PayUponInvoiceOrderEndpoint {
);
}
+ /**
+ * Ensures items contains tax.
+ *
+ * @param array $data The data.
+ * @return array
+ */
+ private function ensure_tax( array $data ): array {
+ $items_count = count( $data['purchase_units'][0]['items'] );
+
+ for ( $i = 0; $i < $items_count; $i++ ) {
+ if ( ! isset( $data['purchase_units'][0]['items'][ $i ]['tax'] ) ) {
+ $data['purchase_units'][0]['items'][ $i ]['tax'] = array(
+ 'currency_code' => 'EUR',
+ 'value' => '0.00',
+ );
+ }
+ }
+
+ return $data;
+ }
+
/**
* Ensures items contains tax rate.
*
From be9c62426423cfe9fcf1080538d67bde8f964f4d Mon Sep 17 00:00:00 2001
From: Alex P
Date: Tue, 28 Jun 2022 12:09:18 +0300
Subject: [PATCH 145/163] Add filter allowing to disable the basic client-side
validation
In case some conflicts occur.
---
modules/ppcp-button/resources/js/button.js | 22 ++---
modules/ppcp-button/services.php | 39 +++++----
.../ppcp-button/src/Assets/SmartButton.php | 81 +++++++++++--------
3 files changed, 82 insertions(+), 60 deletions(-)
diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js
index 8038c936e..c9869dd63 100644
--- a/modules/ppcp-button/resources/js/button.js
+++ b/modules/ppcp-button/resources/js/button.js
@@ -31,17 +31,19 @@ const bootstrap = () => {
const onSmartButtonClick = (data, actions) => {
window.ppcpFundingSource = data.fundingSource;
- // TODO: quick fix to get the error about empty form before attempting PayPal order
- // it should solve #513 for most of the users, but proper solution should be implemented later.
- const requiredFields = jQuery('form.woocommerce-checkout .validate-required:visible :input');
- requiredFields.each((i, input) => {
- jQuery(input).trigger('validate');
- });
- if (jQuery('form.woocommerce-checkout .woocommerce-invalid:visible').length) {
- errorHandler.clear();
- errorHandler.message(PayPalCommerceGateway.labels.error.js_validation);
+ if (PayPalCommerceGateway.basic_checkout_validation_enabled) {
+ // TODO: quick fix to get the error about empty form before attempting PayPal order
+ // it should solve #513 for most of the users, but proper solution should be implemented later.
+ const requiredFields = jQuery('form.woocommerce-checkout .validate-required:visible :input');
+ requiredFields.each((i, input) => {
+ jQuery(input).trigger('validate');
+ });
+ if (jQuery('form.woocommerce-checkout .woocommerce-invalid:visible').length) {
+ errorHandler.clear();
+ errorHandler.message(PayPalCommerceGateway.labels.error.js_validation);
- return actions.reject();
+ return actions.reject();
+ }
}
const form = document.querySelector('form.woocommerce-checkout');
diff --git a/modules/ppcp-button/services.php b/modules/ppcp-button/services.php
index f8b6c415e..b5867aa14 100644
--- a/modules/ppcp-button/services.php
+++ b/modules/ppcp-button/services.php
@@ -27,7 +27,7 @@ use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
return array(
- 'button.client_id' => static function ( ContainerInterface $container ): string {
+ 'button.client_id' => static function ( ContainerInterface $container ): string {
$settings = $container->get( 'wcgateway.settings' );
$client_id = $settings->has( 'client_id' ) ? $settings->get( 'client_id' ) : '';
@@ -45,7 +45,7 @@ return array(
return $env->current_environment_is( Environment::SANDBOX ) ?
CONNECT_WOO_SANDBOX_CLIENT_ID : CONNECT_WOO_CLIENT_ID;
},
- 'button.smart-button' => static function ( ContainerInterface $container ): SmartButtonInterface {
+ 'button.smart-button' => static function ( ContainerInterface $container ): SmartButtonInterface {
$state = $container->get( 'onboarding.state' );
/**
@@ -88,19 +88,20 @@ return array(
$settings_status,
$currency,
$container->get( 'wcgateway.all-funding-sources' ),
+ $container->get( 'button.basic-checkout-validation-enabled' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
- 'button.url' => static function ( ContainerInterface $container ): string {
+ 'button.url' => static function ( ContainerInterface $container ): string {
return plugins_url(
'/modules/ppcp-button/',
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
);
},
- 'button.request-data' => static function ( ContainerInterface $container ): RequestData {
+ 'button.request-data' => static function ( ContainerInterface $container ): RequestData {
return new RequestData();
},
- 'button.endpoint.change-cart' => static function ( ContainerInterface $container ): ChangeCartEndpoint {
+ 'button.endpoint.change-cart' => static function ( ContainerInterface $container ): ChangeCartEndpoint {
if ( ! \WC()->cart ) {
throw new RuntimeException( 'cant initialize endpoint at this moment' );
}
@@ -112,7 +113,7 @@ return array(
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new ChangeCartEndpoint( $cart, $shipping, $request_data, $repository, $data_store, $logger );
},
- 'button.endpoint.create-order' => static function ( ContainerInterface $container ): CreateOrderEndpoint {
+ 'button.endpoint.create-order' => static function ( ContainerInterface $container ): CreateOrderEndpoint {
$request_data = $container->get( 'button.request-data' );
$cart_repository = $container->get( 'api.repository.cart' );
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
@@ -136,7 +137,7 @@ return array(
$logger
);
},
- 'button.helper.early-order-handler' => static function ( ContainerInterface $container ) : EarlyOrderHandler {
+ 'button.helper.early-order-handler' => static function ( ContainerInterface $container ) : EarlyOrderHandler {
$state = $container->get( 'onboarding.state' );
$order_processor = $container->get( 'wcgateway.order-processor' );
@@ -144,7 +145,7 @@ return array(
$prefix = $container->get( 'api.prefix' );
return new EarlyOrderHandler( $state, $order_processor, $session_handler, $prefix );
},
- 'button.endpoint.approve-order' => static function ( ContainerInterface $container ): ApproveOrderEndpoint {
+ 'button.endpoint.approve-order' => static function ( ContainerInterface $container ): ApproveOrderEndpoint {
$request_data = $container->get( 'button.request-data' );
$order_endpoint = $container->get( 'api.endpoint.order' );
$session_handler = $container->get( 'session.handler' );
@@ -164,7 +165,7 @@ return array(
$logger
);
},
- 'button.endpoint.data-client-id' => static function( ContainerInterface $container ) : DataClientIdEndpoint {
+ 'button.endpoint.data-client-id' => static function( ContainerInterface $container ) : DataClientIdEndpoint {
$request_data = $container->get( 'button.request-data' );
$identity_token = $container->get( 'api.endpoint.identity-token' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
@@ -174,31 +175,39 @@ return array(
$logger
);
},
- 'button.endpoint.vault-paypal' => static function( ContainerInterface $container ) : StartPayPalVaultingEndpoint {
+ 'button.endpoint.vault-paypal' => static function( ContainerInterface $container ) : StartPayPalVaultingEndpoint {
return new StartPayPalVaultingEndpoint(
$container->get( 'button.request-data' ),
$container->get( 'api.endpoint.payment-token' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
- 'button.helper.three-d-secure' => static function ( ContainerInterface $container ): ThreeDSecure {
+ 'button.helper.three-d-secure' => static function ( ContainerInterface $container ): ThreeDSecure {
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new ThreeDSecure( $logger );
},
- 'button.helper.messages-apply' => static function ( ContainerInterface $container ): MessagesApply {
+ 'button.helper.messages-apply' => static function ( ContainerInterface $container ): MessagesApply {
return new MessagesApply(
$container->get( 'api.shop.country' )
);
},
- 'button.is-logged-in' => static function ( ContainerInterface $container ): bool {
+ 'button.is-logged-in' => static function ( ContainerInterface $container ): bool {
return is_user_logged_in();
},
- 'button.registration-required' => static function ( ContainerInterface $container ): bool {
+ 'button.registration-required' => static function ( ContainerInterface $container ): bool {
return WC()->checkout()->is_registration_required();
},
- 'button.current-user-must-register' => static function ( ContainerInterface $container ): bool {
+ 'button.current-user-must-register' => static function ( ContainerInterface $container ): bool {
return ! $container->get( 'button.is-logged-in' ) &&
$container->get( 'button.registration-required' );
},
+
+ 'button.basic-checkout-validation-enabled' => static function ( ContainerInterface $container ): bool {
+ /**
+ * The filter allowing to disable the basic client-side validation of the checkout form
+ * when the PayPal button is clicked.
+ */
+ return (bool) apply_filters( 'woocommerce_paypal_payments_basic_checkout_validation_enabled', true );
+ },
);
diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php
index d6b772fbf..a187b8129 100644
--- a/modules/ppcp-button/src/Assets/SmartButton.php
+++ b/modules/ppcp-button/src/Assets/SmartButton.php
@@ -144,6 +144,13 @@ class SmartButton implements SmartButtonInterface {
*/
private $all_funding_sources;
+ /**
+ * Whether the basic JS validation of the form iss enabled.
+ *
+ * @var bool
+ */
+ private $basic_checkout_validation_enabled;
+
/**
* The logger.
*
@@ -176,6 +183,7 @@ class SmartButton implements SmartButtonInterface {
* @param SettingsStatus $settings_status The Settings status helper.
* @param string $currency 3-letter currency code of the shop.
* @param array $all_funding_sources All existing funding sources.
+ * @param bool $basic_checkout_validation_enabled Whether the basic JS validation of the form iss enabled.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
@@ -194,25 +202,27 @@ class SmartButton implements SmartButtonInterface {
SettingsStatus $settings_status,
string $currency,
array $all_funding_sources,
+ bool $basic_checkout_validation_enabled,
LoggerInterface $logger
) {
- $this->module_url = $module_url;
- $this->version = $version;
- $this->session_handler = $session_handler;
- $this->settings = $settings;
- $this->payer_factory = $payer_factory;
- $this->client_id = $client_id;
- $this->request_data = $request_data;
- $this->dcc_applies = $dcc_applies;
- $this->subscription_helper = $subscription_helper;
- $this->messages_apply = $messages_apply;
- $this->environment = $environment;
- $this->payment_token_repository = $payment_token_repository;
- $this->settings_status = $settings_status;
- $this->currency = $currency;
- $this->all_funding_sources = $all_funding_sources;
- $this->logger = $logger;
+ $this->module_url = $module_url;
+ $this->version = $version;
+ $this->session_handler = $session_handler;
+ $this->settings = $settings;
+ $this->payer_factory = $payer_factory;
+ $this->client_id = $client_id;
+ $this->request_data = $request_data;
+ $this->dcc_applies = $dcc_applies;
+ $this->subscription_helper = $subscription_helper;
+ $this->messages_apply = $messages_apply;
+ $this->environment = $environment;
+ $this->payment_token_repository = $payment_token_repository;
+ $this->settings_status = $settings_status;
+ $this->currency = $currency;
+ $this->all_funding_sources = $all_funding_sources;
+ $this->basic_checkout_validation_enabled = $basic_checkout_validation_enabled;
+ $this->logger = $logger;
}
/**
@@ -765,17 +775,17 @@ class SmartButton implements SmartButtonInterface {
$this->request_data->enqueue_nonce_fix();
$localize = array(
- 'script_attributes' => $this->attributes(),
- 'data_client_id' => array(
+ 'script_attributes' => $this->attributes(),
+ 'data_client_id' => array(
'set_attribute' => ( is_checkout() && $this->dcc_is_enabled() ) || $this->can_save_vault_token(),
'endpoint' => \WC_AJAX::get_endpoint( DataClientIdEndpoint::ENDPOINT ),
'nonce' => wp_create_nonce( DataClientIdEndpoint::nonce() ),
'user' => get_current_user_id(),
'has_subscriptions' => $this->has_subscriptions(),
),
- 'redirect' => wc_get_checkout_url(),
- 'context' => $this->context(),
- 'ajax' => array(
+ 'redirect' => wc_get_checkout_url(),
+ 'context' => $this->context(),
+ 'ajax' => array(
'change_cart' => array(
'endpoint' => \WC_AJAX::get_endpoint( ChangeCartEndpoint::ENDPOINT ),
'nonce' => wp_create_nonce( ChangeCartEndpoint::nonce() ),
@@ -793,13 +803,13 @@ class SmartButton implements SmartButtonInterface {
'nonce' => wp_create_nonce( StartPayPalVaultingEndpoint::nonce() ),
),
),
- 'enforce_vault' => $this->has_subscriptions(),
- 'can_save_vault_token' => $this->can_save_vault_token(),
- 'is_free_trial_cart' => $is_free_trial_cart,
- 'vaulted_paypal_email' => ( is_checkout() && $is_free_trial_cart ) ? $this->get_vaulted_paypal_email() : '',
- 'bn_codes' => $this->bn_codes(),
- 'payer' => $this->payerData(),
- 'button' => array(
+ 'enforce_vault' => $this->has_subscriptions(),
+ 'can_save_vault_token' => $this->can_save_vault_token(),
+ 'is_free_trial_cart' => $is_free_trial_cart,
+ 'vaulted_paypal_email' => ( is_checkout() && $is_free_trial_cart ) ? $this->get_vaulted_paypal_email() : '',
+ 'bn_codes' => $this->bn_codes(),
+ 'payer' => $this->payerData(),
+ 'button' => array(
'wrapper' => '#ppc-button',
'mini_cart_wrapper' => '#ppc-button-minicart',
'cancel_wrapper' => '#ppcp-cancel',
@@ -820,7 +830,7 @@ class SmartButton implements SmartButtonInterface {
'tagline' => $this->style_for_context( 'tagline', $this->context() ),
),
),
- 'hosted_fields' => array(
+ 'hosted_fields' => array(
'wrapper' => '#ppcp-hosted-fields',
'mini_cart_wrapper' => '#ppcp-hosted-fields-mini-cart',
'labels' => array(
@@ -840,10 +850,10 @@ class SmartButton implements SmartButtonInterface {
'valid_cards' => $this->dcc_applies->valid_cards(),
'contingency' => $this->get_3ds_contingency(),
),
- 'messages' => $this->message_values(),
- 'labels' => array(
+ 'messages' => $this->message_values(),
+ 'labels' => array(
'error' => array(
- 'generic' => __(
+ 'generic' => __(
'Something went wrong. Please try again or choose another payment source.',
'woocommerce-paypal-payments'
),
@@ -853,9 +863,10 @@ class SmartButton implements SmartButtonInterface {
),
),
),
- 'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0,
- 'single_product_buttons_enabled' => $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ),
- 'mini_cart_buttons_enabled' => $this->settings->has( 'button_mini-cart_enabled' ) && $this->settings->get( 'button_mini-cart_enabled' ),
+ 'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0,
+ 'single_product_buttons_enabled' => $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ),
+ 'mini_cart_buttons_enabled' => $this->settings->has( 'button_mini-cart_enabled' ) && $this->settings->get( 'button_mini-cart_enabled' ),
+ 'basic_checkout_validation_enabled' => $this->basic_checkout_validation_enabled,
);
if ( $this->style_for_context( 'layout', 'mini-cart' ) !== 'horizontal' ) {
From 57e4cb51eaa69fe5cc23c3f18494fc29cf3129cc Mon Sep 17 00:00:00 2001
From: Alex P
Date: Wed, 29 Jun 2022 14:40:51 +0300
Subject: [PATCH 146/163] Fix form fields type
was broken after #680
---
modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
index 98e990b3c..81344bb64 100644
--- a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
+++ b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
@@ -449,12 +449,11 @@ class CreateOrderEndpoint implements EndpointInterface {
/**
* Checks whether the terms input field is checked.
*
- * @param string $form_values The form values.
+ * @param array $form_fields The form fields.
* @throws \RuntimeException When field is not checked.
*/
- private function validate_paynow_form( string $form_values ) {
- $parsed_values = wp_parse_args( $form_values );
- if ( isset( $parsed_values['terms-field'] ) && ! isset( $parsed_values['terms'] ) ) {
+ private function validate_paynow_form( array $form_fields ) {
+ if ( isset( $form_fields['terms-field'] ) && ! isset( $form_fields['terms'] ) ) {
throw new \RuntimeException(
__( 'Please read and accept the terms and conditions to proceed with your order.', 'woocommerce-paypal-payments' )
);
From 7f42fe1882870f5f453b60975932df58af39ace6 Mon Sep 17 00:00:00 2001
From: Alex P
Date: Fri, 1 Jul 2022 11:37:18 +0300
Subject: [PATCH 147/163] Show basic validation error only for required fields
Otherwise it may trigger on some sites when the field is no longer required but still marked as invalid, e.g. after switching to a country without required state
---
modules/ppcp-button/resources/js/button.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js
index c9869dd63..ed8c400cf 100644
--- a/modules/ppcp-button/resources/js/button.js
+++ b/modules/ppcp-button/resources/js/button.js
@@ -38,7 +38,7 @@ const bootstrap = () => {
requiredFields.each((i, input) => {
jQuery(input).trigger('validate');
});
- if (jQuery('form.woocommerce-checkout .woocommerce-invalid:visible').length) {
+ if (jQuery('form.woocommerce-checkout .validate-required.woocommerce-invalid:visible').length) {
errorHandler.clear();
errorHandler.message(PayPalCommerceGateway.labels.error.js_validation);
From b71cff1d57bc82fab0423ad64cab6b5a8f32463a Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 1 Jul 2022 14:57:59 +0200
Subject: [PATCH 148/163] Check pui currency in payment gateways
---
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 5d85638f1..acd2833fe 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -284,7 +284,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' === get_woocommerce_currency() ) {
$methods[] = $container->get( 'wcgateway.pay-upon-invoice-gateway' );
}
From 86f85eff635817e701f24936de61f1d7782e5288 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 1 Jul 2022 15:50:14 +0200
Subject: [PATCH 149/163] Use shop currency service
---
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index acd2833fe..8bb469a9d 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -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();
}
}
@@ -284,7 +284,7 @@ class WCGatewayModule implements ModuleInterface {
$methods[] = $container->get( 'wcgateway.credit-card-gateway' );
}
- if ( 'DE' === $container->get( 'api.shop.country' ) && 'EUR' === get_woocommerce_currency() ) {
+ if ( 'DE' === $container->get( 'api.shop.country' ) && 'EUR' === $container->get( 'api.shop.currency' ) ) {
$methods[] = $container->get( 'wcgateway.pay-upon-invoice-gateway' );
}
From f013d190470fb884a83ad00b30a36e51ade2315b Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 4 Jul 2022 12:20:34 +0200
Subject: [PATCH 150/163] Add PayPal fee to pui order
---
.../Endpoint/PayUponInvoiceOrderEndpoint.php | 12 ++++-----
modules/ppcp-wc-gateway/services.php | 3 ++-
.../Gateway/PayUponInvoice/PayUponInvoice.php | 27 +++++++++++++++++--
3 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
index 91d1ba79a..41e5563ec 100644
--- a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php
@@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
use Psr\Log\LoggerInterface;
use RuntimeException;
+use stdClass;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\RequestTrait;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
@@ -162,14 +163,14 @@ class PayUponInvoiceOrderEndpoint {
}
/**
- * Get Ratepay payment instructions from PayPal order.
+ * Get PayPal order as object.
*
* @param string $id The PayPal order ID.
- * @return array
+ * @return stdClass
* @throws RuntimeException When there is a problem getting the order.
* @throws PayPalApiException When there is a problem getting the order.
*/
- public function order_payment_instructions( string $id ): array {
+ public function order( string $id ): stdClass {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $id;
$args = array(
@@ -191,10 +192,7 @@ class PayUponInvoiceOrderEndpoint {
throw new PayPalApiException( $json, $status_code );
}
- return array(
- $json->payment_source->pay_upon_invoice->payment_reference,
- $json->payment_source->pay_upon_invoice->deposit_bank_details,
- );
+ return $json;
}
/**
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 63a5a4814..e2c2b7053 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -2214,7 +2214,8 @@ return array(
$container->get( 'wcgateway.is-ppcp-settings-page' ),
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
$container->get( 'wcgateway.pay-upon-invoice-product-status' ),
- $container->get( 'wcgateway.pay-upon-invoice-helper' )
+ $container->get( 'wcgateway.pay-upon-invoice-helper' ),
+ $container->get( 'api.factory.capture' )
);
},
'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 0ebec8c17..5b684ea6f 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -17,8 +17,10 @@ use WC_Product;
use WC_Product_Variable;
use WC_Product_Variation;
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\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
@@ -118,6 +120,13 @@ class PayUponInvoice {
*/
protected $pui_product_status;
+ /**
+ * The capture factory.
+ *
+ * @var CaptureFactory
+ */
+ protected $capture_factory;
+
/**
* PayUponInvoice constructor.
*
@@ -133,6 +142,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 CaptureFactory $capture_factory The capture factory.
*/
public function __construct(
string $module_url,
@@ -146,7 +156,8 @@ class PayUponInvoice {
bool $is_ppcp_settings_page,
string $current_ppcp_settings_page_id,
PayUponInvoiceProductStatus $pui_product_status,
- PayUponInvoiceHelper $pui_helper
+ PayUponInvoiceHelper $pui_helper,
+ CaptureFactory $capture_factory
) {
$this->module_url = $module_url;
$this->fraud_net = $fraud_net;
@@ -160,6 +171,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->capture_factory = $capture_factory;
}
/**
@@ -210,7 +222,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
@@ -218,6 +235,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 );
+ $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() );
}
From 7aca62a1a30fbcef72e5e8e7edb96b5fcad45c1f Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 4 Jul 2022 14:34:09 +0200
Subject: [PATCH 151/163] Create capture entity from order response capture
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 5b684ea6f..628ae89e6 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -235,7 +235,7 @@ 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 );
+ $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() );
From d410c0272b34ce74b04d30aa9ff551a0235f25a3 Mon Sep 17 00:00:00 2001
From: Danae Millan
Date: Mon, 4 Jul 2022 10:28:49 -0300
Subject: [PATCH 152/163] Update release date for 1.9.0
---
changelog.txt | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/changelog.txt b/changelog.txt
index 820f8999b..70909097d 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,15 +1,15 @@
*** Changelog ***
-= 1.9.0 - TBD =
+= 1.9.0 - 2022-07-04 =
* Add - New Feature - Pay Upon Invoice (Germany only) #608
* Fix - Order not approved: payment via vaulted PayPal account fails #677
* Fix - Cant' refund : "ERROR Refund failed: No country given for address." #639
-* Fix - Something went wrong error in Virtual products when using vaulted payment #673
+* Fix - Something went wrong error in Virtual products when using vaulted payment #673
* Fix - PayPal smart buttons are not displayed for product variations when parent product is set to out of stock #669
-* Fix - Pay Later messaging displayed for out of stock variable products or with no variation selected #667
-* Fix - "Capture Virtual-Only Orders" intent sets virtual+downloadable product orders to "Processing" instead of "Completed" #665
-* Fix - Free trial period causing incorrerct disable-funding parameters with DCC disabled #661
-* Fix - Smart button not visible on single product page when product price is below 1 and decimal is "," #654
+* Fix - Pay Later messaging displayed for out of stock variable products or with no variation selected #667
+* Fix - "Capture Virtual-Only Orders" intent sets virtual+downloadable product orders to "Processing" instead of "Completed" #665
+* Fix - Free trial period causing incorrerct disable-funding parameters with DCC disabled #661
+* Fix - Smart button not visible on single product page when product price is below 1 and decimal is "," #654
* Fix - Checkout using an email address containing a + symbol results in a "[INVALID_REQUEST]" error #523
* Fix - Order details are sometimes empty in PayPal dashboard #689
* Fix - Incorrect TAX details on PayPal order overview #541
@@ -36,8 +36,8 @@
= 1.8.0 - 2022-05-03 =
* Add - Allow free trial subscriptions #580
* Fix - The Card Processing does not appear as an available payment method when manually creating an order #562
-* Fix - Express buttons & Pay Later visible on variable Subscription products /w disabled vaulting #281
-* Fix - Pay for order (guest) failing when no email address available #535
+* Fix - Express buttons & Pay Later visible on variable Subscription products /w disabled vaulting #281
+* Fix - Pay for order (guest) failing when no email address available #535
* Fix - Emoji in product description causing INVALID_STRING_LENGTH error #491
* Enhancement - Change cart total amount that is sent to PayPal gateway #486
* Enhancement - Include dark Visa and Mastercard gateway icon list for PayPal Card Processing #566
From 5047dfb94e216efd9ea5b96bdec64c5ee218be18 Mon Sep 17 00:00:00 2001
From: Danae Millan
Date: Mon, 4 Jul 2022 10:34:50 -0300
Subject: [PATCH 153/163] Bump version number from 1.8.2 to 1.9.0 in
package.json
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 49df04f52..541f35f98 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "woocommerce-paypal-payments",
- "version": "1.8.2",
+ "version": "1.9.0",
"description": "WooCommerce PayPal Payments",
"repository": "https://github.com/woocommerce/woocommerce-paypal-payments",
"license": "GPL-2.0",
From fff25701249bb4b1df79ad08cab132e3403f9a70 Mon Sep 17 00:00:00 2001
From: Alex P
Date: Tue, 5 Jul 2022 14:25:55 +0300
Subject: [PATCH 154/163] Refactor shipping_preference
Extract its determination to a separate class, also remove useless CartRepository and use single PU to avoid confusion.
---
modules/ppcp-api-client/services.php | 9 +-
.../src/Endpoint/OrderEndpoint.php | 56 +---------
.../src/Factory/PurchaseUnitFactory.php | 8 +-
.../src/Factory/ShippingPreferenceFactory.php | 54 ++++++++++
.../src/Repository/CartRepository.php | 45 --------
.../PurchaseUnitRepositoryInterface.php | 26 -----
modules/ppcp-button/services.php | 7 +-
.../src/Endpoint/ChangeCartEndpoint.php | 42 ++++----
.../src/Endpoint/CreateOrderEndpoint.php | 101 +++++++++---------
modules/ppcp-subscription/services.php | 1 +
.../ppcp-subscription/src/RenewalHandler.php | 44 +++++---
modules/ppcp-wc-gateway/services.php | 2 +
.../src/Gateway/CreditCardGateway.php | 31 ++++--
.../src/Gateway/PayPalGateway.php | 11 ++
.../src/Gateway/ProcessPaymentTrait.php | 7 ++
.../ApiClient/Endpoint/OrderEndpointTest.php | 8 +-
.../Endpoint/ChangeCartEndpointTest.php | 37 +++----
.../Endpoint/CreateOrderEndpointTest.php | 6 +-
.../Subscription/RenewalHandlerTest.php | 10 +-
.../WcGateway/Gateway/WcGatewayTest.php | 4 +
20 files changed, 245 insertions(+), 264 deletions(-)
create mode 100644 modules/ppcp-api-client/src/Factory/ShippingPreferenceFactory.php
delete mode 100644 modules/ppcp-api-client/src/Repository/CartRepository.php
delete mode 100644 modules/ppcp-api-client/src/Repository/PurchaseUnitRepositoryInterface.php
diff --git a/modules/ppcp-api-client/services.php b/modules/ppcp-api-client/services.php
index 6be5355be..f34ac93da 100644
--- a/modules/ppcp-api-client/services.php
+++ b/modules/ppcp-api-client/services.php
@@ -43,13 +43,13 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\SellerReceivableBreakdownFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\SellerStatusFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingFactory;
+use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookEventFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderHelper;
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
-use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\CustomerRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\OrderRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
@@ -221,10 +221,6 @@ return array(
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
return new PartnerReferralsData( $dcc_applies );
},
- 'api.repository.cart' => static function ( ContainerInterface $container ): CartRepository {
- $factory = $container->get( 'api.factory.purchase-unit' );
- return new CartRepository( $factory );
- },
'api.repository.payee' => static function ( ContainerInterface $container ): PayeeRepository {
$merchant_email = $container->get( 'api.merchant_email' );
$merchant_id = $container->get( 'api.merchant_id' );
@@ -298,6 +294,9 @@ return array(
$address_factory = $container->get( 'api.factory.address' );
return new ShippingFactory( $address_factory );
},
+ 'api.factory.shipping-preference' => static function ( ContainerInterface $container ): ShippingPreferenceFactory {
+ return new ShippingPreferenceFactory();
+ },
'api.factory.amount' => static function ( ContainerInterface $container ): AmountFactory {
$item_factory = $container->get( 'api.factory.item' );
return new AmountFactory(
diff --git a/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php
index b12d1a025..41448a542 100644
--- a/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php
@@ -163,57 +163,23 @@ class OrderEndpoint {
* Creates an order.
*
* @param PurchaseUnit[] $items The purchase unit items for the order.
+ * @param string $shipping_preference One of ApplicationContext::SHIPPING_PREFERENCE_ values.
* @param Payer|null $payer The payer off the order.
* @param PaymentToken|null $payment_token The payment token.
* @param PaymentMethod|null $payment_method The payment method.
* @param string $paypal_request_id The paypal request id.
- * @param bool $shipping_address_is_fixed Whether the shipping address is changeable or not.
*
* @return Order
* @throws RuntimeException If the request fails.
*/
public function create(
array $items,
+ string $shipping_preference,
Payer $payer = null,
PaymentToken $payment_token = null,
PaymentMethod $payment_method = null,
- string $paypal_request_id = '',
- bool $shipping_address_is_fixed = false
+ string $paypal_request_id = ''
): Order {
-
- $contains_physical_goods = false;
- $items = array_filter(
- $items,
- static function ( $item ) use ( &$contains_physical_goods ): bool {
- $is_purchase_unit = is_a( $item, PurchaseUnit::class );
- /**
- * A purchase unit.
- *
- * @var PurchaseUnit $item
- */
- if ( $is_purchase_unit && $item->contains_physical_goods() ) {
- $contains_physical_goods = true;
- }
-
- return $is_purchase_unit;
- }
- );
-
- $shipping_preference = ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
- if ( $contains_physical_goods ) {
- if ( $shipping_address_is_fixed ) {
- // Checkout + no address given? Probably something weird happened, like no form validation?
- // Also note that $items currently always seems to be an array with one item.
- if ( $this->has_items_without_shipping( $items ) ) {
- $shipping_preference = ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
- } else {
- $shipping_preference = ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS;
- }
- } else {
- $shipping_preference = ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE;
- }
- }
-
$bearer = $this->bearer->bearer();
$data = array(
'intent' => ( $this->subscription_helper->cart_contains_subscription() || $this->subscription_helper->current_product_is_subscription() ) ? 'AUTHORIZE' : $this->intent,
@@ -598,20 +564,4 @@ class OrderEndpoint {
$new_order = $this->order( $order_to_update->id() );
return $new_order;
}
-
- /**
- * Checks if there is at least one item without shipping.
- *
- * @param PurchaseUnit[] $items The items.
- * @return bool Whether items contains shipping or not.
- */
- private function has_items_without_shipping( array $items ): bool {
- foreach ( $items as $item ) {
- if ( ! $item->shipping() ) {
- return true;
- }
- }
-
- return false;
- }
}
diff --git a/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php b/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php
index 303b7bc6a..c2667fc92 100644
--- a/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php
+++ b/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php
@@ -152,11 +152,15 @@ class PurchaseUnitFactory {
/**
* Creates a PurchaseUnit based off a WooCommerce cart.
*
- * @param \WC_Cart $cart The cart.
+ * @param \WC_Cart|null $cart The cart.
*
* @return PurchaseUnit
*/
- public function from_wc_cart( \WC_Cart $cart ): PurchaseUnit {
+ public function from_wc_cart( ?\WC_Cart $cart = null ): PurchaseUnit {
+ if ( ! $cart ) {
+ $cart = WC()->cart ?? new \WC_Cart();
+ }
+
$amount = $this->amount_factory->from_wc_cart( $cart );
$items = array_filter(
$this->item_factory->from_wc_cart( $cart ),
diff --git a/modules/ppcp-api-client/src/Factory/ShippingPreferenceFactory.php b/modules/ppcp-api-client/src/Factory/ShippingPreferenceFactory.php
new file mode 100644
index 000000000..322d598fd
--- /dev/null
+++ b/modules/ppcp-api-client/src/Factory/ShippingPreferenceFactory.php
@@ -0,0 +1,54 @@
+contains_physical_goods();
+ if ( ! $contains_physical_goods ) {
+ return ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
+ }
+
+ $has_shipping = null !== $purchase_unit->shipping();
+ $needs_shipping = $cart && $cart->needs_shipping();
+ $shipping_address_is_fixed = $needs_shipping && 'checkout' === $context;
+
+ if ( $shipping_address_is_fixed ) {
+ // Checkout + no address given? Probably something weird happened, like no form validation?
+ if ( ! $has_shipping ) {
+ return ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
+ }
+
+ return ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS;
+ }
+
+ return ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE;
+ }
+}
diff --git a/modules/ppcp-api-client/src/Repository/CartRepository.php b/modules/ppcp-api-client/src/Repository/CartRepository.php
deleted file mode 100644
index 226f50d91..000000000
--- a/modules/ppcp-api-client/src/Repository/CartRepository.php
+++ /dev/null
@@ -1,45 +0,0 @@
-factory = $factory;
- }
-
- /**
- * Returns all Pur of the WooCommerce cart.
- *
- * @return PurchaseUnit[]
- */
- public function all(): array {
- $cart = WC()->cart ?? new \WC_Cart();
- return array( $this->factory->from_wc_cart( $cart ) );
- }
-}
diff --git a/modules/ppcp-api-client/src/Repository/PurchaseUnitRepositoryInterface.php b/modules/ppcp-api-client/src/Repository/PurchaseUnitRepositoryInterface.php
deleted file mode 100644
index 6edbb1bbf..000000000
--- a/modules/ppcp-api-client/src/Repository/PurchaseUnitRepositoryInterface.php
+++ /dev/null
@@ -1,26 +0,0 @@
-cart;
$shipping = WC()->shipping();
$request_data = $container->get( 'button.request-data' );
- $repository = $container->get( 'api.repository.cart' );
+ $purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
$data_store = \WC_Data_Store::load( 'product' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
- return new ChangeCartEndpoint( $cart, $shipping, $request_data, $repository, $data_store, $logger );
+ return new ChangeCartEndpoint( $cart, $shipping, $request_data, $purchase_unit_factory, $data_store, $logger );
},
'button.endpoint.create-order' => static function ( ContainerInterface $container ): CreateOrderEndpoint {
$request_data = $container->get( 'button.request-data' );
- $cart_repository = $container->get( 'api.repository.cart' );
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
$order_endpoint = $container->get( 'api.endpoint.order' );
$payer_factory = $container->get( 'api.factory.payer' );
@@ -126,8 +125,8 @@ return array(
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new CreateOrderEndpoint(
$request_data,
- $cart_repository,
$purchase_unit_factory,
+ $container->get( 'api.factory.shipping-preference' ),
$order_endpoint,
$payer_factory,
$session_handler,
diff --git a/modules/ppcp-button/src/Endpoint/ChangeCartEndpoint.php b/modules/ppcp-button/src/Endpoint/ChangeCartEndpoint.php
index 1ad4b451d..1c64ddb0d 100644
--- a/modules/ppcp-button/src/Endpoint/ChangeCartEndpoint.php
+++ b/modules/ppcp-button/src/Endpoint/ChangeCartEndpoint.php
@@ -13,7 +13,7 @@ use Exception;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
-use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
+use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
/**
@@ -46,11 +46,11 @@ class ChangeCartEndpoint implements EndpointInterface {
private $request_data;
/**
- * Contains purchase units based off the current WC cart.
+ * The PurchaseUnit factory.
*
- * @var CartRepository
+ * @var PurchaseUnitFactory
*/
- private $repository;
+ private $purchase_unit_factory;
/**
* The product data store.
@@ -69,28 +69,28 @@ class ChangeCartEndpoint implements EndpointInterface {
/**
* ChangeCartEndpoint constructor.
*
- * @param \WC_Cart $cart The current WC cart object.
- * @param \WC_Shipping $shipping The current WC shipping object.
- * @param RequestData $request_data The request data helper.
- * @param CartRepository $repository The repository for the current purchase items.
- * @param \WC_Data_Store $product_data_store The data store for products.
- * @param LoggerInterface $logger The logger.
+ * @param \WC_Cart $cart The current WC cart object.
+ * @param \WC_Shipping $shipping The current WC shipping object.
+ * @param RequestData $request_data The request data helper.
+ * @param PurchaseUnitFactory $purchase_unit_factory The PurchaseUnit factory.
+ * @param \WC_Data_Store $product_data_store The data store for products.
+ * @param LoggerInterface $logger The logger.
*/
public function __construct(
\WC_Cart $cart,
\WC_Shipping $shipping,
RequestData $request_data,
- CartRepository $repository,
+ PurchaseUnitFactory $purchase_unit_factory,
\WC_Data_Store $product_data_store,
LoggerInterface $logger
) {
- $this->cart = $cart;
- $this->shipping = $shipping;
- $this->request_data = $request_data;
- $this->repository = $repository;
- $this->product_data_store = $product_data_store;
- $this->logger = $logger;
+ $this->cart = $cart;
+ $this->shipping = $shipping;
+ $this->request_data = $request_data;
+ $this->purchase_unit_factory = $purchase_unit_factory;
+ $this->product_data_store = $product_data_store;
+ $this->logger = $logger;
}
/**
@@ -292,11 +292,7 @@ class ChangeCartEndpoint implements EndpointInterface {
* @return array
*/
private function generate_purchase_units(): array {
- return array_map(
- static function ( PurchaseUnit $line_item ): array {
- return $line_item->to_array();
- },
- $this->repository->all()
- );
+ $pu = $this->purchase_unit_factory->from_wc_cart();
+ return array( $pu->to_array() );
}
}
diff --git a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
index 81344bb64..9d3ed2d4e 100644
--- a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
+++ b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
@@ -23,7 +23,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
-use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
+use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\Button\Helper\EarlyOrderHandler;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\Subscription\FreeTrialHandlerTrait;
@@ -48,13 +48,6 @@ class CreateOrderEndpoint implements EndpointInterface {
*/
private $request_data;
- /**
- * The cart repository.
- *
- * @var CartRepository
- */
- private $cart_repository;
-
/**
* The PurchaseUnit factory.
*
@@ -62,6 +55,13 @@ class CreateOrderEndpoint implements EndpointInterface {
*/
private $purchase_unit_factory;
+ /**
+ * The shipping_preference factory.
+ *
+ * @var ShippingPreferenceFactory
+ */
+ private $shipping_preference_factory;
+
/**
* The order endpoint.
*
@@ -105,11 +105,11 @@ class CreateOrderEndpoint implements EndpointInterface {
private $parsed_request_data;
/**
- * The array of purchase units for order.
+ * The purchase unit for order.
*
- * @var PurchaseUnit[]
+ * @var PurchaseUnit|null
*/
- private $purchase_units;
+ private $purchase_unit;
/**
* Whether a new user must be registered during checkout.
@@ -128,21 +128,21 @@ class CreateOrderEndpoint implements EndpointInterface {
/**
* CreateOrderEndpoint constructor.
*
- * @param RequestData $request_data The RequestData object.
- * @param CartRepository $cart_repository The CartRepository object.
- * @param PurchaseUnitFactory $purchase_unit_factory The Purchaseunit factory.
- * @param OrderEndpoint $order_endpoint The OrderEndpoint object.
- * @param PayerFactory $payer_factory The PayerFactory object.
- * @param SessionHandler $session_handler The SessionHandler object.
- * @param Settings $settings The Settings object.
- * @param EarlyOrderHandler $early_order_handler The EarlyOrderHandler object.
- * @param bool $registration_needed Whether a new user must be registered during checkout.
- * @param LoggerInterface $logger The logger.
+ * @param RequestData $request_data The RequestData object.
+ * @param PurchaseUnitFactory $purchase_unit_factory The PurchaseUnit factory.
+ * @param ShippingPreferenceFactory $shipping_preference_factory The shipping_preference factory.
+ * @param OrderEndpoint $order_endpoint The OrderEndpoint object.
+ * @param PayerFactory $payer_factory The PayerFactory object.
+ * @param SessionHandler $session_handler The SessionHandler object.
+ * @param Settings $settings The Settings object.
+ * @param EarlyOrderHandler $early_order_handler The EarlyOrderHandler object.
+ * @param bool $registration_needed Whether a new user must be registered during checkout.
+ * @param LoggerInterface $logger The logger.
*/
public function __construct(
RequestData $request_data,
- CartRepository $cart_repository,
PurchaseUnitFactory $purchase_unit_factory,
+ ShippingPreferenceFactory $shipping_preference_factory,
OrderEndpoint $order_endpoint,
PayerFactory $payer_factory,
SessionHandler $session_handler,
@@ -152,16 +152,16 @@ class CreateOrderEndpoint implements EndpointInterface {
LoggerInterface $logger
) {
- $this->request_data = $request_data;
- $this->cart_repository = $cart_repository;
- $this->purchase_unit_factory = $purchase_unit_factory;
- $this->api_endpoint = $order_endpoint;
- $this->payer_factory = $payer_factory;
- $this->session_handler = $session_handler;
- $this->settings = $settings;
- $this->early_order_handler = $early_order_handler;
- $this->registration_needed = $registration_needed;
- $this->logger = $logger;
+ $this->request_data = $request_data;
+ $this->purchase_unit_factory = $purchase_unit_factory;
+ $this->shipping_preference_factory = $shipping_preference_factory;
+ $this->api_endpoint = $order_endpoint;
+ $this->payer_factory = $payer_factory;
+ $this->session_handler = $session_handler;
+ $this->settings = $settings;
+ $this->early_order_handler = $early_order_handler;
+ $this->registration_needed = $registration_needed;
+ $this->logger = $logger;
}
/**
@@ -198,9 +198,9 @@ class CreateOrderEndpoint implements EndpointInterface {
)
);
}
- $this->purchase_units = array( $this->purchase_unit_factory->from_wc_order( $wc_order ) );
+ $this->purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
} else {
- $this->purchase_units = $this->cart_repository->all();
+ $this->purchase_unit = $this->purchase_unit_factory->from_wc_cart();
// The cart does not have any info about payment method, so we must handle free trial here.
if ( (
@@ -209,10 +209,10 @@ class CreateOrderEndpoint implements EndpointInterface {
)
&& $this->is_free_trial_cart()
) {
- $this->purchase_units[0]->set_amount(
+ $this->purchase_unit->set_amount(
new Amount(
- new Money( 1.0, $this->purchase_units[0]->amount()->currency_code() ),
- $this->purchase_units[0]->amount()->breakdown()
+ new Money( 1.0, $this->purchase_unit->amount()->currency_code() ),
+ $this->purchase_unit->amount()->breakdown()
)
);
}
@@ -329,17 +329,21 @@ class CreateOrderEndpoint implements EndpointInterface {
* phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
*/
private function create_paypal_order( \WC_Order $wc_order = null ): Order {
- $needs_shipping = WC()->cart instanceof \WC_Cart && WC()->cart->needs_shipping();
- $shipping_address_is_fix = $needs_shipping && 'checkout' === $this->parsed_request_data['context'];
+ assert( $this->purchase_unit instanceof PurchaseUnit );
+
+ $shipping_preference = $this->shipping_preference_factory->from_state(
+ $this->purchase_unit,
+ $this->parsed_request_data['context'],
+ WC()->cart
+ );
try {
return $this->api_endpoint->create(
- $this->purchase_units,
+ array( $this->purchase_unit ),
+ $shipping_preference,
$this->payer( $this->parsed_request_data, $wc_order ),
null,
- $this->payment_method(),
- '',
- $shipping_address_is_fix
+ $this->payment_method()
);
} catch ( PayPalApiException $exception ) {
// Looks like currently there is no proper way to validate the shipping address for PayPal,
@@ -354,17 +358,14 @@ class CreateOrderEndpoint implements EndpointInterface {
) ) {
$this->logger->info( 'Invalid shipping address for order creation, retrying without it.' );
- foreach ( $this->purchase_units as $purchase_unit ) {
- $purchase_unit->set_shipping( null );
- }
+ $this->purchase_unit->set_shipping( null );
return $this->api_endpoint->create(
- $this->purchase_units,
+ array( $this->purchase_unit ),
+ $shipping_preference,
$this->payer( $this->parsed_request_data, $wc_order ),
null,
- $this->payment_method(),
- '',
- $shipping_address_is_fix
+ $this->payment_method()
);
}
diff --git a/modules/ppcp-subscription/services.php b/modules/ppcp-subscription/services.php
index b4f25c52d..026d26965 100644
--- a/modules/ppcp-subscription/services.php
+++ b/modules/ppcp-subscription/services.php
@@ -29,6 +29,7 @@ return array(
$repository,
$endpoint,
$purchase_unit_factory,
+ $container->get( 'api.factory.shipping-preference' ),
$payer_factory,
$environment
);
diff --git a/modules/ppcp-subscription/src/RenewalHandler.php b/modules/ppcp-subscription/src/RenewalHandler.php
index 2103e443d..a7b458d0d 100644
--- a/modules/ppcp-subscription/src/RenewalHandler.php
+++ b/modules/ppcp-subscription/src/RenewalHandler.php
@@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
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\Vaulting\PaymentTokenRepository;
use Psr\Log\LoggerInterface;
@@ -58,6 +59,13 @@ class RenewalHandler {
*/
private $purchase_unit_factory;
+ /**
+ * The shipping_preference factory.
+ *
+ * @var ShippingPreferenceFactory
+ */
+ private $shipping_preference_factory;
+
/**
* The payer factory.
*
@@ -75,28 +83,31 @@ class RenewalHandler {
/**
* RenewalHandler constructor.
*
- * @param LoggerInterface $logger The logger.
- * @param PaymentTokenRepository $repository The payment token repository.
- * @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.
+ * @param LoggerInterface $logger The logger.
+ * @param PaymentTokenRepository $repository The payment token repository.
+ * @param OrderEndpoint $order_endpoint The order endpoint.
+ * @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 Environment $environment The environment.
*/
public function __construct(
LoggerInterface $logger,
PaymentTokenRepository $repository,
OrderEndpoint $order_endpoint,
PurchaseUnitFactory $purchase_unit_factory,
+ ShippingPreferenceFactory $shipping_preference_factory,
PayerFactory $payer_factory,
Environment $environment
) {
- $this->logger = $logger;
- $this->repository = $repository;
- $this->order_endpoint = $order_endpoint;
- $this->purchase_unit_factory = $purchase_unit_factory;
- $this->payer_factory = $payer_factory;
- $this->environment = $environment;
+ $this->logger = $logger;
+ $this->repository = $repository;
+ $this->order_endpoint = $order_endpoint;
+ $this->purchase_unit_factory = $purchase_unit_factory;
+ $this->shipping_preference_factory = $shipping_preference_factory;
+ $this->payer_factory = $payer_factory;
+ $this->environment = $environment;
}
/**
@@ -141,11 +152,16 @@ class RenewalHandler {
if ( ! $token ) {
return;
}
- $purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
- $payer = $this->payer_factory->from_customer( $customer );
+ $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,
+ 'renewal'
+ );
$order = $this->order_endpoint->create(
array( $purchase_unit ),
+ $shipping_preference,
$payer,
$token
);
diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 63a5a4814..4c590aeb0 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -87,6 +87,7 @@ return array(
$page_id,
$environment,
$payment_token_repository,
+ $container->get( 'api.factory.shipping-preference' ),
$logger,
$payments_endpoint,
$order_endpoint,
@@ -123,6 +124,7 @@ return array(
$transaction_url_provider,
$payment_token_repository,
$purchase_unit_factory,
+ $container->get( 'api.factory.shipping-preference' ),
$payer_factory,
$order_endpoint,
$subscription_helper,
diff --git a/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php b/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php
index c39d03745..b11116878 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php
@@ -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;
}
/**
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
index 4af143dee..3fcd30456 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
@@ -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;
diff --git a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php
index fa425c6f3..10e0e1313 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php
@@ -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
);
diff --git a/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php b/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php
index d24087925..642d9c4b6 100644
--- a/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php
+++ b/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php
@@ -952,7 +952,7 @@ class OrderEndpointTest extends TestCase
->expects('email_address')
->andReturn('');
- $result = $testee->create([$purchaseUnit], $payer);
+ $result = $testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING, $payer);
$this->assertEquals($expectedOrder, $result);
}
@@ -1049,7 +1049,7 @@ class OrderEndpointTest extends TestCase
$payerName = Mockery::mock(PayerName::class);
$payer->expects('name')->andReturn($payerName);
$payer->expects('to_array')->andReturn(['payer']);
- $result = $testee->create([$purchaseUnit], $payer);
+ $result = $testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE, $payer);
$this->assertEquals($expectedOrder, $result);
}
@@ -1141,7 +1141,7 @@ class OrderEndpointTest extends TestCase
$payerName = Mockery::mock(PayerName::class);
$payer->expects('name')->andReturn($payerName);
$payer->expects('to_array')->andReturn(['payer']);
- $testee->create([$purchaseUnit], $payer);
+ $testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING, $payer);
}
public function testCreateForPurchaseUnitsIsNot201()
@@ -1232,6 +1232,6 @@ class OrderEndpointTest extends TestCase
$payerName = Mockery::mock(PayerName::class);
$payer->expects('name')->andReturn($payerName);
$payer->expects('to_array')->andReturn(['payer']);
- $testee->create([$purchaseUnit], $payer);
+ $testee->create([$purchaseUnit], ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE, $payer);
}
}
diff --git a/tests/PHPUnit/Button/Endpoint/ChangeCartEndpointTest.php b/tests/PHPUnit/Button/Endpoint/ChangeCartEndpointTest.php
index 7b1132c40..9eb6c654b 100644
--- a/tests/PHPUnit/Button/Endpoint/ChangeCartEndpointTest.php
+++ b/tests/PHPUnit/Button/Endpoint/ChangeCartEndpointTest.php
@@ -5,7 +5,7 @@ namespace WooCommerce\PayPalCommerce\Button\Endpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
-use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
+use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
use WooCommerce\WooCommerce\Logging\Logger\NullLogger;
@@ -17,7 +17,7 @@ class ChangeCartEndpointTest extends TestCase
/**
* @dataProvider dataForTestProducts
*/
- public function testProducts($data, $products, $lineItems, $responseExpectation) {
+ public function testProducts($data, $products, $responseExpectation) {
$dataStore = Mockery::mock(\WC_Data_Store::class);
$cart = Mockery::mock(\WC_Cart::class);
@@ -59,16 +59,21 @@ class ChangeCartEndpointTest extends TestCase
->expects('read_request')
->with(ChangeCartEndpoint::nonce())
->andReturn($data);
- $cartRepository = Mockery::mock(CartRepository::class);
- $cartRepository
- ->expects('all')
- ->andReturn($lineItems);
+
+ $pu = Mockery::mock(PurchaseUnit::class);
+ $pu
+ ->shouldReceive('to_array')
+ ->andReturn($responseExpectation[0]);
+ $purchase_unit_factory = Mockery::mock(PurchaseUnitFactory::class);
+ $purchase_unit_factory
+ ->expects('from_wc_cart')
+ ->andReturn($pu);
$testee = new ChangeCartEndpoint(
$cart,
$shipping,
$requestData,
- $cartRepository,
+ $purchase_unit_factory,
$dataStore,
new NullLogger()
);
@@ -97,15 +102,6 @@ class ChangeCartEndpointTest extends TestCase
->with('variable')
->andReturn(true);
- $defaultLineItem = Mockery::mock(PurchaseUnit::class);
- $defaultLineItem
- ->shouldReceive('to_array')
- ->andReturn([1]);
- $variationLineItem = Mockery::mock(PurchaseUnit::class);
- $variationLineItem
- ->shouldReceive('to_array')
- ->andReturn([2]);
-
$testData = [
'default' => [
[
@@ -120,9 +116,6 @@ class ChangeCartEndpointTest extends TestCase
[
$defaultProduct,
],
- [
- $defaultLineItem,
- ],
[
[1],
]
@@ -162,11 +155,7 @@ class ChangeCartEndpointTest extends TestCase
$variationProduct,
],
[
- $defaultLineItem,
- $variationLineItem,
- ],
- [
- [1],[2]
+ [1, 2]
]
]
];
diff --git a/tests/PHPUnit/Button/Endpoint/CreateOrderEndpointTest.php b/tests/PHPUnit/Button/Endpoint/CreateOrderEndpointTest.php
index a6e0bbfb7..00d863a9e 100644
--- a/tests/PHPUnit/Button/Endpoint/CreateOrderEndpointTest.php
+++ b/tests/PHPUnit/Button/Endpoint/CreateOrderEndpointTest.php
@@ -10,7 +10,7 @@ use ReflectionClass;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
-use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
+use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\Button\Helper\EarlyOrderHandler;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\TestCase;
@@ -145,7 +145,7 @@ class CreateOrderEndpointTest extends TestCase
protected function mockTestee()
{
$request_data = Mockery::mock(RequestData::class);
- $cart_repository = Mockery::mock(CartRepository::class);
+ $shippingPreferenceFactory = Mockery::mock(ShippingPreferenceFactory::class);
$purchase_unit_factory = Mockery::mock(PurchaseUnitFactory::class);
$order_endpoint = Mockery::mock(OrderEndpoint::class);
$payer_factory = Mockery::mock(PayerFactory::class);
@@ -155,8 +155,8 @@ class CreateOrderEndpointTest extends TestCase
$testee = new CreateOrderEndpoint(
$request_data,
- $cart_repository,
$purchase_unit_factory,
+ $shippingPreferenceFactory,
$order_endpoint,
$payer_factory,
$session_handler,
diff --git a/tests/PHPUnit/Subscription/RenewalHandlerTest.php b/tests/PHPUnit/Subscription/RenewalHandlerTest.php
index 036e8fd85..de3249fd6 100644
--- a/tests/PHPUnit/Subscription/RenewalHandlerTest.php
+++ b/tests/PHPUnit/Subscription/RenewalHandlerTest.php
@@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
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\TestCase;
use Mockery;
@@ -31,6 +32,7 @@ class RenewalHandlerTest extends TestCase
private $repository;
private $orderEndpoint;
private $purchaseUnitFactory;
+ private $shippingPreferenceFactory;
private $payerFactory;
private $environment;
private $sut;
@@ -43,6 +45,7 @@ class RenewalHandlerTest extends TestCase
$this->repository = Mockery::mock(PaymentTokenRepository::class);
$this->orderEndpoint = Mockery::mock(OrderEndpoint::class);
$this->purchaseUnitFactory = Mockery::mock(PurchaseUnitFactory::class);
+ $this->shippingPreferenceFactory = Mockery::mock(ShippingPreferenceFactory::class);
$this->payerFactory = Mockery::mock(PayerFactory::class);
$this->environment = new Environment(new Dictionary([]));
@@ -56,6 +59,7 @@ class RenewalHandlerTest extends TestCase
$this->repository,
$this->orderEndpoint,
$this->purchaseUnitFactory,
+ $this->shippingPreferenceFactory,
$this->payerFactory,
$this->environment
);
@@ -133,8 +137,12 @@ class RenewalHandlerTest extends TestCase
$this->payerFactory->shouldReceive('from_customer')
->andReturn($payer);
+ $this->shippingPreferenceFactory->shouldReceive('from_state')
+ ->with($purchaseUnit, 'renewal')
+ ->andReturn('no_shipping');
+
$this->orderEndpoint->shouldReceive('create')
- ->with([$purchaseUnit], $payer, $token)
+ ->with([$purchaseUnit], 'no_shipping', $payer, $token)
->andReturn($order);
$wcOrder->shouldReceive('update_status');
diff --git a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php
index f410e0b16..b9b2a87cb 100644
--- a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php
+++ b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php
@@ -10,6 +10,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
use Psr\Log\NullLogger;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
use WooCommerce\PayPalCommerce\ApiClient\Entity\CaptureStatus;
+use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
@@ -44,6 +45,7 @@ class WcGatewayTest extends TestCase
private $subscriptionHelper;
private $environment;
private $paymentTokenRepository;
+ private $shipping_preference_factory;
private $logger;
private $paymentsEndpoint;
private $orderEndpoint;
@@ -67,6 +69,7 @@ class WcGatewayTest extends TestCase
$this->subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
$this->environment = Mockery::mock(Environment::class);
$this->paymentTokenRepository = Mockery::mock(PaymentTokenRepository::class);
+ $this->shipping_preference_factory = Mockery::mock(ShippingPreferenceFactory::class);
$this->logger = Mockery::mock(LoggerInterface::class);
$this->paymentsEndpoint = Mockery::mock(PaymentsEndpoint::class);
$this->orderEndpoint = Mockery::mock(OrderEndpoint::class);
@@ -102,6 +105,7 @@ class WcGatewayTest extends TestCase
PayPalGateway::ID,
$this->environment,
$this->paymentTokenRepository,
+ $this->shipping_preference_factory,
$this->logger,
$this->paymentsEndpoint,
$this->orderEndpoint,
From 9ab091b945a0d6c8f3b45d936d6c3a285b52b43a Mon Sep 17 00:00:00 2001
From: Alex P
Date: Tue, 5 Jul 2022 15:05:57 +0300
Subject: [PATCH 155/163] Fix shipping preference for vaulted card button
---
.../src/Factory/ShippingPreferenceFactory.php | 12 +-
.../src/Endpoint/CreateOrderEndpoint.php | 3 +-
.../Factory/ShippingPreferenceFactoryTest.php | 118 ++++++++++++++++++
3 files changed, 131 insertions(+), 2 deletions(-)
create mode 100644 tests/PHPUnit/ApiClient/Factory/ShippingPreferenceFactoryTest.php
diff --git a/modules/ppcp-api-client/src/Factory/ShippingPreferenceFactory.php b/modules/ppcp-api-client/src/Factory/ShippingPreferenceFactory.php
index 322d598fd..0b433d6c4 100644
--- a/modules/ppcp-api-client/src/Factory/ShippingPreferenceFactory.php
+++ b/modules/ppcp-api-client/src/Factory/ShippingPreferenceFactory.php
@@ -24,12 +24,14 @@ class ShippingPreferenceFactory {
* @param PurchaseUnit $purchase_unit Thw PurchaseUnit.
* @param string $context The operation context like 'checkout', 'cart'.
* @param WC_Cart|null $cart The current cart if relevant.
+ * @param string $funding_source The funding source (PayPal button) like 'paypal', 'venmo', 'card'.
* @return string
*/
public function from_state(
PurchaseUnit $purchase_unit,
string $context,
- ?WC_Cart $cart = null
+ ?WC_Cart $cart = null,
+ string $funding_source = ''
): string {
$contains_physical_goods = $purchase_unit->contains_physical_goods();
if ( ! $contains_physical_goods ) {
@@ -49,6 +51,14 @@ class ShippingPreferenceFactory {
return ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS;
}
+ if ( 'card' === $funding_source ) {
+ if ( ! $has_shipping ) {
+ return ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
+ }
+ // Looks like GET_FROM_FILE does not work for the vaulted card button.
+ return ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS;
+ }
+
return ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE;
}
}
diff --git a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
index 9d3ed2d4e..c0045c8c4 100644
--- a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
+++ b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
@@ -334,7 +334,8 @@ class CreateOrderEndpoint implements EndpointInterface {
$shipping_preference = $this->shipping_preference_factory->from_state(
$this->purchase_unit,
$this->parsed_request_data['context'],
- WC()->cart
+ WC()->cart,
+ $this->parsed_request_data['funding_source'] ?? ''
);
try {
diff --git a/tests/PHPUnit/ApiClient/Factory/ShippingPreferenceFactoryTest.php b/tests/PHPUnit/ApiClient/Factory/ShippingPreferenceFactoryTest.php
new file mode 100644
index 000000000..4da631f06
--- /dev/null
+++ b/tests/PHPUnit/ApiClient/Factory/ShippingPreferenceFactoryTest.php
@@ -0,0 +1,118 @@
+testee = new ShippingPreferenceFactory();
+ }
+
+ /**
+ * @dataProvider forStateData
+ */
+ public function testFromState(
+ PurchaseUnit $purchase_unit,
+ string $context,
+ ?WC_Cart $cart,
+ string $funding_source,
+ string $expected_result
+ ) {
+ $result = $this->testee->from_state($purchase_unit, $context, $cart, $funding_source);
+
+ self::assertEquals($expected_result, $result);
+ }
+
+ public function forStateData()
+ {
+ yield [
+ $this->createPurchaseUnit(true, Mockery::mock(Shipping::class)),
+ 'checkout',
+ $this->createCart(true),
+ '',
+ ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS,
+ ];
+ yield [
+ $this->createPurchaseUnit(false, Mockery::mock(Shipping::class)),
+ 'checkout',
+ $this->createCart(false),
+ '',
+ ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING,
+ ];
+ yield [
+ $this->createPurchaseUnit(true, null),
+ 'checkout',
+ $this->createCart(true),
+ '',
+ ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING,
+ ];
+ yield [
+ $this->createPurchaseUnit(true, Mockery::mock(Shipping::class)),
+ 'checkout',
+ $this->createCart(true),
+ 'card',
+ ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS,
+ ];
+ yield [
+ $this->createPurchaseUnit(true, null),
+ 'product',
+ null,
+ '',
+ ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE,
+ ];
+ yield [
+ $this->createPurchaseUnit(true, null),
+ 'pay-now',
+ null,
+ 'venmo',
+ ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE,
+ ];
+ yield [
+ $this->createPurchaseUnit(true, Mockery::mock(Shipping::class)),
+ 'pay-now',
+ null,
+ 'venmo',
+ ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE,
+ ];
+ yield [
+ $this->createPurchaseUnit(true, Mockery::mock(Shipping::class)),
+ 'pay-now',
+ null,
+ 'card',
+ ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS,
+ ];
+ yield [
+ $this->createPurchaseUnit(true, null),
+ 'pay-now',
+ null,
+ 'card',
+ ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING,
+ ];
+ }
+
+ private function createPurchaseUnit(bool $containsPhysicalGoods, ?Shipping $shipping): PurchaseUnit {
+ $pu = Mockery::mock(PurchaseUnit::class);
+ $pu->shouldReceive('contains_physical_goods')->andReturn($containsPhysicalGoods);
+ $pu->shouldReceive('shipping')->andReturn($shipping);
+ return $pu;
+ }
+
+ private function createCart(bool $needsShipping): WC_Cart {
+ $cart = Mockery::mock(WC_Cart::class);
+ $cart->shouldReceive('needs_shipping')->andReturn($needsShipping);
+ return $cart;
+ }
+}
From 82adf1933f9611e15ba350f777e9470d0dc42f90 Mon Sep 17 00:00:00 2001
From: Alex P
Date: Thu, 7 Jul 2022 12:34:21 +0300
Subject: [PATCH 156/163] Refactor money value formatting
Do not duplicate code and send string value for JPY
---
modules/ppcp-api-client/src/Entity/Amount.php | 16 +++++----
modules/ppcp-api-client/src/Entity/Money.php | 23 ++++++++----
.../src/Helper/MoneyFormatter.php | 36 +++++++++++++++++++
tests/PHPUnit/ApiClient/Entity/AmountTest.php | 8 ++---
tests/e2e/PHPUnit/Order/PurchaseUnitTest.php | 19 ++++++++++
5 files changed, 84 insertions(+), 18 deletions(-)
create mode 100644 modules/ppcp-api-client/src/Helper/MoneyFormatter.php
diff --git a/modules/ppcp-api-client/src/Entity/Amount.php b/modules/ppcp-api-client/src/Entity/Amount.php
index 27ec10581..0b7c022c6 100644
--- a/modules/ppcp-api-client/src/Entity/Amount.php
+++ b/modules/ppcp-api-client/src/Entity/Amount.php
@@ -64,6 +64,15 @@ class Amount {
return $this->money->value();
}
+ /**
+ * The value formatted as string for API requests.
+ *
+ * @return string
+ */
+ public function value_str(): string {
+ return $this->money->value_str();
+ }
+
/**
* Returns the breakdown.
*
@@ -79,12 +88,7 @@ class Amount {
* @return array
*/
public function to_array(): array {
- $amount = array(
- 'currency_code' => $this->currency_code(),
- 'value' => in_array( $this->currency_code(), $this->currencies_without_decimals, true )
- ? round( $this->value(), 0 )
- : number_format( $this->value(), 2, '.', '' ),
- );
+ $amount = $this->money->to_array();
if ( $this->breakdown() && count( $this->breakdown()->to_array() ) ) {
$amount['breakdown'] = $this->breakdown()->to_array();
}
diff --git a/modules/ppcp-api-client/src/Entity/Money.php b/modules/ppcp-api-client/src/Entity/Money.php
index f1f3f848f..5ba49dc43 100644
--- a/modules/ppcp-api-client/src/Entity/Money.php
+++ b/modules/ppcp-api-client/src/Entity/Money.php
@@ -9,6 +9,8 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
+use WooCommerce\PayPalCommerce\ApiClient\Helper\MoneyFormatter;
+
/**
* Class Money
*/
@@ -29,11 +31,11 @@ class Money {
private $value;
/**
- * Currencies that does not support decimals.
+ * The MoneyFormatter.
*
- * @var array
+ * @var MoneyFormatter
*/
- private $currencies_without_decimals = array( 'HUF', 'JPY', 'TWD' );
+ private $money_formatter;
/**
* Money constructor.
@@ -44,6 +46,8 @@ class Money {
public function __construct( float $value, string $currency_code ) {
$this->value = $value;
$this->currency_code = $currency_code;
+
+ $this->money_formatter = new MoneyFormatter();
}
/**
@@ -55,6 +59,15 @@ class Money {
return $this->value;
}
+ /**
+ * The value formatted as string for API requests.
+ *
+ * @return string
+ */
+ public function value_str(): string {
+ return $this->money_formatter->format( $this->value, $this->currency_code );
+ }
+
/**
* The currency code.
*
@@ -72,9 +85,7 @@ class Money {
public function to_array(): array {
return array(
'currency_code' => $this->currency_code(),
- 'value' => in_array( $this->currency_code(), $this->currencies_without_decimals, true )
- ? round( $this->value(), 0 )
- : number_format( $this->value(), 2, '.', '' ),
+ 'value' => $this->value_str(),
);
}
}
diff --git a/modules/ppcp-api-client/src/Helper/MoneyFormatter.php b/modules/ppcp-api-client/src/Helper/MoneyFormatter.php
new file mode 100644
index 000000000..447ba0a0e
--- /dev/null
+++ b/modules/ppcp-api-client/src/Helper/MoneyFormatter.php
@@ -0,0 +1,36 @@
+currencies_without_decimals, true )
+ ? (string) round( $value, 0 )
+ : number_format( $value, 2, '.', '' );
+ }
+}
diff --git a/tests/PHPUnit/ApiClient/Entity/AmountTest.php b/tests/PHPUnit/ApiClient/Entity/AmountTest.php
index 24d4152c9..96b7f0a1c 100644
--- a/tests/PHPUnit/ApiClient/Entity/AmountTest.php
+++ b/tests/PHPUnit/ApiClient/Entity/AmountTest.php
@@ -22,9 +22,7 @@ class AmountTest extends TestCase
public function testBreakdownIsNull()
{
- $money = Mockery::mock(Money::class);
- $money->shouldReceive('currency_code')->andReturn('currencyCode');
- $money->shouldReceive('value')->andReturn(1.10);
+ $money = new Money(1.10, 'currencyCode');
$testee = new Amount($money);
$this->assertNull($testee->breakdown());
@@ -38,9 +36,7 @@ class AmountTest extends TestCase
public function testBreakdown()
{
- $money = Mockery::mock(Money::class);
- $money->shouldReceive('currency_code')->andReturn('currencyCode');
- $money->shouldReceive('value')->andReturn(1.10);
+ $money = new Money(1.10, 'currencyCode');
$breakdown = Mockery::mock(AmountBreakdown::class);
$breakdown->shouldReceive('to_array')->andReturn([1]);
$testee = new Amount($money, $breakdown);
diff --git a/tests/e2e/PHPUnit/Order/PurchaseUnitTest.php b/tests/e2e/PHPUnit/Order/PurchaseUnitTest.php
index 835088cbb..0dbf9485c 100644
--- a/tests/e2e/PHPUnit/Order/PurchaseUnitTest.php
+++ b/tests/e2e/PHPUnit/Order/PurchaseUnitTest.php
@@ -334,6 +334,25 @@ class PurchaseUnitTest extends TestCase
],
]),
];
+
+ yield 'no decimals currency' => [
+ [
+ 'currency' => 'JPY',
+ 'items' => [
+ ['price' => 18.0, 'quantity' => 2],
+ ],
+ 'shipping' => ['total' => 5.0],
+ 'billing' => ['city' => 'city2'],
+ ],
+ self::adaptAmountFormat([
+ 'value' => 66,
+ 'breakdown' => [
+ 'item_total' => 36,
+ 'tax_total' => 25, // 24.60
+ 'shipping' => 5,
+ ],
+ ], 'JPY'),
+ ];
}
public function cartData() {
From 2ca64739dba2ad30025bea36cb0bfb6941fe308c Mon Sep 17 00:00:00 2001
From: Alex P
Date: Thu, 7 Jul 2022 12:36:14 +0300
Subject: [PATCH 157/163] Use str value when checking mismatch
Otherwise the check may fail depending on the rounding used when creating the Money objects
---
.../src/Entity/PurchaseUnit.php | 26 ++++++++---------
.../ApiClient/Entity/PurchaseUnitTest.php | 11 +++-----
tests/e2e/PHPUnit/Order/PurchaseUnitTest.php | 28 ++++++++++++++++---
3 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/modules/ppcp-api-client/src/Entity/PurchaseUnit.php b/modules/ppcp-api-client/src/Entity/PurchaseUnit.php
index 4f4c8b785..fd7973738 100644
--- a/modules/ppcp-api-client/src/Entity/PurchaseUnit.php
+++ b/modules/ppcp-api-client/src/Entity/PurchaseUnit.php
@@ -331,9 +331,9 @@ class PurchaseUnit {
$remaining_item_total = array_reduce(
$items,
function ( float $total, Item $item ): float {
- return $total - $item->unit_amount()->value() * (float) $item->quantity();
+ return $total - (float) $item->unit_amount()->value_str() * (float) $item->quantity();
},
- $item_total->value()
+ (float) $item_total->value_str()
);
$remaining_item_total = round( $remaining_item_total, 2 );
@@ -356,11 +356,11 @@ class PurchaseUnit {
function ( float $total, Item $item ): float {
$tax = $item->tax();
if ( $tax ) {
- $total -= $tax->value() * (float) $item->quantity();
+ $total -= (float) $tax->value_str() * (float) $item->quantity();
}
return $total;
},
- $tax_total->value()
+ (float) $tax_total->value_str()
);
$remaining_tax_total = round( $remaining_tax_total, 2 );
@@ -378,29 +378,29 @@ class PurchaseUnit {
$amount_total = 0.0;
if ( $shipping ) {
- $amount_total += $shipping->value();
+ $amount_total += (float) $shipping->value_str();
}
if ( $item_total ) {
- $amount_total += $item_total->value();
+ $amount_total += (float) $item_total->value_str();
}
if ( $discount ) {
- $amount_total -= $discount->value();
+ $amount_total -= (float) $discount->value_str();
}
if ( $tax_total ) {
- $amount_total += $tax_total->value();
+ $amount_total += (float) $tax_total->value_str();
}
if ( $shipping_discount ) {
- $amount_total -= $shipping_discount->value();
+ $amount_total -= (float) $shipping_discount->value_str();
}
if ( $handling ) {
- $amount_total += $handling->value();
+ $amount_total += (float) $handling->value_str();
}
if ( $insurance ) {
- $amount_total += $insurance->value();
+ $amount_total += (float) $insurance->value_str();
}
- $amount_str = (string) $amount->to_array()['value'];
- $amount_total_str = (string) ( new Money( $amount_total, $amount->currency_code() ) )->to_array()['value'];
+ $amount_str = $amount->value_str();
+ $amount_total_str = ( new Money( $amount_total, $amount->currency_code() ) )->value_str();
$needs_to_ditch = $amount_str !== $amount_total_str;
return $needs_to_ditch;
}
diff --git a/tests/PHPUnit/ApiClient/Entity/PurchaseUnitTest.php b/tests/PHPUnit/ApiClient/Entity/PurchaseUnitTest.php
index 0aadf968a..dbb18c4de 100644
--- a/tests/PHPUnit/ApiClient/Entity/PurchaseUnitTest.php
+++ b/tests/PHPUnit/ApiClient/Entity/PurchaseUnitTest.php
@@ -412,10 +412,8 @@ class PurchaseUnitTest extends TestCase
foreach ($data as $testKey => $test) {
$items = [];
foreach ($test['items'] as $key => $item) {
- $unitAmount = Mockery::mock(Money::class);
- $unitAmount->shouldReceive('value')->andReturn($item['value']);
- $tax = Mockery::mock(Money::class);
- $tax->shouldReceive('value')->andReturn($item['tax']);
+ $unitAmount = new Money($item['value'], 'EUR');
+ $tax = new Money($item['tax'], 'EUR');
$items[$key] = Mockery::mock(
Item::class,
[
@@ -436,15 +434,14 @@ class PurchaseUnitTest extends TestCase
return null;
}
- $money = Mockery::mock(Money::class);
- $money->shouldReceive('value')->andReturn($value);
+ $money = new Money($value, 'EUR');
return $money;
});
}
}
$amount = Mockery::mock(Amount::class);
$amount->shouldReceive('to_array')->andReturn(['value' => number_format( $test['amount'], 2, '.', '' ), 'breakdown' => []]);
- $amount->shouldReceive('value')->andReturn($test['amount']);
+ $amount->shouldReceive('value_str')->andReturn(number_format( $test['amount'], 2, '.', '' ));
$amount->shouldReceive('currency_code')->andReturn('EUR');
$amount->shouldReceive('breakdown')->andReturn($breakdown);
diff --git a/tests/e2e/PHPUnit/Order/PurchaseUnitTest.php b/tests/e2e/PHPUnit/Order/PurchaseUnitTest.php
index 0dbf9485c..655830693 100644
--- a/tests/e2e/PHPUnit/Order/PurchaseUnitTest.php
+++ b/tests/e2e/PHPUnit/Order/PurchaseUnitTest.php
@@ -68,8 +68,6 @@ class PurchaseUnitTest extends TestCase
$pu = $this->puFactory->from_wc_order($wcOrder);
$puData = $pu->to_array();
- self::assertTrue(isset($puData['amount']['breakdown']));
-
self::assertEquals($expectedAmount, $puData['amount']);
}
@@ -83,8 +81,6 @@ class PurchaseUnitTest extends TestCase
$pu = $this->puFactory->from_wc_cart($this->cart);
$puData = $pu->to_array();
- self::assertTrue(isset($puData['amount']['breakdown']));
-
self::assertEquals($expectedAmount, $puData['amount']);
}
@@ -353,6 +349,18 @@ class PurchaseUnitTest extends TestCase
],
], 'JPY'),
];
+
+ yield [
+ [
+ 'items' => [
+ ['price' => 5.345, 'quantity' => 2],
+ ],
+ 'billing' => ['city' => 'city0'],
+ ],
+ self::adaptAmountFormat([
+ 'value' => 10.69,
+ ]),
+ ];
}
public function cartData() {
@@ -409,6 +417,18 @@ class PurchaseUnitTest extends TestCase
],
], get_woocommerce_currency()),
];
+
+ yield [
+ [
+ 'products' => [
+ ['price' => 5.345, 'quantity' => 2],
+ ],
+ 'billing' => ['city' => 'city0'],
+ ],
+ self::adaptAmountFormat([
+ 'value' => 10.69,
+ ], get_woocommerce_currency()),
+ ];
}
private static function adaptAmountFormat(array $data, string $currency = null): array {
From e7a4522f8d34ed0a069d47bc6abb832f952a7aa6 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 8 Jul 2022 10:53:35 +0200
Subject: [PATCH 158/163] Bump 1.9.1 version
---
changelog.txt | 9 +++++++++
package.json | 2 +-
readme.txt | 11 ++++++++++-
woocommerce-paypal-payments.php | 2 +-
4 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/changelog.txt b/changelog.txt
index 70909097d..72fd09378 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,5 +1,14 @@
*** Changelog ***
+= 1.9.1 - TBD =
+* Fix - ITEM_TOTAL_MISMATCH error when checking out with multiple products #721
+* Fix - Unable to purchase a product with Credit card button in pay for order page #718
+* Fix - Pay Later messaging only displayed when smart button is active on the same page #283
+* Fix - Pay Later messaging displayed for out of stock variable products or with no variation selected #667
+* Fix - Placeholders and card type detection not working for PayPal Card Processing (260) #685
+* Fix - PUI gateway is displayed with unsupported store currency #711
+* Enhancement - Missing PayPal fee in WC order details for PUI purchase #714
+
= 1.9.0 - 2022-07-04 =
* Add - New Feature - Pay Upon Invoice (Germany only) #608
* Fix - Order not approved: payment via vaulted PayPal account fails #677
diff --git a/package.json b/package.json
index 541f35f98..f9b601973 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "woocommerce-paypal-payments",
- "version": "1.9.0",
+ "version": "1.9.1",
"description": "WooCommerce PayPal Payments",
"repository": "https://github.com/woocommerce/woocommerce-paypal-payments",
"license": "GPL-2.0",
diff --git a/readme.txt b/readme.txt
index 63e9e8361..d1b6b3339 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Tags: woocommerce, paypal, payments, ecommerce, e-commerce, store, sales, sell,
Requires at least: 5.3
Tested up to: 6.0
Requires PHP: 7.1
-Stable tag: 1.9.0
+Stable tag: 1.9.1
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -81,6 +81,15 @@ Follow the steps below to connect the plugin to your PayPal account:
== Changelog ==
+= 1.9.1 =
+* Fix - ITEM_TOTAL_MISMATCH error when checking out with multiple products #721
+* Fix - Unable to purchase a product with Credit card button in pay for order page #718
+* Fix - Pay Later messaging only displayed when smart button is active on the same page #283
+* Fix - Pay Later messaging displayed for out of stock variable products or with no variation selected #667
+* Fix - Placeholders and card type detection not working for PayPal Card Processing (260) #685
+* Fix - PUI gateway is displayed with unsupported store currency #711
+* Enhancement - Missing PayPal fee in WC order details for PUI purchase #714
+
= 1.9.0 =
* Add - New Feature - Pay Upon Invoice (Germany only) #608
* Fix - Order not approved: payment via vaulted PayPal account fails #677
diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php
index 4aa932a36..38817fd03 100644
--- a/woocommerce-paypal-payments.php
+++ b/woocommerce-paypal-payments.php
@@ -3,7 +3,7 @@
* 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.9.0
+ * Version: 1.9.1
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* License: GPL-2.0
From 31823216e9835d64d80aa9744415a89c77c90b45 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 8 Jul 2022 11:54:23 +0200
Subject: [PATCH 159/163] Load pui js script only in chekcout page
---
.../Gateway/PayUponInvoice/PayUponInvoice.php | 37 +++++++++----------
1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 628ae89e6..f8a627616 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -11,11 +11,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface;
use WC_Order;
-use WC_Order_Item;
-use WC_Order_Item_Product;
-use WC_Product;
-use WC_Product_Variable;
-use WC_Product_Variation;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Factory\CaptureFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
@@ -518,21 +513,23 @@ 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
- );
+ if ( 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
+ );
- 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 ),
+ )
+ );
+ }
}
}
From 37c608474bdacdfa3c35c576ea93197ca1921235 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 8 Jul 2022 12:01:19 +0200
Subject: [PATCH 160/163] Make pui capitalizacion consistent
---
.../ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php | 2 +-
.../src/Render/OnboardingOptionsRenderer.php | 2 +-
modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php | 2 +-
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 2 +-
.../src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php | 6 +++---
modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php | 2 +-
6 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
index 5f81ca8a7..695e54b83 100644
--- a/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
+++ b/modules/ppcp-onboarding/src/Endpoint/PayUponInvoiceEndpoint.php
@@ -1,6 +1,6 @@
' .
- __( 'Onboard with Pay Upon Invoice', 'woocommerce-paypal-payments' ) . '
+ __( 'Onboard with Pay upon Invoice', 'woocommerce-paypal-payments' ) . '
';
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
index 3fcd30456..1aabbfc5a 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
@@ -364,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' );
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 628ae89e6..10fdd2484 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -418,7 +418,7 @@ class PayUponInvoice {
printf(
'',
- 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' )
);
}
}
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
index b6923942d..fe9d53d38 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php
@@ -103,7 +103,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' );
@@ -141,7 +141,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' ),
@@ -206,7 +206,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 );
diff --git a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
index 049038e48..24faa5201 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php
@@ -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' ),
);
From be219340768643eac2c428374a3be97f120168e4 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Fri, 8 Jul 2022 14:08:05 +0200
Subject: [PATCH 161/163] Update changelog
---
changelog.txt | 2 ++
readme.txt | 4 +++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/changelog.txt b/changelog.txt
index 72fd09378..10b2f8a1f 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -8,6 +8,8 @@
* Fix - Placeholders and card type detection not working for PayPal Card Processing (260) #685
* Fix - PUI gateway is displayed with unsupported store currency #711
* Enhancement - Missing PayPal fee in WC order details for PUI purchase #714
+* Enhancement - Skip loading of PUI js file on all pages where PUI gateway is not displayed #723
+* Enhancement - PUI feature capitalization not consistent #724
= 1.9.0 - 2022-07-04 =
* Add - New Feature - Pay Upon Invoice (Germany only) #608
diff --git a/readme.txt b/readme.txt
index d1b6b3339..2cc995602 100644
--- a/readme.txt
+++ b/readme.txt
@@ -88,7 +88,9 @@ Follow the steps below to connect the plugin to your PayPal account:
* Fix - Pay Later messaging displayed for out of stock variable products or with no variation selected #667
* Fix - Placeholders and card type detection not working for PayPal Card Processing (260) #685
* Fix - PUI gateway is displayed with unsupported store currency #711
-* Enhancement - Missing PayPal fee in WC order details for PUI purchase #714
+* Enhancement - Missing PayPal fee in WC order details for PUI purchase #714
+* Enhancement - Skip loading of PUI js file on all pages where PUI gateway is not displayed #723
+* Enhancement - PUI feature capitalization not consistent #724
= 1.9.0 =
* Add - New Feature - Pay Upon Invoice (Germany only) #608
From e73ebbadb66659c99a741f51578b9b30de9ed0b8 Mon Sep 17 00:00:00 2001
From: Alex P
Date: Mon, 11 Jul 2022 09:19:27 +0300
Subject: [PATCH 162/163] Fix phpcs warnings
---
modules/ppcp-subscription/src/RenewalHandler.php | 2 +-
.../src/Gateway/PayUponInvoice/FraudNetSessionId.php | 1 +
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 3 ++-
3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-subscription/src/RenewalHandler.php b/modules/ppcp-subscription/src/RenewalHandler.php
index a7b458d0d..eebd76533 100644
--- a/modules/ppcp-subscription/src/RenewalHandler.php
+++ b/modules/ppcp-subscription/src/RenewalHandler.php
@@ -144,7 +144,7 @@ class RenewalHandler {
*
* @throws \Exception If customer cannot be read/found.
*/
- private function process_order( \WC_Order $wc_order ) {
+ private function process_order( \WC_Order $wc_order ): void {
$user_id = (int) $wc_order->get_customer_id();
$customer = new \WC_Customer( $user_id );
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
index 966b5733f..358c50958 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/FraudNetSessionId.php
@@ -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 ) {
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index a9094607e..16bdbb3e8 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -518,7 +518,8 @@ class PayUponInvoice {
'ppcp-pay-upon-invoice',
trailingslashit( $this->module_url ) . 'assets/js/pay-upon-invoice.js',
array(),
- $this->asset_version
+ $this->asset_version,
+ true
);
wp_localize_script(
From d699ba61bf82a5bbfeadd7b97d6746cf1cf20b69 Mon Sep 17 00:00:00 2001
From: dinamiko
Date: Mon, 11 Jul 2022 09:34:40 +0200
Subject: [PATCH 163/163] Check gateway enabled to load pui js
---
.../src/Gateway/PayUponInvoice/PayUponInvoice.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
index 16bdbb3e8..87f89997a 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php
@@ -513,7 +513,9 @@ class PayUponInvoice {
* Registers PUI assets.
*/
public function register_assets(): void {
- if ( is_checkout() || is_checkout_pay_page() ) {
+ $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',