Skip to content

Commit

Permalink
Merge pull request #99 from bold-commerce/CHK-5127
Browse files Browse the repository at this point in the history
As a brand with Braintree Wallet pays enabled, I am a offered these w…
  • Loading branch information
NickolasMalovanets authored Oct 29, 2024
2 parents b601303 + 224d49b commit a34c503
Show file tree
Hide file tree
Showing 42 changed files with 789 additions and 537 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Bold\CheckoutPaymentBooster\Plugin\Quote\Model\QuoteManagement;
Expand All @@ -8,27 +9,34 @@
use Magento\Quote\Model\QuoteManagement;

/**
* Disable fastlane billing address validation plugin.
* Disable fastlane|express pay orders billing and shipping addresses validation plugin.
*/
class DisableFastlaneAddressValidationPlugin
class DisableBoldAddressValidationPlugin
{
/**
* Disable fastlane billing address validation as it may have no phone number.
* Bold payment methods codes.
*/
private const BOLD_METHODS_CODES = [
Service::CODE_FASTLANE,
Service::CODE,
];

/**
* Disable fastlane|express pay orders billing and shipping addresses validation as they may have no phone number.
*
* @param QuoteManagement $subject
* @param Quote $quote
* @param array $orderData
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeSubmit(
QuoteManagement $subject,
Quote $quote,
$orderData = []
Quote $quote
) {
if ($quote->getPayment()->getMethod() !== Service::CODE_FASTLANE) {
if (!in_array($quote->getPayment()->getMethod(), self::BOLD_METHODS_CODES)) {
return;
}
$quote->getBillingAddress()->setShouldIgnoreValidation(true);
$quote->getShippingAddress()->setShouldIgnoreValidation(true);
}
}
1 change: 1 addition & 0 deletions etc/csp_whitelist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<values>
<value id="bold_commerce_static" type="host">static.boldcommerce.com</value>
<value id="bold_paypal_images" type="host">*.paypal.com</value>
<value id="bold-google-static" type="host">www.gstatic.com</value>
</values>
</policy>
<policy id="style-src">
Expand Down
2 changes: 1 addition & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</arguments>
</type>
<type name="Magento\Quote\Model\QuoteManagement">
<plugin name="disable_fastlane_address_validation" type="Bold\CheckoutPaymentBooster\Plugin\Quote\Model\QuoteManagement\DisableFastlaneAddressValidationPlugin" />
<plugin name="disable_bold_address_validation" type="Bold\CheckoutPaymentBooster\Plugin\Quote\Model\QuoteManagement\DisableBoldAddressValidationPlugin" />
</type>
<type name="Bold\CheckoutPaymentBooster\Model\Http\Client\RequestsLogger">
<arguments>
Expand Down
19 changes: 19 additions & 0 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,33 @@ let config = {
},
},
paths: {
bold_braintree_client: 'https://js.braintreegateway.com/web/3.106.0/js/client.min',
bold_braintree_data_collector: 'https://js.braintreegateway.com/web/3.106.0/js/data-collector.min',
bold_braintree_google_payment: 'https://js.braintreegateway.com/web/3.106.0/js/google-payment.min',
bold_braintree_paypal_checkout: 'https://js.braintreegateway.com/web/3.106.0/js/paypal-checkout.min',
bold_google_pay: 'https://pay.google.com/gp/p/js/pay',
bold_apple_pay: 'https://js.braintreegateway.com/web/3.106.0/js/apple-pay.min',
bold_braintree_fastlane_client: 'https://js.braintreegateway.com/web/3.107.1/js/client.min',
bold_braintree_fastlane: 'https://js.braintreegateway.com/web/3.107.1/js/fastlane',
bold_braintree_fastlane_data_collector: 'https://js.braintreegateway.com/web/3.107.1/js/data-collector.min',
bold_braintree_fastlane_hosted_fields: 'https://js.braintreegateway.com/web/3.107.1/js/hosted-fields.min',
bold_ppcp_fastlane_client: 'https://js.braintreegateway.com/web/3.107.1/js/client.min',
bold_ppcp_fastlane_hosted_fields: 'https://js.braintreegateway.com/web/3.107.1/js/hosted-fields.min',
'fastlane/axo': 'https://www.paypalobjects.com/connect-boba/axo',
'fastlane/axo.min': 'https://www.paypalobjects.com/connect-boba/axo.min'
},
shim: {
'bold_braintree_client': {
exports: 'braintree.client'
},
'bold_braintree_data_collector': {
deps: ['bold_braintree_client'],
exports: 'braintree.dataCollector'
},
'bold_braintree_data_google_payment': {
deps: ['bold_braintree_client'],
exports: 'braintree.googlePayment'
},
'bold_braintree_fastlane_client': {
exports: 'braintree.fastlane_client'
},
Expand Down
47 changes: 0 additions & 47 deletions view/frontend/web/js/action/convert-bold-address.js

This file was deleted.

22 changes: 0 additions & 22 deletions view/frontend/web/js/action/create-wallet-pay-order-action.js

This file was deleted.

20 changes: 0 additions & 20 deletions view/frontend/web/js/action/eps-initialize-action.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
define(
[
'Magento_Checkout/js/model/new-customer-address',
'Magento_Customer/js/customer-data',
'checkoutData'
], function (
NewCustomerAddressModel,
customerData,
checkoutData
) {
'use strict';
/**
* Convert Magento address to Bold address.
*
* @param {Object} boldAddress
* @param {Object} magentoAddress
* @return {Object}
*/
return function (magentoAddress) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
define(
[
'Bold_CheckoutPaymentBooster/js/model/platform-client'
],
function (
platformClient
) {
'use strict';

/**
* Create Wallet Pay order.
*
* @param {{}}
* @return {Promise}
*/
return async function (paymentPayload) {
return platformClient.post(
'rest/V1/express_pay/order/create',
{
quoteMaskId: window.checkoutConfig.quoteData.entity_id,
gatewayId: paymentPayload.gateway_id,
shippingStrategy: paymentPayload.shipping_strategy || 'dynamic'
}
);
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
define(
[
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/checkout-data',
'Magento_Checkout/js/model/shipping-service',
'Bold_CheckoutPaymentBooster/js/action/express-pay/convert-magento-address-action'
],
function (
quote,
checkoutData,
shippingService,
convertMagentoAddressAction
) {
'use strict';

/**
* Get required order data for express pay.
*
* @return {Promise}
*/
return function (requirements) {
const payload = {};

for (const requirement of requirements) {
switch (requirement) {
case 'customer':
let billingAddress = quote.billingAddress();
const email = checkoutData.getValidatedEmailValue()
? checkoutData.getValidatedEmailValue()
: window.checkoutConfig.customerData.email;

payload[requirement] = {
first_name: billingAddress.firstname,
last_name: billingAddress.lastname,
email_address: email,
};
break;
case 'items':
payload[requirement] = quote.getItems().map(item => ({
amount: parseInt(parseFloat(item.base_price) * 100),
label: item.name
}));
break;
case 'billing_address':
payload[requirement] = convertMagentoAddressAction(quote.billingAddress());
break;
case 'shipping_address':
payload[requirement] = convertMagentoAddressAction(quote.shippingAddress());
break;
case 'shipping_options':
payload[requirement] = shippingService.getShippingRates().map(option => ({
label: `${option.carrier_title} - ${option.method_title}`,
amount: parseFloat(option.amount) * 100,
id: `${option.carrier_code}_${option.method_code}`,
is_selected: option.carrier_code === quote.shippingMethod()?.carrier_code &&
option.method_code === quote.shippingMethod()?.method_code
}));
break;
case 'totals':
const totals = quote.getTotals();
payload[requirement] = {
order_total: parseFloat(totals()['grand_total'] || 0) * 100,
order_balance: parseFloat(totals()['grand_total'] || 0) * 100,
shipping_total: parseFloat(totals()['shipping_amount'] || 0) * 100,
discounts_total: parseFloat(totals()['discount_amount'] || 0) * 100,
fees_total: parseFloat(totals()['fee_amount'] || 0) * 100,
taxes_total: parseFloat(totals()['tax'] || 0) * 100,
};
break;
}
}
return payload;
};
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
define(
[
'Magento_Checkout/js/model/quote',
'mage/storage',
'Magento_Checkout/js/model/resource-url-manager',
'Magento_Checkout/js/model/shipping-save-processor/payload-extender',
'Magento_Checkout/js/model/error-processor'
],
function (
quote,
storage,
resourceUrlManager,
payloadExtender,
errorProcessor
) {
'use strict';

/**
* Save shipping information.
*
* @param {Boolean} saveBillingAddress - Save billing address with shipping information.
* @return {Deferred}
*/
return function (saveBillingAddress = false) {
let payload;
payload = {
addressInformation: {
'shipping_address': quote.shippingAddress(),
'shipping_method_code': quote.shippingMethod() ? quote.shippingMethod()['method_code'] : null,
'shipping_carrier_code': quote.shippingMethod() ? quote.shippingMethod()['carrier_code'] : null,
}
};
if (saveBillingAddress) {
payload.addressInformation.billing_address = quote.billingAddress();
}
payloadExtender(payload);
return storage.post(
resourceUrlManager.getUrlForSetShippingInformation(quote),
JSON.stringify(payload)
).fail((response) => {
errorProcessor.process(response);
});
}
}
);
Loading

0 comments on commit a34c503

Please sign in to comment.