From ea0897544c2f6cb9f3f2d00a07e4c9095cf11c7a Mon Sep 17 00:00:00 2001 From: Xiaolei Wheelock Date: Tue, 2 May 2017 14:10:00 -0500 Subject: [PATCH] Add getToken() to Payment class to get the EC token from the Approval URL --- lib/PayPal/Api/Payment.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php index c0747ae..0d06b04 100644 --- a/lib/PayPal/Api/Payment.php +++ b/lib/PayPal/Api/Payment.php @@ -544,7 +544,19 @@ class Payment extends PayPalResourceModel { return $this->getLink(PayPalConstants::APPROVAL_URL); } - + + /** + * Get token from Approval Link + * + * @return null|string + */ + public function getToken() + { + $parameter_name = "token"; + parse_str(parse_url($this->getApprovalLink())['query'], $query); + return (!isset($query[$parameter_name]) || is_null($query[$parameter_name])) ? null : $query[$parameter_name]; + } + /** * Creates and processes a payment. In the JSON request body, include a `payment` object with the intent, payer, and transactions. For PayPal payments, include redirect URLs in the `payment` object. *