-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced.php
More file actions
117 lines (97 loc) · 4.24 KB
/
advanced.php
File metadata and controls
117 lines (97 loc) · 4.24 KB
1
2
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
session_start();
global $environment;
$environment = "sandbox";
require_once('PayflowNVPAPI.php');
function getName($n) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $n; $i++) {
$index = rand(0, strlen($characters) - 1);
$randomString .= $characters[$index];
}
return $randomString;
}
////////
////
//// First, handle any return/responses
////
//Check if we just returned inside the iframe. If so, store payflow response and redirect parent window with javascript.
if (isset($_POST['RESULT']) || isset($_GET['RESULT']) ) {
$_SESSION['payflowresponse'] = array_merge($_GET, $_POST);
echo '<script type="text/javascript">window.top.location.href = "' . script_url() . '";</script>';
exit(0);
}
echo "<span style='font-family:sans-serif;font-size:160%;font-weight:bold;'>PayPal Payments Advanced - basic demo</span>
<p style='margin-left:1em;font-family:monospace;'>Hosted checkout page (Layout C) embedded in your site as an iframe</p><hr/>";
//Check whether we stored a server response. If so, print it out.
if(!empty($_SESSION['payflowresponse'])) {
$response= $_SESSION['payflowresponse'];
unset($_SESSION['payflowresponse']);
$success = ($response['RESULT'] == 0);
if($success) echo "<span style='font-family:sans-serif;font-weight:bold;'>Transaction approved! Thank you for your order.</span>";
else echo "<span style='font-family:sans-serif;'>Transaction failed! Please try again with another payment method.</span>";
echo "<pre>(server response follows)\n";
print_r($response);
echo "</pre>";
exit(0);
}
/////////
////
//// Otherwise, begin hosted checkout pages flow
////
//Build the Secure Token request
$request = array(
"PARTNER" => "PayPal",
"VENDOR" => "minjwang",
"USER" => "minjwang",
"PWD" => "abcd1234",
"TRXTYPE" => "S",
"AMT" => "101",
"CURRENCY" => "USD",
"CREATESECURETOKEN" => "Y",
"SECURETOKENID" => getName(10), //Should be unique, never used before
"RETURNURL" => script_url(),
"CANCELURL" => script_url(),
"ERRORURL" => script_url(),
// In practice you'd collect billing and shipping information with your own form,
// then request a secure token and display the payment iframe.
// --> See page 7 of https://cms.paypal.com/cms_content/US/en_US/files/developer/Embedded_Checkout_Design_Guide.pdf
// This example uses hardcoded values for simplicity.
"BILLTOFIRSTNAME" => "John",
"BILLTOLASTNAME" => "Doe",
"BILLTOSTREET" => "123 Main St.",
"BILLTOCITY" => "San Jose",
"BILLTOSTATE" => "CA",
"BILLTOZIP" => "95101",
"BILLTOCOUNTRY" => "US",
"SHIPTOFIRSTNAME" => "Jane",
"SHIPTOLASTNAME" => "Smith",
"SHIPTOSTREET" => "1234 Park Ave",
"SHIPTOCITY" => "San Jose",
"SHIPTOSTATE" => "CA",
"SHIPTOZIP" => "95101",
"SHIPTOCOUNTRY" => "US",
);
//Run request and get the secure token response
$response = run_payflow_call($request);
if ($response['RESULT'] != 0) {
pre($response, "Payflow call failed");
exit(0);
} else {
$securetoken = $response['SECURETOKEN'];
$securetokenid = $response['SECURETOKENID'];
}
if($environment == "sandbox" || $environment == "pilot") $mode='TEST'; else $mode='LIVE';
echo '<div style="border: 1px dashed; margin-left:40px; width:492px; height:567px;">'; // wrap iframe in a dashed wireframe for demo purposes
echo " <iframe src='https://payflowlink.paypal.com?SECURETOKEN=$securetoken&SECURETOKENID=$securetokenid&MODE=$mode' width='1490' height='1565' border='0' frameborder='0' scrolling='no' allowtransparency='true'>\n</iframe>";
echo "</div><p style='margin-left:40px;font-family:monospace;'>(end of hosted iframe, marked with dashed line)</p>";
?>
<div style="font-family:sans-serif;font-weight:normal;">
<p><big><strong>References</strong></big></p>
<ol>
<li><a href="https://cms.paypal.com/cms_content/US/en_US/files/developer/PayflowGateway_Guide.pdf">Payflow Gateway Developer Guide</a> (.pdf)</li>
<li><a href="https://cms.paypal.com/cms_content/US/en_US/files/developer/Embedded_Checkout_Design_Guide.pdf">Embedded Checkout Design Guide</a> (for Layout C)</li>
<li><a href="https://www.x.com/developers/community/blogs/pp_integrations_preston/testing-paypal-payflow-gateway">Testing with the PayPal Payflow Gateway</a></li>
</ol>
</div>