【问题标题】:paypal web experience profile list is empty but can't create new profile贝宝网络体验配置文件列表为空,但无法创建新配置文件
【发布时间】: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"}]}

有人知道那里发生了什么吗?

提前非常感谢!

其他测试运行和信息:

我知道个人资料名称必须是唯一的。 (但我不知道是否可以使用在删除所有配置文件之前使用过的名称。)

所以我测试如下:

  1. 调用函数set_pp_profile(),但将第14行修改如下:

    "name" => substr(md5("" .time() .rand()), 0, 12),

正如预期的那样,结果是一个配置文件对象。

  1. 调用函数get_pp_profiles()。该函数返回一个空数组。我用 var_dump 把它放出来,会得到:

    数组(0) { }

我的结论是,问题与唯一的配置文件名称无关。 PayPal 开发人员文档说配置文件将持续 3 小时或永远,具体取决于“临时”参数。但这似乎不是真的。

【问题讨论】:

    标签: paypal paypal-sandbox


    【解决方案1】:

    已解决:问题出在 PayPal developer manual。 API 调用

    GET /v1/payment-experience/web-profiles
    

    将返回 参数“临时”设置为“false”的配置文件。但是,如果您使用临时 == true 创建配置文件,它们也会存在(但隐藏)!这就是为什么您不能在 3 小时内创建具有相同名称的新配置文件的原因。相当糟糕的文档。

    【讨论】:

    • 哈!是的,这真的很愚蠢 - 并且 GET /v1/payment-experience/web-profiles/ 也返回一个 404,对于临时配置文件 - 在 imo 中没有多大意义 ... :-/跨度>
    【解决方案2】:

    您每次都需要使用唯一的体验资料名称。

    【讨论】:

    • 谢谢,但这不是问题。即使我创建了一个具有唯一名称的全新配置文件(请参见下面的新示例),我也会得到一个空的配置文件列表。
    猜你喜欢
    • 2014-01-21
    • 1970-01-01
    • 2014-10-10
    • 2020-07-14
    • 2019-06-22
    • 2018-01-03
    • 1970-01-01
    • 2013-03-05
    • 2013-06-14
    相关资源
    最近更新 更多