Skip to content

Commit

Permalink
Merge branch 'release-1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
chesio committed Aug 19, 2019
2 parents 08f3e18 + 6c875e7 commit c2d50e3
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/phpcs.xml export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/).

Expand All @@ -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.
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.
15 changes: 8 additions & 7 deletions bc-woocommerce-mpay24-gateway.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* Plugin Name: WooCommerce mPAY24 Gateway
* Plugin Name: BC 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: 1.1.0
* Author: Česlav Przywara <[email protected]>
* Author URI: https://www.chesio.com
* Requires PHP: 7.1
Expand Down Expand Up @@ -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('plugins_loaded', function () {
// Construct plugin instance.
$bc_woocommerce_mpay24_gateway = new \BlueChip\WooCommerce\Mpay24Gateway\Plugin();
// Load the plugin.
$bc_woocommerce_mpay24_gateway->load();
}, 10, 0);
2 changes: 1 addition & 1 deletion classes/BlueChip/WooCommerce/Mpay24Gateway/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Gateway extends \WC_Payment_Gateway


/**
* @var \BlueChip\WooCommerce\MPay24Gateway\Mpay24
* @var \BlueChip\WooCommerce\Mpay24Gateway\Mpay24
*/
private $mpay24;

Expand Down
5 changes: 3 additions & 2 deletions classes/BlueChip/WooCommerce/Mpay24Gateway/IPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ protected static function generateTransactionSecret(\WC_Order $order): string
*/
public static function processConfirmationRequest()
{
/** @var array<string, mixed> */
$request_data = wp_unslash($_GET);

$status = $request_data['STATUS'] ?? '';
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion classes/BlueChip/WooCommerce/Mpay24Gateway/IpTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 19 additions & 1 deletion classes/BlueChip/WooCommerce/Mpay24Gateway/Mpay24.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 1 addition & 12 deletions classes/BlueChip/WooCommerce/Mpay24Gateway/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c2d50e3

Please sign in to comment.