Created
June 29, 2013 00:44
-
-
Save braidn/5889159 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once "inc/incConstants.php"; | |
include 'request_model.php'; | |
if($logon!=1){ | |
header("Location:".$secureURL."/home"); | |
} | |
$client_info = getAccountByID('client', $userID); | |
$selected_bids = get_bids(null, 'selected', $get['id']); | |
//get_bids returns an array that usually has more than one bid | |
$bid = $selected_bids[0]; | |
if ($userID != $bid['request_data']['requester']['client_id']) { | |
header("Location:".$secureURL.'/home'); | |
} | |
ob_start(); | |
?> | |
<div class="container" id="con_payment"> | |
<h2>almost finished</h2> | |
<div class="row"> | |
<div id= accordion1 class="accordion"> | |
<div class="accordion-group"> | |
<div class="accordion-heading"> | |
<a href="#accone" class="accordion-toggle" data-toggle='' | |
data-parent="#accordion1">request info</a> | |
</div> | |
<div id="accone" class="accordion-body collapse in"> | |
<div class="accordion-inner"> | |
<!-- all content for tab 1 goes here --> | |
<div class="page-header"> | |
<h1><?php | |
echo $bid['request_data']['cat_data']['category_name']; | |
?> <small>assistance</small></h1> | |
<div class="row"> | |
<div class="span9"> | |
<h3>with laywer: <?php echo $bid['bidder']['lawyer_fname'].', '. | |
$bid['bidder']['lawyer_lname']; ?></h3> | |
</div> | |
<div class="pull-right"> | |
<h3><small>total: $</small><?php echo $bid['amount']; ?></h3> | |
</div> | |
</div> | |
</div> | |
<!-- finish content tab1 --> | |
</div> | |
</div> | |
</div> | |
<div class="accordion-group"> | |
<div class="accordion-heading"> | |
<a href="#acctwo" class="accordion-toggle" data-toggle='' | |
data-parent="#accordion1">billing info</a> | |
</div> | |
<div id="acctwo" class="accordion-body collapse in"> | |
<div class="accordion-inner"> | |
<!-- all content for tab 2 goes here --> | |
<div class="row"> | |
<form action="#" method='post' class="form-horizontal" id='payment-form'> | |
<div class="controls controls-row"> | |
<input type="text" name="inputfname" id="inputfname" value="" placeholder="first name"/> | |
<input type="text" name="inputlname" id="inputlname" value="" placeholder="last name"/> | |
</div> | |
<div class="control-group"> | |
<div class="controls controls-row"> | |
<input type="text" name="inputstreet" id="inputstreet" value="" placeholder="street" /> | |
<input type="text" name="inputcity" id="inputcity" value="" placeholder="city" /> | |
</div> | |
</div> | |
<div class="control-group"> | |
<div class="controls controls-row"> | |
<select id="inputstate" name="inputstate"> | |
<option value="">select a state</option> | |
<?php foreach ($arrStates as $key => $value): ?> | |
<option value="<?php echo $value; ?>"><?php echo $key; ?></option> | |
<?php endforeach; ?> | |
</select> | |
<input type="text" name="inputzip" id="inputzip" value="" placeholder="zip" /> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
</div> | |
<!-- finish content tab2 --> | |
</div> | |
</div> | |
</div> | |
<div class="accordion-group"> | |
<div class="accordion-heading"> | |
<a href="#accthree" class="accordion-toggle" data-toggle='' | |
data-parent="#accordion1">payment info</a> | |
</div> | |
<div id="accthree" class="accordion-body collapse in"> | |
<div class="accordion-inner"> | |
<!-- all content for tab 3 goes here --> | |
<div id=ccErrors class="alert alert-error" style='display:none;'></div> | |
<div class="control-group"> | |
<div class="controls"> | |
<input type='text' class='input-xlarge' name="inputname" id='inputname' placeholder='name on card' /> | |
<input class="input-xlarge" type="text" name="inputcc" id='inputcc' placeholder="credit card number" /> | |
<img src="http://www.myonlinebookingsystem.com/icon-creditcards.png" alt="credit cards" /> | |
</div> | |
</div> | |
<div class="control-group"> | |
<div class="controls controls-list"> | |
<select name="inputmonth" id="inputmonth"> | |
<option value="">expiration month</option> | |
<?php foreach ($arrCCMonths as $month): ?> | |
<option value="<?php echo array_search($month, $arrCCMonths) + 1; ?>"><?php echo $month; ?></option> | |
<?php endforeach; ?> | |
</select> | |
<select name="inputyear" id="inputyear"> | |
<option value="">expiration year</option> | |
<?php foreach ($arrCCYears as $year): ?> | |
<option value="<?php echo $year; ?>"><?php echo $year; ?></option> | |
<?php endforeach; ?> | |
</select> | |
<input type="text" name="inputsecurity" id="inputsecurity" value="" placeholder="security code" /> | |
<input type="text" name="amount" id="inputmoney" placeholder="amount for this card" | |
value="<?php echo $bid['amount'] ?>" style="display: none"/> | |
</div> | |
</div> | |
</form> <!-- end of form in tab 2 --> | |
<div class="span12"> | |
<div id="second-card"></div> | |
</div> | |
<button class='btn btn-success' id="submit-payment"/>Submit Payment</button> | |
<button class="btn btn-info add-card">Pay With Another Card</button> | |
<!-- finish content tab3 --> | |
</div> <!-- accordion inner--> | |
</div> <!-- accordion body --> | |
</div><!-- accordion group --> | |
</div><!-- accordion --> | |
</div><!-- row --> | |
</div><!-- end .container --> | |
<div id='paymentModal' class="modal hide fade"> | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | |
<h3>Processing Payments</h3> | |
</div> | |
<div class="modal-body"> | |
<p>Your purchase is purchasing</p> | |
</div> | |
<div class="modal-footer"> | |
</div> | |
</div> | |
<script type="text/javascript" src="https://js.balancedpayments.com/v1/balanced.js"></script> | |
<script src="/components/accounting/accounting.min.js" type="text/javascript"></script> | |
<script type="text/javascript" src="/assets/js/payment.js"></script> | |
<script type="text/javascript"> | |
//initialize with balanced payments with our marketplace id | |
balanced.init('/v1/marketplaces/TEST-MP2LlPCdlPIAZT5pgS0LNCOa'); | |
//event after the submit payment button is clicked | |
var multipleCards = false, | |
total = <?php echo $bid['amount']?>; | |
$(document).on('click', 'button.add-card', function(event) { | |
//if the button is selected, we want to hide it | |
//show the second card info | |
$.get('second_credit_card.php', function(html) { | |
$('#second-card').html(html); | |
}); | |
payment.moneyToggle($('#inputmoney')); | |
payment.buttonToggle(this, 'add-card', 'remove-card', 'btn-info', 'btn-warning', 'Pay With One Card'); | |
multipleCards = true; | |
}); | |
$(document).on('click', '.remove-card', function() { | |
$('#second-card').empty(); | |
payment.moneyToggle($('#inputmoney')) | |
payment.buttonToggle(this, 'remove-card', 'add-card', 'btn-warning', 'btn-info', 'Pay With Another Card'); | |
$('inputmoney').val(total); | |
multipleCards = false; | |
}); | |
//these load balance between each card | |
payment.totalBalancer('#inputmoney', '#inputmoney2', total); | |
payment.totalBalancer('#inputmoney2', '#inputmoney', total); | |
$('#submit-payment').click(function(event) { | |
event.preventDefault(); | |
//grab credit card data information | |
var cardName = $('#inputname').val(), | |
cardNumb = $('#inputcc').val(), | |
cardMonth = $('#inputmonth option:selected').val(), | |
cardYear = $('#inputyear option:selected').val(), | |
cardCode = $('#inputsecurity').val(), | |
validCard = {}, validCard2 = {}, firstDebit = ''; | |
var cardData = { | |
"name": cardName, | |
"card_number": cardNumb, | |
"expiration_month": cardMonth, | |
"expiration_year": cardYear | |
}; | |
validCard = balanced.card.validate ({ | |
card_number: cardNumb, | |
security_code: cardCode, | |
expiration_month: cardMonth, | |
expiration_year: cardYear | |
}); | |
if (multipleCards == true) { | |
var cardName2 = $('#inputnam2').val(), | |
cardNumb = $('#inputcc2').val(), | |
cardMonth = $('#inputmonth2 option:selected').val(), | |
cardYear = $('#inputyear2 option:selected').val(), | |
cardCode = $('#inputsecurity2').val(); | |
var cardData2 = { | |
"name": cardName, | |
"card_number": cardNumb, | |
"expiration_month": cardMonth, | |
"expiration_year": cardYear | |
}; | |
validCard2 = balanced.card.validate ({ | |
card_number: cardNumb, | |
security_code: cardCode, | |
expiration_month: cardMonth, | |
expiration_year: cardYear | |
}); | |
} | |
//if balanced.card.validate thinks everything looks a-ok | |
if ($.isEmptyObject(validCard) && $.isEmptyObject(validCard2)) { | |
$('#paymentModal').modal(); | |
//create a card item and than pass the uri to the server using ajax/post | |
balanced.card.create(cardData, function(response) { | |
//TODO should this be here or in the form so we could serialize it? | |
var postData = $('#payment-form').serialize() | |
+ "&userBalancedUri=" + response.data.uri | |
+ "&userID=<?php echo $userID ?>" | |
+ "&lawyerID=<?php echo $bid['bidder']['lawyer_id']?>" | |
+ "&requestID=<?php echo $bid['request_data']['id']?>"; | |
var request1 = $.ajax({ | |
url: 'balanced_confirm.php', | |
type: 'POST', | |
async: false, | |
data: postData, | |
success: function(data) { | |
data = JSON.parse(data); | |
firstDebit = data.debit; | |
} | |
}); | |
request1.done(function(data){ | |
data = JSON.parse(data); | |
$('#paymentModal').modal('hide'); | |
if (multipleCards != true && data.success == true) { | |
window.location.replace('/paymentConfirm.php'); | |
} else if (multipleCards != true && data.success == false) { | |
$('#paymentModal').modal('hide'); | |
$('#ccErrors').toggle().prepend(data.error); | |
} | |
}); | |
}); | |
} else { | |
$('#ccErrors').toggle().prepend('There is an error with your card, please make sure everything is correct'); | |
} | |
//start multiple card stuff | |
if (multipleCards == true) { | |
//create a card item and than pass the uri to the server using ajax/post | |
balanced.card.create(cardData2, function(response) { | |
//TODO should this be here or in the form so we could serialize it? | |
var postData = $('#payment-form2').serialize() | |
+ "&userBalancedUri=" + response.data.uri | |
+ "&userID=<?php echo $userID ?>" | |
+ "&lawyerID=<?php echo $bid['bidder']['lawyer_id']?>" | |
+ "&requestID=<?php echo $bid['request_data']['id']?>"; | |
var request2 = $.ajax({ | |
url: 'balanced_confirm.php', | |
type: 'POST', | |
data: postData | |
}); | |
request2.done(function(data){ | |
data = JSON.parse(data); | |
if (data.success == true) { | |
$('#paymentModal').modal('hide'); | |
window.location.replace('/paymentConfirm.php'); | |
} else { | |
console.log(firstDebit); | |
var rollback = $.ajax({ | |
url: 'balanced_rollback.php', | |
type: 'POST', | |
data: {uri: firstDebit} | |
}); | |
rollback.done(function(data) { | |
$('#paymentModal').modal('hide'); | |
$('#ccErrors').toggle().prepend('Your card was rejected. We rolled back both transactions, please try again'); | |
}); | |
} | |
}); | |
}); | |
} //end of multiCard if | |
}); //end of click event on submit button | |
//TODO save all information except the cc number in the transactions table | |
</script> | |
<?php | |
$content = ob_get_clean(); | |
?> | |
<?php include 'mainLayout.html.php'; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment