Final Webhook Management API Changes

- Updated Samples
- Additional Functional Tests
- Enabled Travis to do functional tests (with allowed failures) on each build
This commit is contained in:
japatel
2014-12-15 13:52:00 -06:00
parent fb9584ba66
commit d24a4afdb6
21 changed files with 439 additions and 38 deletions

View File

@@ -5,9 +5,13 @@ php:
- 5.5
- 5.6
- hhvm
env:
- REST_MODE=mock
- REST_MODE=sandbox
matrix:
allow_failures:
- php: hhvm
- env: REST_MODE=sandbox
fast_finish: true
before_script:
- composer self-update

View File

@@ -2,6 +2,7 @@ PayPal PHP SDK release notes
============================
v0.16.0
----
* Enabled Webhook Management Capabilities
* Enabled Caching Abilities for Access Tokens
v0.15.1

View File

@@ -49,8 +49,8 @@ The result would be as shown below:
The sample comes pre-configured with a test account but in case you need to try them against your account, you must
* Obtain your client id and client secret from the developer portal
* Update the bootstrap.php file with your new client id and secret.
* Obtain your client id and client secret from the [developer portal](https://developer.paypal.com/webapps/developer/applications/myapps)
* Update the [bootstrap.php](https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/bootstrap.php#L29) file with your new client id and secret.
#### More Help

View File

@@ -1268,7 +1268,18 @@ 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": "Basic Information",
"slug": "basic-information"
},
"depth": 1
"depth": 1,
"children": [
{
"type": "heading",
"data": {
"level": 4,
"title": "NOTE: Please note that you need an https url for paypal webhooks. You can however override the url with https, and accept",
"slug": "note-please-note-that-you-need-an-https-url-for-paypal-webhooks-you-can-however-override-the-url-with-https-and-accept"
},
"depth": 4
}
]
}, {
"type": "heading",
"data": {
@@ -1988,6 +1999,110 @@ 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
]
}
]
}, {
"type": "file",
"data": {
"language": {
"nameMatchers": [{}, ".fbp"],
"pygmentsLexer": "php",
"singleLineComment": ["//"],
"ignorePrefix": "}",
"foldPrefix": "^",
"name": "PHP"
},
"sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/PayPal-PHP-SDK/sample/payments/AuthorizePaymentUsingPayPal.php",
"projectPath": "payments/AuthorizePaymentUsingPayPal.php",
"targetPath": "payments/AuthorizePaymentUsingPayPal",
"pageTitle": "payments/AuthorizePaymentUsingPayPal",
"title": "AuthorizePaymentUsingPayPal"
},
"depth": 2,
"outline": [
{
"type": "heading",
"data": {
"level": 1,
"title": "Authorize Payment using PayPal as payment method",
"slug": "authorize-payment-using-paypal-as-payment-method"
},
"depth": 1,
"children": [
{
"type": "heading",
"data": {
"level": 3,
"title": "Payer",
"slug": "payer"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Itemized information",
"slug": "itemized-information"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Additional payment details",
"slug": "additional-payment-details"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Amount",
"slug": "amount"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Transaction",
"slug": "transaction"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Redirect urls",
"slug": "redirect-urls"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Payment",
"slug": "payment"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Create Payment",
"slug": "create-payment"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Get redirect url",
"slug": "get-redirect-url"
},
"depth": 3
}
]
}
]
}, {
"type": "file",
"data": {

View File

@@ -6,6 +6,7 @@ API used: GET /v1/notifications/webhooks-events</p></div></div></div><div class=
<p>Creating webhook is sample purposes only. In real scenario, you dont need to create a new webhook everytime you want to search
for a webhook events. This is made in a sample just to make sure there is minimum of one webhook to listen to.</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-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;
<span class="hljs-variable">$params</span> = <span class="hljs-keyword">array</span>(</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>&#39;start_time&#39;=&gt;&#39;2014-12-06T11:00:00Z&#39;,
&#39;end_time&#39;=&gt;&#39;2014-12-12T11:00:00Z&#39;</p></div></div><div class="code"><div class="wrapper">);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="search-webhook-events">Search Webhook events</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
@@ -17,4 +18,5 @@ for a webhook events. This is made in a sample just to make sure there is minimu
ResultPrinter::printResult(<span class="hljs-string">"Search Webhook events"</span>, <span class="hljs-string">"WebhookEventList"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$params</span>, <span class="hljs-variable">$output</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

View File

@@ -14,7 +14,11 @@ API used: POST /v1/notifications/webhooks</p></div></div><div class="code"><div
]
}</code></pre>
<p>Fill up the basic information that is required for the webhook
The URL should be actually accessible over the internet. Having a localhost here would not work.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$webhook</span>-&gt;setUrl(<span class="hljs-string">"https://requestb.in/10ujt3c1?uniqid="</span> . uniqid());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="event-types">Event Types</h1>
The URL should be actually accessible over the internet. Having a localhost here would not work.</p>
<h4 id="there-is-an-open-source-tool-http-requestb-in-that-allows-you-to-receive-any-web-requests-to-a-url-given-there-">There is an open source tool <a href="http://requestb.in/">http://requestb.in/</a> that allows you to receive any web requests to a url given there.</h4>
<h4 id="note-please-note-that-you-need-an-https-url-for-paypal-webhooks-you-can-however-override-the-url-with-https-and-accept">NOTE: Please note that you need an https url for paypal webhooks. You can however override the url with https, and accept</h4>
<p>any warnings your browser might show you. Also, please note that this is entirely for demo purposes, and you should not
be using this in production</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$webhook</span>-&gt;setUrl(<span class="hljs-string">"https://requestb.in/10ujt3c1?uniqid="</span> . uniqid());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="event-types">Event Types</h1>
<p>Event types correspond to what kind of notifications you want to receive on the given URL.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$webhookEventTypes</span> = <span class="hljs-keyword">array</span>();
<span class="hljs-variable">$webhookEventTypes</span>[] = <span class="hljs-keyword">new</span> \PayPal\Api\WebhookEventType(
<span class="hljs-string">'{

View File

@@ -0,0 +1,85 @@
<!DOCTYPE html><html lang="en"><head><title>payments/AuthorizePaymentUsingPayPal</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="payments/AuthorizePaymentUsingPayPal"><meta name="groc-project-path" content="payments/AuthorizePaymentUsingPayPal.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">payments/AuthorizePaymentUsingPayPal.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="authorize-payment-using-paypal-as-payment-method">Authorize Payment using PayPal as payment method</h1>
<p>This sample code demonstrates how you can process a
PayPal Account based Payment.
API used: /v1/payments/payment
As you can see, there is only one difference between creating a payment using PayPal with sale or authorize as intent.
You need to set the proper intent in the request, and the remaining data would be the same</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Details</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Item</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ItemList</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payer</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">RedirectUrls</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Transaction</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payer">Payer</h3>
<p>A resource representing a Payer that funds a payment
For paypal account payments, set payment method
to &#39;paypal&#39;.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payer</span> = <span class="hljs-keyword">new</span> Payer();
<span class="hljs-variable">$payer</span>-&gt;setPaymentMethod(<span class="hljs-string">"paypal"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="itemized-information">Itemized information</h3>
<p>(Optional) Lets you specify item wise
information</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$item1</span> = <span class="hljs-keyword">new</span> Item();
<span class="hljs-variable">$item1</span>-&gt;setName(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
-&gt;setQuantity(<span class="hljs-number">1</span>)
-&gt;setPrice(<span class="hljs-number">7.5</span>);
<span class="hljs-variable">$item2</span> = <span class="hljs-keyword">new</span> Item();
<span class="hljs-variable">$item2</span>-&gt;setName(<span class="hljs-string">'Granola bars'</span>)
-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
-&gt;setQuantity(<span class="hljs-number">5</span>)
-&gt;setPrice(<span class="hljs-number">2</span>);
<span class="hljs-variable">$itemList</span> = <span class="hljs-keyword">new</span> ItemList();
<span class="hljs-variable">$itemList</span>-&gt;setItems(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$item1</span>, <span class="hljs-variable">$item2</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="additional-payment-details">Additional payment details</h3>
<p>Use this optional field to set additional
payment information such as tax, shipping
charges etc.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$details</span> = <span class="hljs-keyword">new</span> Details();
<span class="hljs-variable">$details</span>-&gt;setShipping(<span class="hljs-number">1.2</span>)
-&gt;setTax(<span class="hljs-number">1.3</span>)
-&gt;setSubtotal(<span class="hljs-number">17.50</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="amount">Amount</h3>
<p>Lets you specify a payment amount.
You can also specify additional details
such as shipping, tax.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
<span class="hljs-variable">$amount</span>-&gt;setCurrency(<span class="hljs-string">"USD"</span>)
-&gt;setTotal(<span class="hljs-number">20</span>)
-&gt;setDetails(<span class="hljs-variable">$details</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="transaction">Transaction</h3>
<p>A transaction defines the contract of a
payment - what is the payment for and who
is fulfilling it. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$transaction</span> = <span class="hljs-keyword">new</span> Transaction();
<span class="hljs-variable">$transaction</span>-&gt;setAmount(<span class="hljs-variable">$amount</span>)
-&gt;setItemList(<span class="hljs-variable">$itemList</span>)
-&gt;setDescription(<span class="hljs-string">"Payment description"</span>)
-&gt;setInvoiceNumber(uniqid());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="redirect-urls">Redirect urls</h3>
<p>Set the urls that the buyer must be redirected to after
payment approval/ cancellation.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$baseUrl</span> = getBaseUrl();
<span class="hljs-variable">$redirectUrls</span> = <span class="hljs-keyword">new</span> RedirectUrls();
<span class="hljs-variable">$redirectUrls</span>-&gt;setReturnUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=true"</span>)
-&gt;setCancelUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=false"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
<p>A Payment Resource; create one using
the above types and intent set to &#39;sale&#39;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();
<span class="hljs-variable">$payment</span>-&gt;setIntent(<span class="hljs-string">"authorize"</span>)
-&gt;setPayer(<span class="hljs-variable">$payer</span>)
-&gt;setRedirectUrls(<span class="hljs-variable">$redirectUrls</span>)
-&gt;setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
<p>Create a payment by calling the &#39;create&#39; method
passing it a valid apiContext.
(See bootstrap.php for more on <code>ApiContext</code>)
The return object contains the state and the
url to which the buyer must be redirected to
for payment approval</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$payment</span>-&gt;create(<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">"Created Payment Authorization Using PayPal. Please visit the URL to Authorize."</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-redirect-url">Get redirect url</h3>
<p>The API response provides the url that you must redirect
the buyer to. Retrieve the url from the $payment-&gt;getLinks()
method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$payment</span>-&gt;getLinks() <span class="hljs-keyword">as</span> <span class="hljs-variable">$link</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$link</span>-&gt;getRel() == <span class="hljs-string">'approval_url'</span>) {
<span class="hljs-variable">$approvalUrl</span> = <span class="hljs-variable">$link</span>-&gt;getHref();
<span class="hljs-keyword">break</span>;
}
}
ResultPrinter::printResult(<span class="hljs-string">"Created Payment Authorization Using PayPal. Please visit the URL to Authorize."</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-string">"&lt;a href='$approvalUrl' &gt;$approvalUrl&lt;/a&gt;"</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>

View File

@@ -54,7 +54,7 @@ payment approval/ cancellation.</p></div></div><div class="code"><div class="wra
-&gt;setCancelUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=false"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
<p>A Payment Resource; create one using
the above types and intent set to &#39;sale&#39;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();
<span class="hljs-variable">$payment</span>-&gt;setIntent(<span class="hljs-string">"authorize"</span>)
<span class="hljs-variable">$payment</span>-&gt;setIntent(<span class="hljs-string">"sale"</span>)
-&gt;setPayer(<span class="hljs-variable">$payer</span>)
-&gt;setRedirectUrls(<span class="hljs-variable">$redirectUrls</span>)
-&gt;setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>

View File

@@ -3,18 +3,18 @@
of an authorized payment.
API used: /v1/payments/authorization/&lt;$authorizationId&gt;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Authorization $authorization */</span>
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizePayment.php'</span>;
<span class="hljs-variable">$authorizationId</span> = <span class="hljs-string">'4U805254HC285294Y'</span>; <span class="hljs-comment">// $authorization-&gt;getId();</span>
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="getauthorization">GetAuthorization</h3>
<p>You can retrieve info about an Authorization
by invoking the Authorization::get method
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)
The return object contains the authorization state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieve the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$result</span> = Authorization::get(<span class="hljs-variable">$authorization</span>-&gt;getId(), <span class="hljs-variable">$apiContext</span>);
The return object contains the authorization state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieve the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$result</span> = Authorization::get(<span class="hljs-variable">$authorizationId</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">"Get Authorization"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-keyword">null</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">"Get Authorization"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-variable">$authorization</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$result</span>);
ResultPrinter::printResult(<span class="hljs-string">"Get Authorization"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-variable">$authorizationId</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$result</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$authorization</span>;</div></div></div></div></body></html>
<span class="hljs-keyword">return</span> <span class="hljs-variable">$result</span>;</div></div></div></div></body></html>

View File

@@ -2,12 +2,11 @@
<p>This sample code demonstrates how you can
void an authorized payment.
API used: /v1/payments/authorization/&lt;{authorizationid}&gt;/void&quot;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Authorization $authorization */</span>
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizePayment.php'</span>;
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizePayment.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Replace $authorizationid with any static Id you might already have. It will do a void on it</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$authorizationId</span> = <span class="hljs-string">'1BF65516U6866543H'</span>; <span class="hljs-comment">// $authorization-&gt;getId();</span>
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="voidauthorization">VoidAuthorization</h3>
<p>You can void a previously authorized payment
by invoking the $authorization-&gt;void method
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lookup the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authorization</span>-&gt;getId(), <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Void the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$voidedAuth</span> = <span class="hljs-variable">$authorization</span>-&gt;void(<span class="hljs-variable">$apiContext</span>);
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lookup the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authorizationId</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Void the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$voidedAuth</span> = <span class="hljs-variable">$authorization</span>-&gt;void(<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">"Void Authorization"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-keyword">null</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>);

View File

@@ -81,13 +81,14 @@
color: #FFF;
text-decoration: none;
}
/*
.string { color: green; }
.string { color: #428bca; }
.number { color: darkorange; }
.boolean { color: blue; }
.null { color: magenta; }
.key { color: red; }
*/
.key { color: slategray; font-weight: bold; }
.id { color: red; }
</style>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
@@ -103,16 +104,16 @@
$("#accordion .panel-collapse:last").collapse('toggle');
$(document.body).append('<footer class="footer"> <div class="container"> <div class="footer-div"> <ul class="footer-links"> <li> <a href="https://github.com/paypal/PayPal-PHP-SDK" target="_blank"><i class="fa fa-github"></i> Github</a></li><li> <a href="https://developer.paypal.com/webapps/developer/docs/api/" target="_blank"><i class="fa fa-book"></i> REST API Reference</a> </li><li> <a href="https://github.com/paypal/PayPal-PHP-SDK/issues" target="_blank"><i class="fa fa-exclamation-triangle"></i> Report Issues </a> </li></ul> </div></div></footer>');
/*
$(".prettyprint").each(function() {
$(this).html(syntaxHighlight($(this).html()));
});
*/
});
/* http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript
/* http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript */
function syntaxHighlight(json) {
json = json.replace(/&/g, '&').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
@@ -120,6 +121,10 @@
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
if (match == '"id":') {
console.log("Matched ID" + match);
cls = 'key id';
}
} else {
cls = 'string';
}
@@ -131,7 +136,6 @@
return '<span class="' + cls + '">' + match + '</span>';
});
}
*/
</script>
</head>
<body>

View File

@@ -137,7 +137,7 @@ if (PHP_SAPI == 'cli') {
<![endif]-->
</head>
<body data-spy="scroll" data-target="#leftNavigation" data-offset="10" class="scrollspy-example">
<body data-spy="scroll" data-target="#leftNavigation" data-offset="15" class="scrollspy-example">
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container-fluid">
@@ -315,6 +315,18 @@ if (PHP_SAPI == 'cli') {
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Authorize Payment Using PayPal</h5></div>
<div class="col-md-4">
<a href="payments/AuthorizePaymentUsingPayPal.php" class="btn btn-primary pull-left execute"> Try It
<i
class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/AuthorizePaymentUsingPayPal.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>Get details of an authorized payment</h5></div>
@@ -794,7 +806,7 @@ if (PHP_SAPI == 'cli') {
<a href="notifications/GetWebhook.php" class="btn btn-primary pull-left execute"> Try It
<i
class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/GetAuthorization.html" class="btn btn-default pull-right">Source <i
<a href="doc/notifications/GetWebhook.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
@@ -805,7 +817,7 @@ if (PHP_SAPI == 'cli') {
<div class="col-md-4">
<a href="notifications/ListSubscribedWebhookEventTypes.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/GetCapture.html" class="btn btn-default pull-right">Source <i
<a href="doc/notifications/ListSubscribedWebhookEventTypes.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
@@ -817,7 +829,7 @@ if (PHP_SAPI == 'cli') {
<a href="notifications/ListWebhooks.php" class="btn btn-primary pull-left execute">
Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/AuthorizationCapture.html" class="btn btn-default pull-right">Source
<a href="doc/notifications/ListWebhooks.html" class="btn btn-default pull-right">Source
<i
class="fa fa-file-code-o"></i></a>
</div>
@@ -830,7 +842,7 @@ if (PHP_SAPI == 'cli') {
<a href="notifications/UpdateWebhook.php" class="btn btn-primary pull-left execute"> Try It
<i
class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/VoidAuthorization.html" class="btn btn-default pull-right">Source <i
<a href="doc/notifications/UpdateWebhook.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
@@ -841,7 +853,18 @@ if (PHP_SAPI == 'cli') {
<div class="col-md-4">
<a href="notifications/DeleteWebhook.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/Reauthorization.html" class="btn btn-default pull-right">Source <i
<a href="doc/notifications/DeleteWebhook.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>Delete all webhooks</h5></div>
<div class="col-md-4">
<a href="notifications/DeleteAllWebhooks.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/notifications/DeleteAllWebhooks.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
@@ -852,7 +875,7 @@ if (PHP_SAPI == 'cli') {
<div class="col-md-4">
<a href="notifications/SearchWebhookEvents.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/RefundCapture.html" class="btn btn-default pull-right">Source <i
<a href="doc/notifications/SearchWebhookEvents.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>

View File

@@ -12,6 +12,7 @@
// for a webhook events. This is made in a sample just to make sure there is minimum of one webhook to listen to.
/** @var \PayPal\Api\Webhook $webhook */
$webhook = require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Authorization;
$params = array(
// 'start_time'=>'2014-12-06T11:00:00Z',
@@ -28,4 +29,5 @@ try {
ResultPrinter::printResult("Search Webhook events", "WebhookEventList", null, $params, $output);
return $output;

View File

@@ -25,6 +25,10 @@ $webhook = new \PayPal\Api\Webhook();
// }
// Fill up the basic information that is required for the webhook
// The URL should be actually accessible over the internet. Having a localhost here would not work.
// #### There is an open source tool http://requestb.in/ that allows you to receive any web requests to a url given there.
// #### NOTE: Please note that you need an https url for paypal webhooks. You can however override the url with https, and accept
// any warnings your browser might show you. Also, please note that this is entirely for demo purposes, and you should not
// be using this in production
$webhook->setUrl("https://requestb.in/10ujt3c1?uniqid=" . uniqid());
// # Event Types

View File

@@ -0,0 +1,120 @@
<?php
// # Authorize Payment using PayPal as payment method
// This sample code demonstrates how you can process a
// PayPal Account based Payment.
// API used: /v1/payments/payment
// As you can see, there is only one difference between creating a payment using PayPal with sale or authorize as intent.
// You need to set the proper intent in the request, and the remaining data would be the same
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
// ### Payer
// A resource representing a Payer that funds a payment
// For paypal account payments, set payment method
// to 'paypal'.
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// ### Itemized information
// (Optional) Lets you specify item wise
// information
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setPrice(7.5);
$item2 = new Item();
$item2->setName('Granola bars')
->setCurrency('USD')
->setQuantity(5)
->setPrice(2);
$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));
// ### Additional payment details
// Use this optional field to set additional
// payment information such as tax, shipping
// charges etc.
$details = new Details();
$details->setShipping(1.2)
->setTax(1.3)
->setSubtotal(17.50);
// ### Amount
// Lets you specify a payment amount.
// You can also specify additional details
// such as shipping, tax.
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal(20)
->setDetails($details);
// ### Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it.
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
// ### Redirect urls
// Set the urls that the buyer must be redirected to after
// payment approval/ cancellation.
$baseUrl = getBaseUrl();
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");
// ### Payment
// A Payment Resource; create one using
// the above types and intent set to 'sale'
$payment = new Payment();
$payment->setIntent("authorize")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
// For Sample Purposes Only.
$request = clone $payment;
// ### Create Payment
// Create a payment by calling the 'create' method
// passing it a valid apiContext.
// (See bootstrap.php for more on `ApiContext`)
// The return object contains the state and the
// url to which the buyer must be redirected to
// for payment approval
try {
$payment->create($apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Created Payment Authorization Using PayPal. Please visit the URL to Authorize.", "Payment", null, $request, $ex);
exit(1);
}
// ### Get redirect url
// The API response provides the url that you must redirect
// the buyer to. Retrieve the url from the $payment->getLinks()
// method
foreach ($payment->getLinks() as $link) {
if ($link->getRel() == 'approval_url') {
$approvalUrl = $link->getHref();
break;
}
}
ResultPrinter::printResult("Created Payment Authorization Using PayPal. Please visit the URL to Authorize.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);
return $payment;

View File

@@ -79,7 +79,7 @@ $redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
// A Payment Resource; create one using
// the above types and intent set to 'sale'
$payment = new Payment();
$payment->setIntent("authorize")
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));

View File

@@ -6,7 +6,7 @@
/** @var Authorization $authorization */
$authorization = require 'AuthorizePayment.php';
$authorizationId = '4U805254HC285294Y'; // $authorization->getId();
use PayPal\Api\Authorization;
use PayPal\Api\Payment;
@@ -18,12 +18,12 @@ use PayPal\Api\Payment;
try {
// Retrieve the authorization
$result = Authorization::get($authorization->getId(), $apiContext);
$result = Authorization::get($authorizationId, $apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Get Authorization", "Authorization", null, null, $ex);
exit(1);
}
ResultPrinter::printResult("Get Authorization", "Authorization", $authorization->getId(), null, $result);
ResultPrinter::printResult("Get Authorization", "Authorization", $authorizationId, null, $result);
return $authorization;
return $result;

View File

@@ -6,7 +6,8 @@
/** @var Authorization $authorization */
$authorization = require 'AuthorizePayment.php';
// Replace $authorizationid with any static Id you might already have. It will do a void on it
$authorizationId = '1BF65516U6866543H'; // $authorization->getId();
use PayPal\Api\Authorization;
@@ -17,7 +18,7 @@ use PayPal\Api\Authorization;
try {
// Lookup the authorization
$authorization = Authorization::get($authorization->getId(), $apiContext);
$authorization = Authorization::get($authorizationId, $apiContext);
// Void the authorization
$voidedAuth = $authorization->void($apiContext);

View File

@@ -12,7 +12,11 @@ use PayPal\Api\Sale;
use PayPal\Api\Webhook;
use PayPal\Api\WebhookEvent;
use PayPal\Api\WebhookEventList;
use PayPal\Api\WebhookEventType;
use PayPal\Api\WebhookEventTypeList;
use PayPal\Api\WebhookList;
use PayPal\Common\PPModel;
use PayPal\Exception\PPConnectionException;
use PayPal\Rest\ApiContext;
use PayPal\Rest\IResource;
use PayPal\Api\CreateProfileResponse;
@@ -62,11 +66,30 @@ class WebhookFunctionalTest extends \PHPUnit_Framework_TestCase
$obj = new Webhook($request);
// Adding a random url request to make it unique
$obj->setUrl($obj->getUrl() . '?rand=' . uniqid());
$result = $obj->create(null, $this->mockPPRestCall);
$result = null;
try {
$result = $obj->create(null, $this->mockPPRestCall);
} catch (PPConnectionException $ex) {
$data = $ex->getData();
if (strpos($data,'WEBHOOK_NUMBER_LIMIT_EXCEEDED') !== false) {
$this->deleteAll();
$result = $obj->create(null, $this->mockPPRestCall);
} else {
$this->fail($ex->getMessage());
}
}
$this->assertNotNull($result);
return $result;
}
public function deleteAll()
{
$result = Webhook::getAll(null, $this->mockPPRestCall);
foreach ($result->getWebhooks() as $webhookObject) {
$webhookObject->delete(null, $this->mockPPRestCall);
}
}
/**
* @depends testCreate
* @param $webhook Webhook
@@ -84,6 +107,20 @@ class WebhookFunctionalTest extends \PHPUnit_Framework_TestCase
/**
* @depends testGet
* @param $webhook Webhook
* @return WebhookEventTypeList
*/
public function testGetSubscribedEventTypes($webhook)
{
$result = WebhookEventType::subscribedEventTypes($webhook->getId(), null, $this->mockPPRestCall);
$this->assertNotNull($result);
$this->assertEquals(2, sizeof($result->getEventTypes()));
return $result;
}
/**
* @depends testGet
* @param $webhook Webhook
* @return WebhookList
*/
public function testGetAll($webhook)
{
@@ -100,7 +137,7 @@ class WebhookFunctionalTest extends \PHPUnit_Framework_TestCase
}
$this->assertTrue($found, "The Created Web Profile was not found in the get list");
$this->assertEquals($webhook->getId(), $foundObject->getId());
return $result;
}
/**

View File

@@ -33,7 +33,7 @@
"id":"8PT597110X687430LKGECATA",
"create_time":"2013-06-25T21:41:28Z",
"resource_type":"authorization",
"trigger_event":"PAYMENT.AUTHORIZATION.CREATED",
"event_type":"PAYMENT.AUTHORIZATION.CREATED",
"summary":"A payment authorization was created",
"resource":{
"id":"2DC87612EK520411B",