<?php
include "masspay_class.php";
$credentials['API_USERNAME'] = 'username';
$credentials['API_PASSWORD'] = 'password';
$credentials['API_SIGNATURE'] = 'signature';
$credentials['API_ENDPOINT'] = 'https://api-3t.live.paypal.com/nvp';
$sitename = "PHPorium";
$amount = urlencode($_POST['Amount']);
$id = urlencode(rand(123456,123456789));
$note = urlencode('This is a note that will show up in the email.');
$subject = urlencode("Payment from $sitename");
$type = urlencode('EmailAddress');
$currency = urlencode($_POST['Currency']);
foreach($_POST['mem_email'] as $extra)
{
$customer_email = urlencode($_POST['EmailAddress'.$extra]);
}
$base_call = "&L_EMAIL0=".$customer_email.
"&L_AMT0=".$amount.
"&L_UNIQUEID0=".$id.
"&L_NOTE0=".$refund_note.
"&EMAILSUBJECT=".$subject.
"&RECEIVERTYPE=".$type.
"&CURRENCYCODE=".$currency;
$PayPal = new PayPal_CallerService($credentials);
$status = $PayPal->callPayPal("MassPay", $base_call);
//Do something if it is successfully sent
if($status)
{
if($status['ACK'] == "Success")
{
//Check the balance of the account that was just debited, and make sure we have at least $500 left in our account
$balance = $PayPal->callPayPal("GetBalance", '');
if($balance['L_AMT0'] < 500)
{
$message = "The balance is low... Please replenish the funds... \n\n".$balance['L_AMT0']." ".$balance['L_CURRENCYCODE0'];
mail('[email protected]','PayPal Refund Balance Low',$message);
}
}
elseif($status['ACK'] == "Failure")
{
if($status['L_ERRORCODE0'] == '10321')
{
$error = "Insufficient Funds to Send Refund to: "'.$_POST['EmailAddress'].' via PayPal in the amount of: '.$_POST['Amount'].' '.$_POST['Currency'].'. ';
}
elseif($status['L_ERRORCODE0'] == '10004')
{
$this->view->error = "Invalid Amount of Refund to: "'.$_POST['EmailAddress'].' via PayPal in the amount of: '.$_POST['Amount'].' '.$_POST['Currency'].'. Must be more than 0 '.$_POST['Currency'].'.';
}
else
{
$this->view->error = "There was an unknown error when attempting to submit the payment.";
var_dump($status);
}
}
}
else
{
?>
<form action="paythem.php" method="post">
<p>Amount To Pay: <input type="text" name="amount<?php echo $i; ?>" value="" /></p>
<p>Select Members To Pay: <select name="EmailAddress<?php echo $i; ?>">
<?php
$i=0;
$s=mysql_query("SELECT email FROM members WHERE email != NULL") or die(mysql_error());
if(mysql_num_rows($s) > 0)
{
while($mail=mysql_fetch_array($s))
{
$i++;
print "<option value='".$mail['email'.$i]."'>".$mail['email']."</option>";
}
}
else
{
print "<option value='0' selected>no emails</option>";
}
?>
</select></p>
<p>Currency: <input type="text" name="currency<?php echo $i; ?>" value="USD" /></p>
<p><input type="submit" name="submit" value="Pay Now" /></p>
</form>
<?php
}
?>
if($status['L_ERRORCODE0'] == '10321')
{
$error = "Insufficient Funds to Send Refund to: ".$_POST['EmailAddress']." via PayPal in the amount of: ".$_POST['Amount'].' '.$_POST['Currency'];
}
elseif($status['L_ERRORCODE0'] == '10004')
{
$this->view->error = "Invalid Amount of Refund to: ".$_POST['EmailAddress']." via PayPal in the amount of: ".$_POST['Amount']." ".$_POST['Currency']." Must be more than 0 ".$_POST['Currency'];
}
else
{
$this->view->error = "There was an unknown error when attempting to submit the payment.";
var_dump($status);
}