我使用PayPal REST API在我的网上商店应用程序中创建结帐流程。几乎一切都运行良好,但网络体验配置文件。
到目前为止,我尝试检查是否已存在具有特定名称的配置文件(因为Web应用程序已创建它):
function get_pp_profiles($pp_token)
{
$ct = curl_init();
// set URL and other appropriate options
curl_setopt($ct, CURLOPT_URL, PP_PROFILE_ENDPOINT);
curl_setopt($ct, CURLOPT_HEADER, false);
curl_setopt($ct, CURLOPT_RETURNTRANSFER, true);
$curl_http_headers = array('Content-Type: application/json', 'Accept: application/json', 'Authorization: ' . $pp_token->token_type . ' ' . $pp_token->access_token);
curl_setopt($ct, CURLOPT_HTTPHEADER, $curl_http_headers);
if ( $out = curl_exec($ct) )
{
$profile_list = json_decode($out);
curl_close($ct);
return $profile_list;
} else
{
curl_close($ct);
return false;
}
}
然后我得到一个空数组(没有错误)。我在控制台上尝试了这个" plain"卷曲(没有PHP) - 同样的结果。
所以,由于没有个人资料,我应该建立一个像这样的新人:
function set_pp_profile(&$pp_token)
{
$ct = curl_init();
$now = time();
// set URL and other appropriate options
curl_setopt($ct, CURLOPT_URL, PP_PROFILE_ENDPOINT);
curl_setopt($ct, CURLOPT_HEADER, false);
curl_setopt($ct, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ct, CURLOPT_POST, true);
$profile =
array(
"name" => PP_PROFILE_NAME,
"temporary" => true,
"presentation" => array(
"brand_name" => "My brand name",
"logo_image" => "http://sonedomain.com/whatever.png",
"locale_code" => "DE"
),
"input_fields" => array(
"no_shipping" => 1,
"address_override" => 1
),
"flow_config" => array(
"landing_page_type" => "billing",
"user_action" => "commit",
"bank_txn_pending_url" => "http://somedomain.com/some_path/"
)
);
$pdata = json_encode($profile, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$curl_http_headers = array('Content-Type: application/json', 'Accept: application/json', 'Authorization: ' . $pp_token->token_type . ' ' . $pp_token->access_token, 'Content-length: ' . strlen($pdata));
curl_setopt($ct, CURLOPT_HTTPHEADER, $curl_http_headers);
curl_setopt($ct, CURLOPT_POSTFIELDS, $pdata);
if ( $out = curl_exec($ct) )
{
echo $out;
curl_close($ct);
$profile_object = json_decode($out);
return $profile_object;
} else
{
curl_close($ct);
return false;
}
}
但是这将从PayPal返回失败:
{"name":"VALIDATION_ERROR","debug_id":"956cbce081ac2","message":"Invalid request - see details","information_link":"https://developer.paypal.com/webapps/developer/docs/api/","details":[{"field":"name","issue":"A profile with this name already exists"}]}
有人知道那里发生了什么吗?
提前多多感谢!
其他测试运行和信息:
我知道个人资料名称必须是唯一的。 (但我不知道我是否可以使用在删除所有配置文件之前使用的名称。)
所以我测试如下:
调用函数set_pp_profile(),但更改了第14行,如下所示:
"名称" => substr(md5("" .time()。rand()),0,12),
正如预期的那样,结果是一个配置文件对象。
调用函数get_pp_profiles()。该函数返回一个空数组。我用var_dump把它拿出来并得到:
array(0){}
我的结论是问题与唯一的个人资料名称无关。 PayPal开发人员文档称该配置文件将持续3小时或永久,具体取决于"临时" - 参数。但这似乎不是真的。
答案 0 :(得分:2)
已解决:问题是PayPal developer manual。 API调用
GET /v1/payment-experience/web-profiles
将返回仅个人资料,参数“temporary”设置为“false”。但是,如果您创建了临时== true的配置文件,它们也将存在(但隐藏)!这就是为什么你不能在3小时内创建一个具有相同名称的新配置文件。相当差的文档。
答案 1 :(得分:0)
每次都需要使用唯一的体验档案名称。