Repository navigation
Expand file tree
/
Copy pathpay.php
More file actions
72 lines (62 loc) · 2.73 KB
/
Copy pathpay.php
File metadata and controls
72 lines (62 loc) · 2.73 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
<?php
session_start();
include 'paypal.class.php';
global $wp_query, $current_user, $wpdb;
$pid = $wp_query->query_vars['pid'];
$uid = $_GET['user'];
$status = $_GET['status'];
$action = $_GET['action'];
$p = new paypal_class;
$p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; // testing paypal url
//$p->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; // paypal url
$auctionTheme_enable_paypal_sandbox = get_option( 'PennyTheme_paypal_enable_sdbx' );
if ( $auctionTheme_enable_paypal_sandbox == "yes" ) {
$p->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
}
$this_script = get_bloginfo( 'siteurl' ) . '/?action=pay_second&pid='.$pid.'&status='.$status.'&user='.$uid;
$paypal_email = get_option('PennyTheme_payPal_email');
$second_chance_db = $wpdb->prefix.'penny_second_chance';
$wpdb->query("UPDATE $second_chance_db SET accepted = $status WHERE pid = $pid AND uid = $uid");
if ( empty( $action ) ) {
$action = 'process';
}
switch ( $action ) {
case 'process': // Process and order...
$title = get_the_title($pid);
$total = 0;
$results = "SELECT sc.pid, sc.uid, sc.total_bids, sc.winner, sc.offered, sc.status FROM $second_chance_db AS sc
WHERE sc.pid = $pid AND sc.uid = $uid AND sc.winner <> 1";
$poster = $wpdb->get_results($results);
foreach ($poster as $post):
setup_postdata($post);
$total_bids = $post->total_bids;
$msrp = get_post_meta($pid,'retail_price',true);
$total_wo = SecondChance_calculate_discounted_price($pid,$total_bids);
$discount = $msrp - $total_wo;
$shp = get_post_meta($pid,'shipping',true); if(empty($shp)) {$shp = 0;}
$total = $total_wo + $shp;
endforeach;
$payTotal = $total;
$p->add_field( 'business', $paypal_email );
$p->add_field( 'currency_code', get_option( 'PennyTheme_currency' ) );
$p->add_field( 'return', $this_script . '&action=success' );
$p->add_field( 'cancel_return', $this_script . '&action=cancel' );
$p->add_field( 'notify_url', $this_script . '&action=ipn' );
$p->add_field( 'item_name', $title );
$p->add_field( 'custom', $pid . '|' . current_time( 'timestamp', 0 ) . "|" . $uid );
$p->add_field( 'amount', SecondChance_formats_special( $payTotal, 2 ) );
$p->submit_paypal_post();
break;
case 'success':
global $wpdb;
$wpdb->query("UPDATE $second_chance_db set status = 2 WHERE pid = $pid AND uid = $uid");
break;
case 'ipn':
global $wpdb;
$wpdb->query("UPDATE $second_chance_db set status = 2 WHERE pid = $pid AND uid = $uid");
wp_redirect( get_permalink( get_option( 'PennyTheme_my_account_won_auctions_page_id' ) ) );
break;
case 'cancel': // Order was canceled...
wp_redirect( get_permalink( get_option( 'PennyTheme_my_account_won_auctions_page_id' ) ) );
break;
}