/
ajax_paypal_direct_payment.php
76 lines (70 loc) · 3.24 KB
/
ajax_paypal_direct_payment.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
<?php
include("conf/config.inc.php");
include("classes/Paypal.php");
$firstName = $_POST['first_name'];
$lastName = $_POST['last_name']; // as we dont have last name in order session
$cardNumber = $_POST['card_number'];
$cardType = $_POST['card_type'];
$expMonth = $_POST['month'];
$expMonth = str_pad($expMonth, 2, '0', STR_PAD_LEFT); //Month must be padded with leading zero
$expYear = $_POST['year'];
$cvv = $_POST['cvv'];
$price = $_POST['car_price'];
$amount = 10;
$countryCode = "US";
$street = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['postal_code'];
$desc = $_POST['item'];
$carId = $_POST['car_id'];
$caryear = $_POST['caryear'];
$make = $_POST['make'];
$model = $_POST['model'];
$first_name = $_POST['first_name'];
$name = $_POST['first_name']+" "+$_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['telephone'];
$country = $_POST['country'];
$price = $_POST['carprice'];
$exterior_color = $_POST['exterior_color'];
$interior_color = $_POST['interior_color'];
$trim = $_POST['trim'];
//Insert into temp table
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_SYL_NAME, $link) or die('Could not select database.');
$insertQuery = "INSERT INTO temp_car_detail_payment_info ( first_name, last_name, address, telephone, country, city, postal_code,email, make, model, year, price, exterior_color, interior_color, trim ) VALUES( '".mysql_real_escape_string($firstName)."', '".mysql_real_escape_string($lastName)."', '".mysql_real_escape_string($street)."', '".mysql_real_escape_string($phone)."', '".mysql_real_escape_string($country)."', '".mysql_real_escape_string($city)."', '".mysql_real_escape_string($zip)."', '".mysql_real_escape_string($email)."', '".mysql_real_escape_string($make)."', '".mysql_real_escape_string($model)."', '".mysql_real_escape_string($caryear)."', '".mysql_real_escape_string($price)."', '".mysql_real_escape_string($exterior_color)."', '".mysql_real_escape_string($interior_color)."', '".mysql_real_escape_string($trim)."' )";
$result = mysql_query($insertQuery);
$lastid = mysql_query('select id from temp_car_detail_payment_info order by id DESC limit 0,1');
$lastfetch = mysql_fetch_object($lastid);
$custom = serialize(
array(
"pg"=>1, // page
"ty"=>1, // type
"id" =>$lastfetch->id
)
);
$pay = new Paypal();
$currencyCode = 'USD';
$userdata = array(
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'PAYMENTACTION' => 'Sale',
'CREDITCARDTYPE' => $cardType ,
'DESC'=> $desc,
'ACCT' => $cardNumber,
'EXPDATE' => $expMonth.$expYear, // Make sure this is without slashes (NOT in the format 07/2017 or 07-2017)
'CVV2' => $cvv,
'FIRSTNAME' => $firstName,
'LASTNAME' => $lastName,
'EMAIL' => $email,
'SOFTDESCRIPTORCITY' => $email,
'COUNTRYCODE' => 'US',
'CITY' => $city,
'STREET' => $street,
'ZIP' => $zip,
'NOTIFYURL' => 'http://seobrand-dev.com/ipn.php',
'AMT' => $amount, // This should be equal to ITEMAMT + SHIPPINGAMT
'CURRENCYCODE' => $currencyCode, // USD for US Dollars
'CUSTOM' => $custom // USD for US Dollars
);
$payInfo = $pay->request('DoDirectPayment',$userdata);
echo json_encode($payInfo);die;