2020-03-16 11:09:29 +00:00
/ * *
* External dependencies
* /
import { _ _ } from '@wordpress/i18n' ;
import { Fragment } from '@wordpress/element' ;
2020-03-20 18:33:18 +00:00
import { filter , some } from 'lodash' ;
2020-03-27 23:24:32 +00:00
import interpolateComponents from 'interpolate-components' ;
2020-03-16 11:09:29 +00:00
/ * *
* WooCommerce dependencies
* /
import {
getSetting ,
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-03-16 11:09:29 +00:00
/ * *
* Internal dependencies
* /
2020-03-16 11:57:23 +00:00
import Bacs from './bacs' ;
import BacsIcon from './images/bacs' ;
import CodIcon from './images/cod' ;
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' ;
import WCPayIcon from './images/wcpay' ;
2020-03-16 11:09:29 +00:00
import PayPal from './paypal' ;
import Klarna from './klarna' ;
import PayFast from './payfast' ;
export function getPaymentMethods ( {
activePlugins ,
countryCode ,
2020-04-09 23:10:47 +00:00
isJetpackConnected ,
2020-03-16 11:09:29 +00:00
options ,
profileItems ,
} ) {
2020-05-22 10:40:10 +00:00
const settings = getSetting ( 'onboarding' , {
2020-03-16 11:09:29 +00:00
stripeSupportedCountries : [ ] ,
2020-05-22 10:40:10 +00:00
wcPayIsConnected : false ,
} ) ;
const { stripeSupportedCountries , wcPayIsConnected } = settings ;
2020-03-16 11:09:29 +00:00
2020-03-20 18:33:18 +00:00
const hasCbdIndustry =
some ( profileItems . industry , {
slug : 'cbd-other-hemp-derived-products' ,
} ) || false ;
2020-03-27 23:24:32 +00:00
const methods = [ ] ;
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
2020-04-08 23:17:32 +00:00
href = {
'https://docs.woocommerce.com/document/payments/testing/dev-mode/'
}
2020-03-27 23:24:32 +00:00
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
2020-05-20 18:25:28 +00:00
href = { getAdminLink (
'admin.php?page=wc-settings&tab=checkout§ion=woocommerce_payments'
) }
type = "wp-admin"
2020-03-27 23:24:32 +00:00
>
{ _ _ ( 'Settings' , 'woocommerce-admin' ) }
< / L i n k >
) ;
methods . push ( {
key : 'wcpay' ,
title : _ _ ( 'WooCommerce Payments' , 'woocommerce-admin' ) ,
content : (
< Fragment >
{ _ _ (
'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'
) }
2020-05-22 10:40:10 +00:00
{ wcPayIsConnected && wcPaySettingsLink }
{ ! wcPayIsConnected && < p > { tosPrompt } < / p > }
2020-03-27 23:24:32 +00:00
{ profileItems . setup _client && < p > { wcPayDocPrompt } < / p > }
< / F r a g m e n t >
) ,
before : < WCPayIcon / > ,
2020-04-09 23:10:47 +00:00
visible :
[ 'US' ] . includes ( countryCode ) &&
! hasCbdIndustry &&
isJetpackConnected ,
2020-03-27 23:24:32 +00:00
plugins : [ 'woocommerce-payments' ] ,
container : < WCPay / > ,
2020-05-22 10:40:10 +00:00
isConfigured : wcPayIsConnected ,
2020-03-27 23:24:32 +00:00
isEnabled :
options . woocommerce _woocommerce _payments _settings &&
options . woocommerce _woocommerce _payments _settings . enabled ===
'yes' ,
optionName : 'woocommerce_woocommerce_payments_settings' ,
} ) ;
}
methods . push (
2020-03-16 11:09:29 +00:00
{
key : 'stripe' ,
title : _ _ (
'Credit cards - powered by Stripe' ,
'woocommerce-admin'
) ,
content : (
< Fragment >
{ _ _ (
'Accept debit and credit cards in 135+ currencies, methods such as Alipay, ' +
'and one-touch checkout with Apple Pay.' ,
'woocommerce-admin'
) }
< / F r a g m e n t >
) ,
before : < img src = { wcAssetUrl + 'images/stripe.png' } alt = "" / > ,
2020-03-20 18:33:18 +00:00
visible :
2020-05-22 10:40:10 +00:00
stripeSupportedCountries . includes ( countryCode ) && ! hasCbdIndustry ,
2020-03-16 11:09:29 +00:00
plugins : [ 'woocommerce-gateway-stripe' ] ,
container : < Stripe / > ,
isConfigured :
options . woocommerce _stripe _settings &&
options . woocommerce _stripe _settings . publishable _key &&
options . woocommerce _stripe _settings . secret _key ,
isEnabled :
options . woocommerce _stripe _settings &&
options . woocommerce _stripe _settings . enabled === 'yes' ,
optionName : 'woocommerce_stripe_settings' ,
} ,
{
key : 'paypal' ,
title : _ _ ( 'PayPal Checkout' , 'woocommerce-admin' ) ,
content : (
< Fragment >
{ _ _ (
"Safe and secure payments using credit cards or your customer's PayPal account." ,
'woocommerce-admin'
) }
< / F r a g m e n t >
) ,
before : < img src = { wcAssetUrl + 'images/paypal.png' } alt = "" / > ,
2020-03-20 18:33:18 +00:00
visible : ! hasCbdIndustry ,
2020-03-16 11:09:29 +00:00
plugins : [ 'woocommerce-gateway-paypal-express-checkout' ] ,
container : < PayPal / > ,
isConfigured :
options . woocommerce _ppec _paypal _settings &&
options . woocommerce _ppec _paypal _settings . api _username &&
options . woocommerce _ppec _paypal _settings . api _password ,
isEnabled :
options . woocommerce _ppec _paypal _settings &&
options . woocommerce _ppec _paypal _settings . enabled === 'yes' ,
optionName : 'woocommerce_ppec_paypal_settings' ,
} ,
{
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 :
[ 'SE' , 'FI' , 'NO' , 'NL' ] . includes ( countryCode ) &&
! 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 :
[ 'DK' , 'DE' , 'AT' ] . 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' ,
} ,
{
key : 'square' ,
title : _ _ ( 'Square' , 'woocommerce-admin' ) ,
2020-03-20 18:33:18 +00:00
content : (
< Fragment >
{ _ _ (
'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 >
) }
< / F r a g m e n t >
2020-03-16 11:09:29 +00:00
) ,
before : (
< img src = { wcAssetUrl + 'images/square-black.png' } alt = "" / >
) ,
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 : (
< Fragment >
{ _ _ (
'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 >
< / F r a g m e n t >
) ,
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-03-16 11:57:23 +00:00
{
key : 'cod' ,
title : _ _ ( 'Cash on delivery' , 'woocommerce-admin' ) ,
content : _ _ (
'Take payments in cash upon delivery.' ,
'woocommerce-admin'
) ,
before : < CodIcon / > ,
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'
) ,
before : < BacsIcon / > ,
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' ,
2020-03-27 23:24:32 +00:00
}
) ;
2020-03-16 11:09:29 +00:00
return filter ( methods , ( method ) => method . visible ) ;
}