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
|
<?php session_start(); include("../schnitte/login.php"); include("../schnitte/connect.php"); include_once("config.php"); include_once("paypal.class.php"); /*include("../schnitte/login.php"); include("../schnitte/connect.php");*/ $GLOBALS['buyitem'] = $_POST['selitem']; $_SESSION['xxx'] = $_POST['selitem']; /////eingefügt /*$ppresult = MYSQL_QUERY( "SELECT bezeichnung, description, id, preis FROM $tabelle WHERE (id = $buyitem) ") OR die("Keine Einträge vorhanden! So a Scheiss!"); $payitem = mysql_fetch_array($ppresult);*/ $paypalmode = ($PayPalMode=='sandbox') ? '.sandbox' : '';
if($_POST) //Post Data received from product list page. { $ppresult = MYSQL_QUERY( "SELECT bezeichnung, description, id, preis FROM $tabelle WHERE (id = $buyitem) ") OR die("Keine Einträge vorhanden!"); $payitem = mysql_fetch_array($ppresult); //Mainly we need 4 variables from product page Item Name, Item Price, Item Number and Item Quantity. //Please Note : People can manipulate hidden field amounts in form, //In practical world you must fetch actual price from database using item id. Eg: //$ItemPrice = $mysqli->query("SELECT item_price FROM products WHERE id = Product_Number");
/*$ItemName = $_POST["itemname"]; //Item Name*/ $ItemName = $payitem["bezeichnung"]; //Item Name /*$ItemPrice = $_POST["itemprice"]; //Item Price*/ $ItemPrice = $payitem["preis"]; //Item Price /*$ItemNumber = $_POST["itemnumber"]; //Item Number*/ $ItemNumber = $payitem["id"]; //Item Number /*$ItemDesc = $_POST["itemdesc"]; //Item Description*/ $ItemDesc = $payitem["desription"]; //Item Description /*$ItemQty = $_POST["itemQty"]; // Item Quantity*/ $ItemQty = 1; // Item Quantity $ItemTotalPrice = ($ItemPrice*$ItemQty); //(Item Price x Quantity = Total) Get total amount of product; mysql_data_seek($ppresult, 0); /*include("../schnitte/close.php");*/ //Other important variables like tax, shipping cost /* $TotalTaxAmount = 2.58; //Sum of tax for all items in this order. $HandalingCost = 2.00; //Handling cost for this order. $InsuranceCost = 1.00; //shipping insurance cost for this order. $ShippinDiscount = -3.00; //Shipping discount for this order. Specify this as negative number. $ShippinCost = 3.00; //Although you may change the value later, try to pass in a shipping amount that is reasonably accurate. */
$TotalTaxAmount = 0; //Sum of tax for all items in this order. $HandalingCost = 0; //Handling cost for this order. $InsuranceCost = 0; //shipping insurance cost for this order. $ShippinDiscount = 0; //Shipping discount for this order. Specify this as negative number. $ShippinCost = 0; //Although you may change the value later, try to pass in a shipping amount that is reasonably accurate.
//Grand total including all tax, insurance, shipping cost and discount $GrandTotal = ($ItemTotalPrice + $TotalTaxAmount + $HandalingCost + $InsuranceCost + $ShippinCost + $ShippinDiscount); //Parameters for SetExpressCheckout, which will be sent to PayPal $padata = '&METHOD=SetExpressCheckout'. '&RETURNURL='.urlencode($PayPalReturnURL ). '&CANCELURL='.urlencode($PayPalCancelURL). '&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode("SALE"). '&L_PAYMENTREQUEST_0_NAME0='.urlencode($ItemName). '&L_PAYMENTREQUEST_0_NUMBER0='.urlencode($ItemNumber). '&L_PAYMENTREQUEST_0_DESC0='.urlencode($ItemDesc). '&L_PAYMENTREQUEST_0_AMT0='.urlencode($ItemPrice). '&L_PAYMENTREQUEST_0_QTY0='. urlencode($ItemQty). /* //Additional products (L_PAYMENTREQUEST_0_NAME0 becomes L_PAYMENTREQUEST_0_NAME1 and so on) '&L_PAYMENTREQUEST_0_NAME1='.urlencode($ItemName2). '&L_PAYMENTREQUEST_0_NUMBER1='.urlencode($ItemNumber2). '&L_PAYMENTREQUEST_0_DESC1='.urlencode($ItemDesc2). '&L_PAYMENTREQUEST_0_AMT1='.urlencode($ItemPrice2). '&L_PAYMENTREQUEST_0_QTY1='. urlencode($ItemQty2). */ /* //Override the buyer's shipping address stored on PayPal, The buyer cannot edit the overridden address. '&ADDROVERRIDE=1'. '&PAYMENTREQUEST_0_SHIPTONAME=J Smith'. '&PAYMENTREQUEST_0_SHIPTOSTREET=1 Main St'. '&PAYMENTREQUEST_0_SHIPTOCITY=San Jose'. '&PAYMENTREQUEST_0_SHIPTOSTATE=CA'. '&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=US'. '&PAYMENTREQUEST_0_SHIPTOZIP=95131'. '&PAYMENTREQUEST_0_SHIPTOPHONENUM=408-967-4444'. */ '&NOSHIPPING=1'. //set 1 to hide buyer's shipping address, in-case products that does not require shipping '&PAYMENTREQUEST_0_ITEMAMT='.urlencode($ItemTotalPrice). '&PAYMENTREQUEST_0_TAXAMT='.urlencode($TotalTaxAmount). '&PAYMENTREQUEST_0_SHIPPINGAMT='.urlencode($ShippinCost). '&PAYMENTREQUEST_0_HANDLINGAMT='.urlencode($HandalingCost). '&PAYMENTREQUEST_0_SHIPDISCAMT='.urlencode($ShippinDiscount). '&PAYMENTREQUEST_0_INSURANCEAMT='.urlencode($InsuranceCost). '&PAYMENTREQUEST_0_AMT='.urlencode($GrandTotal). '&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode($PayPalCurrencyCode). // '&LOCALECODE=AT'. //PayPal pages to match the language on your website. '&LOGOIMG=http://patterns.bplaced.net/img/pp_header.png'. //site logo '&CARTBORDERCOLOR=FFFFFF'. //border color of cart '&ALLOWNOTE=1'; ############# set session variable we need later for "DoExpressCheckoutPayment" ####### $_SESSION['ItemName'] = $ItemName; //Item Name $_SESSION['ItemPrice'] = $ItemPrice; //Item Price $_SESSION['ItemNumber'] = $ItemNumber; //Item Number $_SESSION['ItemDesc'] = $ItemDesc; //Item Number $_SESSION['ItemQty'] = $ItemQty; // Item Quantity $_SESSION['ItemTotalPrice'] = $ItemTotalPrice; //(Item Price x Quantity = Total) Get total amount of product; $_SESSION['TotalTaxAmount'] = $TotalTaxAmount; //Sum of tax for all items in this order. $_SESSION['HandalingCost'] = $HandalingCost; //Handling cost for this order. $_SESSION['InsuranceCost'] = $InsuranceCost; //shipping insurance cost for this order. $_SESSION['ShippinDiscount'] = $ShippinDiscount; //Shipping discount for this order. Specify this as negative number. $_SESSION['ShippinCost'] = $ShippinCost; //Although you may change the value later, try to pass in a shipping amount that is reasonably accurate. $_SESSION['GrandTotal'] = $GrandTotal;
//We need to execute the "SetExpressCheckOut" method to obtain paypal token $paypal= new MyPayPal(); $httpParsedResponseAr = $paypal->PPHttpPost('SetExpressCheckout', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode); //Respond according to message we receive from Paypal if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
//Redirect user to PayPal store with Token received. $paypalurl ='https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$httpParsedResponseAr["TOKEN"].''; header('Location: '.$paypalurl); }else{ //Show error message echo '<div style="color:red"><b>Error : </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>'; echo '<pre>'; print_r($httpParsedResponseAr); echo '</pre>'; }
} ?>
|