2024-10-31 14:44:45 +01:00
import OnboardingHeader from '../../ReusableComponents/OnboardingHeader' ;
2024-10-23 08:56:47 +02:00
import { _ _ , sprintf } from '@wordpress/i18n' ;
import { Button , TextControl } from '@wordpress/components' ;
2024-10-23 15:24:52 +02:00
import PaymentMethodIcons from '../../ReusableComponents/PaymentMethodIcons' ;
import SettingsToggleBlock from '../../ReusableComponents/SettingsToggleBlock' ;
import Separator from '../../ReusableComponents/Separator' ;
2024-10-31 17:41:01 +01:00
import { useOnboardingStepWelcome , useManualConnect } from '../../../data' ;
2024-10-24 16:58:03 +02:00
import DataStoreControl from '../../ReusableComponents/DataStoreControl' ;
2024-10-23 08:56:47 +02:00
2024-10-31 09:47:06 +02:00
const StepWelcome = ( { setStep , currentStep , setCompleted } ) => {
2024-10-23 08:56:47 +02:00
return (
< div className = "ppcp-r-page-welcome" >
< OnboardingHeader
title = { _ _ (
'Welcome to PayPal Payments' ,
'woocommerce-paypal-payments'
) }
description = { _ _ (
'Your all-in-one checkout solution with PayPal, Venmo, Pay Later, all major credit/debit cards, Apple Pay, Google Pay, and more.' ,
'woocommerce-paypal-payments'
) }
/ >
< div className = "ppcp-r-inner-container" >
< PaymentMethodIcons icons = "all" / >
< WelcomeFeatures / >
< Button
className = "ppcp-r-button-activate-paypal"
variant = "primary"
2024-10-24 06:35:48 +02:00
onClick = { ( ) => setStep ( currentStep + 1 ) }
2024-10-23 08:56:47 +02:00
>
{ _ _ (
'Activate PayPal Payments' ,
'woocommerce-paypal-payments'
) }
< / B u t t o n >
< Separator
className = "ppcp-r-page-welcome-or-separator"
text = { _ _ ( 'or' , 'woocommerce-paypal-payments' ) }
/ >
2024-10-31 09:47:06 +02:00
< WelcomeForm setCompleted = { setCompleted } / >
2024-10-23 08:56:47 +02:00
< / d i v >
< / d i v >
) ;
} ;
const WelcomeFeatures = ( ) => {
return (
< div className = "ppcp-r-welcome-features" >
< div className = "ppcp-r-welcome-features__col" >
< span > { _ _ ( 'Deposits' , 'woocommerce-paypal-payments' ) } < / s p a n >
< p > { _ _ ( 'Instant' , 'woocommerce-paypal-payments' ) } < / p >
< / d i v >
< div className = "ppcp-r-welcome-features__col" >
< span >
{ _ _ ( 'Payment Capture' , 'woocommerce-paypal-payments' ) }
< / s p a n >
< p >
{ _ _ (
'Authorize only or Capture' ,
'woocommerce-paypal-payments'
) }
< / p >
< / d i v >
< div className = "ppcp-r-welcome-features__col" >
< span >
{ _ _ (
'Recurring payments' ,
'woocommerce-paypal-payments'
) }
< / s p a n >
< p > { _ _ ( 'Supported' , 'woocommerce-paypal-payments' ) } < / p >
< / d i v >
< / d i v >
) ;
} ;
2024-10-31 09:47:06 +02:00
const WelcomeForm = ( { setCompleted } ) => {
2024-10-23 16:31:00 +02:00
const {
isSandboxMode ,
setSandboxMode ,
isManualConnectionMode ,
setManualConnectionMode ,
2024-10-23 18:17:08 +02:00
clientId ,
setClientId ,
clientSecret ,
setClientSecret ,
2024-10-31 17:41:01 +01:00
} =
( ) ;
2024-10-23 16:31:00 +02:00
2024-10-31 09:47:06 +02:00
const { connectManual } = useManualConnect ( ) ;
const handleConnect = async ( ) => {
try {
const res = await connectManual (
clientId ,
clientSecret ,
isSandboxMode
) ;
if ( ! res . success ) {
throw new Error ( 'Request failed.' ) ;
}
setCompleted ( true ) ;
} catch ( exc ) {
console . error ( exc ) ;
alert ( 'Connection failed.' ) ;
}
} ;
2024-10-23 08:56:47 +02:00
const advancedUsersDescription = sprintf (
// translators: %s: Link to PayPal REST application guide
_ _ (
2024-10-29 13:03:24 +01:00
'For advanced users: Connect a custom PayPal REST app for full control over your integration. For more information on creating a PayPal REST application, <a target="_blank" href="%s">click here</a>.' ,
2024-10-23 08:56:47 +02:00
'woocommerce-paypal-payments'
) ,
2024-10-29 13:03:24 +01:00
'https://woocommerce.com/document/woocommerce-paypal-payments/#manual-credential-input '
2024-10-23 08:56:47 +02:00
) ;
return (
< >
< SettingsToggleBlock
label = { _ _ (
'Enable Sandbox Mode' ,
'woocommerce-paypal-payments'
) }
description = { _ _ (
'Activate Sandbox mode to safely test PayPal with sample data. Once your store is ready to go live, you can easily switch to your production account.' ,
'woocommerce-paypal-payments'
) }
2024-10-23 16:31:00 +02:00
isToggled = { ! ! isSandboxMode }
setToggled = { setSandboxMode }
2024-10-23 08:56:47 +02:00
>
< Button variant = "secondary" >
{ _ _ ( 'Connect Account' , 'woocommerce-paypal-payments' ) }
< / B u t t o n >
< / S e t t i n g s T o g g l e B l o c k >
< Separator className = "ppcp-r-page-welcome-mode-separator" / >
< SettingsToggleBlock
label = { _ _ (
2024-10-29 13:03:24 +01:00
'Manually Connect' ,
2024-10-23 08:56:47 +02:00
'woocommerce-paypal-payments'
) }
description = { advancedUsersDescription }
2024-10-23 16:31:00 +02:00
isToggled = { ! ! isManualConnectionMode }
setToggled = { setManualConnectionMode }
2024-10-23 08:56:47 +02:00
>
2024-10-24 16:58:03 +02:00
< DataStoreControl
control = { TextControl }
2024-10-31 09:44:57 +02:00
label = {
isSandboxMode
? _ _ (
'Sandbox Client ID' ,
'woocommerce-paypal-payments'
)
: _ _ (
'Live Client ID' ,
'woocommerce-paypal-payments'
)
}
2024-10-24 16:58:03 +02:00
value = { clientId }
onChange = { setClientId }
/ >
< DataStoreControl
control = { TextControl }
2024-10-31 09:44:57 +02:00
label = {
isSandboxMode
? _ _ (
'Sandbox Secret Key' ,
'woocommerce-paypal-payments'
)
: _ _ (
'Live Secret Key' ,
'woocommerce-paypal-payments'
)
}
2024-10-24 16:58:03 +02:00
value = { clientSecret }
onChange = { setClientSecret }
2024-10-23 08:56:47 +02:00
type = "password"
2024-10-24 16:58:03 +02:00
/ >
2024-10-31 09:47:06 +02:00
< Button variant = "secondary" onClick = { handleConnect } >
2024-10-23 08:56:47 +02:00
{ _ _ ( 'Connect Account' , 'woocommerce-paypal-payments' ) }
< / B u t t o n >
< / S e t t i n g s T o g g l e B l o c k >
< / >
) ;
} ;
export default StepWelcome ;