【发布时间】:2017-09-01 06:53:48
【问题描述】:
我使用 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;
}
}
然后我得到一个空数组(没有错误)。我也在控制台上用“普通”卷曲(不带 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行修改如下:
"name" => substr(md5("" .time() .rand()), 0, 12),
正如预期的那样,结果是一个配置文件对象。
-
调用函数get_pp_profiles()。该函数返回一个空数组。我用 var_dump 把它放出来,会得到:
数组(0) { }
我的结论是,问题与唯一的配置文件名称无关。 PayPal 开发人员文档说配置文件将持续 3 小时或永远,具体取决于“临时”参数。但这似乎不是真的。
【问题讨论】:
标签: paypal paypal-sandbox