Skip to content

Commit

Permalink
PFW-1668, Display smart button for WooCommerce product shortcode. (#1969
Browse files Browse the repository at this point in the history
)

* PFW-1668, Display smart button for WooCommerce product shortcode.

* PFW-1686 - Fixed the Apple & Google pay payments for product_page shortcode on non-woocommerce product page

---------

Co-authored-by: Deepak Maurya <[email protected]>
  • Loading branch information
kcppdevelopers and deepakmaurya authored Nov 23, 2023
1 parent 05d82cc commit 8b79195
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 31 deletions.
29 changes: 22 additions & 7 deletions ppcp-gateway/angelleye-paypal-ppcp-common-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function angelleye_ppcp_get_raw_data() {
}
return $HTTP_RAW_POST_DATA;
} catch (Exception $ex) {

}
}

Expand Down Expand Up @@ -392,7 +392,7 @@ function angelleye_ppcp_round($price, $precision) {
$round_price = round($price, $precision);
$price = number_format($round_price, $precision, '.', '');
} catch (Exception $ex) {

}

return $price;
Expand Down Expand Up @@ -520,7 +520,7 @@ function angelleye_ppcp_is_product_purchasable($product, $enable_tokenized_payme
if ($enable_tokenized_payments === false && $product->is_type('subscription')) {
return apply_filters('angelleye_ppcp_is_product_purchasable', false, $product);
}
if (!is_product() || !$product->is_in_stock() || $product->is_type('external') || ($product->get_price() == '' || $product->get_price() == 0)) {
if (!$product->is_in_stock() || $product->is_type('external') || ($product->get_price() == '' || $product->get_price() == 0)) {
return apply_filters('angelleye_ppcp_is_product_purchasable', false, $product);
}
return apply_filters('angelleye_ppcp_is_product_purchasable', true, $product);
Expand Down Expand Up @@ -798,7 +798,7 @@ function angelleye_ppcp_get_token_id_by_token($token_id) {
}
return '';
} catch (Exception $ex) {

}
}

Expand All @@ -823,7 +823,7 @@ function angelleye_ppcp_add_used_payment_method_name_to_subscription($order_id)
}
}
} catch (Exception $ex) {

}
}

Expand Down Expand Up @@ -1033,7 +1033,7 @@ function angelleye_ppcp_get_paypal_details($account_details) {
}
return '';
} catch (Exception $ex) {

}
}

Expand Down Expand Up @@ -1072,7 +1072,7 @@ function angelleye_ppcp_get_classic_paypal_details($gateway_id) {
}
}
} catch (Exception $ex) {

}
}

Expand Down Expand Up @@ -1218,3 +1218,18 @@ function angelleye_ppcp_get_platform_fee_refund_amount() {
return 0.00;
}
}

