-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPayPalPayment.php
100 lines (83 loc) · 3.36 KB
/
PayPalPayment.php
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
<?php
if (session_id() == "") session_start();
/*
* This is called on return from PayPal when the user has completed the process
*/
require_once("common.php");
require_once ("paypalfunctions.php");
if (!IsSet($_SESSION['RegData']))
{
TraceMsg("PayPalPayment.php: Can't find the information in the session");
echo "Can't find the information in the session";
exit;
}
if (!isset($_REQUEST['token']))
{
TraceMsg("PayPalPayment.php: Can't find the PayPal Token in the request");
echo "Can't find the PayPal Token in the request";
exit;
}
$data = $_SESSION['RegData'];
$_SESSION['token'] = $_REQUEST['token'];
$_SESSION['payer_id'] = $_REQUEST['PayerID'];
$_SESSION['paymentType'] = 'Sale';
$token = $_SESSION['token'];
if (!array_key_exists('amountDue',$data))
{
TraceMsg("PayPalPayment: Error: Could not find amount due in the data block");
echo "Could not find amount due in the data block";
exit;
}
$finalPaymentAmount = $data['amountDue'];
/*
'------------------------------------
' Calls the DoExpressCheckoutPayment API call
'
' The ConfirmPayment function is defined in the file PayPalFunctions.jsp,
' that is included at the top of this file.
'-------------------------------------------------
*/
$resArray = ConfirmPayment ( $finalPaymentAmount );
$ack = strtoupper($resArray["ACK"]);
TraceMsg("PayPalPayment.php: ConfirmPayment returned $ack");
if( $ack == "SUCCESS" )
{
$transactionId = $resArray["TRANSACTIONID"];
/*
$transactionType = $resArray["TRANSACTIONTYPE"];
$paymentType = $resArray["PAYMENTTYPE"];
$orderTime = $resArray["ORDERTIME"];
$paypalAmount = $resArray["AMT"];
$currencyCode = $resArray["CURRENCYCODE"];
$feeAmt = IsSet($resArray["FEEAMT"]) ? $resArray["FEEAMT"] : 0;
$settleAmt = IsSet($resArray["SETTLEAMT"]) ? $resArray["SETTLEAMT"] : null;
$taxAmt = IsSet($resArray["TAXAMT"]) ? $resArray["TAXAMT"] : null;
$exchangeRate = IsSet($resArray["EXCHANGERATE"]) ? $resArray["EXCHANGERATE"] : null;
$paymentStatus = IsSet($resArray["PAYMENTSTATUS"]) ? $resArray["PAYMENTSTATUS"] : null;
$pendingReason = IsSet($resArray["PENDINGREASON"]) ? $resArray["PENDINGREASON"] : null;
$reasonCode = IsSet($resArray["REASONCODE"]) ? $resArray["REASONCODE"] : null;
*/
TraceMsg("PayPalPayment: " . json_encode($resArray));
include_once "OpenDb.php";
$db = OpenPDO();
$stmt = $db->prepare("UPDATE edc_event SET transactionId=:transactionID WHERE edc_event_id=:regNbr");
$stmt->bindValue(':transactionID', $transactionId);
$stmt->bindValue(':regNbr', $data['regNbr']);
ExecutePDO($stmt);
include_once "Finalize.php";
}
else
{
TraceMsg("PayPalPayment(ERROR): " . json_encode($resArray));
//Display a user friendly Error on the page using any of the following error information returned by PayPal
$ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
$ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
echo "GetExpressCheckoutDetails API call failed. ";
echo "Detailed Error Message: " . $ErrorLongMsg;
echo "Short Error Message: " . $ErrorShortMsg;
echo "Error Code: " . $ErrorCode;
echo "Error Severity Code: " . $ErrorSeverityCode;
}
?>