Skip to content

Commit

Permalink
Merge branch 'release/7.3.6-beta2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Mar 27, 2023
2 parents bc1bf2b + 67943a7 commit e41de50
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function _clean({baseDir, buildDir}) {
function _copy({baseDir, buildDir, distDir}) {
return function copy(done) {
pump(
src([`**/*.*`, `!${buildDir}/**/*.*`, `!${distDir}/**/*.*`, '!.git/**/*.*', '!vendor/**/*.*', '!node_modules/**/*.*'], {base: baseDir, cwd: baseDir, dot: true}),
src([`**/*.*`, `!${buildDir}/**/*.*`, `!${distDir}/**/*.*`, '!.git/**/*.*', '!vendor/**/*.*', '!node_modules/**/*.*', '!.ddev/**/*.*', '!.github/**/*.*', '!.psalm/**/*.*'], {base: baseDir, cwd: baseDir, dot: true}),
dest(buildDir),
done
)
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: 7.3.6-beta
* Version: 7.3.6-beta2
* Author: Mollie
* Author URI: https://www.mollie.com
* Requires at least: 5.0
Expand Down
30 changes: 24 additions & 6 deletions resources/js/applepayDirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import {request} from './applePayRequest.js';
return
}

const {product: {id, needShipping = true, isVariation = false, price}, shop: {countryCode, currencyCode = 'EUR', totalLabel = ''}, ajaxUrl} = mollieApplePayDirectData
const {product: {id, needShipping = true, isVariation = false, price, stock}, shop: {countryCode, currencyCode = 'EUR', totalLabel = ''}, ajaxUrl} = mollieApplePayDirectData

if (!id || !price || !countryCode || !ajaxUrl) {
return
}
if(!maybeShowButton()){
let outOfStock = stock === 'outofstock'
if (outOfStock || !maybeShowButton()){
return
}

Expand All @@ -27,19 +28,35 @@ import {request} from './applePayRequest.js';
productQuantity = event.currentTarget.value
})

function disableButton(appleButton) {
appleButton.disabled = true;
appleButton.classList.add("buttonDisabled");
}

function enableButton(appleButton) {
appleButton.disabled = false;
appleButton.classList.remove("buttonDisabled");
}

if (isVariation) {
let appleButton = document.querySelector('#mollie_applepay_button');
jQuery('.single_variation_wrap').on('hide_variation', function (event, variation) {
disableButton(appleButton);
return;
});
jQuery('.single_variation_wrap').on('show_variation', function (event, variation) {
// Fired when the user selects all the required dropdowns / attributes
// and a final variation is selected / shown
if (!variation.is_in_stock) {
disableButton(appleButton);
return;
}
if (variation.variation_id) {
productId = variation.variation_id
}
appleButton.disabled = false;
appleButton.classList.remove("buttonDisabled");
enableButton(appleButton);
});
appleButton.disabled = true;
appleButton.classList.add("buttonDisabled");
disableButton(appleButton);
}
const amountWithoutTax = productQuantity * price
let applePaySession = () => {
Expand Down Expand Up @@ -197,6 +214,7 @@ import {request} from './applePayRequest.js';
}
}
document.querySelector('#mollie_applepay_button').addEventListener('click', (evt) => {
evt.preventDefault()
applePaySession()
})
}
Expand Down
4 changes: 3 additions & 1 deletion resources/js/applepayDirectCart.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {maybeShowButton} from './maybeShowApplePayButton.js';
let selectedShippingMethod = []
let redirectionUrl = ''
let applePaySession = () => {
const session = new ApplePaySession(3, request(countryCode, currencyCode, totalLabel, subtotal))
const session = new ApplePaySession(3, request(countryCode, currencyCode, totalLabel, Math.round(subtotal)))
session.begin()
session.onshippingmethodselected = function (event) {
jQuery.ajax({
Expand Down Expand Up @@ -172,11 +172,13 @@ import {maybeShowButton} from './maybeShowApplePayButton.js';
jQuery(document.body).on('updated_cart_totals', function (event) {
maybeShowButton()
document.querySelector('#mollie_applepay_button').addEventListener('click', (evt) => {
evt.preventDefault()
applePaySession()
})
})

document.querySelector('#mollie_applepay_button').addEventListener('click', (evt) => {
evt.preventDefault()
applePaySession()
})
}
Expand Down
44 changes: 11 additions & 33 deletions src/Activation/ActivationModule.php

Large diffs are not rendered by default.

46 changes: 29 additions & 17 deletions src/Assets/AssetsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
use Mollie\WooCommerce\Shared\Data;
use Psr\Container\ContainerInterface;

use function Psalm\getPsalmHelpText;

class AssetsModule implements ExecutableModule
{
use ModuleClassNameIdTrait;
Expand Down Expand Up @@ -111,6 +109,15 @@ public function registerButtonsBlockScripts(string $pluginUrl, string $pluginPat
public function enqueueApplePayDirectScripts(): void
{
if (mollieWooCommerceIsApplePayDirectEnabled('product') && is_product()) {
$product = wc_get_product(get_the_id());
if (!$product) {
return;
}

if ($product->is_type('subscription') && !is_user_logged_in()) {
return;
}

$dataToScripts = new DataToAppleButtonScripts();
wp_enqueue_style('mollie-applepaydirect');
wp_enqueue_script('mollie_applepaydirect');
Expand All @@ -121,6 +128,10 @@ public function enqueueApplePayDirectScripts(): void
);
}
if (mollieWooCommerceIsApplePayDirectEnabled('cart') && is_cart()) {
$cart = WC()->cart;
if ($this->cartHasSubscription($cart) && !is_user_logged_in()) {
return;
}
$dataToScripts = new DataToAppleButtonScripts();
wp_enqueue_style('mollie-applepaydirect');
wp_enqueue_script('mollie_applepaydirectCart');
Expand All @@ -143,25 +154,23 @@ public function enqueuePayPalButtonScripts(string $pluginUrl): void
return;
}
$productNeedShipping = mollieWooCommerceCheckIfNeedShipping($product);
if (!$productNeedShipping) {
$dataToScripts = new DataToPayPal($pluginUrl);
wp_enqueue_style('unabledButton');
wp_enqueue_script('mollie_paypalButton');
wp_localize_script(
'mollie_paypalButton',
'molliepaypalbutton',
$dataToScripts->paypalbuttonScriptData()
);
if ($productNeedShipping) {
return;
}
$dataToScripts = new DataToPayPal($pluginUrl);
wp_enqueue_style('unabledButton');
wp_enqueue_script('mollie_paypalButton');
wp_localize_script(
'mollie_paypalButton',
'molliepaypalbutton',
$dataToScripts->paypalbuttonScriptData()
);
}
if (mollieWooCommerceIsPayPalButtonEnabled('cart') && is_cart()) {
$cart = WC()->cart;
foreach ($cart->get_cart_contents() as $product) {
if ($product['data']->is_type('subscription')) {
return;
}
if ($this->cartHasSubscription($cart)) {
return;
}

$dataToScripts = new DataToPayPal($pluginUrl);
wp_enqueue_style('unabledButton');
wp_enqueue_script('mollie_paypalButtonCart');
Expand Down Expand Up @@ -565,7 +574,10 @@ public function enqueueAdvancedSettingsJS($ar)
protected function cartHasSubscription(\WC_Cart $cart): bool
{
foreach ($cart->cart_contents as $cart_content) {
if ($cart_content['data'] instanceof \WC_Product_Subscription_Variation) {
if (
$cart_content['data'] instanceof \WC_Product_Subscription
|| $cart_content['data'] instanceof \WC_Product_Subscription_Variation
) {
return true;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Buttons/ApplePayButton/AppleAjaxRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function createWcOrder()

$cartItemKey = $cart->add_to_cart(
filter_input(INPUT_POST, 'productId'),
filter_input(INPUT_POST, 'productQuantity')
(bool) filter_input(INPUT_POST, 'productQuantity', FILTER_VALIDATE_INT)
);
$this->addAddressesToOrder($applePayRequestDataObject);

Expand Down Expand Up @@ -297,16 +297,16 @@ protected function whichCalculateTotals(

if ($applePayRequestDataObject->callerPage === 'productDetail') {
return $this->calculateTotalsSingleProduct(
$applePayRequestDataObject->productId,
$applePayRequestDataObject->productQuantity,
$applePayRequestDataObject->simplifiedContact,
$applePayRequestDataObject->shippingMethod
$applePayRequestDataObject->productId(),
$applePayRequestDataObject->productQuantity(),
$applePayRequestDataObject->simplifiedContact(),
$applePayRequestDataObject->shippingMethod()
);
}
if ($applePayRequestDataObject->callerPage === 'cart') {
return $this->calculateTotalsCartPage(
$applePayRequestDataObject->simplifiedContact,
$applePayRequestDataObject->shippingMethod
$applePayRequestDataObject->simplifiedContact(),
$applePayRequestDataObject->shippingMethod()
);
}
return false;
Expand Down
11 changes: 8 additions & 3 deletions src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ApplePayDataObjectHttp
/**
* @var array|mixed
*/
protected $shippingMethod;
protected $shippingMethod = [];
/**
* @var string[]
*/
Expand Down Expand Up @@ -241,7 +241,7 @@ protected function hasRequiredFieldsValuesOrError(array $data, array $required)
$this->errors[] = ['errorCode' => 'unknown'];
continue;
}
if (!$data[$requiredField]) {
if ($data[$requiredField] === null || $data[$requiredField] === '') {
$this->logger->debug(
sprintf('ApplePay Data Error: Missing value for %s', $requiredField)
);
Expand Down Expand Up @@ -442,7 +442,7 @@ public function shippingAddress(): array

public function shippingMethod(): array
{
return $this->shippingMethod;
return $this->shippingMethod ?? [];
}

public function needShipping(): bool
Expand All @@ -455,6 +455,11 @@ public function productId(): string
return $this->productId;
}

public function productQuantity(): string
{
return $this->productQuantity;
}

public function nonce()
{
return $this->nonce;
Expand Down
4 changes: 3 additions & 1 deletion src/Buttons/ApplePayButton/DataToAppleButtonScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,21 @@ protected function dataForProductPage(
return [];
}
$isVariation = false;
if ($product->get_type() === 'variable') {
if ($product->get_type() === 'variable' || $product->get_type() === 'variable-subscription') {
$isVariation = true;
}
$productNeedShipping = $this->checkIfNeedShipping($product);
$productId = get_the_id();
$productPrice = $product->get_price();
$productStock = $product->get_stock_status();

return [
'product' => [
'needShipping' => $productNeedShipping,
'id' => $productId,
'price' => $productPrice,
'isVariation' => $isVariation,
'stock' => $productStock,
],
'shop' => [
'countryCode' => $shopCountryCode,
Expand Down
8 changes: 4 additions & 4 deletions src/Buttons/ApplePayButton/ResponsesToApple.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,26 @@ protected function appleNewLineItemsResponse(array $paymentDetails): array
$response = [];
$response[] = $this->appleItemFormat(
'Subtotal',
$paymentDetails['subtotal'],
round(floatval($paymentDetails['subtotal']), 2),
$type
);

if ($paymentDetails['shipping']['amount']) {
$response[] = $this->appleItemFormat(
$paymentDetails['shipping']['label'] ?: '',
$paymentDetails['shipping']['amount'],
round(floatval($paymentDetails['shipping']['amount']), 2),
$type
);
}
$issetFeeAmount = isset($paymentDetails['fee']) && isset($paymentDetails['fee']['amount']);
if ($issetFeeAmount) {
$response[] = $this->appleItemFormat(
$paymentDetails['fee']['label'] ?: '',
$paymentDetails['fee']['amount'],
round(floatval($paymentDetails['fee']['amount']), 2),
$type
);
}
$response[] = $this->appleItemFormat('Estimated Tax', $paymentDetails['taxes'], $type);
$response[] = $this->appleItemFormat('Estimated Tax', round(floatval($paymentDetails['taxes']), 2), $type);
return $response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function testApplePayScriptDataOnProduct()
'id' => $postDummyData->productId,
'price' => '1',
'isVariation' => false,
'stock' => 'instock',
],
'shop' => [
'countryCode' => 'IT',
Expand Down Expand Up @@ -123,6 +124,8 @@ private function wcProduct()
'get_price' => '1',
'get_type' => 'simple',
'needs_shipping' => true,
'get_stock_status' => 'instock',

]
);

Expand Down
3 changes: 3 additions & 0 deletions tests/php/Stubs/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ public function is_taxable()
public function is_type($type){
}

public function get_stock_status()
{
}

}

Expand Down

0 comments on commit e41de50

Please sign in to comment.