Skip to content

Commit

Permalink
show hardcoded gateway in checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Oct 6, 2021
1 parent f7eb497 commit cd3cd34
Show file tree
Hide file tree
Showing 29 changed files with 8,549 additions and 8,272 deletions.
12 changes: 12 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
]
}
}
],
[
"@babel/preset-react",
{
"useBuiltIns": "entry",
"targets": {
"browsers": [
"last 2 versions",
"ie 10"
]
}
}
]
]
}
4 changes: 4 additions & 0 deletions inc/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*/
function mollieWooCommerceIsCheckoutContext()
{
global $wp_query;
if(!isset($wp_query)){
return false;
}
return is_checkout() || is_checkout_pay_page();
}

Expand Down
2 changes: 1 addition & 1 deletion mollie-payments-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Mollie Payments for WooCommerce
* Plugin URI: https://www.mollie.com
* Description: Accept payments in WooCommerce with the official Mollie plugin
* Version: 6.5.2
* Version: 6.7.0
* Author: Mollie
* Author URI: https://www.mollie.com
* Requires at least: 5.0
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"minimist": "^1.2.3",
"node-sass": "^4.13.0",
"pump": "^3.0.0",
"react": "^17.0.2",
"sass-loader": "^7.0.1"
},
"scripts": {
Expand Down
37 changes: 37 additions & 0 deletions resources/js/mollieBlockIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

(
function ({ mollieBlockData, wc, _}) {
console.log(mollieBlockData)
if (_.isEmpty(mollieBlockData)) {
return
}
const { registerPaymentMethod } = wc.wcBlocksRegistry;
console.log('register')
console.log(registerPaymentMethod)
const { gatewayData } = mollieBlockData;
console.log('gateway')
console.log(gatewayData)

gatewayData.forEach(item=>{
console.log('item')
console.log(item)
let paymentMethod = {
name: item.name,
label: <strong>{item.label}</strong>,
content: <div>{item.content}</div>,
edit: <div>{item.edit}</div>,
paymentMethodId: item.paymentMethodId,
canMakePayment: () => item.canMakePayment,
ariaLabel: item.ariaLabel,
supports: {
features: item.supports,
},
};

registerPaymentMethod( paymentMethod );
})
}
)
(
window, wc
)
35 changes: 33 additions & 2 deletions src/Assets/AssetsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ public function registerFrontendScripts()
);
wp_register_script(
'mollie_paypalButton',
$this->getPluginUrl('/resources/js/paypalButton.js'),
$this->getPluginUrl('/public/js/paypalButton.min.js'),
['underscore', 'jquery'],
filemtime($this->getPluginPath('/resources/js/paypalButton.js')),
filemtime($this->getPluginPath('/public/js/paypalButton.min.js')),
true
);
wp_register_script(
Expand Down Expand Up @@ -268,6 +268,13 @@ public function registerFrontendScripts()
filemtime($this->getPluginPath('/public/js/gatewaySurcharge.min.js')),
true
);
wp_register_script(
'mollie_block_index',
$this->getPluginUrl('/public/js/mollieBlockIndex.min.js'),
['wc-blocks-registry', 'underscore'],
filemtime($this->getPluginPath('/public/js/mollieBlockIndex.min.js')),
true
);
}

/**
Expand All @@ -277,6 +284,14 @@ public function registerFrontendScripts()
*/
public function enqueueFrontendScripts()
{
wp_enqueue_script('mollie_block_index');
wp_localize_script(
'mollie_block_index',
'mollieBlockData',
[
'gatewayData' => $this->gatewayDataForWCBlocks()
]
);
if (is_admin() || !mollieWooCommerceIsCheckoutContext()) {
return;
}
Expand Down Expand Up @@ -367,6 +382,22 @@ public function enqueueComponentsAssets()
);
}

protected function gatewayDataForWCBlocks(): array
{
return [
[
'name' => 'mollie_wc_gateway_ideal',
'label' => 'ideal',
'content' => 'Ideal content',
'edit' => 'Ideal edit',
'paymentMethodId' => 'mollie_wc_gateway_ideal',
'canMakePayment' => true,
'ariaLabel' => 'Payment via Mollie',
'supports' => []
]
];
}

