From 4326394447b946885e654eb46b569cf1bfa2ac63 Mon Sep 17 00:00:00 2001
From: japatel
Date: Tue, 20 Jan 2015 10:46:22 -0600
Subject: [PATCH] Fixes to Agreement Search Transaction
- Added searchTransactions method to include params
- Updated Tests accordingly.
- Updated Samples accordingly
---
lib/PayPal/Api/Agreement.php | 34 +++
sample/billing/SearchBillingTransactions.php | 24 ++
sample/doc/assets/behavior.js | 253 +++---------------
.../billing/SearchBillingTransactions.html | 18 ++
sample/doc/notifications/UpdateWebhook.html | 34 +--
sample/index.php | 12 +
tests/PayPal/Test/Api/AgreementTest.php | 2 +-
.../Api/BillingAgreementsFunctionalTest.php | 8 +-
8 files changed, 147 insertions(+), 238 deletions(-)
create mode 100644 sample/billing/SearchBillingTransactions.php
create mode 100644 sample/doc/billing/SearchBillingTransactions.html
diff --git a/lib/PayPal/Api/Agreement.php b/lib/PayPal/Api/Agreement.php
index 0348de5..12d61c3 100644
--- a/lib/PayPal/Api/Agreement.php
+++ b/lib/PayPal/Api/Agreement.php
@@ -589,6 +589,7 @@ class Agreement extends PayPalResourceModel
/**
* List transactions for a billing agreement by passing the ID of the agreement, as well as the start and end dates of the range of transactions to list, to the request URI.
*
+ * @deprecated Please use searchTransactions Instead
* @param string $agreementId
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
@@ -611,4 +612,37 @@ class Agreement extends PayPalResourceModel
return $ret;
}
+ /**
+ * List transactions for a billing agreement by passing the ID of the agreement, as well as the start and end dates of the range of transactions to list, to the request URI.
+ *
+ * @param string $agreementId
+ * @param array $params Parameters for search string. Options: start_date, and end_date
+ * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
+ * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
+ * @return AgreementTransactions
+ */
+ public static function searchTransactions($agreementId, $params = array(), $apiContext = null, $restCall = null)
+ {
+ ArgumentValidator::validate($agreementId, 'agreementId');
+ ArgumentValidator::validate($params, 'params');
+
+ $allowedParams = array(
+ 'start_date' => 1,
+ 'end_date' => 1,
+ );
+
+ $payLoad = "";
+ $json = self::executeCall(
+ "/v1/payments/billing-agreements/$agreementId/transactions?" . http_build_query(array_intersect_key($params, $allowedParams)),
+ "GET",
+ $payLoad,
+ null,
+ $apiContext,
+ $restCall
+ );
+ $ret = new AgreementTransactions();
+ $ret->fromJson($json);
+ return $ret;
+ }
+
}
diff --git a/sample/billing/SearchBillingTransactions.php b/sample/billing/SearchBillingTransactions.php
new file mode 100644
index 0000000..35fe660
--- /dev/null
+++ b/sample/billing/SearchBillingTransactions.php
@@ -0,0 +1,24 @@
+/transactions? start-date=yyyy-mm-dd&end-date=yyyy-mm-dd
+
+// Retrieving the Agreement object from Create Agreement From Credit Card Sample
+/** @var Agreement $agreement */
+$agreement = require 'GetBillingAgreement.php';
+$agreementId = $agreement->getId();
+use PayPal\Api\Agreement;
+
+try {
+ $result = Agreement::searchTransactions($agreementId,array('start_date' => '2013-01-01', 'end_date' => '2015-01-20'), $apiContext);
+} catch (Exception $ex) {
+ ResultPrinter::printError("Search for Transactions", "AgreementTransaction", $agreementId, null, $ex);
+ exit(1);
+}
+
+ResultPrinter::printResult("Search for Transactions", "AgreementTransaction", $agreementId, null, $result);
+
+return $agreement;
diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js
index 88f5f6f..8f79a71 100644
--- a/sample/doc/assets/behavior.js
+++ b/sample/doc/assets/behavior.js
@@ -175,6 +175,35 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"title": "ReactivateBillingAgreement"
},
"depth": 2
+ }, {
+ "type": "file",
+ "data": {
+ "language": {
+ "nameMatchers": [{}, ".fbp"],
+ "pygmentsLexer": "php",
+ "singleLineComment": ["//"],
+ "ignorePrefix": "}",
+ "foldPrefix": "^",
+ "name": "PHP"
+ },
+ "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/billing/SearchBillingTransactions.php",
+ "projectPath": "billing/SearchBillingTransactions.php",
+ "targetPath": "billing/SearchBillingTransactions",
+ "pageTitle": "billing/SearchBillingTransactions",
+ "title": "SearchBillingTransactions"
+ },
+ "depth": 2,
+ "outline": [
+ {
+ "type": "heading",
+ "data": {
+ "level": 1,
+ "title": "Search Billing Transactions Sample",
+ "slug": "search-billing-transactions-sample"
+ },
+ "depth": 1
+ }
+ ]
}, {
"type": "file",
"data": {
@@ -328,29 +357,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "invoice/GetInvoice",
"title": "GetInvoice"
},
- "depth": 2,
- "outline": [
- {
- "type": "heading",
- "data": {
- "level": 1,
- "title": "Get Invoice Sample",
- "slug": "get-invoice-sample"
- },
- "depth": 1,
- "children": [
- {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Retrieve Invoice",
- "slug": "retrieve-invoice"
- },
- "depth": 3
- }
- ]
- }
- ]
+ "depth": 2
}, {
"type": "file",
"data": {
@@ -386,45 +393,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "invoice/RecordPayment",
"title": "RecordPayment"
},
- "depth": 2,
- "outline": [
- {
- "type": "heading",
- "data": {
- "level": 1,
- "title": "Record Payment Sample",
- "slug": "record-payment-sample"
- },
- "depth": 1,
- "children": [
- {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Record Object",
- "slug": "record-object"
- },
- "depth": 3
- }, {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Record Payment for Invoice",
- "slug": "record-payment-for-invoice"
- },
- "depth": 3
- }, {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Retrieve Invoice",
- "slug": "retrieve-invoice"
- },
- "depth": 3
- }
- ]
- }
- ]
+ "depth": 2
}, {
"type": "file",
"data": {
@@ -442,45 +411,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "invoice/RecordRefund",
"title": "RecordRefund"
},
- "depth": 2,
- "outline": [
- {
- "type": "heading",
- "data": {
- "level": 1,
- "title": "Record Refund Sample",
- "slug": "record-refund-sample"
- },
- "depth": 1,
- "children": [
- {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Record Object",
- "slug": "record-object"
- },
- "depth": 3
- }, {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Record Refund for Invoice",
- "slug": "record-refund-for-invoice"
- },
- "depth": 3
- }, {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Retrieve Invoice",
- "slug": "retrieve-invoice"
- },
- "depth": 3
- }
- ]
- }
- ]
+ "depth": 2
}, {
"type": "file",
"data": {
@@ -498,45 +429,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "invoice/RemindInvoice",
"title": "RemindInvoice"
},
- "depth": 2,
- "outline": [
- {
- "type": "heading",
- "data": {
- "level": 1,
- "title": "Remind Invoice Sample",
- "slug": "remind-invoice-sample"
- },
- "depth": 1,
- "children": [
- {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Notification Object",
- "slug": "notification-object"
- },
- "depth": 3
- }, {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Remind Invoice",
- "slug": "remind-invoice"
- },
- "depth": 3
- }, {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Retrieve Invoice",
- "slug": "retrieve-invoice"
- },
- "depth": 3
- }
- ]
- }
- ]
+ "depth": 2
}, {
"type": "file",
"data": {
@@ -590,37 +483,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "invoice/SendInvoice",
"title": "SendInvoice"
},
- "depth": 2,
- "outline": [
- {
- "type": "heading",
- "data": {
- "level": 1,
- "title": "Create Invoice Sample",
- "slug": "create-invoice-sample"
- },
- "depth": 1,
- "children": [
- {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Send Invoice",
- "slug": "send-invoice"
- },
- "depth": 3
- }, {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Retrieve Invoice",
- "slug": "retrieve-invoice"
- },
- "depth": 3
- }
- ]
- }
- ]
+ "depth": 2
}, {
"type": "file",
"data": {
@@ -638,53 +501,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "invoice/UpdateInvoice",
"title": "UpdateInvoice"
},
- "depth": 2,
- "outline": [
- {
- "type": "heading",
- "data": {
- "level": 1,
- "title": "Update Invoice Sample",
- "slug": "update-invoice-sample"
- },
- "depth": 1,
- "children": [
- {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Update Invoice",
- "slug": "update-invoice"
- },
- "depth": 3
- }, {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "NOTE: These are the work-around added to the",
- "slug": "note-these-are-the-work-around-added-to-the"
- },
- "depth": 3
- }, {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Update Invoice",
- "slug": "update-invoice"
- },
- "depth": 3
- }, {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Retrieve Invoice",
- "slug": "retrieve-invoice"
- },
- "depth": 3
- }
- ]
- }
- ]
+ "depth": 2
}
]
}, {
diff --git a/sample/doc/billing/SearchBillingTransactions.html b/sample/doc/billing/SearchBillingTransactions.html
new file mode 100644
index 0000000..8d362a0
--- /dev/null
+++ b/sample/doc/billing/SearchBillingTransactions.html
@@ -0,0 +1,18 @@
+billing/SearchBillingTransactions
+$agreement = require 'GetBillingAgreement.php' ;
+$agreementId = $agreement ->getId();
+use PayPal \Api \Agreement ;
+
+try {
+ $result = Agreement::searchTransactions($agreementId ,array ('start_date' => '2013-01-01' , 'end_date' => '2015-01-20' ), $apiContext );
+} catch (Exception $ex ) {
+ ResultPrinter::printError("Search for Transactions" , "AgreementTransaction" , $agreementId , null , $ex );
+ exit (1 );
+}
+
+ResultPrinter::printResult("Search for Transactions" , "AgreementTransaction" , $agreementId , null , $result );
+
+return $agreement ;
\ No newline at end of file
diff --git a/sample/doc/notifications/UpdateWebhook.html b/sample/doc/notifications/UpdateWebhook.html
index cd52035..57e1547 100644
--- a/sample/doc/notifications/UpdateWebhook.html
+++ b/sample/doc/notifications/UpdateWebhook.html
@@ -4,23 +4,23 @@
API used: PATCH v1/notifications/webhooks/
-$webhook = require 'CreateWebhook.php' ;
$patch = new \PayPal\Api\Patch();
+$webhook = require 'CreateWebhook.php' ;
$patch = new \PayPal\Api\Patch();
$patch ->setOp("replace" )
->setPath("/url" )
->setValue("https://requestb.in/10ujt3c1?uniqid=" . uniqid());
diff --git a/sample/index.php b/sample/index.php
index f9039bf..54484fd 100644
--- a/sample/index.php
+++ b/sample/index.php
@@ -664,6 +664,18 @@ if (PHP_SAPI == 'cli') {
+
+
+
Search for Transactions
+
+
+
Update Billing Agreement
diff --git a/tests/PayPal/Test/Api/AgreementTest.php b/tests/PayPal/Test/Api/AgreementTest.php
index d0d9b3b..b01ca91 100644
--- a/tests/PayPal/Test/Api/AgreementTest.php
+++ b/tests/PayPal/Test/Api/AgreementTest.php
@@ -274,7 +274,7 @@ class AgreementTest extends \PHPUnit_Framework_TestCase
AgreementTransactionsTest::getJson()
));
- $result = $obj->transactions("agreementId", $mockApiContext, $mockPayPalRestCall);
+ $result = $obj->searchTransactions("agreementId", array(), $mockApiContext, $mockPayPalRestCall);
$this->assertNotNull($result);
}
diff --git a/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php b/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php
index ca41177..0031649 100644
--- a/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php
+++ b/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php
@@ -175,9 +175,13 @@ class BillingAgreementsFunctionalTest extends \PHPUnit_Framework_TestCase
*/
public function testGetTransactions($agreement)
{
- $this->markTestSkipped('Skipped as the fix is on the way.');
- $result = Agreement::transactions($agreement->getId(), null, $this->mockPayPalRestCall);
+ $result = Agreement::searchTransactions($agreement->getId(),array('start_date' => '2013-01-01', 'end_date' => '2015-01-20'), null, $this->mockPayPalRestCall);
$this->assertNotNull($result);
+ $this->assertTrue(is_array($result->getAgreementTransactionList()));
+ $this->assertTrue(sizeof($result->getAgreementTransactionList()) > 0);
+ $list = $result->getAgreementTransactionList();
+ $first = $list[0];
+ $this->assertEquals($first->getTransactionId(), $agreement->getId());
}
/**
Search Billing Transactions Sample
+This sample code demonstrate how you can search all billing transactions, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#search-for-transactions +API used: GET /v1/payments/billing-agreements//transactions? start-date=yyyy-mm-dd&end-date=yyyy-mm-dd