From ea0897544c2f6cb9f3f2d00a07e4c9095cf11c7a Mon Sep 17 00:00:00 2001 From: Xiaolei Wheelock Date: Tue, 2 May 2017 14:10:00 -0500 Subject: [PATCH 1/4] 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. * From 1d1f1d46ad02be6596f47ab27f4a7b1e485b883b Mon Sep 17 00:00:00 2001 From: Xiaolei Wheelock Date: Tue, 2 May 2017 15:19:41 -0500 Subject: [PATCH 2/4] Add getToken() function to Payment class by getting the EC token from the Approval URL --- lib/PayPal/Api/Payment.php | 2 +- mskrpqzz.osv.txt | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 mskrpqzz.osv.txt diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php index 0d06b04..4ac9ef4 100644 --- a/lib/PayPal/Api/Payment.php +++ b/lib/PayPal/Api/Payment.php @@ -553,7 +553,7 @@ class Payment extends PayPalResourceModel public function getToken() { $parameter_name = "token"; - parse_str(parse_url($this->getApprovalLink())['query'], $query); + parse_str(parse_url($this->getApprovalLink(), PHP_URL_QUERY), $query); return (!isset($query[$parameter_name]) || is_null($query[$parameter_name])) ? null : $query[$parameter_name]; } diff --git a/mskrpqzz.osv.txt b/mskrpqzz.osv.txt new file mode 100644 index 0000000..d71f6b1 --- /dev/null +++ b/mskrpqzz.osv.txt @@ -0,0 +1,14 @@ +Add getToken() to Payment class to get the EC token from the Approval URL + +# Please enter the commit message for your changes. Lines starting +# with '#' will be ignored, and an empty message aborts the commit. +# +# Date: Tue May 2 14:10:00 2017 -0500 +# +# On branch master +# Your branch is up-to-date with 'origin/master'. +# +# Changes to be committed: +# modified: lib/PayPal/Api/Payment.php +# + From fa2d202970c5620726f5387a26dd878a26ce0d79 Mon Sep 17 00:00:00 2001 From: Xiaolei Wheelock Date: Thu, 4 May 2017 11:03:33 -0500 Subject: [PATCH 3/4] Remove unnecessary check --- lib/PayPal/Api/Payment.php | 2 +- mskrpqzz.osv.txt | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 mskrpqzz.osv.txt diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php index 4ac9ef4..3197485 100644 --- a/lib/PayPal/Api/Payment.php +++ b/lib/PayPal/Api/Payment.php @@ -554,7 +554,7 @@ class Payment extends PayPalResourceModel { $parameter_name = "token"; parse_str(parse_url($this->getApprovalLink(), PHP_URL_QUERY), $query); - return (!isset($query[$parameter_name]) || is_null($query[$parameter_name])) ? null : $query[$parameter_name]; + return !isset($query[$parameter_name]) ? null : $query[$parameter_name]; } /** diff --git a/mskrpqzz.osv.txt b/mskrpqzz.osv.txt deleted file mode 100644 index d71f6b1..0000000 --- a/mskrpqzz.osv.txt +++ /dev/null @@ -1,14 +0,0 @@ -Add getToken() to Payment class to get the EC token from the Approval URL - -# Please enter the commit message for your changes. Lines starting -# with '#' will be ignored, and an empty message aborts the commit. -# -# Date: Tue May 2 14:10:00 2017 -0500 -# -# On branch master -# Your branch is up-to-date with 'origin/master'. -# -# Changes to be committed: -# modified: lib/PayPal/Api/Payment.php -# - From f488f869954fbe047dda62f74d39032510cd60c7 Mon Sep 17 00:00:00 2001 From: Xiaolei Wheelock Date: Thu, 4 May 2017 11:32:30 -0500 Subject: [PATCH 4/4] Add test for Payment.getToken() --- tests/PayPal/Test/Api/PaymentTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/PayPal/Test/Api/PaymentTest.php b/tests/PayPal/Test/Api/PaymentTest.php index e74f093..9f2e67e 100644 --- a/tests/PayPal/Test/Api/PaymentTest.php +++ b/tests/PayPal/Test/Api/PaymentTest.php @@ -29,6 +29,27 @@ class PaymentTest extends \PHPUnit_Framework_TestCase return new Payment(self::getJson()); } + public function testGetToken_returnsNullIfApprovalLinkNull() + { + $payment = new Payment(); + $token = $payment->getToken(); + $this->assertNull($token); + } + + public function testGetToken_returnsNullIfApprovalLinkDoesNotHaveToken() + { + $payment = new Payment('{"links": [ { "href": "https://api.sandbox.paypal.com/v1/payments//cgi-bin/webscr?cmd=_express-checkout", "rel": "approval_url", "method": "REDIRECT" } ]}'); + $token = $payment->getToken(); + $this->assertNull($token); + } + + public function testGetToken_returnsNullIfApprovalLinkHasAToken() + { + $payment = new Payment('{"links": [ { "href": "https://api.sandbox.paypal.com/v1/payments//cgi-bin/webscr?cmd=_express-checkout&token=EC-60385559L1062554J", "rel": "approval_url", "method": "REDIRECT" } ]}'); + $token = $payment->getToken(); + $this->assertNotNull($token); + $this->assertEquals($token, 'EC-60385559L1062554J'); + } /** * Tests for Serialization and Deserialization Issues