本文介绍了从贝宝阵列获取状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用paypal-sdk.一切工作正常,但是在用户付款后,他被发送回我的网站,并且贝宝向我发送了很多信息,而贝宝-sdk将其添加到一个数组中.我只需要抓住"paypal" [状态"] =>字符串(8)"VERIFIED"以确保付款已发送/完成,并确保他们使用付款的用户电子邮件.

I am using the paypal-sdk. Everything is working great, but after a user pays, he is sent back to my site and paypal sends a lot of info back to me and the paypal-sdk adds it in an array. I just need to grab the"paypal" ["status"]=> string(8) "VERIFIED"to make sure that the payment has been sent/done and the user's email that they paid with.

我使用 var_dump($ result); 来获得这些结果.

I use var_dump($result); to get these results.

这是完整的数组: https://pastebin.com/aRWcqkXH

我尝试过

json_decode($result,true);

$status = $result->_propMap["payer"]->_propMap["status"];

但两个结果都返回NULL.

but both results return NULL.

推荐答案

如果您使用回答并稍加修改,使其包含搜索键,以产生以下内容:

If you use this answer and modify it slightly to include a searchkey so as to produce this:

public static function displayRecursiveResults($arrayObject,$searchkey) {
    foreach($arrayObject as $key => $data) {
        if(is_array($data)) {
            displayRecursiveResults($data,$searchkey);
        } elseif(is_object($data)) {
            displayRecursiveResults($data,$searchkey);
        } else {
            if ($key === $searchkey)
            echo "$key " . $data."<br />";
        }
    }
}

您将可以像这样使用它:

You will be able to use it like this:


displayRecursiveResults($arr,'status');

通过使用扩展 PayPalModel的 toArray()函数(第278行),该函数将转换_propMap.

Get the $arr value by using any api that extends the PayPalModel's toArray() function (line 278) that will convert _propMap.

例如我的协议Api 检索使用

 $payerinfo = $agreement->getPayer();

我的$ agreement值是在客户批准订阅并重定向到我的网站并运行重定向功能后获得的.

My $agreement value is obtained after the customer has approved the subscription and been redirected to my site and the redirect function run.

try {
                        $agreement = \PayPal\Api\Agreement::get($agreement->getId(), $apiContext);
                    } catch (Exception $ex) {
                        \Yii::$app->response->format = \yii\web\Response::FORMAT_HTML;
                        \Yii::$app->response->data = $ex->getData();
                        exit(1);
                    }

然后我可以使用以下命令将其分配给$ arr:

I can then assign this to $arr by using:

$arr = $payerinfo->toArray();

根据您的数据,您正在使用 Payment api ,它扩展了PayPalResearchModel,而后者又扩展了PayPalModel,因此您可以使用toArray()函数.通过使用子数组Payer来减小Payment数组的大小.

From your data you are using the Payment api which extends the PayPalResearchModel which inturn extends the PayPalModel so you will be able to use the toArray() function. Reduce the Payment array size by using the subarray Payer.

$payer = New Payer;
$my_payer = $payer->getStatus();
$arr = $my_payer->toArray();

然后将其分配给上述功能

And then assign this to the above function

displayRecursiveResults($arr,'status');

,返回的值应为'verified'.

and the value returned should be 'verified'.

这篇关于从贝宝阵列获取状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:24