-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathppcharge.php
77 lines (68 loc) · 2.81 KB
/
ppcharge.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
<?php
/*****************************************************************
* Advanced Membership System *
* Copyright (c) 2012 MasDyn Studio, All Rights Reserved. *
*****************************************************************/
(isset($_GET['action']) && $_GET['action'] == "cancel") ? $title = "Canceled" : $title = "Charge";
require_once 'includes/header.php';
require_once 'paypal_charge/paypal.class.php';
$pp = new paypal(); // initiate an instance
define("PAYPAL_SANDBOX", "NO");
define("PAYPAL_EMAIL", "ahmed.mostafa1198@gmail.com");
define("CURRENCY_CODE", "USD");
if(PAYPAL_SANDBOX == "YES"){
$pp->paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
} else {
$pp->paypal_url = "https://www.paypal.com/cgi-bin/webscr";
}
$this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if(isset($_POST['pay'])) {
$item_price = BS1st::postValues($_POST['amount']);
if(empty($item_price)){
$_SESSION['charge_msg'] = "Please, Insert The Amount You Want To Charge it .";
header("Location: balance.php?error=1");
}else if($item_price < 10){
$_SESSION['charge_msg'] = "Sorry, The Minimum of Amount is $10 .";
header("Location: balance.php?error=2");
}else{
$pp_item_name = "Charge Balance $".$item_price." To ".$_SERVER['HTTP_HOST'];
$pp_item_price = $item_price;
$user_id = $_SESSION['user_id'];
$amount = $pp_item_price;
$custom = "add//".$user_id."//".$amount;
}
}
// if no action variable, set 'process' as default action
if (empty($_GET['action'])) $_GET['action'] = 'process';
switch ($_GET['action']) {
case 'process': // Process and order...
$pp->add_field('business', PAYPAL_EMAIL);
$pp->add_field('return', $this_script.'?action=success');
$pp->add_field('cancel_return', $this_script.'?action=cancel');
$pp->add_field('notify_url', $this_script.'?action=ipn');
$pp->add_field('item_name', $pp_item_name);
$pp->add_field('amount', $pp_item_price);
$pp->add_field('currency_code', CURRENCY_CODE);
$pp->add_field('custom', $custom);
$pp->submit_paypal_post();
break;
case 'success': // successful order...
$_SESSION['charge_msg'] = "<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>×</button>Thank You, your payment has been received & Your Balance Has Been Updated.</div>";
header("Location: ../balance.php");
break;
case 'cancel': // Canceled Order...
echo "<h2>The order was canceled.</h2>";
break;
case 'ipn': // For IPN validation...
if ($pp->validate_ipn()) {
if($pp->ipn_data['payment_status'] == "Completed"){
$return_data = explode("//", $pp->ipn_data['custom']);
if($return_data[0] == "add"){
BS1st::SQL("UPDATE `users` SET balance = balance + '".$return_data[2]."' WHERE id = '".$return_data[1]."'");
}
}
}
break;
}
include_once "includes/footer.php";
?>