2

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.

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

That is the full array: https://pastebin.com/aRWcqkXH

I've tried

json_decode($result,true); 

and

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

but both results return NULL.

Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57
Shadow1300
  • 21
  • 2

2 Answers2

0

@see paypal php sdk http://paypal.github.io/PayPal-PHP-SDK/docs/source-class-PayPal.Api.Payer.html#60-68

maybe you can get by $result->getStatus()

0

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');

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

eg. my Agreement Api retrieves the payer info including the status field by using

 $payerinfo = $agreement->getPayer(); 

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);
                    }

I can then assign this to $arr by using:

$arr = $payerinfo->toArray();

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');

and the value returned should be 'verified'.

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Addi
  • 199
  • 14