Skip to content

Commit

Permalink
Merge branch 'trunk' into PRESS4_495
Browse files Browse the repository at this point in the history
  • Loading branch information
ramyakrishnai authored Apr 5, 2024
2 parents 58f2730 + 7e10fe1 commit 4ee77f9
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 144 deletions.
13 changes: 13 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@

use function NewfoldLabs\WP\ModuleLoader\register;

define( 'NFD_WOOCOMMERCE_MODULE_VERSION', '1.3.26' );

if ( function_exists( 'is_admin' ) && is_admin() ) {
$old_woocommerce_module_version = get_option( 'nfd_woocommerce_module_version' );

if ( $old_woocommerce_module_version < NFD_WOOCOMMERCE_MODULE_VERSION ) {
update_option( 'nfd_woocommerce_module_version', NFD_WOOCOMMERCE_MODULE_VERSION, true );
}
}

/**
* Skips woocommerce onboarding
*/
function skip_woo_onboarding() {
$wc_option = 'woocommerce_onboarding_profile';
$skip_onboarding = array(
Expand Down
20 changes: 20 additions & 0 deletions src/components/PayPalButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {useEffect, useRef} from '@wordpress/element';

const PaypalButton = () => {
const ppButton = useRef();

useEffect(() => {
const paypalBtn = document.querySelector('.yith-btn-paypal');
paypalBtn && ppButton.current.appendChild(paypalBtn);
return () => {
const hiddenWrapper = document.querySelector('.yith-ppcp-hidden-button-wrapper');
hiddenWrapper && hiddenWrapper.appendChild(paypalBtn);
};
}, []);

return (
<div className="pp-button-wapper" ref={ppButton}></div>
);
};

export default PaypalButton;
250 changes: 109 additions & 141 deletions src/components/Paypal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Badge, Button, Title, Link } from "@newfold/ui-component-library";
import { useEffect } from "@wordpress/element";
import { Badge, Button, Title } from "@newfold/ui-component-library";
import { __ } from "@wordpress/i18n";
import classNames from "classnames";
import { ReactComponent as AmexBrand } from "../icons/brands/amex.svg";
Expand All @@ -12,153 +11,122 @@ import { ReactComponent as SofortBrand } from "../icons/brands/sofort.svg";
import { ReactComponent as VenmoBrand } from "../icons/brands/venmo.svg";
import { ReactComponent as VisaBrand } from "../icons/brands/visa.svg";
import { ThirdPartyIntegration } from "./ThirdPartyIntegration";
import PayPalButton from "./PayPalButton";

const Paypal = ({ notify }) => {
useEffect(() => {
const ppButton = document.querySelector( ".yith-btn-paypal" );
if( ppButton ){
(function( d, s, id ) {
var js, ref = d.getElementsByTagName( s )[0];
if ( !d.getElementById( id ) ) {
js = d.createElement( s );
js.id = id;
js.async = true;
js.src = "https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js";
ref.parentNode.insertBefore( js, ref );
}
}( document, "script", "paypal-js" ));
window?.PAYPAL?.apps?.Signup?.loadScripts( document, "script" );
window?.PAYPAL?.apps?.Signup?.render();
}

return ()=>{
const panel = document.querySelector( '#payment-details' );
if( !panel && ppButton ){
ppButton.remove();
}
};
});
return (
<ThirdPartyIntegration
id="paypal"
title={__("Paypal", "wp-module-ecommerce")}
description={__(
"Online payments built for success. We help you do business in 200+ markets and 100+ currencies—even if your customers don't have PayPal.",
"wp-module-ecommerce"
)}
notify={notify}
>
{({ integrationStatus, onConnect, isInstalling }) => {
const isSetupComplete = integrationStatus?.complete;
const environment = integrationStatus?.details?.environment;
return (
<div className="nfd-border nfd-rounded-md nfd-p-6">
<div
className={classNames(
"max-[359px]:nfd-flex-col",
"min-[360px]:nfd-flex nfd-justify-between nfd-items-center min-[360px]:nfd-mb-8"
)}
<ThirdPartyIntegration
id="paypal"
title={__("Paypal", "wp-module-ecommerce")}
description={__(
"Online payments built for success. We help you do business in 200+ markets and 100+ currencies—even if your customers don't have PayPal.",
"wp-module-ecommerce",
)}
notify={notify}
>
{({ integrationStatus, onConnect, isInstalling }) => {
const isSetupComplete = integrationStatus?.complete;
const environment = integrationStatus?.details?.environment;
return (
<div className="nfd-border nfd-rounded-md nfd-p-6">
<div
className={classNames(
"max-[359px]:nfd-flex-col",
"min-[360px]:nfd-flex nfd-justify-between nfd-items-center min-[360px]:nfd-mb-8",
)}
>
<PaypalBrand />
{isInstalling ? (
<Button
variant="secondary"
isLoading
className={classNames(
"max-[359px]:nfd-my-2",
"min-[360px]:nfd-m-0",
)}
>
{__("Installing...", "wp-module-ecommerce")}
</Button>
) : isSetupComplete ? (
<Button
variant="secondary"
as="a"
href={integrationStatus?.integration?.plugin?.url}
className={classNames(
"max-[359px]:nfd-my-2",
"min-[360px]:nfd-m-0",
)}
>
{__("Manage", "wp-module-ecommerce")}
</Button>
) : typeof yith_ppwc_login !== "undefined" &&
!parseInt(yith_ppwc_login?.liveConnected) ? (
<PayPalButton />
) : (
<Button
onClick={onConnect}
className={classNames(
"max-[359px]:nfd-my-2",
"min-[360px]:nfd-m-0",
)}
>
{__("Install", "wp-module-ecommerce")}
</Button>
)}
</div>
{isSetupComplete && environment && (
<div className="nfd-flex nfd-gap-4 nfd-mt-4">
<span>{__("Environment:", "wp-module-ecommerce")}</span>
<Badge
size="large"
variant={environment === "sandbox" ? "upsell" : "plain"}
className={classNames(
"nfd-text-sm nfd-capitalize",
environment === "live" && "nfd-bg-[#178113] nfd-text-white",
)}
>
<PaypalBrand />
{isInstalling ? (
<Button
variant="secondary"
isLoading
className={classNames(
"max-[359px]:nfd-my-2",
"min-[360px]:nfd-m-0"
)}
>
{__("Installing...", "wp-module-ecommerce")}
</Button>
) : isSetupComplete ? (
<Button
variant="secondary"
as="a"
href={integrationStatus?.integration?.plugin?.url}
className={classNames(
"max-[359px]:nfd-my-2",
"min-[360px]:nfd-m-0"
)}
>
{__("Manage", "wp-module-ecommerce")}
</Button>
) : typeof yith_ppwc_login !== "undefined" &&
!parseInt(yith_ppwc_login?.liveConnected) ? (
<Link
href={yith_ppwc_login.loginURL}
variant="primary"
className="nfd-button nfd-button--primary yith-btn-paypal nfd-text-white"
target="_blank"
data-paypal-onboard-complete="onboardedCallback"
data-paypal-button="PPLtBlue"
>
{__("Connect", "wp-module-ecommerce")}
</Link>
) : (
<Button
onClick={onConnect}
className={classNames(
"max-[359px]:nfd-my-2",
"min-[360px]:nfd-m-0"
)}
>
{__("Install", "wp-module-ecommerce")}
</Button>
{environment}
</Badge>
</div>
)}
{!isSetupComplete && (
<div className="nfd-space-y-4 nfd-text-[#5B5B5B]">
<Title size="3">
{__("Provides flexible checkout options", "wp-module-ecommerce")}
</Title>
<ul className="nfd-pl-5 nfd-list-disc">
<li>{__("PayPal Buy Now Pay Later", "wp-module-ecommerce")}</li>
<li>{__("White-Labeling", "wp-module-ecommerce")}</li>
<li>
{__(
"Country-specific payment methods",
"wp-module-ecommerce",
)}
</li>
</ul>
<Title size="3">
{__(
" Supports many popular payment methods",
"wp-module-ecommerce",
)}
</Title>
<div className="nfd-flex nfd-items-end nfd-gap-2 nfd-flex-wrap">
<VisaBrand />
<MasterCardBrand />
<AmexBrand />
<DiscoverBrand />
<VenmoBrand />
<IdealBrand />
<GiroPayBrand />
<SofortBrand />
</div>
{isSetupComplete && environment && (
<div className="nfd-flex nfd-gap-4 nfd-mt-4">
<span>{__("Environment:", "wp-module-ecommerce")}</span>
<Badge
size="large"
variant={environment === "sandbox" ? "upsell" : "plain"}
className={classNames(
"nfd-text-sm nfd-capitalize",
environment === "live" && "nfd-bg-[#178113] nfd-text-white"
)}
>
{environment}
</Badge>
</div>
)}
{!isSetupComplete && (
<div className="nfd-space-y-4 nfd-text-[#5B5B5B]">
<Title size="3">
{__("Provides flexible checkout options", "wp-module-ecommerce")}
</Title>
<ul className="nfd-pl-5 nfd-list-disc">
<li>{__("PayPal Buy Now Pay Later", "wp-module-ecommerce")}</li>
<li>{__("White-Labeling", "wp-module-ecommerce")}</li>
<li>
{__(
"Country-specific payment methods",
"wp-module-ecommerce"
)}
</li>
</ul>
<Title size="3">
{__(
" Supports many popular payment methods",
"wp-module-ecommerce"
)}
</Title>
<div className="nfd-flex nfd-items-end nfd-gap-2 nfd-flex-wrap">
<VisaBrand />
<MasterCardBrand />
<AmexBrand />
<DiscoverBrand />
<VenmoBrand />
<IdealBrand />
<GiroPayBrand />
<SofortBrand />
</div>
</div>
)}
</div>
);
}}
</ThirdPartyIntegration>
)}
</div>
);
}}
</ThirdPartyIntegration>
);
};
export default Paypal;
6 changes: 3 additions & 3 deletions src/sdk/woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { WordPressSdk } from "./wordpress";
const Endpoints = {
ORDERS: (period) => NewfoldRuntime.createApiUrl("/wc/v3/orders", period),
ALL_TIME_ORDERS: NewfoldRuntime.createApiUrl("/wc/v3/orders"),
PRODUCTS: NewfoldRuntime.createApiUrl("/wc/v3/products"),
PRODUCTS: NewfoldRuntime.createApiUrl("/wc/store/products"),
Analytics: {
JETPACK: (range) =>
NewfoldRuntime.createApiUrl("/jetpack/v4/module/stats/data", { range }),
Expand Down Expand Up @@ -111,7 +111,7 @@ export const WooCommerceSdk = {
visitors: [this_period[visitorsIndex], prior_period[visitorsIndex]],
};
}
return { views: [], visitors: [] };
return { views: [], visitors: [] };
},
async sales(period) {
if (NewfoldRuntime.isWoo) {
Expand Down Expand Up @@ -142,7 +142,7 @@ export const WooCommerceSdk = {
},
async get() {
if (NewfoldRuntime.isWoo) {
return apiFetch({ url: Endpoints.ALL_TIME_ORDERS });
return apiFetch({ url: Endpoints.ALL_TIME_ORDERS });
}
},
},
Expand Down

0 comments on commit 4ee77f9

Please sign in to comment.