Tinypass获取访问详细信息

时间:2013-11-14 19:13:21

标签: php html payment

我正在尝试获取用户对TinyPass资源的访问详细信息。

我刚开始尝试将其集成并使用示例代码。

    $params = array();
    $params["rid"] =  $rid;
    $params["user_ref"] = $username;
    $result = TinyPass::fetchAccessDetails($params, 1, 200);
    echo $result->getTotal();

但是我在上面的行($ result = ...)

上收到了一个Uncaught Exception API错误

有人能帮我一些帮忙吗?

PS:我正在尝试将自定义PHP站点的用户名发送到tinypass,之后想要获取该用户的数据。

这是我的代码

$rid = "PW_74296909";
$store = new TPAccessTokenStore();
$store->loadTokensFromCookie($_COOKIE);
$token = $store->getAccessToken($rid);
if($token->isAccessGranted()) {
    //Access granted! Display requested resource to the user
    echo 'WEELCOOOE';
} else {
    //Access denied! Proceed with the next steps and display a Tinypass button...

    $resource = new TPResource($rid, "Site wide premium content access");

    $po1 = new TPPriceOption(".50", "24 hours");
    $po2 = new TPPriceOption(".99", "1 week");
    $offer = new TPOffer($resource, array($po1, $po2));

    /*$request = new TPPurchaseRequest($offer);
    $buttonHTML = $request->setCallback("myFunction")->generateTag();

    //output button HTML in the place where Tinypass button is supposed to be rendered
    echo $buttonHTML;
    */

    //set user reference (username in this case)
    $username='member';


    $purchaseRequest = new TPPurchaseRequest($offer);
    $purchaseRequest->setUserRef($username);
    $link = $purchaseRequest->generateLink("http://localhost/Tinypass/index.php?action=success", "http://localhost/Tinypass/index.php?action=success");
    $buttonHTML= '<a href="'.$link.'" style="color:white; font-size:20px;">BUY IT</a>';

    //$buttonHTML = $purchaseRequest->setCallback("myFunction")->generateTag();
    echo $buttonHTML;

    $params = array();
    $params["rid"] =  $rid;
    $params["user_ref"] = $username;
    $result = TinyPass::fetchAccessDetails($params, 1, 200);
    echo $result->getTotal();

1 个答案:

答案 0 :(得分:1)

也许你应该只使用单数函数:

$result = Tinypass:fetchaccessDetail(array('rid'=>$rid,'user_ref'=>$userref));
if ($result) {echo "<!-- "; print_r($result); echo " -->";}

如果您使用复数函数,请尝试使用getTotal以外的其他函数:

$results = TinyPass::fetchAccessDetails($params, 1, 200);
if (count($results['data') > 0) {
    foreach ($results['data'] as $record) {
        echo "<!-- "; print_r($record); echo " -->";
    }
}

看起来更像是你需要的单一功能,它给你的信息比复数更多。 http://developer.tinypass.com/main/restapi

如果一切正常,您应该返回一个数组,其中列出的值为数组键。 注意:fetchAccessDetails仍会返回&#39; user_email&#39;不是&#39;电子邮件&#39;正如API页面所示。​​

如果您仍然遇到麻烦(就像我一样),您可以做的另一件事就是编辑文件TinyPassGateway.php,其中包含这些函数以及之前的每个函数:

throw $e;

添加:

return $e->getMessage;

因为您可以通过这种方式获得更直接的调试信息......