protected function getPluginUrl(string $path = ''): string
{
return $this->pluginUrl . ltrim($path, '/');
Expand Down
2 changes: 1 addition & 1 deletion src/Core/CoreModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function services(): array
},
'core.plugin_version' => function (): string {
//Get plugin version TODO handle with properties
return '6.6.0';
return '6.7.0';
},
'core.plugin_title' => function (): string {
//Get plugin version TODO handle with properties
Expand Down
2 changes: 1 addition & 1 deletion src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function services(): array
'Belfius',
'Creditcard',
'DirectDebit',
'EPS',
'Eps',
'Giropay',
'Ideal',
'Kbc',
Expand Down
2 changes: 1 addition & 1 deletion src/Payment/OrderInstructionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Mollie\WooCommerce\Payment;

use Mollie\WooCommerce\Gateway\MolliePaymentGateway;
use Mollie\WooCommerce\PaymentMethods\DefaultInstructionStrategy;
use Mollie\WooCommerce\PaymentMethods\InstructionStrategies\DefaultInstructionStrategy;

class OrderInstructionsService
{
Expand Down
4 changes: 2 additions & 2 deletions src/Payment/PaymentCheckoutRedirectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Mollie\WooCommerce\Payment;

use Mollie\WooCommerce\Notice\NoticeInterface;
use Mollie\WooCommerce\PaymentMethods\PaymentFieldsStrategies\DefaultRedirectStrategy;
use Mollie\WooCommerce\PaymentMethods\PaymentFieldsStrategies\PaymentRedirectStrategyI;
use Mollie\WooCommerce\PaymentMethods\PaymentRedirectStrategies\DefaultRedirectStrategy;
use Mollie\WooCommerce\PaymentMethods\PaymentRedirectStrategies\PaymentRedirectStrategyI;
use Mollie\WooCommerce\Utils\Data;
use Psr\Log\LoggerInterface as Logger;
use WC_Order;
Expand Down
5 changes: 3 additions & 2 deletions src/Payment/PaymentModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ public function cancelOrderAtMollie($order_id)

public function handleExpiryDateCancelation()
{
if(!mollieWooCommercIsExpiryDateEnabled()){
//todo this doesnt work
/*if(!mollieWooCommercIsExpiryDateEnabled()){
as_unschedule_action( 'mollie_woocommerce_cancel_unpaid_orders' );
return;
}
Expand All @@ -439,7 +440,7 @@ public function handleExpiryDateCancelation()
11,
2
);
}
}*/
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Payment/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ protected function processAsMollieOrder(
? $data['orderNumber'] : ''
];

$this->logger->log( \WC_Log_Levels::DEBUG, $apiCallLog);
$this->logger->log( \WC_Log_Levels::DEBUG, json_encode($apiCallLog));
$paymentOrder = $paymentObject;
$paymentObject = $this->apiHelper->getApiClient($apiKey)->orders->create($data);
$settingsHelper = $this->settingsHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

class ApplepayInstructionStrategy implements InstructionStrategyI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

use Mollie\WooCommerce\Plugin;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

class CreditcardInstructionStrategy implements InstructionStrategyI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

class DefaultInstructionStrategy implements InstructionStrategyI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

class DirectdebitInstructionStrategy implements InstructionStrategyI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

class IdealInstructionStrategy implements InstructionStrategyI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

interface InstructionStrategyI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

class MybankInstructionStrategy implements InstructionStrategyI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

class PaypalInstructionStrategy implements InstructionStrategyI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

class Przelewy24InstructionStrategy implements InstructionStrategyI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;
namespace Mollie\WooCommerce\PaymentMethods\InstructionStrategies;

class SofortInstructionStrategy implements InstructionStrategyI
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods\PaymentFieldsStrategies;
namespace Mollie\WooCommerce\PaymentMethods\PaymentRedirectStrategies;

use Mollie\WooCommerce\Payment\MollieObject;
use Mollie\WooCommerce\Payment\MollieOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods\PaymentFieldsStrategies;
namespace Mollie\WooCommerce\PaymentMethods\PaymentRedirectStrategies;

use Mollie\WooCommerce\Payment\MollieOrder;
use Mollie\WooCommerce\Payment\MolliePayment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods\PaymentFieldsStrategies;
namespace Mollie\WooCommerce\PaymentMethods\PaymentRedirectStrategies;

use Mollie\WooCommerce\Payment\MollieObject;
use WC_Order;
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public function getOrderCurrency(\WC_Order $order)
public function formatCurrencyValue($value, $currency)
{
// Only the Japanese Yen has no decimals in the currency
$value = $value;
$value = (int) $value;

return $currency == "JPY" ? number_format($value, 0, '.', '') : number_format($value, 2, '.', '');
}
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function configJavaScript ({ basePath })
.addEntry('gatewaySettings.min', './resources/js/gatewaySettings.js')
.addEntry('gatewaySurcharge.min', './resources/js/gatewaySurcharge.js')
.addEntry('mollie-components.min', './resources/js/mollie-components.js')
.enableSourceMaps(!Encore.isProduction())
.addEntry('mollieBlockIndex.min', './resources/js/mollieBlockIndex.js')
.enableSourceMaps(!Encore.isProduction())

return extractEncoreConfig('javascript-configuration')
}
Expand Down
Loading

0 comments on commit cd3cd34

Please sign in to comment.