merchantModel = $merchantDetail;
$this->merchantRepository = $merchantDetailRepository;
$this->settingRepository = $settings;
}
/**
* Bootstrap fields.
*
* @since 2.9.0
*/
public function boot()
{
add_action('give_admin_field_paypal_commerce_account_manger', [$this, 'payPalCommerceAccountManagerField']);
add_action('give_admin_field_paypal_commerce_account_country', [$this, 'accountCountryField']);
add_action('give_admin_field_paypal_commerce_introduction', [$this, 'introductionSection']);
}
/**
* Render account country field.
*
* @since 2.9.0
*/
public function accountCountryField()
{
/* @var Give_HTML_Elements $htmlElements */
$htmlElements = give('html');
$settingHtml = $htmlElements->select(
[
'id' => 'paypal_commerce_account_country',
'options' => give_get_country_list(),
'chosen' => true,
'placeholder' => esc_html__('Choose a country', 'give'),
'show_option_all' => false,
'show_option_none' => false,
'data' => [
'search-type' => 'no_ajax',
],
'selected' => $this->merchantModel->accountCountry ?: $this->settingRepository->getAccountCountry(),
]
);
?>
|
|
%2$s',
$settingHtml,
esc_html__('The country the PayPal account is based from. Make sure to select before connecting.', 'give')
)
?>
|
label = esc_html__('PayPal Connection', 'give');
$paypalLiveSetting->mode = 'live';
$paypalLiveSetting->connectButtonLabel = esc_html__('Connect with PayPal Live', 'give');
$paypalLiveSetting->description = esc_html__('PayPal is currently NOT connected.', 'give');
$paypalLiveSetting->isRecurringAddonActive = $isRecurringAddonActive;
echo $this->getPayPalConnectionSettingView($paypalLiveSetting);
// Show sandbox PayPal connect button.
$paypalSandboxSetting = new \stdClass();
$paypalSandboxSetting->label = esc_html__('PayPal Sandbox Connection', 'give');
$paypalSandboxSetting->mode = 'sandbox';
$paypalSandboxSetting->connectButtonLabel = esc_html__('Connect with PayPal Sandbox', 'give');
$paypalSandboxSetting->description = sprintf(
'%1$s %3$s %4$s',
esc_html__('PayPal sandbox is currently NOT connected.', 'give'),
esc_url('https://docs.givewp.com/paypal-sandbox-setup'),
esc_html__('Set up a separate PayPal Sandbox account for testing.', 'give'),
esc_html__('Live PayPal accounts will not work.', 'give')
);
$paypalSandboxSetting->isRecurringAddonActive = $isRecurringAddonActive;
echo $this->getPayPalConnectionSettingView($paypalSandboxSetting);
echo $this->getBanner();
}
/**
* PayPal Commerce introduction section.
*
* @since 2.9.0
*/
public function introductionSection()
{
?>
settingRepository->getAccountCountry();
return in_array($accountCountry, $northAmericaCountryList, true);
}
/**
* Return admin guidance notice to fix PayPal on boarding error.
*
* @since 3.10.0 Updated phone number for contact
* @since 2.9.6
*
* @param bool $completeMessage
*
* @return string
*/
public function getAdminGuidanceNotice($completeMessage = true)
{
if ($this->isCountryInNorthAmerica()) {
$telephone = sprintf(
'%1$s',
'1-888-350-2387'
);
$message = sprintf(
esc_html__('Please call a PayPal support representative at %1$s', 'give'),
$telephone
);
} else {
$message = esc_html__(
'Please reach out to PayPal support from your PayPal account Resolution Center',
'give'
);
}
$message .= $completeMessage ? esc_html__(' and relay the following message:', 'give') : '.';
return $message;
}
/**
* Print on boarding errors.
*
* @since 2.9.6
*/
private function printErrors(MerchantDetails $merchantDetailsRepository)
{
$accountErrors = $merchantDetailsRepository->getAccountErrors();
if (! empty($accountErrors)) :
?>
getAdminGuidanceNotice()
)
?>
formatErrors($accountErrors); ?>
merchantRepository->accountIsConnected()) :?>
'give_forms',
'page' => 'give-settings',
'tab' => 'gateways',
'section' => 'paypal',
'group' => 'paypal-commerce',
'paypalStatusCheck' => '1',
'mode' => $merchantDetailsRepository->getMode()
],
admin_url('edit.php')
),
'give_paypal_status_refresh'
);
?>
1);
$formattedArray = array_map(
static function ($arr) use ($isSingleError) {
if (is_array($arr)) {
switch ($arr['type']) {
case 'url':
return sprintf(
'<%1$s>%2$s
%3$s%1$s>',
$isSingleError ? 'p' : 'li',
$arr['message'],
urldecode_deep($arr['value'])
);
case 'json':
return sprintf(
'<%1$s>%2$s
%3$s%1$s>',
$isSingleError ? 'p' : 'li',
$arr['message'],
$arr['value']
);
}
}
return sprintf(
'<%1$s>%2$s%1$s>',
$isSingleError ? 'p' : 'li',
$arr
);
},
$errors
);
$output = implode('', $formattedArray);
if (! $isSingleError) {
$output = sprintf(
'',
$output
);
}
return $output;
}
/**
* This function return html for "PayPal Connection" and "PayPal Sandbox Connection".
*
* @param \stdClass $paypalSetting PayPal setting data.
*/
private function getPayPalConnectionSettingView(\stdClass $paypalSetting): string
{
ob_start();
/** @var MerchantDetails $mechantDetailsRepository */
$mechantDetailsRepository = give(MerchantDetails::class);
$mechantDetailsRepository->setMode($paypalSetting->mode);
$merchantDetail = $mechantDetailsRepository->getDetails();
$canShowAccountInformation = $mechantDetailsRepository->accountIsConnected();
?>
|
|
|
accountIsReady
&& give_is_gateway_active(PayPalCommerce::id())
) {
return '';
}
?>
|
|
render(); ?>
|