Fixes to Agreement Search Transaction

- Added searchTransactions method to include params
- Updated Tests accordingly.
- Updated Samples accordingly
This commit is contained in:
japatel
2015-01-20 10:46:22 -06:00
parent baf06a66be
commit 4326394447
8 changed files with 147 additions and 238 deletions

View File

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

View File

@@ -0,0 +1,24 @@
<?php
// # 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/<Agreement-Id>/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;

View File

@@ -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
}
]
}, {

View File

@@ -0,0 +1,18 @@
<!DOCTYPE html><html lang="en"><head><title>billing/SearchBillingTransactions</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="billing/SearchBillingTransactions"><meta name="groc-project-path" content="billing/SearchBillingTransactions.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">billing/SearchBillingTransactions.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="search-billing-transactions-sample">Search Billing Transactions Sample</h1>
<p>This sample code demonstrate how you can search all billing transactions, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#search-for-transactions">https://developer.paypal.com/webapps/developer/docs/api/#search-for-transactions</a>
API used: GET /v1/payments/billing-agreements/<Agreement-Id>/transactions? start-date=yyyy-mm-dd&amp;end-date=yyyy-mm-dd</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement From Credit Card Sample</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Agreement $agreement */</span>
<span class="hljs-variable">$agreement</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'GetBillingAgreement.php'</span>;
<span class="hljs-variable">$agreementId</span> = <span class="hljs-variable">$agreement</span>-&gt;getId();
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
<span class="hljs-keyword">try</span> {
<span class="hljs-variable">$result</span> = Agreement::searchTransactions(<span class="hljs-variable">$agreementId</span>,<span class="hljs-keyword">array</span>(<span class="hljs-string">'start_date'</span> =&gt; <span class="hljs-string">'2013-01-01'</span>, <span class="hljs-string">'end_date'</span> =&gt; <span class="hljs-string">'2015-01-20'</span>), <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Search for Transactions"</span>, <span class="hljs-string">"AgreementTransaction"</span>, <span class="hljs-variable">$agreementId</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"Search for Transactions"</span>, <span class="hljs-string">"AgreementTransaction"</span>, <span class="hljs-variable">$agreementId</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$result</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$agreement</span>;</div></div></div></div></body></html>

View File

@@ -4,23 +4,23 @@
API used: PATCH v1/notifications/webhooks/<Webhook-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="get-webhook-id">Get Webhook ID.</h2>
<p>In samples we are using CreateWebhook.php sample to get the created instance of webhook.
However, in real case scenario, we could use just the ID from database or use an already existing webhook.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> \PayPal\Api\Webhook $webhook */</span>
<span class="hljs-variable">$webhook</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateWebhook.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Updating the webhook as per given request
[
{
&quot;op&quot;:&quot;replace&quot;,
&quot;path&quot;:&quot;/url&quot;,
&quot;value&quot;:&quot;<a href="https://requestb.in/10ujt3c1">https://requestb.in/10ujt3c1</a>&quot;
},
{
&quot;op&quot;:&quot;replace&quot;,
&quot;path&quot;:&quot;/event_types&quot;,
&quot;value&quot;:[
{
&quot;name&quot;:&quot;PAYMENT.SALE.REFUNDED&quot;
}
]
}
]</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$patch</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Patch();
<span class="hljs-variable">$webhook</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateWebhook.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Updating the webhook as per given request</p>
<pre><code> [
{
&quot;op&quot;:&quot;replace&quot;,
&quot;path&quot;:&quot;/url&quot;,
&quot;value&quot;:&quot;https://requestb.in/10ujt3c1&quot;
},
{
&quot;op&quot;:&quot;replace&quot;,
&quot;path&quot;:&quot;/event_types&quot;,
&quot;value&quot;:[
{
&quot;name&quot;:&quot;PAYMENT.SALE.REFUNDED&quot;
}
]
}
]</code></pre></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$patch</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Patch();
<span class="hljs-variable">$patch</span>-&gt;setOp(<span class="hljs-string">"replace"</span>)
-&gt;setPath(<span class="hljs-string">"/url"</span>)
-&gt;setValue(<span class="hljs-string">"https://requestb.in/10ujt3c1?uniqid="</span>. uniqid());

View File

@@ -664,6 +664,18 @@ if (PHP_SAPI == 'cli') {
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Search for Transactions</h5></div>
<div class="col-md-4">
<a href="billing/SearchBillingTransactions.php" class="btn btn-primary pull-left execute"> Try It
<i
class="fa fa-play-circle-o"></i></a>
<a href="doc/billing/SearchBillingTransactions.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Update Billing Agreement</h5></div>

View File

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

View File

@@ -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());
}
/**