<?php
	session_start(); 

	include("../include/config.php");

	include("../include/functions.php"); 

	validate_admin();

if($_REQUEST['submitForm']=='yes'){ 

$storeid=$_POST['storeid'];
$btname=$_POST['btname'];

//individual detail
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$dob=$_POST['dob'];
$ssn=$_POST['ssn'];
$streetindi=$_POST['streetindi'];
$localityindi=$_POST['localityindi'];
$regionindi=$_POST['regionindi'];
$postalindi=$_POST['postalindi'];

//business detail
$legalname=$_POST['legalname'];
$dba=$_POST['dba'];
$taxid=$_POST['taxid'];
$streetbus=$_POST['streetbus'];
$localitybus=$_POST['localitybus'];
$regionbus=$_POST['regionbus'];
$postalbus=$_POST['postalbus'];

//funding detail
$descriptor=$_POST['descriptor'];
$emaildesc=$_POST['emaildesc'];
$mobile=$_POST['mobile'];
$acno=$_POST['acno'];
$routing=$_POST['routing'];

//BT setup starts
require_once('../braintree/final/braintree/lib/Braintree.php');
	
// braintree sandbox
/*
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('d68m73wzrttmy8t9');
Braintree_Configuration::publicKey('h7c2bm97b72bm9fd');
Braintree_Configuration::privateKey('67cf79121710d11dfe308c95c8bb3987');
*/
//braintree production
  Braintree_Configuration::environment('production');
  Braintree_Configuration::merchantId('85f4dtcxzp6p924q');
  Braintree_Configuration::publicKey('3hw5mfz536gzn4jc');
  Braintree_Configuration::privateKey('47f67be7bf627608c012b98a0b8b30d1');


$merchantAccountParams = [

  'individual' => [

    'firstName' => $fname,

    'lastName' => $lname,

    'email' => $email,

    'phone' => $phone,

    'dateOfBirth' => $dob,

    'ssn' => $ssn,

    'address' => [

      'streetAddress' => $streetindi,

      'locality' => $localityindi,

      'region' => $regionindi,

      'postalCode' => $postalindi

    ]

  ],

  'business' => [

    'legalName' => $legalname,

    'dbaName' => $dba,

    'taxId' => $taxid,

    'address' => [

      'streetAddress' => $streetbus,

      'locality' => $localitybus,

      'region' => $regionbus,

      'postalCode' => $postalbus

    ]

  ],

  'funding' => [

    'descriptor' => $descriptor,

    'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK,

    'email' => $emaildesc,

    'mobilePhone' => $mobile,

    'accountNumber' => $acno,

    'routingNumber' => $routing

  ],

  'tosAccepted' => true,

  //'masterMerchantAccountId' => 'myvalue365',
  'masterMerchantAccountId' => 'MyValue365Inc_marketplace',

  'id' => $btname

];

$result = Braintree_MerchantAccount::create($merchantAccountParams);
//echo "<pre>";
//print_r($result);
//BT setup ends

if($result->message!=''){
$_SESSION['sess_msg']="<strong>ERROR:</strong> ".$result->message;
}else{
$obj->query("update stores set BT_storename='$btname' where storeid='$storeid'");
	$_SESSION['sess_msg']='Merchant name added sucessfully';  
  	header("location:btsubmerchant-list.php");
   	exit();
}

}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title><?php echo SITE_TITLE; ?></title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="css/admin.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php include("header.php") ?>
<br />
<div style="padding:1%">
<span style="float:left; padding-left:50px"><img src="images/arrow2.gif" width="21" height="21" hspace="10" align="absmiddle" /><strong style="font-size:14px; color:#555">Admin: Add BT Submerchant </strong> </span>
<span  style="float:right; padding-right:10px;">
<input type="button" name="add" value="View Submerchant List"  class="button" onclick="location.href='btsubmerchant-list.php'" />
</span>
</div>
<br />
<hr style="border:1px solid #ccc" />
<div style="background:#eee; padding:25px 30px">
<div style=" margin-left:50px; color:#555; font-size:18px;"><strong>Add BT Submerchant  Details</strong></div>
<br />
<div style="color:#FF3300; text-align:center"><?php echo $_SESSION['sess_msg']; $_SESSION['sess_msg']=''; ?></div>
<br /><br />
<form name="frm" method="POST" enctype="multipart/form-data" action="">
<input type="hidden" name="submitForm" value="yes" />
<input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" />
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="26%" align="right" class="paddBot11 paddRt14"><strong>Store Name :</strong></td>
<td width="74%" align="left" class="paddBot11"><select name="storeid" required style="width:240px">
<option value="">Select Store...</option>
<?php $sql=$obj->query("select storename,storeid from stores where status=1 and BT_storename='' order by storename");
while($record=$obj->fetchNextObject($sql)){ ?>
<option value="<?php echo $record->storeid; ?>" <?php if($record->storeid==$result->storeid){ ?> selected="selected" <?php } ?>><?php echo ucwords(strtolower($record->storename)); ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Suggested Merchant Name :</strong></td>
<td align="left" class="paddBot11"><input name="btname" type="text" id="btname" value="<?php echo $btname; ?>" size="36" required />  Note: Use only lowercase text and underscore ( _ ), Do not use space, any special charecters, uppercase and numbers.</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong><strong>Individual details :</strong></strong></td>
<td align="left" class="paddBot11"></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>First Name :</strong></td>
<td align="left" class="paddBot11"><input name="fname" type="text" id="fname" value="<?php echo $fname; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Last Name :</strong></td>
<td align="left" class="paddBot11"><input name="lname" type="text" id="lname" value="<?php echo $lname; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Email  :</strong></td>
<td align="left" class="paddBot11"><input name="email" type="email" id="email" value="<?php echo $email; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Phone :</strong></td>
<td align="left" class="paddBot11"><input name="phone" type="text" id="phone" value="<?php echo $phone; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Date of Birth : </strong></td>
<td align="left" class="paddBot11"><input name="dob" type="text" required size="36" value="<?php echo $dob; ?>" /> eg. YYYY-MM-DD</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>SSN :</strong></td>
<td align="left" class="paddBot11"><input name="SSN" type="text" size="36" value="<?php echo $ssn; ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Street Address :</strong></td>
<td align="left" class="paddBot11"><input name="streetindi" type="text" size="36" value="<?php echo $streetindi; ?>"  required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Locality :</strong></td>
<td align="left" class="paddBot11"><input name="localityindi" type="text" id="localityindi" value="<?php echo $localityindi; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Region :</strong></td>
<td align="left" class="paddBot11"><input name="regionindi" type="text" id="regionindi" value="<?php echo $regionindi; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Postal Code :</strong></td>
<td align="left" class="paddBot11"><input name="postalindi" type="text" id="postalindi" value="<?php echo $postalindi; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong><strong>Business Details :</strong></strong></td>
<td align="left" class="paddBot11"></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Legal Name :</strong></td>
<td align="left" class="paddBot11"><input name="legalname" type="text" id="legalname" value="<?php echo $legalname; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>DBA Name :</strong></td>
<td align="left" class="paddBot11"><input name="dba" type="text" id="dba" value="<?php echo $dba; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Tax Id :</strong></td>
<td align="left" class="paddBot11"><input name="taxid" type="text" id="taxid" value="<?php echo $taxid; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Street Address :</strong></td>
<td align="left" class="paddBot11"><input name="streetbus" type="text" id="streetbus" value="<?php echo $streetbus; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Locality :</strong></td>
<td align="left" class="paddBot11"><input name="localitybus" type="text" id="localitybus" value="<?php echo $localitybus; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Region :</strong></td>
<td align="left" class="paddBot11"><input name="regionbus" type="text" id="regionbus" value="<?php echo $regionbus; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Postal Code :</strong></td>
<td align="left" class="paddBot11"><input name="postalbus" type="text" id="postalbus" value="<?php echo $postalbus; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong><strong>Funding Details :</strong></strong></td>
<td align="left" class="paddBot11"></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Descriptor :</strong></td>
<td align="left" class="paddBot11"><input name="descriptor" type="text" id="descriptor" value="<?php echo $descriptor; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Email :</strong></td>
<td align="left" class="paddBot11"><input name="emaildesc" type="email" id="emaildesc" value="<?php echo $emaildesc; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Mobile Phone :</strong></td>
<td align="left" class="paddBot11"><input name="mobile" type="text" id="mobile" value="<?php echo $mobile; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Bank Account Number :</strong></td>
<td align="left" class="paddBot11"><input name="acno" type="text" id="acno" value="<?php echo $acno; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Routing Number :</strong></td>
<td align="left" class="paddBot11"><input name="routing" type="text" id="routing" value="<?php echo $routing; ?>" size="36" required /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14">&nbsp;</td>
<td align="left" class="paddBot11">&nbsp;</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"></td>
<td align="left" class="paddBot11"><input type="submit" name="submit" value="Submit"  class="submit" border="0"/></td>
</tr>								   
</table>
                                  
</form>
</div>
<?php include('footer.php'); ?>

</body>

</html>





