Repository navigation
Expand file tree
/
Copy pathDoDirectPaymentReceipt.php
More file actions
151 lines (124 loc) · 4.39 KB
/
Copy pathDoDirectPaymentReceipt.php
File metadata and controls
151 lines (124 loc) · 4.39 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/***********************************************************
DoDirectPaymentReceipt.php
Submits a credit card transaction to PayPal using a
DoDirectPayment request.
The code collects transaction parameters from the form
displayed by DoDirectPayment.php then constructs and sends
the DoDirectPayment request string to the PayPal server.
The paymentType variable becomes the PAYMENTACTION parameter
of the request string.
After the PayPal server returns the response, the code
displays the API request and response in the browser.
If the response from PayPal was a success, it displays the
response parameters. If the response was an error, it
displays the errors.
Called by DoDirectPayment.php.
Calls CallerService.php and APIError.php.
***********************************************************/
require_once 'CallerService.php';
session_start();
/**
* Get required parameters from the web form for the request
*/
$paymentType =urlencode( $_POST['paymentType']);
$firstName =urlencode( $_POST['firstName']);
$lastName =urlencode( $_POST['lastName']);
$creditCardType =urlencode( $_POST['creditCardType']);
$creditCardNumber = urlencode($_POST['creditCardNumber']);
$expDateMonth =urlencode( $_POST['expDateMonth']);
// Month must be padded with leading zero
$padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
$expDateYear =urlencode( $_POST['expDateYear']);
$cvv2Number = urlencode($_POST['cvv2Number']);
$address1 = urlencode($_POST['address1']);
$address2 = urlencode($_POST['address2']);
$city = urlencode($_POST['city']);
$state =urlencode( $_POST['state']);
$zip = urlencode($_POST['zip']);
$amount = urlencode($_POST['payment_amount']);
//$currencyCode=urlencode($_POST['currency']);
$currencyCode="GBP";
$paymentType=urlencode($_POST['paymentType']);
/* Construct the request string that will be sent to PayPal.
The variable $nvpstr contains all the variables and is a
name value pair string with & as a delimiter */
$nvpstr="&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber&EXPDATE=". $padDateMonth.$expDateYear."&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName&STREET=$address1&CITY=$city&STATE=$state".
"&ZIP=$zip&COUNTRYCODE=US&CURRENCYCODE=$currencyCode";
/* Make the API call to PayPal, using API signature.
The API response is stored in an associative array called $resArray */
$resArray=hash_call("doDirectPayment",$nvpstr);
/* Display the API response back to the browser.
If the response from PayPal was a success, display the response parameters'
If the response was an error, display the errors received using APIError.php.
*/
$ack = strtoupper($resArray["ACK"]);
if($ack!="SUCCESS") {
$_SESSION['reshash']=$resArray;
$location = "APIError.php";
header("Location: $location");
}
?>
<html>
<head>
<title>PayPal PHP SDK - DoDirectPayment API</title>
<link href="sdk.css" rel="stylesheet" type="text/css" />
</head>
<body>
<br>
<center>
<font size=2 color=black face=Verdana><b>Do Direct Payment</b></font>
<br><br>
<b>Thank you for your payment!</b><br><br>
<pre>
<?php var_dump($resArray);
/*array(10) {
["TIMESTAMP"]=>
string(20) "2012-01-04T10:48:19Z"
["CORRELATIONID"]=>
string(13) "f08fca1b4ce4a"
["ACK"]=>
string(7) "Success"
["VERSION"]=>
string(4) "59.0"
["BUILD"]=>
string(7) "2278658"
["AMT"]=>
string(5) "90.00"
["CURRENCYCODE"]=>
string(3) "USD"
["AVSCODE"]=>
string(1) "X"
["CVV2MATCH"]=>
string(1) "M"
["TRANSACTIONID"]=>
string(17) "9C767396FE554194E"
}*/
?>
</pre>
<table width = 400>
<tr>
<td>
Transaction ID:</td>
<td><?=$resArray['TRANSACTIONID'] ?></td>
</tr>
<tr>
<td>
Amount:</td>
<td><?=$currencyCode?> <?=$resArray['AMT'] ?></td>
</tr>
<tr>
<td>
AVS:</td>
<td><?=$resArray['AVSCODE'] ?></td>
</tr>
<tr>
<td>
CVV2:</td>
<td><?=$resArray['CVV2MATCH'] ?></td>
</tr>
</table>
<?php echo $ack; ?>
</center>
<a class="home" id="CallsLink" href="index.html">Home</a>
</body>