Я не могу использовать это внутри другой функции. Поэтому у меня есть функция user_authnet ($ user), где я передаю массив из моего БД объекта пользователя. Внутри этого объекта я сохранил идентификатор профиля клиента authorize.net. Поэтому я пытаюсь вызвать API Auth.net, чтобы получить способы оплаты и подписки.AuthnetJson Namespace John Conde
Если я включаю
namespace JohnConde\Authnet;
в верхней части моего сценария, то я получаю
function 'user_authnet' not found or invalid function name
как ошибка. Я думаю, потому что это не часть любого из ваших классов.
Если я не ставлю объявление пространства имен, я получаю
Class 'AuthnetApiFactory' not found
даже несмотря на то, autoload.php работает.
Я пытаюсь создать плагин для Wordpress. Вот мой полный код:
namespace JohnConde\Authnet;
include get_template_directory() . '/assets/vendor/authnetjson/config.inc.php';
include get_template_directory() . '/assets/vendor/authnetjson/src/autoload.php';
$request = AuthnetApiFactory::getJsonApiHandler(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetApiFactory::USE_DEVELOPMENT_SERVER);
add_action('show_user_profile', 'user_authnet');
add_action('edit_user_profile', 'user_authnet');
function user_authnet($user)
{
global $request;
?>
<h3>Stored Payment Methods</h3>
<input type="text" name="authnet_customerProfileId" value="<?php echo esc_attr(get_the_author_meta('authnet_customerProfileId', $user->ID)); ?>">
<?php
if(get_the_author_meta('authnet_customerProfileId', $user->ID)) {
$response = $request->getCustomerProfileRequest(array(
"customerProfileId" => get_the_author_meta('authnet_customerProfileId', $user->ID)
));
print_r($response);
}
}
add_action('personal_options_update', 'save_authnet');
add_action('edit_user_profile_update', 'save_authnet');
function save_authnet($user_id)
{
update_user_meta($user_id, 'authnet_customerProfileId', $_POST['authnet_customerProfileId']);
}