【发布时间】:2016-11-28 00:40:18
【问题描述】:
我似乎无法在另一个函数中使用它。所以我有一个名为 user_authnet($user) 的函数,我从我的数据库中传递一个数组作为用户对象。在该对象中,我存储了 authorize.net 客户资料 ID。所以我尝试调用 Auth.net API 来获取付款方式和订阅。
如果我包含
namespace JohnConde\Authnet;
在我的脚本顶部,然后我得到 p>
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']);
}
【问题讨论】:
标签: php authorize.net