if (!function_exists('angelleye_get_matched_shortcode_attributes')) {
function angelleye_get_matched_shortcode_attributes($tag, $text)
{
preg_match_all('/' . get_shortcode_regex() . '/s', $text, $matches);
$out = array();
if (isset($matches[2])) {
foreach ((array)$matches[2] as $key => $value) {
if ($tag === $value)
$out[] = shortcode_parse_atts($matches[3][$key]);
}
}
return $out;
}
}
68 changes: 44 additions & 24 deletions ppcp-gateway/class-angelleye-paypal-ppcp-smart-button.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,27 +198,8 @@ public function angelleye_ppcp_smart_button_style_properties() {
$this->apple_pay_button_props = [
'buttonStyle' => 'black', 'buttonType' => 'plain', 'height' => ''
];
if (is_product()) {
$this->disable_funding = $this->setting_obj->get('product_disallowed_funding_methods', array());
$this->style_layout = $this->setting_obj->get('product_button_layout', 'horizontal');
$this->style_color = $this->setting_obj->get('product_style_color', 'gold');
$this->style_shape = $this->setting_obj->get('product_style_shape', 'rect');
$this->style_size = $this->setting_obj->get('product_button_size', 'responsive');
$this->style_height = $this->setting_obj->get('product_button_height', '');
$this->style_label = $this->setting_obj->get('product_button_label', 'paypal');
$this->style_tagline = $this->setting_obj->get('product_button_tagline', 'yes');
$this->google_pay_button_props = [
'buttonColor' => $this->setting_obj->get('product_google_style_color', 'default'),
'buttonType' => $this->setting_obj->get('product_google_button_type', 'plain'),
'height' => $this->setting_obj->get('product_google_button_height', ''),
];
$this->apple_pay_button_props = [
'buttonColor' => $this->setting_obj->get('product_apple_style_color', 'black'),
'buttonType' => $this->setting_obj->get('product_apple_button_type', 'plain'),
'height' => $this->setting_obj->get('product_apple_button_height', ''),
];
$this->common_button_props['width'] = $this->setting_obj->get('product_button_width', '');
} elseif (is_cart()) {

if (is_cart()) {
$this->disable_funding = $this->setting_obj->get('cart_disallowed_funding_methods', array());
$this->style_layout = $this->setting_obj->get('cart_button_layout', 'vertical');
$this->style_color = $this->setting_obj->get('cart_style_color', 'gold');
Expand Down Expand Up @@ -258,6 +239,27 @@ public function angelleye_ppcp_smart_button_style_properties() {
'height' => $this->setting_obj->get('cart_apple_button_height', ''),
];
$this->common_button_props['width'] = $this->setting_obj->get('checkout_button_width', '');
} else {
// Make the product style settings as default styled property
$this->disable_funding = $this->setting_obj->get('product_disallowed_funding_methods', array());
$this->style_layout = $this->setting_obj->get('product_button_layout', 'horizontal');
$this->style_color = $this->setting_obj->get('product_style_color', 'gold');
$this->style_shape = $this->setting_obj->get('product_style_shape', 'rect');
$this->style_size = $this->setting_obj->get('product_button_size', 'responsive');
$this->style_height = $this->setting_obj->get('product_button_height', '');
$this->style_label = $this->setting_obj->get('product_button_label', 'paypal');
$this->style_tagline = $this->setting_obj->get('product_button_tagline', 'yes');
$this->google_pay_button_props = [
'buttonColor' => $this->setting_obj->get('product_google_style_color', 'default'),
'buttonType' => $this->setting_obj->get('product_google_button_type', 'plain'),
'height' => $this->setting_obj->get('product_google_button_height', ''),
];
$this->apple_pay_button_props = [
'buttonColor' => $this->setting_obj->get('product_apple_style_color', 'black'),
'buttonType' => $this->setting_obj->get('product_apple_button_type', 'plain'),
'height' => $this->setting_obj->get('product_apple_button_height', ''),
];
$this->common_button_props['width'] = $this->setting_obj->get('product_button_width', '');
}
$this->mini_cart_disable_funding = $this->setting_obj->get('mini_cart_disallowed_funding_methods', array());
$this->mini_cart_style_layout = $this->setting_obj->get('mini_cart_button_layout', 'vertical');
Expand Down Expand Up @@ -496,13 +498,30 @@ public function enqueue_scripts() {
$smart_js_arg['buyer-country'] = WC()->customer->get_billing_country();
}
}

$product_cart_amounts = $this->payment_request->ae_get_updated_checkout_payment_data();

$this->paymentaction = apply_filters('angelleye_ppcp_paymentaction', $this->paymentaction, null);
if (is_product()) {

// Adds a button selector when the product_page shortcode is added to a Non-WooCommerce page. Currently this supports single product_page shortcode if a page contains multiple shortcodes
$is_product_page_shortcode_used = !empty($post) && isset($post->post_content) && has_shortcode($post->post_content, 'product_page');
if ($is_product_page_shortcode_used) {
$shortcodes = angelleye_get_matched_shortcode_attributes('product_page', $post->post_content);
if (count($shortcodes)) {
foreach ($shortcodes as $shortcode) {
if (!empty($shortcode['id'])) {
$product_id = $shortcode['id'];
break;
}
}
}
if (empty($product_id)) {
$is_product_page_shortcode_used = false;
}
}

if (is_product() || $is_product_page_shortcode_used) {
$page = 'product';
$product_id = $post->ID;
$product_id = $is_product_page_shortcode_used ? $product_id : $post->ID;
$product = wc_get_product($product_id);
if (class_exists('WC_Subscriptions_Product') && WC_Subscriptions_Product::is_subscription($product)) {
$product_cart_amounts['isSubscriptionRequired'] = true;
Expand Down Expand Up @@ -597,6 +616,7 @@ public function enqueue_scripts() {
} elseif (is_add_payment_method_page()) {
$page = 'add_payment_method';
}

$smart_js_arg['commit'] = $this->angelleye_ppcp_is_skip_final_review() ? 'true' : 'false';
$smart_js_arg['intent'] = ($this->paymentaction === 'capture') ? 'capture' : 'authorize';
$smart_js_arg['locale'] = AngellEYE_Utility::get_button_locale_code();
Expand Down

0 comments on commit 8b79195

Please sign in to comment.