Skip to content

Commit d24a4af

Browse files
author
japatel
committed
Final Webhook Management API Changes
- Updated Samples - Additional Functional Tests - Enabled Travis to do functional tests (with allowed failures) on each build
1 parent fb9584b commit d24a4af

21 files changed

+439
-38
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ php:
55
- 5.5
66
- 5.6
77
- hhvm
8+
env:
9+
- REST_MODE=mock
10+
- REST_MODE=sandbox
811
matrix:
912
allow_failures:
1013
- php: hhvm
14+
- env: REST_MODE=sandbox
1115
fast_finish: true
1216
before_script:
1317
- composer self-update

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ PayPal PHP SDK release notes
22
============================
33
v0.16.0
44
----
5+
* Enabled Webhook Management Capabilities
56
* Enabled Caching Abilities for Access Tokens
67

78
v0.15.1

sample/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ The result would be as shown below:
4949

5050
The sample comes pre-configured with a test account but in case you need to try them against your account, you must
5151

52-
* Obtain your client id and client secret from the developer portal
53-
* Update the bootstrap.php file with your new client id and secret.
52+
* Obtain your client id and client secret from the [developer portal](https://developer.paypal.com/webapps/developer/applications/myapps)
53+
* 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.
5454

5555
#### More Help
5656

sample/doc/assets/behavior.js

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
12681268
"title": "Basic Information",
12691269
"slug": "basic-information"
12701270
},
1271-
"depth": 1
1271+
"depth": 1,
1272+
"children": [
1273+
{
1274+
"type": "heading",
1275+
"data": {
1276+
"level": 4,
1277+
"title": "NOTE: Please note that you need an https url for paypal webhooks. You can however override the url with https, and accept",
1278+
"slug": "note-please-note-that-you-need-an-https-url-for-paypal-webhooks-you-can-however-override-the-url-with-https-and-accept"
1279+
},
1280+
"depth": 4
1281+
}
1282+
]
12721283
}, {
12731284
"type": "heading",
12741285
"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
19881999
]
19892000
}
19902001
]
2002+
}, {
2003+
"type": "file",
2004+
"data": {
2005+
"language": {
2006+
"nameMatchers": [{}, ".fbp"],
2007+
"pygmentsLexer": "php",
2008+
"singleLineComment": ["//"],
2009+
"ignorePrefix": "}",
2010+
"foldPrefix": "^",
2011+
"name": "PHP"
2012+
},
2013+
"sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/PayPal-PHP-SDK/sample/payments/AuthorizePaymentUsingPayPal.php",
2014+
"projectPath": "payments/AuthorizePaymentUsingPayPal.php",
2015+
"targetPath": "payments/AuthorizePaymentUsingPayPal",
2016+
"pageTitle": "payments/AuthorizePaymentUsingPayPal",
2017+
"title": "AuthorizePaymentUsingPayPal"
2018+
},
2019+
"depth": 2,
2020+
"outline": [
2021+
{
2022+
"type": "heading",
2023+
"data": {
2024+
"level": 1,
2025+
"title": "Authorize Payment using PayPal as payment method",
2026+
"slug": "authorize-payment-using-paypal-as-payment-method"
2027+
},
2028+
"depth": 1,
2029+
"children": [
2030+
{
2031+
"type": "heading",
2032+
"data": {
2033+
"level": 3,
2034+
"title": "Payer",
2035+
"slug": "payer"
2036+
},
2037+
"depth": 3
2038+
}, {
2039+
"type": "heading",
2040+
"data": {
2041+
"level": 3,
2042+
"title": "Itemized information",
2043+
"slug": "itemized-information"
2044+
},
2045+
"depth": 3
2046+
}, {
2047+
"type": "heading",
2048+
"data": {
2049+
"level": 3,
2050+
"title": "Additional payment details",
2051+
"slug": "additional-payment-details"
2052+
},
2053+
"depth": 3
2054+
}, {
2055+
"type": "heading",
2056+
"data": {
2057+
"level": 3,
2058+
"title": "Amount",
2059+
"slug": "amount"
2060+
},
2061+
"depth": 3
2062+
}, {
2063+
"type": "heading",
2064+
"data": {
2065+
"level": 3,
2066+
"title": "Transaction",
2067+
"slug": "transaction"
2068+
},
2069+
"depth": 3
2070+
}, {
2071+
"type": "heading",
2072+
"data": {
2073+
"level": 3,
2074+
"title": "Redirect urls",
2075+
"slug": "redirect-urls"
2076+
},
2077+
"depth": 3
2078+
}, {
2079+
"type": "heading",
2080+
"data": {
2081+
"level": 3,
2082+
"title": "Payment",
2083+
"slug": "payment"
2084+
},
2085+
"depth": 3
2086+
}, {
2087+
"type": "heading",
2088+
"data": {
2089+
"level": 3,
2090+
"title": "Create Payment",
2091+
"slug": "create-payment"
2092+
},
2093+
"depth": 3
2094+
}, {
2095+
"type": "heading",
2096+
"data": {
2097+
"level": 3,
2098+
"title": "Get redirect url",
2099+
"slug": "get-redirect-url"
2100+
},
2101+
"depth": 3
2102+
}
2103+
]
2104+
}
2105+
]
19912106
}, {
19922107
"type": "file",
19932108
"data": {

sample/doc/notifications/SearchWebhookEvents.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ <h2 id="please-note">PLEASE NOTE:</h2>
66
<p>Creating webhook is sample purposes only. In real scenario, you dont need to create a new webhook everytime you want to search
77
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>
88
<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>;
9+
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;
910

1011
<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;,
1112
&#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 @@ <h2 id="please-note">PLEASE NOTE:</h2>
1718

1819
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>);
1920

21+
2022
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

sample/doc/notifications/createWebhook.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
]
1515
}</code></pre>
1616
<p>Fill up the basic information that is required for the webhook
17-
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>
17+
The URL should be actually accessible over the internet. Having a localhost here would not work.</p>
18+
<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>
19+
<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>
20+
<p>any warnings your browser might show you. Also, please note that this is entirely for demo purposes, and you should not
21+
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>
1822
<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>();
1923
<span class="hljs-variable">$webhookEventTypes</span>[] = <span class="hljs-keyword">new</span> \PayPal\Api\WebhookEventType(
2024
<span class="hljs-string">'{
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<!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>
2+
<p>This sample code demonstrates how you can process a
3+
PayPal Account based Payment.
4+
API used: /v1/payments/payment
5+
As you can see, there is only one difference between creating a payment using PayPal with sale or authorize as intent.
6+
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>;
7+
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
8+
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Details</span>;
9+
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Item</span>;
10+
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ItemList</span>;
11+
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payer</span>;
12+
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;
13+
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">RedirectUrls</span>;
14+
<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>
15+
<p>A resource representing a Payer that funds a payment
16+
For paypal account payments, set payment method
17+
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();
18+
<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>
19+
<p>(Optional) Lets you specify item wise
20+
information</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$item1</span> = <span class="hljs-keyword">new</span> Item();
21+
<span class="hljs-variable">$item1</span>-&gt;setName(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
22+
-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
23+
-&gt;setQuantity(<span class="hljs-number">1</span>)
24+
-&gt;setPrice(<span class="hljs-number">7.5</span>);
25+
<span class="hljs-variable">$item2</span> = <span class="hljs-keyword">new</span> Item();
26+
<span class="hljs-variable">$item2</span>-&gt;setName(<span class="hljs-string">'Granola bars'</span>)
27+
-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
28+
-&gt;setQuantity(<span class="hljs-number">5</span>)
29+
-&gt;setPrice(<span class="hljs-number">2</span>);
30+
31+
<span class="hljs-variable">$itemList</span> = <span class="hljs-keyword">new</span> ItemList();
32+
<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>
33+
<p>Use this optional field to set additional
34+
payment information such as tax, shipping
35+
charges etc.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$details</span> = <span class="hljs-keyword">new</span> Details();
36+
<span class="hljs-variable">$details</span>-&gt;setShipping(<span class="hljs-number">1.2</span>)
37+
-&gt;setTax(<span class="hljs-number">1.3</span>)
38+
-&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>
39+
<p>Lets you specify a payment amount.
40+
You can also specify additional details
41+
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();
42+
<span class="hljs-variable">$amount</span>-&gt;setCurrency(<span class="hljs-string">"USD"</span>)
43+
-&gt;setTotal(<span class="hljs-number">20</span>)
44+
-&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>
45+
<p>A transaction defines the contract of a
46+
payment - what is the payment for and who
47+
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();
48+
<span class="hljs-variable">$transaction</span>-&gt;setAmount(<span class="hljs-variable">$amount</span>)
49+
-&gt;setItemList(<span class="hljs-variable">$itemList</span>)
50+
-&gt;setDescription(<span class="hljs-string">"Payment description"</span>)
51+
-&gt;setInvoiceNumber(uniqid());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="redirect-urls">Redirect urls</h3>
52+
<p>Set the urls that the buyer must be redirected to after
53+
payment approval/ cancellation.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$baseUrl</span> = getBaseUrl();
54+
<span class="hljs-variable">$redirectUrls</span> = <span class="hljs-keyword">new</span> RedirectUrls();
55+
<span class="hljs-variable">$redirectUrls</span>-&gt;setReturnUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=true"</span>)
56+
-&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>
57+
<p>A Payment Resource; create one using
58+
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();
59+
<span class="hljs-variable">$payment</span>-&gt;setIntent(<span class="hljs-string">"authorize"</span>)
60+
-&gt;setPayer(<span class="hljs-variable">$payer</span>)
61+
-&gt;setRedirectUrls(<span class="hljs-variable">$redirectUrls</span>)
62+
-&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>
63+
<p>Create a payment by calling the &#39;create&#39; method
64+
passing it a valid apiContext.
65+
(See bootstrap.php for more on <code>ApiContext</code>)
66+
The return object contains the state and the
67+
url to which the buyer must be redirected to
68+
for payment approval</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
69+
<span class="hljs-variable">$payment</span>-&gt;create(<span class="hljs-variable">$apiContext</span>);
70+
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
71+
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>);
72+
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
73+
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-redirect-url">Get redirect url</h3>
74+
<p>The API response provides the url that you must redirect
75+
the buyer to. Retrieve the url from the $payment-&gt;getLinks()
76+
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>) {
77+
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$link</span>-&gt;getRel() == <span class="hljs-string">'approval_url'</span>) {
78+
<span class="hljs-variable">$approvalUrl</span> = <span class="hljs-variable">$link</span>-&gt;getHref();
79+
<span class="hljs-keyword">break</span>;
80+
}
81+
}
82+
83+
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>);
84+
85+
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>

0 commit comments

Comments
 (0)