2020-03-16 11:09:29 +00:00
/ * *
* External dependencies
* /
import { _ _ } from '@wordpress/i18n' ;
2020-06-12 09:38:02 +00:00
import apiFetch from '@wordpress/api-fetch' ;
2020-03-27 23:24:32 +00:00
import interpolateComponents from 'interpolate-components' ;
2020-03-16 11:09:29 +00:00
import {
2020-05-20 18:25:28 +00:00
getAdminLink ,
2020-03-16 11:09:29 +00:00
WC _ASSET _URL as wcAssetUrl ,
} from '@woocommerce/wc-admin-settings' ;
2020-03-27 23:24:32 +00:00
import { Link } from '@woocommerce/components' ;
2020-09-03 21:45:40 +00:00
import { WC _ADMIN _NAMESPACE } from '@woocommerce/data' ;
2021-02-23 10:56:20 +00:00
import { recordEvent } from '@woocommerce/tracks' ;
2020-03-16 11:09:29 +00:00
/ * *
* Internal dependencies
* /
2020-03-16 11:57:23 +00:00
import Bacs from './bacs' ;
2021-02-05 03:41:55 +00:00
import BacsLogo from './images/bacs' ;
import CodLogo from './images/cod' ;
import WCPayLogo from './images/wcpay' ;
import RazorpayLogo from './images/razorpay' ;
import { MollieLogo } from './images/mollie' ;
2021-02-16 21:08:35 +00:00
import { PayUIndiaLogo } from './images/payu-india' ;
2020-03-16 11:09:29 +00:00
import Stripe from './stripe' ;
import Square from './square' ;
2020-03-27 23:24:32 +00:00
import WCPay from './wcpay' ;
2021-02-05 23:41:26 +00:00
import PayPal , { PAYPAL _PLUGIN } from './paypal' ;
2020-03-16 11:09:29 +00:00
import Klarna from './klarna' ;
import PayFast from './payfast' ;
2020-08-07 00:09:10 +00:00
import EWay from './eway' ;
2020-12-01 22:10:57 +00:00
import Razorpay from './razorpay' ;
2021-02-05 03:41:55 +00:00
import { Mollie } from './mollie' ;
2021-02-16 21:08:35 +00:00
import { PayUIndia } from './payu-india' ;
2021-02-05 03:41:55 +00:00
import WCPayUsageModal from './wcpay-usage-modal' ;
import { createNoticesFromResponse } from '../../../lib/notices' ;
2020-03-16 11:09:29 +00:00
2020-07-14 01:40:56 +00:00
export function installActivateAndConnectWcpay (
resolve ,
reject ,
createNotice ,
installAndActivatePlugins
) {
const errorMessage = _ _ (
'There was an error connecting to WooCommerce Payments. Please try again or connect later in store settings.' ,
'woocommerce-admin'
) ;
const connect = ( ) => {
apiFetch ( {
path : WC _ADMIN _NAMESPACE + '/plugins/connect-wcpay' ,
method : 'POST' ,
} )
. then ( ( response ) => {
window . location = response . connectUrl ;
} )
. catch ( ( ) => {
createNotice ( 'error' , errorMessage ) ;
reject ( ) ;
} ) ;
} ;
installAndActivatePlugins ( [ 'woocommerce-payments' ] )
2021-02-23 10:56:20 +00:00
. then ( ( ) => {
recordEvent ( 'woocommerce_payments_install' , {
context : 'tasklist' ,
} ) ;
connect ( ) ;
} )
2020-07-14 01:40:56 +00:00
. catch ( ( error ) => {
createNoticesFromResponse ( error ) ;
reject ( ) ;
} ) ;
}
2020-03-16 11:09:29 +00:00
export function getPaymentMethods ( {
activePlugins ,
countryCode ,
2020-06-12 09:38:02 +00:00
createNotice ,
installAndActivatePlugins ,
2020-08-24 13:20:57 +00:00
onboardingStatus ,
2020-03-16 11:09:29 +00:00
options ,
profileItems ,
2021-02-05 23:41:26 +00:00
paypalOnboardingStatus ,
loadingPaypalStatus ,
2020-03-16 11:09:29 +00:00
} ) {
2020-08-24 13:20:57 +00:00
const {
stripeSupportedCountries = [ ] ,
wcPayIsConnected = false ,
2021-02-05 23:41:26 +00:00
enabledPaymentGateways = [ ] ,
2020-08-24 13:20:57 +00:00
} = onboardingStatus ;
2020-03-16 11:09:29 +00:00
2021-02-09 12:37:27 +00:00
const hasCbdIndustry = ( profileItems . industry || [ ] ) . some (
( { slug } ) => {
return slug === 'cbd-other-hemp-derived-products' ;
}
) ;
2020-03-27 23:24:32 +00:00
2020-11-11 20:09:44 +00:00
// Whether publishable and secret keys are filled for given mode.
const isStripeConfigured =
options . woocommerce _stripe _settings &&
( options . woocommerce _stripe _settings . testmode === 'no'
? options . woocommerce _stripe _settings . publishable _key &&
options . woocommerce _stripe _settings . secret _key
: options . woocommerce _stripe _settings . test _publishable _key &&
options . woocommerce _stripe _settings . test _secret _key ) ;
2021-02-05 03:41:55 +00:00
const methods = [
2020-03-16 11:09:29 +00:00
{
key : 'stripe' ,
title : _ _ (
'Credit cards - powered by Stripe' ,
'woocommerce-admin'
) ,
content : (
2021-02-05 03:41:55 +00:00
< >
2020-03-16 11:09:29 +00:00
{ _ _ (
'Accept debit and credit cards in 135+ currencies, methods such as Alipay, ' +
'and one-touch checkout with Apple Pay.' ,
'woocommerce-admin'
) }
2021-02-05 03:41:55 +00:00
< / >
2020-03-16 11:09:29 +00:00
) ,
before : < img src = { wcAssetUrl + 'images/stripe.png' } alt = "" / > ,
2020-03-20 18:33:18 +00:00
visible :
2020-06-12 09:38:02 +00:00
stripeSupportedCountries . includes ( countryCode ) &&
! hasCbdIndustry ,
2020-03-16 11:09:29 +00:00
plugins : [ 'woocommerce-gateway-stripe' ] ,
container : < Stripe / > ,
2020-11-11 20:09:44 +00:00
isConfigured : isStripeConfigured ,
2020-03-16 11:09:29 +00:00
isEnabled :
options . woocommerce _stripe _settings &&
options . woocommerce _stripe _settings . enabled === 'yes' ,
optionName : 'woocommerce_stripe_settings' ,
} ,
{
key : 'paypal' ,
2021-02-05 23:41:26 +00:00
title : _ _ ( 'PayPal Payments' , 'woocommerce-admin' ) ,
2020-03-16 11:09:29 +00:00
content : (
2021-02-05 03:41:55 +00:00
< >
2020-03-16 11:09:29 +00:00
{ _ _ (
"Safe and secure payments using credit cards or your customer's PayPal account." ,
'woocommerce-admin'
) }
2021-02-05 03:41:55 +00:00
< / >
2020-03-16 11:09:29 +00:00
) ,
before : < img src = { wcAssetUrl + 'images/paypal.png' } alt = "" / > ,
2020-03-20 18:33:18 +00:00
visible : ! hasCbdIndustry ,
2021-02-05 23:41:26 +00:00
plugins : [ PAYPAL _PLUGIN ] ,
2020-03-16 11:09:29 +00:00
container : < PayPal / > ,
isConfigured :
2021-02-05 23:41:26 +00:00
paypalOnboardingStatus &&
paypalOnboardingStatus . production &&
paypalOnboardingStatus . production . onboarded ,
isEnabled : enabledPaymentGateways . includes ( 'ppcp-gateway' ) ,
optionName : 'woocommerce_ppcp-gateway_settings' ,
loading : activePlugins . includes ( PAYPAL _PLUGIN )
? loadingPaypalStatus
: false ,
2020-03-16 11:09:29 +00:00
} ,
{
key : 'klarna_checkout' ,
title : _ _ ( 'Klarna Checkout' , 'woocommerce-admin' ) ,
content : _ _ (
'Choose the payment that you want, pay now, pay later or slice it. No credit card numbers, no passwords, no worries.' ,
'woocommerce-admin'
) ,
before : (
< img src = { wcAssetUrl + 'images/klarna-black.png' } alt = "" / >
) ,
2020-03-20 18:33:18 +00:00
visible :
2020-12-16 02:04:56 +00:00
[ 'SE' , 'FI' , 'NO' ] . includes ( countryCode ) &&
2020-03-20 18:33:18 +00:00
! hasCbdIndustry ,
2020-03-16 11:09:29 +00:00
plugins : [ 'klarna-checkout-for-woocommerce' ] ,
container : < Klarna plugin = { 'checkout' } / > ,
// @todo This should check actual Klarna connection information.
isConfigured : activePlugins . includes (
'klarna-checkout-for-woocommerce'
) ,
isEnabled :
options . woocommerce _kco _settings &&
options . woocommerce _kco _settings . enabled === 'yes' ,
optionName : 'woocommerce_kco_settings' ,
} ,
{
key : 'klarna_payments' ,
title : _ _ ( 'Klarna Payments' , 'woocommerce-admin' ) ,
content : _ _ (
'Choose the payment that you want, pay now, pay later or slice it. No credit card numbers, no passwords, no worries.' ,
'woocommerce-admin'
) ,
before : (
< img src = { wcAssetUrl + 'images/klarna-black.png' } alt = "" / >
) ,
2020-03-20 18:33:18 +00:00
visible :
2020-12-16 02:04:56 +00:00
[
'DK' ,
'DE' ,
'AT' ,
'NL' ,
'CH' ,
'BE' ,
'SP' ,
'PL' ,
'FR' ,
'IT' ,
2021-02-05 03:41:55 +00:00
'GB' ,
2020-12-16 02:04:56 +00:00
] . includes ( countryCode ) && ! hasCbdIndustry ,
2020-03-16 11:09:29 +00:00
plugins : [ 'klarna-payments-for-woocommerce' ] ,
container : < Klarna plugin = { 'payments' } / > ,
// @todo This should check actual Klarna connection information.
isConfigured : activePlugins . includes (
'klarna-payments-for-woocommerce'
) ,
isEnabled :
options . woocommerce _klarna _payments _settings &&
options . woocommerce _klarna _payments _settings . enabled === 'yes' ,
optionName : 'woocommerce_klarna_payments_settings' ,
} ,
2021-02-05 03:41:55 +00:00
{
key : 'mollie' ,
title : _ _ ( 'Mollie Payments for WooCommerce' , 'woocommerce-admin' ) ,
before : < MollieLogo / > ,
plugins : [ 'mollie-payments-for-woocommerce' ] ,
isConfigured : activePlugins . includes (
'mollie-payments-for-woocommerce'
) ,
content : (
< >
{ _ _ (
'Effortless payments by Mollie: Offer global and local payment methods, get onboarded in minutes, and supported in your language.' ,
'woocommerce-admin'
) }
< / >
) ,
visible : [
'FR' ,
'DE' ,
'GB' ,
'AT' ,
'CH' ,
'ES' ,
'IT' ,
'PL' ,
'FI' ,
'NL' ,
'BE' ,
] . includes ( countryCode ) ,
container : < Mollie / > ,
isEnabled :
options . woocommerce _mollie _payments _settings &&
options . woocommerce _mollie _payments _settings . enabled === 'yes' ,
optionName : 'woocommerce_mollie_payments_settings' ,
} ,
2020-03-16 11:09:29 +00:00
{
key : 'square' ,
title : _ _ ( 'Square' , 'woocommerce-admin' ) ,
2020-03-20 18:33:18 +00:00
content : (
2021-02-05 03:41:55 +00:00
< >
2020-03-20 18:33:18 +00:00
{ _ _ (
'Securely accept credit and debit cards with one low rate, no surprise fees (custom rates available). ' +
'Sell online and in store and track sales and inventory in one place.' ,
'woocommerce-admin'
) }
{ hasCbdIndustry && (
< span className = "text-style-strong" >
{ _ _ (
' Selling CBD products is only supported by Square.' ,
'woocommerce-admin'
) }
< / s p a n >
) }
2021-02-05 03:41:55 +00:00
< / >
2020-03-16 11:09:29 +00:00
) ,
before : (
2021-02-05 03:41:55 +00:00
< img src = { ` ${ wcAssetUrl } images/square-black.png ` } alt = "" / >
2020-03-16 11:09:29 +00:00
) ,
visible :
2020-03-20 18:33:18 +00:00
( hasCbdIndustry && [ 'US' ] . includes ( countryCode ) ) ||
( [ 'brick-mortar' , 'brick-mortar-other' ] . includes (
2020-03-16 11:09:29 +00:00
profileItems . selling _venues
2020-03-20 18:33:18 +00:00
) &&
[ 'US' , 'CA' , 'JP' , 'GB' , 'AU' ] . includes ( countryCode ) ) ,
2020-03-16 11:09:29 +00:00
plugins : [ 'woocommerce-square' ] ,
container : < Square / > ,
isConfigured :
options . wc _square _refresh _tokens &&
options . wc _square _refresh _tokens . length ,
isEnabled :
options . woocommerce _square _credit _card _settings &&
options . woocommerce _square _credit _card _settings . enabled ===
'yes' ,
optionName : 'woocommerce_square_credit_card_settings' ,
2020-04-08 23:17:32 +00:00
hasCbdIndustry ,
2020-03-16 11:09:29 +00:00
} ,
{
key : 'payfast' ,
title : _ _ ( 'PayFast' , 'woocommerce-admin' ) ,
content : (
2021-02-05 03:41:55 +00:00
< >
2020-03-16 11:09:29 +00:00
{ _ _ (
'The PayFast extension for WooCommerce enables you to accept payments by Credit Card and EFT via one of South Africa’ s most popular payment gateways. No setup fees or monthly subscription costs.' ,
'woocommerce-admin'
) }
< p >
{ _ _ (
'Selecting this extension will configure your store to use South African rands as the selected currency.' ,
'woocommerce-admin'
) }
< / p >
2021-02-05 03:41:55 +00:00
< / >
2020-03-16 11:09:29 +00:00
) ,
before : (
< img
src = { wcAssetUrl + 'images/payfast.png' }
alt = "PayFast logo"
/ >
) ,
2020-03-20 18:33:18 +00:00
visible : [ 'ZA' ] . includes ( countryCode ) && ! hasCbdIndustry ,
2020-03-16 11:09:29 +00:00
plugins : [ 'woocommerce-payfast-gateway' ] ,
container : < PayFast / > ,
isConfigured :
options . woocommerce _payfast _settings &&
options . woocommerce _payfast _settings . merchant _id &&
options . woocommerce _payfast _settings . merchant _key &&
options . woocommerce _payfast _settings . pass _phrase ,
isEnabled :
options . woocommerce _payfast _settings &&
options . woocommerce _payfast _settings . enabled === 'yes' ,
optionName : 'woocommerce_payfast_settings' ,
} ,
2020-08-07 00:09:10 +00:00
{
key : 'eway' ,
title : _ _ ( 'eWAY' , 'woocommerce-admin' ) ,
content : (
2021-02-05 03:41:55 +00:00
< >
2020-08-07 00:09:10 +00:00
{ _ _ (
'The eWAY extension for WooCommerce allows you to take credit card payments directly on your store without redirecting your customers to a third party site to make payment.' ,
'woocommerce-admin'
) }
2021-02-05 03:41:55 +00:00
< / >
2020-08-07 00:09:10 +00:00
) ,
before : (
< img
src = { wcAssetUrl + 'images/eway-logo.jpg' }
alt = "eWAY logo"
/ >
) ,
visible : [ 'AU' , 'NZ' ] . includes ( countryCode ) && ! hasCbdIndustry ,
plugins : [ 'woocommerce-gateway-eway' ] ,
container : < EWay / > ,
isConfigured :
options . woocommerce _eway _settings &&
options . woocommerce _eway _settings . customer _api &&
options . woocommerce _eway _settings . customer _password ,
isEnabled :
options . woocommerce _eway _settings &&
options . woocommerce _eway _settings . enabled === 'yes' ,
optionName : 'woocommerce_eway_settings' ,
} ,
2020-12-01 22:10:57 +00:00
{
key : 'razorpay' ,
title : _ _ ( 'Razorpay' , 'woocommerce-admin' ) ,
content : (
2021-02-05 03:41:55 +00:00
< >
2020-12-01 22:10:57 +00:00
{ _ _ (
'The official Razorpay extension for WooCommerce allows you to accept credit cards, debit cards, netbanking, wallet, and UPI payments.' ,
'woocommerce-admin'
) }
2021-02-05 03:41:55 +00:00
< / >
2020-12-01 22:10:57 +00:00
) ,
2021-02-05 03:41:55 +00:00
before : < RazorpayLogo / > ,
2020-12-01 22:10:57 +00:00
visible : countryCode === 'IN' && ! hasCbdIndustry ,
plugins : [ 'woo-razorpay' ] ,
container : < Razorpay / > ,
isConfigured :
options . woocommerce _razorpay _settings &&
options . woocommerce _razorpay _settings . key _id &&
options . woocommerce _razorpay _settings . key _secret ,
isEnabled :
options . woocommerce _razorpay _settings &&
options . woocommerce _razorpay _settings . enabled === 'yes' ,
optionName : 'woocommerce_razorpay_settings' ,
} ,
2021-02-16 21:08:35 +00:00
{
key : 'payubiz' ,
title : _ _ ( 'PayU for WooCommerce' , 'woocommerce-admin' ) ,
content : (
< >
{ _ _ (
'Enable PayU’ s exclusive plugin for WooCommerce to start accepting payments in 100+ payment methods available in India including credit cards, debit cards, UPI, & more!' ,
'woocommerce-admin'
) }
< / >
) ,
before : < PayUIndiaLogo / > ,
visible : countryCode === 'IN' && ! hasCbdIndustry ,
plugins : [ 'payu-india' ] ,
container : < PayUIndia / > ,
isConfigured : activePlugins . includes ( 'payu-india' ) ,
isEnabled : enabledPaymentGateways . includes ( 'payubiz' ) ,
optionName : 'woocommerce_payubiz_settings' ,
} ,
2020-03-16 11:57:23 +00:00
{
key : 'cod' ,
title : _ _ ( 'Cash on delivery' , 'woocommerce-admin' ) ,
content : _ _ (
'Take payments in cash upon delivery.' ,
'woocommerce-admin'
) ,
2021-02-05 03:41:55 +00:00
before : < CodLogo / > ,
2020-03-20 18:33:18 +00:00
visible : ! hasCbdIndustry ,
isEnabled :
options . woocommerce _cod _settings &&
options . woocommerce _cod _settings . enabled === 'yes' ,
2020-03-16 11:57:23 +00:00
optionName : 'woocommerce_cod_settings' ,
} ,
{
key : 'bacs' ,
title : _ _ ( 'Direct bank transfer' , 'woocommerce-admin' ) ,
content : _ _ (
'Take payments via bank transfer.' ,
'woocommerce-admin'
) ,
2021-02-05 03:41:55 +00:00
before : < BacsLogo / > ,
2020-03-20 18:33:18 +00:00
visible : ! hasCbdIndustry ,
2020-03-16 11:57:23 +00:00
container : < Bacs / > ,
2020-03-20 18:33:18 +00:00
isConfigured :
options . woocommerce _bacs _accounts &&
options . woocommerce _bacs _accounts . length ,
isEnabled :
options . woocommerce _bacs _settings &&
options . woocommerce _bacs _settings . enabled === 'yes' ,
2020-03-16 11:57:23 +00:00
optionName : 'woocommerce_bacs_settings' ,
2021-02-05 03:41:55 +00:00
} ,
] ;
if ( window . wcAdminFeatures . wcpay ) {
const tosLink = (
< Link
href = { 'https://wordpress.com/tos/' }
target = "_blank"
type = "external"
/ >
) ;
const tosPrompt = interpolateComponents ( {
mixedString : _ _ (
'By clicking "Set up," you agree to the {{link}}Terms of Service{{/link}}' ,
'woocommerce-admin'
) ,
components : {
link : tosLink ,
} ,
} ) ;
const wcPayDocLink = (
< Link
href = {
'https://docs.woocommerce.com/document/payments/testing/dev-mode/'
}
target = "_blank"
type = "external"
/ >
) ;
const wcPayDocPrompt = interpolateComponents ( {
mixedString : _ _ (
'Setting up a store for a client? {{link}}Start here{{/link}}' ,
'woocommerce-admin'
) ,
components : {
link : wcPayDocLink ,
} ,
} ) ;
const wcPaySettingsLink = (
< Link
href = { getAdminLink (
'admin.php?page=wc-settings&tab=checkout§ion=woocommerce_payments'
) }
type = "wp-admin"
>
{ _ _ ( 'Settings' , 'woocommerce-admin' ) }
< / L i n k >
) ;
methods . unshift ( {
key : 'wcpay' ,
title : _ _ ( 'WooCommerce Payments' , 'woocommerce-admin' ) ,
content : (
< >
{ _ _ (
'Accept credit card payments the easy way! No setup fees. No ' +
'monthly fees. Just 2.9% + $0.30 per transaction ' +
'on U.S. issued cards. ' ,
'woocommerce-admin'
) }
{ wcPayIsConnected && wcPaySettingsLink }
{ ! wcPayIsConnected && < p > { tosPrompt } < / p > }
{ profileItems . setup _client && < p > { wcPayDocPrompt } < / p > }
< WCPayUsageModal / >
< / >
) ,
before : < WCPayLogo / > ,
onClick : ( resolve , reject ) => {
return installActivateAndConnectWcpay (
resolve ,
reject ,
createNotice ,
installAndActivatePlugins
) ;
} ,
visible : [ 'US' , 'PR' ] . includes ( countryCode ) && ! hasCbdIndustry ,
plugins : [ 'woocommerce-payments' ] ,
container : < WCPay / > ,
isConfigured : wcPayIsConnected ,
isEnabled :
options . woocommerce _woocommerce _payments _settings &&
options . woocommerce _woocommerce _payments _settings . enabled ===
'yes' ,
optionName : 'woocommerce_woocommerce_payments_settings' ,
} ) ;
}
2020-03-16 11:09:29 +00:00
2021-02-05 03:41:55 +00:00
return methods . filter ( ( method ) => method . visible ) ;
2020-03-16 11:09:29 +00:00
}