Skip to content

Commit

Permalink
PFW-635, Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed May 6, 2024
1 parent 9867039 commit 074c176
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
5 changes: 2 additions & 3 deletions assets/js/angelleye-script-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ function canShowPlaceOrderBtn() {
}

function showHidePlaceOrderBtn() {
// console.log(canShowPlaceOrderBtn(), abc.sss);
if (canShowPlaceOrderBtn()) {
jQuery('#place_order').removeClass('hide_place_order_btn').show();
jQuery('#place_order, .wc-block-components-checkout-place-order-button').removeClass('hide_place_order_btn').show();
} else {
jQuery('#place_order').addClass('hide_place_order_btn').hide();
jQuery('#place_order, .wc-block-components-checkout-place-order-button').addClass('hide_place_order_btn').hide();
}
}

Expand Down
44 changes: 38 additions & 6 deletions ppcp-gateway/checkout-block/ppcp-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var {createElement} = wp.element;
var {registerPlugin} = wp.plugins;
var {ExperimentalOrderMeta} = wc.blocksCheckout;
var {registerExpressPaymentMethod, registerPaymentMethod} = wc.wcBlocksRegistry;
var {addAction} = wp.hooks;

(function (e) {
var t = {};
function n(o) {
Expand Down Expand Up @@ -87,14 +89,36 @@ var {registerExpressPaymentMethod, registerPaymentMethod} = wc.wcBlocksRegistry;
const l = Object(u.getSetting)("angelleye_ppcp_data", {});
const p = () => Object(a.decodeEntities)(l.description || "");
const {useEffect} = window.wp.element;
const Content_PPCP_Smart_Button = () => {

const {extensionCartUpdate} = window.wc.blocksCheckout;
const {dispatch, select} = wp.data;
const {CHECKOUT_STORE_KEY} = window.wc.wcBlocksData;
const checkoutStore = select(CHECKOUT_STORE_KEY);
const Content_PPCP_Smart_Button = (props) => {
const {eventRegistration, emitResponse, onSubmit, billing, shippingData} = props;
const {onPaymentSetup} = eventRegistration;

jQuery(document.body).on('ppcp_checkout_updated', function () {
let address = {
'billing': billing.billingAddress,
'shipping': shippingData.shippingAddress
};
console.log(address);
angelleyeOrder.renderPaymentButtons(address);
});
useEffect(() => {
jQuery(document.body).trigger('trigger_angelleye_ppcp');
let address = {
'billing': billing.billingAddress,
'shipping': shippingData.shippingAddress
};
angelleyeOrder.renderPaymentButtons(address);
}, []);

//
return createElement(
"div",
{id: "angelleye_ppcp_checkout"}
);
);
};
const Content_PPCP_Smart_Button_Express = () => {
useEffect(() => {
Expand All @@ -119,7 +143,6 @@ var {registerExpressPaymentMethod, registerPaymentMethod} = wc.wcBlocksRegistry;
};
Object(c.registerPaymentMethod)(s);
const ppcp_settings = angelleye_ppcp_manager_block.settins;
console.log(ppcp_settings);
const {is_order_confirm_page, is_paylater_enable_incart_page, page} = angelleye_ppcp_manager_block;
const commonExpressPaymentMethodConfig = {
name: "angelleye_ppcp_top",
Expand Down Expand Up @@ -161,5 +184,14 @@ var {registerExpressPaymentMethod, registerPaymentMethod} = wc.wcBlocksRegistry;
document.addEventListener('DOMContentLoaded', function () {
setTimeout(function () {
jQuery(document.body).trigger('ppcp_block_ready');
}, 1000);
});
}, 2000);
});

addAction('experimental__woocommerce_blocks-checkout-set-shipping-address', 'c', function () {
jQuery(document.body).trigger('ppcp_checkout_updated');
});
addAction('experimental__woocommerce_blocks-checkout-set-billing-address', 'd', function () {
jQuery(document.body).trigger('ppcp_checkout_updated');
});


22 changes: 9 additions & 13 deletions ppcp-gateway/js/wc-angelleye-common-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ const angelleyeOrder = {
angelleye_ppcp_manager.woocommerce_process_checkout = nonce;
jQuery("#woocommerce-process-checkout-nonce").val(nonce);
},
createSmartButtonOrder: ({angelleye_ppcp_button_selector, errorLogId}) => {
return angelleyeOrder.createOrder({angelleye_ppcp_button_selector, errorLogId}).then((data) => {
createSmartButtonOrder: ({angelleye_ppcp_button_selector, errorLogId, address}) => {
return angelleyeOrder.createOrder({angelleye_ppcp_button_selector, errorLogId, address}).then((data) => {
return data.orderID;
});
},
Expand Down Expand Up @@ -353,7 +353,6 @@ const angelleyeOrder = {
jQuery('#angelleye_ppcp_checkout, #angelleye_ppcp_checkout_apple_pay, #angelleye_ppcp_checkout_google_pay').hide();
},
hideShowPlaceOrderButton: () => {
console.log('352');
let selectedPaymentMethod = angelleyeOrder.getSelectedPaymentMethod();
console.log('hideShowPlaceOrderButton', selectedPaymentMethod)
let isAePpcpMethodSelected = angelleyeOrder.isAngelleyePpcpPaymentMethodSelected();
Expand Down Expand Up @@ -404,27 +403,23 @@ const angelleyeOrder = {
if (!element) {
payment_method_element_selector = document.body; // Use body as the default if appendToSelector doesn't exist
}
console.log(paymentMethod);
angelleyeOrder.createHiddenInputField({
fieldId: 'angelleye_ppcp_payment_method_title',
fieldName: 'angelleye_ppcp_payment_method_title',
fieldValue: paymentMethod,
appendToSelector: payment_method_element_selector
});
},
renderSmartButton: () => {
console.log('412');
renderSmartButton: (address) => {
console.log('render smart buttons');
jQuery.each(angelleye_ppcp_manager.button_selector, function (key, angelleye_ppcp_button_selector) {
console.log(angelleye_ppcp_button_selector);
if (!jQuery(angelleye_ppcp_button_selector).length || jQuery(angelleye_ppcp_button_selector).children().length) {
return;
}
console.log('419');
if (typeof angelleye_paypal_sdk === 'undefined') {
return;
}
console.log('423');
let angelleye_ppcp_style = {
layout: angelleye_ppcp_manager.style_layout,
color: angelleye_ppcp_manager.style_color,
Expand All @@ -437,15 +432,14 @@ const angelleyeOrder = {
if (angelleye_ppcp_manager.style_layout !== 'vertical') {
angelleye_ppcp_style['tagline'] = (angelleye_ppcp_manager.style_tagline === 'yes') ? true : false;
}
console.log('436');
let errorLogId = null;
angelleye_paypal_sdk.Buttons({
style: angelleye_ppcp_style,
createOrder: function (data, actions) {
errorLogId = angelleyeJsErrorLogger.generateErrorId();
angelleyeJsErrorLogger.addToLog(errorLogId, 'PayPal Smart Button Payment Started');
return angelleyeOrder.createSmartButtonOrder({
angelleye_ppcp_button_selector, errorLogId
angelleye_ppcp_button_selector, errorLogId, address
})
},
onApprove: function (data, actions) {
Expand Down Expand Up @@ -513,6 +507,9 @@ const angelleyeOrder = {
if (jQuery(checkoutSelector).is('.HostedFields')) {
return false;
}
if (angelleyeOrder.isCCPaymentMethodSelected() === false) {
return false;
}
if (typeof angelleye_paypal_sdk === 'undefined') {
return;
}
Expand Down Expand Up @@ -832,9 +829,8 @@ const angelleyeOrder = {
}
},
renderPaymentButtons: (address) => {
console.log('827');
angelleyeOrder.hideShowPlaceOrderButton();
angelleyeOrder.renderSmartButton();
angelleyeOrder.renderSmartButton(address);
if (angelleyeOrder.isHostedFieldEligible() === true) {
jQuery('#angelleye_ppcp_cc-card-number iframe').length === 0 ? jQuery(angelleyeOrder.getCheckoutSelectorCss()).removeClass('HostedFields') : null;
jQuery('.checkout_cc_separator').show();
Expand Down Expand Up @@ -864,7 +860,7 @@ const angelleyeOrder = {
angelleyeOrder.renderPaymentButtons(address);
});
jQuery(document.body).on('trigger_angelleye_ppcp', function (event, address) {
angelleyeOrder.renderPaymentButtons();
angelleyeOrder.renderPaymentButtons(address);
});
},
handleRaceConditionOnWooHooks: () => {
Expand Down

0 comments on commit 074c176

Please sign in to comment.