├── .github
└── ISSUE_TEMPLATE.md
├── LICENSE.txt
├── README.md
├── paypal_pdt.cfm
├── paypal_pdt.cs
├── paypal_pdt.php
├── paypal_pdt.pl
└── paypal_pdt.vb
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### General information
2 |
3 | * Environment:
4 | * `PayPal-Debug-ID` values:
5 | * Language, language version, and OS:
6 |
7 | ### Issue description
8 |
9 |
10 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | PAYPAL, INC.
2 |
3 | SDK LICENSE
4 |
5 | NOTICE TO USER: PayPal, Inc. is providing the Software and Documentation for use under the terms of this Agreement. Any use, reproduction, modification or distribution of the Software or Documentation, or any derivatives or portions hereof, constitutes your acceptance of this Agreement.
6 |
7 | As used in this Agreement, "PayPal" means PayPal, Inc. "Software" means the software code accompanying this agreement. "Documentation" means the documents, specifications and all other items accompanying this Agreement other than the Software.
8 |
9 | 1. LICENSE GRANT Subject to the terms of this Agreement, PayPal hereby grants you a non-exclusive, worldwide, royalty free license to use, reproduce, prepare derivative works from, publicly display, publicly perform, distribute and sublicense the Software for any purpose, provided the copyright notice below appears in a conspicuous location within the source code of the distributed Software and this license is distributed in the supporting documentation of the Software you distribute. Furthermore, you must comply with all third party licenses in order to use the third party software contained in the Software.
10 |
11 | Subject to the terms of this Agreement, PayPal hereby grants you a non-exclusive, worldwide, royalty free license to use, reproduce, publicly display, publicly perform, distribute and sublicense the Documentation for any purpose. You may not modify the Documentation.
12 |
13 | No title to the intellectual property in the Software or Documentation is transferred to you under the terms of this Agreement. You do not acquire any rights to the Software or the Documentation except as expressly set forth in this Agreement.
14 |
15 | If you choose to distribute the Software in a commercial product, you do so with the understanding that you agree to defend, indemnify and hold harmless PayPal and its suppliers against any losses, damages and costs arising from the claims, lawsuits or other legal actions arising out of such distribution. You may distribute the Software in object code form under your own license, provided that your license agreement:
16 |
17 | (a) complies with the terms and conditions of this license agreement;
18 |
19 | (b) effectively disclaims all warranties and conditions, express or implied, on behalf of PayPal;
20 |
21 | (c) effectively excludes all liability for damages on behalf of PayPal;
22 |
23 | (d) states that any provisions that differ from this Agreement are offered by you alone and not PayPal; and
24 |
25 | (e) states that the Software is available from you or PayPal and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
26 |
27 | 2. DISCLAIMER OF WARRANTY
28 | PAYPAL LICENSES THE SOFTWARE AND DOCUMENTATION TO YOU ONLY ON AN "AS IS" BASIS WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. PAYPAL MAKES NO WARRANTY THAT THE SOFTWARE OR DOCUMENTATION WILL BE ERROR-FREE. Each user of the Software or Documentation is solely responsible for determining the appropriateness of using and distributing the Software and Documentation and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs, or equipment, and unavailability or interruption of operations. Use of the Software and Documentation is made with the understanding that PayPal will not provide you with any technical or customer support or maintenance. Some states or jurisdictions do not allow the exclusion of implied warranties or limitations on how long an implied warranty may last, so the above limitations may not apply to you. To the extent permissible, any implied warranties are limited to ninety (90) days.
29 |
30 |
31 | 3. LIMITATION OF LIABILITY
32 | PAYPAL AND ITS SUPPLIERS SHALL NOT BE LIABLE FOR LOSS OR DAMAGE ARISING OUT OF THIS AGREEMENT OR FROM THE USE OF THE SOFTWARE OR DOCUMENTATION. IN NO EVENT WILL PAYPAL OR ITS SUPPLIERS BE LIABLE TO YOU OR ANY THIRD PARTY FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR SPECIAL DAMAGES INCLUDING LOST PROFITS, LOST SAVINGS, COSTS, FEES, OR EXPENSES OF ANY KIND ARISING OUT OF ANY PROVISION OF THIS AGREEMENT OR THE USE OR THE INABILITY TO USE THE SOFTWARE OR DOCUMENTATION, HOWEVER CAUSED AND UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. PAYPAL'S AGGREGATE LIABILITY AND THAT OF ITS SUPPLIERS UNDER OR IN CONNECTION WITH THIS AGREEMENT SHALL BE LIMITED TO THE AMOUNT PAID BY YOU FOR THE SOFTWARE AND DOCUMENTATION.
33 |
34 | 4. TRADEMARK USAGE
35 | PayPal is a trademark PayPal, Inc. in the United States and other countries. Such trademarks may not be used to endorse or promote any product unless expressly permitted under separate agreement with PayPal.
36 |
37 | 5. TERM
38 | Your rights under this Agreement shall terminate if you fail to comply with any of the material terms or conditions of this Agreement and do not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all your rights under this Agreement terminate, you agree to cease use and distribution of the Software and Documentation as soon as reasonably practicable.
39 |
40 | 6. GOVERNING LAW AND JURISDICTION. This Agreement is governed by the statutes and laws of the State of California, without regard to the conflicts of law principles thereof. If any part of this Agreement is found void and unenforceable, it will not affect the validity of the balance of the Agreement, which shall remain valid and enforceable according to its terms. Any dispute arising out of or related to this Agreement shall be brought in the courts of Santa Clara County, California, USA.
41 |
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | PDT Overview :
2 | ------------
3 | * Payment Data Transfer (PDT) is a secure method to retrieve the details about a PayPal transaction so that you can
4 | display them to your customer. It is used in combination with Website Payments Standard, so that after a customer
5 | returns to your website after paying on the PayPal site, they can instantly view a confirmation message with the
6 | details of the transaction.
7 |
8 | PDT How to run?
9 | --------------
10 | * Enable PDT for your PayPal account.
11 | * Log in to your PayPal account.
12 | * Click the Profile subtab.
13 | * Click the My Selling Tools button in the left column.
14 | * Find the Selling online section and click Update in the Website preferences row.
15 | * Under Auto Return for Website Payments, click the On radio button.
16 | * For the Return URL, enter the URL on your site that will receive the transaction ID posted by
17 | PayPal after a customer payment.
18 | * Under Payment Data Transfer, click the On radio button.
19 | * Click Save.
20 | * Find the Selling online section and click Update in the Website preferences row again.
21 | * Scroll down to the Payment Data Transfer section of the page and take note of your PDT identity token.
22 | * Create a button. The PayPal buttons consist of a form which has a number of hidden key/value pairs and a submit button.
23 | You can find info on how to make those in their Website Payments Standard Integration Guide.
24 | * A transactionId will be returned in the returnURL.
25 | * POST request back to PayPal with TransactionId and PDT identity token as specified in scripts above in different language.
26 | * Check the response. The first variable is 'SUCCESS' followed by PDT variables. if it is a failure, the
27 | first variable will be a 'FAIL'.
28 |
29 | PDT Reference :
30 | --------------
31 | * More information on PDT can be found in [the PDT integration guide](https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/).
32 |
--------------------------------------------------------------------------------
/paypal_pdt.cfm:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | Your order has been received.
36 | Details
37 | Name: #firstName# #lastName#
38 | Description: #itemName#
39 | Amount: #mcCurrency# #mcGross#
40 |
41 |
42 |
43 |
44 | ERROR
45 |
46 |
--------------------------------------------------------------------------------
/paypal_pdt.cs:
--------------------------------------------------------------------------------
1 | // ASP .NET C#
2 |
3 | using System;
4 | using System.IO;
5 | using System.Text;
6 | using System.Net;
7 | using System.Web;
8 | using System.Collections.Generic;
9 |
10 | public partial class csPDTSample : System.Web.UI.Page
11 | {
12 | protected void Page_Load(object sender, EventArgs e)
13 | {
14 | // CUSTOMIZE THIS: This is the seller's Payment Data Transfer authorization token.
15 | // Replace this with the PDT token in "Website Payment Preferences" under your account.
16 | string authToken = "Dc7P6f0ZadXW-U1X8oxf8_vUK09EHBMD7_53IiTT-CfTpfzkN0nipFKUPYy";
17 | string txToken = Request.QueryString["tx"];
18 | string query = "cmd=_notify-synch&tx=" + txToken + "&at=" + authToken;
19 |
20 | //Post back to either sandbox or live
21 | string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
22 | string strLive = "https://www.paypal.com/cgi-bin/webscr";
23 | HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
24 |
25 | //Set values for the request back
26 | req.Method = "POST";
27 | req.ContentType = "application/x-www-form-urlencoded";
28 | req.ContentLength = query.Length;
29 |
30 |
31 | //Send the request to PayPal and get the response
32 | StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
33 | streamOut.Write(query);
34 | streamOut.Close();
35 | StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
36 | string strResponse = streamIn.ReadToEnd();
37 | streamIn.Close();
38 |
39 | Dictionary results = new Dictionary();
40 | if(strResponse != "")
41 | {
42 | StringReader reader = new StringReader(strResponse);
43 | string line=reader.ReadLine();
44 |
45 | if(line == "SUCCESS")
46 | {
47 |
48 | while ((line = reader.ReadLine()) != null)
49 | {
50 | results.Add(line.Split('=')[0], line.Split('=')[1]);
51 |
52 | }
53 | Response.Write("Your order has been received.
");
54 | Response.Write("Details
");
55 | Response.Write("Name: " + results["first_name"] + " " + results["last_name"] + "");
56 | Response.Write("Item: " + results["item_name"] + "");
57 | Response.Write("Amount: " + results["payment_gross"] + "");
58 | Response.Write("
");
59 | }
60 | else if(line == "FAIL")
61 | {
62 | // Log for manual investigation
63 | Response.Write("Unable to retrive transaction detail");
64 | }
65 | }
66 | else
67 | {
68 | //unknown error
69 | Response.Write("ERROR");
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/paypal_pdt.php:
--------------------------------------------------------------------------------
1 | Thank you for your purchase!
");
48 |
49 | echo ("Payment Details
\n");
50 | echo ("Name: $firstname $lastname\n");
51 | echo ("Item: $itemname\n");
52 | echo ("Amount: $amount\n");
53 | echo ("");
54 | }
55 | else if (strcmp ($lines[0], "FAIL") == 0) {
56 | // log for manual investigation
57 | }
58 | }
59 |
60 | ?>
61 |
62 |
63 | Your transaction has been completed, and a receipt for your purchase has been emailed to you.
You may log into your account at www.paypal.com to view details of this transaction.
64 |
--------------------------------------------------------------------------------
/paypal_pdt.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl -w
2 |
3 |
4 | # It is highly recommended that you use version 6 upwards of
5 | # the UserAgent module since it provides for tighter server
6 | # certificate validation
7 | ###
8 |
9 | #
10 |
11 | # PayPal PDT (Payment Data Transfer) CGI
12 |
13 | #
14 |
15 | ###
16 |
17 |
18 | use strict;
19 |
20 | use CGI qw(:all unescape);
21 |
22 | use CGI::Carp qw(fatalsToBrowser);
23 |
24 |
25 | # These modules are required to make the secure HTTP request to PayPal.
26 |
27 | use LWP::UserAgent 6;
28 |
29 |
30 |
31 | ###
32 |
33 | # CUSTOMIZE THIS: This is the seller's Payment Data Transfer authorization token.
34 |
35 | # Replace this with the PDT token in "Website Payment Preferences" under your account.
36 |
37 | ###
38 |
39 |
40 | my $auth_token = "VUDGCF2EA5huqlEqbSLPbg0JY3F-Pokyf-99r2sZWPR4x7GkWZEa-zIG49O";
41 |
42 |
43 | sub done_text {
44 |
45 | return (p('Your transaction has been completed, and a receipt for your purchase has been
46 | emailed to you. You may log into your account at www.paypal.com to view details of this transaction.'),
48 | end_html());
49 |
50 | }
51 |
52 |
53 | print header(), start_html("Thank you for your purchase!");
54 |
55 |
56 | # Set up the secure request to the PayPal server to fetch the transaction info
57 |
58 | my $paypal_server = "www.paypal.com";
59 |
60 |
61 | my $transaction = param("tx");
62 |
63 |
64 | if (not $transaction) {
65 |
66 | print (h2("The transaction ID was not found."), done_text());
67 |
68 |
69 | exit();
70 |
71 | }
72 |
73 |
74 | my $paypal_url = "https://$paypal_server/cgi-bin/webscr";
75 |
76 | my $query = join("&", "cmd=_notify-synch", "tx=$transaction", "at=$auth_token");
77 |
78 |
79 |
80 | my $user_agent = new LWP::UserAgent;
81 |
82 | my $request = new HTTP::Request("POST", $paypal_url);
83 |
84 |
85 | $request->content_type("application/x-www-form-urlencoded");
86 | $request->header(Host => $paypal_server);
87 | $request->content($query);
88 |
89 | # Make the request
90 |
91 |
92 | my $result = $user_agent->request($request);
93 |
94 |
95 | if ($result->is_error) {
96 |
97 | print(h1("An error was encountered"), br(), p("An error was encountered contacting the PayPal
98 | server:"),
99 |
100 | $result->error_as_HTML, done_text());
101 |
102 | exit();
103 |
104 | }
105 |
106 |
107 | # Decode the response into individual lines and unescape any HTML escapes
108 |
109 | my @response = split("\n", unescape($result->content));
110 |
111 |
112 | # The status is always the first line of the response.
113 |
114 | my $status = shift @response;
115 |
116 |
117 | if ($status eq "SUCCESS") {
118 |
119 | # success
120 |
121 | my %transaction;
122 |
123 |
124 | foreach my $response_line (@response) {
125 |
126 | my ($key, $value) = split "=", $response_line;
127 |
128 | $transaction{$key} = $value;
129 |
130 | }
131 |
132 | # These are only some of the transaction details available; there are others.
133 |
134 | # You should print all the transaction details appropriate.
135 |
136 | print(h2("Here are the details of your purchase:"),
137 |
138 | ul(li("Customer Name: " . $transaction{'first_name'} . " " . $transaction{'last_name'}),
139 |
140 | li("Item: " . $transaction{'item_name'}),
141 |
142 | li("Amount: " . $transaction{'payment_gross'})));
143 |
144 |
145 | } elsif ($status eq "FAIL") {
146 |
147 | print(h2("Unable to retrieve transaction details."));
148 |
149 | # failure
150 |
151 | } else {
152 |
153 | # unknown error
154 |
155 | print(h2("Error retrieving transaction details."));
156 |
157 | }
158 |
159 |
160 | print done_text();
161 |
--------------------------------------------------------------------------------
/paypal_pdt.vb:
--------------------------------------------------------------------------------
1 | // ASP VB.Net
2 |
3 | Imports System.Collections.Generic
4 | Imports System.Net
5 | Imports System.IO
6 |
7 | Partial Public Class vbPDTSample Inherits System.Web.UI.Page
8 |
9 | Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
10 |
11 | ' CUSTOMIZE THIS: This is the seller's Payment Data Transfer authorization token.
12 | ' Replace this with the PDT token in "Website Payment Preferences" under your account.
13 | Dim authToken As String = "Dc7P6f0ZadXW-U1X8oxf8_vUK09EHBMD7_53IiTT-CfTpfzkN0nipFKUPYy"
14 | Dim txToken As String = Request.QueryString("tx")
15 | Dim strRequest As String = "cmd=_notify-synch&tx=" & txToken & "&at=" & authToken
16 |
17 | 'Post back to either sandbox or live
18 | Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
19 | Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr"
20 | Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest)
21 |
22 | 'Set values for the request back
23 | req.Method = "POST"
24 | req.ContentType = "application/x-www-form-urlencoded"
25 | req.ContentLength = strRequest.Length
26 |
27 | 'for proxy
28 | 'Dim proxy As New WebProxy(New System.Uri("http://url:port#"))
29 | 'req.Proxy = proxy
30 |
31 | 'Send the request to PayPal and get the response
32 | Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
33 | streamOut.Write(strRequest)
34 | streamOut.Close()
35 | Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
36 | Dim strResponse As String = streamIn.ReadToEnd()
37 | streamIn.Close()
38 |
39 | If Not String.IsNullOrEmpty(strResponse) Then
40 | Dim results As New Dictionary(Of String, String)
41 | Dim reader As New StringReader(strResponse)
42 | Dim line As String = reader.ReadLine()
43 | If line = "SUCCESS" Then
44 | While True
45 | Dim aLine As String
46 | aLine = reader.ReadLine
47 | If aLine IsNot Nothing Then
48 | Dim strArr() As String
49 | strArr = aLine.Split("=")
50 | results.Add(strArr(0), strArr(1))
51 | Else
52 | Exit While
53 | End If
54 | End While
55 | Response.Write("Your order has been received.
")
56 | Response.Write("Details
")
57 | Response.Write("Name: " + results("first_name") & " " & results("last_name") & "")
58 | Response.Write("Item: " & results("item_name") & "")
59 | Response.Write("Amount: " & results("payment_gross") & "")
60 | Response.Write("
")
61 | ElseIf line = "FAIL" Then
62 | 'log for manual investigation
63 | Response.Write("Unable to retrive transaction detail")
64 |
65 | End If
66 | Else
67 | Response.Write("Unknown Error")
68 |
69 |
70 | End If
71 |
72 | End Sub
73 | End Class
74 |
--------------------------------------------------------------------------------