如何从PayPal SDK访问交易数据? [英] How to access transaction data from the PayPal SDK?

查看:69
本文介绍了如何从PayPal SDK访问交易数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PayPal SDK,当我完成交易时,它将返回以下内容:

I am working with the PayPal SDK, and when I finish a transaction it returns this:

object(PayPal\Api\Payment)#8 (1) {
  ["_propMap":"PayPal\Common\PPModel":private]=>
  array(8) {
    ["id"]=>
    string(28) "PAY-66N6061121216644JKKS6LVQ"
    ["create_time"]=>
    string(20) "2013-12-09T15:46:30Z"
    ["update_time"]=>
    string(20) "2013-12-09T15:53:32Z"
    ["state"]=>
    string(8) "approved"
    ["intent"]=>
    string(4) "sale"
    ["payer"]=>
    object(PayPal\Api\Payer)#33 (1) {
      ["_propMap":"PayPal\Common\PPModel":private]=>
      array(2) {
        ["payment_method"]=>
        string(6) "paypal"
        ["payer_info"]=>
        object(PayPal\Api\PayerInfo)#30 (1) {
          ["_propMap":"PayPal\Common\PPModel":private]=>
          array(5) {
            ["email"]=>
            string(19) "indi3.rok@gmail.com"
            ["first_name"]=>
            string(7) "Cliente"
            ["last_name"]=>
            string(6) "Orozco"
            ["payer_id"]=>
            string(13) "U8C2RMNA4SP9E"
            ["shipping_address"]=>
            object(PayPal\Api\Address)#31 (1) {
              ["_propMap":"PayPal\Common\PPModel":private]=>
              array(5) {
                ["line1"]=>
                string(9) "1 Main St"
                ["city"]=>
                string(8) "San Jose"
                ["state"]=>
                string(2) "CA"
                ["postal_code"]=>
                string(5) "95131"
                ["country_code"]=>
                string(2) "US"
              }
            }
          }
        }
      }
    }
    ["transactions"]=>
    array(1) {
      [0]=>
      object(PayPal\Api\Transaction)#34 (1) {
        ["_propMap":"PayPal\Common\PPModel":private]=>
        array(4) {
          ["amount"]=>
          object(PayPal\Api\Amount)#35 (1) {
            ["_propMap":"PayPal\Common\PPModel":private]=>
            array(3) {
              ["total"]=>
              string(6) "100.00"
              ["currency"]=>
              string(3) "USD"
              ["details"]=>
              object(PayPal\Api\Details)#36 (1) {
                ["_propMap":"PayPal\Common\PPModel":private]=>
                array(1) {
                  ["subtotal"]=>
                  string(6) "100.00"
                }
              }
            }
          }
          ["description"]=>
          string(14) "Lo que pagaras"
          ["item_list"]=>
          object(PayPal\Api\ItemList)#37 (1) {
            ["_propMap":"PayPal\Common\PPModel":private]=>
            array(1) {
              ["items"]=>
              array(1) {
                [0]=>
                object(PayPal\Api\Item)#38 (1) {
                  ["_propMap":"PayPal\Common\PPModel":private]=>
                  array(4) {
                    ["name"]=>
                    string(23) "video: federer en paris"
                    ["price"]=>
                    string(6) "100.00"
                    ["currency"]=>
                    string(3) "USD"
                    ["quantity"]=>
                    string(1) "1"
                  }
                }
              }
            }
          }
          ["related_resources"]=>
          array(1) {
            [0]=>
            object(PayPal\Api\RelatedResources)#40 (1) {
              ["_propMap":"PayPal\Common\PPModel":private]=>
              array(1) {
                ["sale"]=>
                object(PayPal\Api\Sale)#42 (1) {
                  ["_propMap":"PayPal\Common\PPModel":private]=>
                  array(7) {
                    ["id"]=>
                    string(17) "2ES44750XJ1684301"
                    ["create_time"]=>
                    string(20) "2013-12-09T15:46:30Z"
                    ["update_time"]=>
                    string(20) "2013-12-09T15:53:32Z"
                    ["state"]=>
                    string(9) "completed"
                    ["amount"]=>
                    object(PayPal\Api\Amount)#44 (1) {
                      ["_propMap":"PayPal\Common\PPModel":private]=>
                      array(2) {
                        ["total"]=>
                        string(6) "100.00"
                        ["currency"]=>
                        string(3) "USD"
                      }
                    }
                    ["parent_payment"]=>
                    string(28) "PAY-66N6061121216644JKKS6LVQ"
                    ["links"]=>
                    array(3) {
                      [0]=>
                      object(PayPal\Api\Links)#46 (1) {
                        ["_propMap":"PayPal\Common\PPModel":private]=>
                        array(3) {
                          ["href"]=>
                          string(65) "https://api.sandbox.paypal.com/v1/payments/sale/2ES44750XJ1684301"
                          ["rel"]=>
                          string(4) "self"
                          ["method"]=>
                          string(3) "GET"
                        }
                      }
                      [1]=>
                      object(PayPal\Api\Links)#47 (1) {
                        ["_propMap":"PayPal\Common\PPModel":private]=>
                        array(3) {
                          ["href"]=>
                          string(72) "https://api.sandbox.paypal.com/v1/payments/sale/2ES44750XJ1684301/refund"
                          ["rel"]=>
                          string(6) "refund"
                          ["method"]=>
                          string(4) "POST"
                        }
                      }
                      [2]=>
                      object(PayPal\Api\Links)#48 (1) {
                        ["_propMap":"PayPal\Common\PPModel":private]=>
                        array(3) {
                          ["href"]=>
                          string(79) "https://api.sandbox.paypal.com/v1/payments/payment/PAY-66N6061121216644JKKS6LVQ"
                          ["rel"]=>
                          string(14) "parent_payment"
                          ["method"]=>
                          string(3) "GET"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    ["links"]=>
    array(1) {
      [0]=>
      object(PayPal\Api\Links)#49 (1) {
        ["_propMap":"PayPal\Common\PPModel":private]=>
        array(3) {
          ["href"]=>
          string(79) "https://api.sandbox.paypal.com/v1/payments/payment/PAY-66N6061121216644JKKS6LVQ"
          ["rel"]=>
          string(4) "self"
          ["method"]=>
          string(3) "GET"
        }
      }
    }
  }
}

我不确定这是什么. (我认为这是JSON,但我不确定.)

I am not sure what it is. (I think it is JSON but I am not sure.)

我想做的就是通过这种数组访问该信息:

What I want to do is get access to that info in this kind of array:

$transaction["payment"]

我该怎么办?

推荐答案

PayPal返回一个使用其自身内部fromJSON()函数格式化的对象-在OP的情况下,它是从Payment类调用的:

PayPal returns an object that is formatted using its own internal fromJSON() function - in the OP's case it was called from the Payment class:

$json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment/{$this->getId()}/execute", "POST", $payLoad);
$ret = new Payment();
$ret->fromJson($json);
return $ret;

要将其用作JSON对象,您需要使用toJSON()函数:

To use this as a JSON object, you need to use the toJSON() function:

$execution = new PaymentExecution();
$execution->setPayerId($_GET['PayerID']);
//Execute the payment
// (See bootstrap.php for more on `ApiContext`)
$result = $payment->execute($execution, $apiContext);
// use the result 
$jsonResult = $result->toJSON();

我希望这会有所帮助.

I hope this helps.

这篇关于如何从PayPal SDK访问交易数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