From da42ba82e7bfbb00df0da4db1a689012a8cb717c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Ceslav=20Przywara?= Date: Mon, 29 Jul 2019 13:36:31 +0200 Subject: [PATCH 01/10] Add .gitattributes and .gitignore files --- .gitattributes | 3 +++ .gitignore | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c4aef23 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +/.gitattributes export-ignore +/.gitignore export-ignore +/phpcs.xml export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..22d0d82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor From 89b3d6aa366fd51fa128d2e96e67fca99b2d020c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Ceslav=20Przywara?= Date: Mon, 29 Jul 2019 13:37:05 +0200 Subject: [PATCH 02/10] Set version to develop in development branch --- bc-woocommerce-mpay24-gateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bc-woocommerce-mpay24-gateway.php b/bc-woocommerce-mpay24-gateway.php index 8f630e7..675005d 100644 --- a/bc-woocommerce-mpay24-gateway.php +++ b/bc-woocommerce-mpay24-gateway.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce mPAY24 Gateway * Plugin URI: https://github.com/chesio/bc-woocommerce-mpay24-gateway * Description: Integrate mPAY24 payment gateway into WooCommerce - * Version: 1.0.0 + * Version: develop * Author: Česlav Przywara * Author URI: https://www.chesio.com * Requires PHP: 7.1 From 7e4b09580869fd8139c87e73e0b259b7318da327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Mon, 29 Jul 2019 14:00:43 +0200 Subject: [PATCH 03/10] 'init' is enough for us --- bc-woocommerce-mpay24-gateway.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bc-woocommerce-mpay24-gateway.php b/bc-woocommerce-mpay24-gateway.php index 675005d..c71e5d4 100644 --- a/bc-woocommerce-mpay24-gateway.php +++ b/bc-woocommerce-mpay24-gateway.php @@ -48,8 +48,9 @@ // Bootstrap mPAY24 PHP SDK (= effectively register autoloader for the SDK). require_once __DIR__ . '/includes/mpay24-php/bootstrap.php'; -// Construct plugin instance. -$bc_woocommerce_mpay24_gateway = new \BlueChip\WooCommerce\Mpay24Gateway\Plugin(); - -// Load the plugin. -$bc_woocommerce_mpay24_gateway->load(); +add_action('init', function () { + // Construct plugin instance. + $bc_woocommerce_mpay24_gateway = new \BlueChip\WooCommerce\Mpay24Gateway\Plugin(); + // Load the plugin. + $bc_woocommerce_mpay24_gateway->load(); +}); From 18834c99bc0e6bc5d2bb2855d57a6b7d465ec1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Mon, 29 Jul 2019 12:49:16 +0000 Subject: [PATCH 04/10] Fix phpstan Level 5-ish errors --- classes/BlueChip/WooCommerce/Mpay24Gateway/Gateway.php | 2 +- classes/BlueChip/WooCommerce/Mpay24Gateway/IPN.php | 5 +++-- classes/BlueChip/WooCommerce/Mpay24Gateway/IpTools.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/classes/BlueChip/WooCommerce/Mpay24Gateway/Gateway.php b/classes/BlueChip/WooCommerce/Mpay24Gateway/Gateway.php index 8f1815f..c726555 100644 --- a/classes/BlueChip/WooCommerce/Mpay24Gateway/Gateway.php +++ b/classes/BlueChip/WooCommerce/Mpay24Gateway/Gateway.php @@ -19,7 +19,7 @@ class Gateway extends \WC_Payment_Gateway /** - * @var \BlueChip\WooCommerce\MPay24Gateway\Mpay24 + * @var \BlueChip\WooCommerce\Mpay24Gateway\Mpay24 */ private $mpay24; diff --git a/classes/BlueChip/WooCommerce/Mpay24Gateway/IPN.php b/classes/BlueChip/WooCommerce/Mpay24Gateway/IPN.php index 43c18c4..e64e565 100644 --- a/classes/BlueChip/WooCommerce/Mpay24Gateway/IPN.php +++ b/classes/BlueChip/WooCommerce/Mpay24Gateway/IPN.php @@ -114,6 +114,7 @@ protected static function generateTransactionSecret(\WC_Order $order): string */ public static function processConfirmationRequest() { + /** @var array */ $request_data = wp_unslash($_GET); $status = $request_data['STATUS'] ?? ''; @@ -142,7 +143,7 @@ public static function processConfirmationRequest() /** * @param array $data Request data. - * @return null|WC_Order Order instance if confirmation request is valid, null otherwise. + * @return null|\WC_Order Order instance if confirmation request is valid, null otherwise. */ protected static function validateConfirmationRequest(array $data): ?\WC_Order { @@ -211,7 +212,7 @@ protected static function validateConfirmationRequest(array $data): ?\WC_Order * @link https://docs.mpay24.com/docs/transaction-states All transaction states * @link https://docs.mpay24.com/docs/payment-notification#section-notification-values Request data items * - * @param \WC_Order $order_id + * @param \WC_Order $order * @param string $status * @param string $tid * @param string $mpay_tid diff --git a/classes/BlueChip/WooCommerce/Mpay24Gateway/IpTools.php b/classes/BlueChip/WooCommerce/Mpay24Gateway/IpTools.php index 6979118..687c868 100644 --- a/classes/BlueChip/WooCommerce/Mpay24Gateway/IpTools.php +++ b/classes/BlueChip/WooCommerce/Mpay24Gateway/IpTools.php @@ -18,7 +18,7 @@ public static function isIpInSubnet(string $ip, string $subnet): bool [$net, $mask] = explode('/', $subnet); $_net = ip2long($net); - $_mask = ~((1 << (32 - $mask)) - 1); + $_mask = ~((1 << (32 - intval($mask))) - 1); $_ip = ip2long($ip); From 3582dde5117632bffd5755178922b907ceea527e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Ceslav=20Przywara?= Date: Mon, 29 Jul 2019 15:35:14 +0200 Subject: [PATCH 05/10] Initialize the plugin directly in `plugins_loaded` action --- bc-woocommerce-mpay24-gateway.php | 2 +- .../BlueChip/WooCommerce/Mpay24Gateway/Plugin.php | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/bc-woocommerce-mpay24-gateway.php b/bc-woocommerce-mpay24-gateway.php index c71e5d4..c23084a 100644 --- a/bc-woocommerce-mpay24-gateway.php +++ b/bc-woocommerce-mpay24-gateway.php @@ -48,7 +48,7 @@ // Bootstrap mPAY24 PHP SDK (= effectively register autoloader for the SDK). require_once __DIR__ . '/includes/mpay24-php/bootstrap.php'; -add_action('init', function () { +add_action('plugins_loaded', function () { // Construct plugin instance. $bc_woocommerce_mpay24_gateway = new \BlueChip\WooCommerce\Mpay24Gateway\Plugin(); // Load the plugin. diff --git a/classes/BlueChip/WooCommerce/Mpay24Gateway/Plugin.php b/classes/BlueChip/WooCommerce/Mpay24Gateway/Plugin.php index aa90f7e..de565e3 100644 --- a/classes/BlueChip/WooCommerce/Mpay24Gateway/Plugin.php +++ b/classes/BlueChip/WooCommerce/Mpay24Gateway/Plugin.php @@ -7,24 +7,13 @@ */ class Plugin { - /** - * Load the plugin by hooking into WordPress actions and filters. - * Method should be invoked immediately on plugin load. - */ - public function load() - { - // Register initialization method. - add_action('plugins_loaded', [$this, 'init'], 10, 0); - } - - /** * Perform initialization tasks. * Method should be run in `plugins_loaded` hook. * * @action https://developer.wordpress.org/reference/hooks/plugins_loaded/ */ - public function init() + public function load() { if (class_exists('WC_Payment_Gateway')) { add_filter('woocommerce_payment_gateways', [$this, 'registerPaymentMethod'], 10, 1); From 0e245b5b1881b72df830d71c05a47a252420603e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Ceslav=20Przywara?= Date: Mon, 29 Jul 2019 15:40:07 +0200 Subject: [PATCH 06/10] Update bc-woocommerce-mpay24-gateway.php Just a nitpicking... --- bc-woocommerce-mpay24-gateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bc-woocommerce-mpay24-gateway.php b/bc-woocommerce-mpay24-gateway.php index c23084a..a13c535 100644 --- a/bc-woocommerce-mpay24-gateway.php +++ b/bc-woocommerce-mpay24-gateway.php @@ -53,4 +53,4 @@ $bc_woocommerce_mpay24_gateway = new \BlueChip\WooCommerce\Mpay24Gateway\Plugin(); // Load the plugin. $bc_woocommerce_mpay24_gateway->load(); -}); +}, 10, 0); From 007d4c7eddd50d406c62aab103cb50dcd7d33732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Ceslav=20Przywara?= Date: Mon, 19 Aug 2019 12:30:32 +0200 Subject: [PATCH 07/10] Note in README that only credit card integration is supported --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15c0cca..1e46bfc 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,8 @@ A WordPress plugin that integrates [mPAY24](https://www.mpay24.com/) payment gat ## Compatibility -Plugin is based on [mPAY24 PHP SDK](https://github.com/mpay24/mpay24-php) in version 4.3.2. \ No newline at end of file +Plugin is based on [mPAY24 PHP SDK](https://github.com/mpay24/mpay24-php) in version 4.3.2. + +## Limitations + +mPAY24 supports integration with a lot of payment providers (like PayPal, Klarna etc.), but the plugin currently only supports credit card payments. \ No newline at end of file From 1f988a3855ecc80f7923a923ef988ef2d818cf6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Ceslav=20Przywara?= Date: Mon, 19 Aug 2019 13:13:54 +0200 Subject: [PATCH 08/10] Send customer billing data to mPAY24 This is going to be necessary as later phases of PSD2 kick in. --- .../WooCommerce/Mpay24Gateway/Mpay24.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/classes/BlueChip/WooCommerce/Mpay24Gateway/Mpay24.php b/classes/BlueChip/WooCommerce/Mpay24Gateway/Mpay24.php index c3cfc75..0785aab 100644 --- a/classes/BlueChip/WooCommerce/Mpay24Gateway/Mpay24.php +++ b/classes/BlueChip/WooCommerce/Mpay24Gateway/Mpay24.php @@ -110,9 +110,27 @@ protected function buildOrder(\WC_Order $order, string $return_url): \Mpay24\Mpa $mdxi->Order->Price = $order->get_total(); $mdxi->Order->Currency = $order->get_currency(); - // Add customer data. + // Add customer name. $mdxi->Order->Customer = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(); + // Add billing address. + $mdxi->Order->BillingAddr->setMode("ReadOnly"); + $mdxi->Order->BillingAddr->Name = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(); + $mdxi->Order->BillingAddr->Street = $order->get_billing_address_1(); + if ($order->get_billing_address_2()) { + // Set only if provided, because mPAY24 payment page features an empty field otherwise... + $mdxi->Order->BillingAddr->Street2 = $order->get_billing_address_2(); + } + $mdxi->Order->BillingAddr->Zip = $order->get_billing_postcode(); + $mdxi->Order->BillingAddr->City = $order->get_billing_city(); + if ($order->get_billing_state()) { + // Set only if provided, because mPAY24 payment page features an empty field otherwise... + $mdxi->Order->BillingAddr->State = $order->get_billing_state(); + } + $mdxi->Order->BillingAddr->Country->setCode($order->get_billing_country()); + $mdxi->Order->BillingAddr->Email = $order->get_billing_email(); + $mdxi->Order->BillingAddr->Phone = $order->get_billing_phone(); + // Note: Redirect to "thank you" page even in case of error, because the order-received endpoint is not a mere // "Thank you" page. If order status is "failed", it will display proper message and offer an option to repeat // the payment - I believe this is much better UX than canceling the order right away. From 7c218346abf2e56ac806119ab17680e2937c3bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Ceslav=20Przywara?= Date: Mon, 19 Aug 2019 13:15:41 +0200 Subject: [PATCH 09/10] Prefix plugin name with "BC" --- README.md | 2 +- bc-woocommerce-mpay24-gateway.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e46bfc..3134d54 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# WooCommerce mPAY24 Gateway +# BC WooCommerce mPAY24 Gateway A WordPress plugin that integrates [mPAY24](https://www.mpay24.com/) payment gateway into [WooCommerce](https://woocommerce.com/). diff --git a/bc-woocommerce-mpay24-gateway.php b/bc-woocommerce-mpay24-gateway.php index a13c535..2865dfc 100644 --- a/bc-woocommerce-mpay24-gateway.php +++ b/bc-woocommerce-mpay24-gateway.php @@ -1,6 +1,6 @@ Date: Mon, 19 Aug 2019 13:18:09 +0200 Subject: [PATCH 10/10] Bump version to 1.1.0 --- bc-woocommerce-mpay24-gateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bc-woocommerce-mpay24-gateway.php b/bc-woocommerce-mpay24-gateway.php index 2865dfc..8edcaa6 100644 --- a/bc-woocommerce-mpay24-gateway.php +++ b/bc-woocommerce-mpay24-gateway.php @@ -3,7 +3,7 @@ * Plugin Name: BC WooCommerce mPAY24 Gateway * Plugin URI: https://github.com/chesio/bc-woocommerce-mpay24-gateway * Description: Integrate mPAY24 payment gateway into WooCommerce - * Version: develop + * Version: 1.1.0 * Author: Česlav Przywara * Author URI: https://www.chesio.com * Requires PHP: 7.1