<?
	$this->title = $this->restaurnt->name;
	$this->titleicon = 'food';
	$this->titleLink = '/restaurants/'.$this->restaurnt->id_restaurant;

	$this->title2 = 'Pay ' . $this->restaurant->name ;
	$this->title2icon = 'money';
?>
<div class="container-fluid padded">
	<div class="row-fluid">
		<div class="container-fluid padded">
			<div class="row-fluid">
				<div class="span6">

					<div class="box">
						<div class="box-header">
							<div class="title">Payments</div>

							<ul class="nav nav-tabs nav-tabs-right">
								<li class="active"><a href="#balanced" data-toggle="tab">Balanced</i></a></li>
								<li><a href="#stripe" class="active" data-toggle="tab">Stripe</a></li>
							</ul>

						</div>

						<div class="box-content padded">
							<div class="tab-content">
								<div class="tab-pane active" id="balanced" style="overflow:hidden;">
									<!-- Balanced stuff BEGIN -->
									<div class="box">
										<div class="box-header"><span class="title">Bank Info</span></div>
										<div class="box-content padded">
											<? if ($this->payment->balanced_bank) : ?>
											<b>This restaurant already has a bank account. <a href="javascript:;" class="restaurant-merchant-button-accountremove">Remove</a></b>
											<? else : ?>
											<h4 class="restaurant-item-title">Add <?=$this->payment->balanced_bank ? 'New ' : ''?>Bank Info</h4>
											<form id="restaurant-bank-info" onsubmit="return false;">
												<table class="admin-restaurant-pay-form">
													<tr>
														<td>Routing #</td>
														<td>
															<input type="text" class="span8" name="routing">
														</td>
													</tr>
													<tr>
														<td>Account #</td>
														<td>
															<input type="text" class="span8" name="account">
														</td>
													</tr>
													<tr>
														<td>Name on Account</td>
														<td>
															<input type="text" class="span8" name="name">
														</td>
													</tr>
													<tr>
														<td>Type</td>
														<td>
															<select name="type" class="chzn-select span8" >
																	<option value="checking" default>Checking</option>
																	<option value="savings">Savings</option>
															</select>
														</td>
													</tr>
													<tr>
														<td colspan="2">
															<br />
															<button type="submit" class="btn btn-blue restaurant-bank-info-button"><i class="icon-save"></i>&nbsp;&nbsp;&nbsp; Save </button>
															&nbsp;&nbsp;&nbsp;<i class="restaurant-bank-info-button-loading icon-spinner icon-spin" style="display:none;"></i>
														</td>
													</tr>
												</table>
											</form>
											<? endif ; ?>
										</div>
									</div>
									<div class="box">
										<div class="box-header"><span class="title">Merchant Configuration</span></div>
										<div class="box-content padded">
											<? if ($this->payment->balanced_id == c::config()->balanced->sharedMerchant) : ?>
											<b><?=$this->restaurant->name?> is using a global merchant configuration. <a href="javascript:;" class="restaurant-merchant-button-fakeremove">Remove</a></b>
											<? elseif ($this->payment->balanced_id) : ?>
											<b><?=$this->payment->name?> already has a merchant configuration. <a href="javascript:;" class="restaurant-merchant-button-fakeremove">Remove</a></b>
											<? else : ?>
											<h4 class="restaurant-item-title">Create a Merchant Account</h4>
											<form id="restaurant-merchant" onsubmit="return false;">
												<table class="admin-restaurant-pay-form ">
													<? /*
														<tr>
															<td class="label-sub">Merchant Type</td>
															<td class="content-sub">
																<select name="type">
																	<option value="person">Person</option>
																	<option value="business">Business</option>
																</select>
															</td>
														</tr>
														<tr>
															<td>taxid (business)</td>
															<td>
																<input type="text" name="taxid">
															</td>
														</tr>
														<tr>
															<td>person name (business)</td>
															<td>
																<input type="text" name="person">
															</td>
														</tr>
														*/ ?>
													<tr>
														<td>Name</td>
														<td>
															<input type="text" class="span8" name="name">
														</td>
													</tr>
													<tr>
														<td>Date of Birth (YYYY-MM)</td>
														<td>
															<input type="text" name="dob" class="span8">
														</td>
													</tr>
													<tr>
														<td>Address</td>
														<td>
															<input type="text" name="address" class="span8">
														</td>
													</tr>
													<tr>
														<td>ZIP code</td>
														<td>
															<input type="text" name="zip" class="span8">
														</td>
													</tr>
													<tr>
														<td colspan="2">
															<br />
															<button type="submit" class="btn btn-blue restaurant-merchant-button"><i class="icon-save"></i>&nbsp;&nbsp;&nbsp; Save </button>
															<button type="submit" class="btn btn-blue restaurant-merchant-button-fake"><i class="icon-globe"></i>&nbsp;&nbsp;&nbsp; Use global merchant </button>
														</td>
													</tr>
												</table>
											</form>
											<? endif ; ?>
										</div>
									</div>
									<div class="box">
										<div class="box-header"><span class="title">Send Payment</span></div>
										<div class="box-content padded">
											<form id="restaurant-pay" onsubmit="return false;">
												<table class="admin-restaurant-pay-form">
													<tr>
														<td>Amount</td>
														<td>
															<input type="text" name="amount" class="span8">
														</td>
													</tr>
													<tr>
														<td>Note</td>
														<td>
															<input type="text" name="note" class="span8">
														</td>
													</tr>
													<tr>
														<td colspan="2">
															<br />
															<button type="submit" class="btn btn-blue restaurant-pay-button"><i class="icon-cloud-upload"></i>&nbsp;&nbsp;&nbsp; Send </button>
														</td>
													</tr>
												</table>
											</form>
										</div>
									</div>
									<!-- Balanced stuff END -->
								</div>
								<div class="tab-pane" id="stripe" style="overflow:hidden;">
<!-- Stripe stuff - BEGIN -->
									<div class="box">

										<div class="box-header"><span class="title">Recipient</span></div>
										<div class="box-content padded">

											<?php if( $this->payment->stripe_id ) {

												$recipient = $this->payment->getRecipientInfo();
												?>
											<b>This restaurant already has a recipient (Stripe).
												<br/><br/><a href="https://manage.stripe.com/recipients/<?php echo $this->payment->stripe_id; ?>" target="_blank"><i class="icon-external-link"></i> Recipient info</a></b>
												| <a href="javascript:$('.stripe-recipient-form').show();" ><i class="icon-edit"></i> Update</a></b>
												| <a href="javascript:;" class="restaurant-stripe-recipient-remove"><i class="icon-remove"></i> Remove</a></b>
											<?php } ?>

											<div class="stripe-recipient-form" <?php if( $this->payment->stripe_id ){ echo 'style="display:none;"'; }?> >

											<h4 class="restaurant-item-title">
											<?php if( $this->payment->stripe_id ){ echo '<hr/>'; } ?>
											 Recipient Info</h4>


											<form >
												<table class="admin-restaurant-pay-form">
													<tr>
														<td>Name</td>
														<td>
															<input type="text" class="span8" name="stripe-name" value="<?php echo $recipient->name; ?>" >
														</td>
													</tr>
													<tr>
														<td>SSN or EIN</td>
														<td>
															<input type="text" class="span8" name="stripe-tax-id" value="">
														</td>
													</tr>
													<tr>
														<td>Type</td>
														<td>
															<select name="stripe-type" class="chzn-select span8" >
																	<option <?php if( $recipient->type == 'individual' ){ echo 'selected="selected"'; } ?> value="individual" default>Individual</option>
																	<option <?php if( $recipient->type == 'corporation' ){ echo 'selected="selected"'; } ?> value="corporation">Corporation</option>
															</select>
														</td>
													</tr>

													<tr>
														<td colspan="2">
															<br />
															<button type="button" class="btn btn-blue stripe-recipient-info"><i class="icon-save"></i>&nbsp;&nbsp;&nbsp; Save </button>
															&nbsp;&nbsp;&nbsp;<i class="stripe-recipient-info-loading icon-spinner icon-spin" style="display:none;"></i>
														</td>
													</tr>
												</table>
											</form>
											</div>
										</div>
									</div>

									<?php if( $this->payment->stripe_id ) { ?>
									<div class="box">
										<div class="box-header"><span class="title">
										<?php if( $this->payment->stripe_account_id ){ echo 'Change '; } else { echo 'Add ';} ?>Account</span></div>
										<div class="box-content padded">
											<?php if( $this->payment->stripe_account_id ){ ?>
												<b>This restaurant already has an account (Stripe).</b>
												<hr/>
											<?php } ?>
											<form>
												<table class="admin-restaurant-pay-form">
													<tr>
														<td>Account #</td>
														<td>
															<input type="text" name="stripe-routing-number" class="span8" value="">
														</td>
													</tr>
													<tr>
														<td>Routing #</td>
														<td>
															<input type="text" name="stripe-account-number" class="span8" value="">
														</td>
													</tr>
													<tr>
														<td colspan="2">
															<br />
															<button type="button" class="btn btn-blue stripe-account-add"><i class="icon-cloud-upload"></i>&nbsp;&nbsp;&nbsp; <?php if( $this->payment->stripe_account_id ){ echo 'Update '; } else { echo 'Add ';} ?> Account </button>
														</td>
													</tr>
												</table>
											</form>
										</div>
									</div>
								<?php } ?>

								<?php if( $this->payment->stripe_id && $this->payment->stripe_account_id ) { ?>
									<div class="box">
										<div class="box-header"><span class="title">Send Payment</span></div>
										<div class="box-content padded">
											<form id="stripe-restaurant-pay" onsubmit="return false;">
												<table class="admin-restaurant-pay-form">
													<tr>
														<td>Amount</td>
														<td>
															<input type="text" name="stripe-amount" class="span8">
														</td>
													</tr>
													<tr>
														<td>Note</td>
														<td>
															<input type="text" name="stripe-note" class="span8">
														</td>
													</tr>
													<tr>
														<td colspan="2">
															<br />
															<button type="button" class="btn btn-blue restaurant-pay-stripe-button"><i class="icon-cloud-upload"></i>&nbsp;&nbsp;&nbsp; Send </button>
														</td>
													</tr>
												</table>
											</form>
										</div>
									</div>
								<?php } ?>
<!-- Stripe stuff - END -->

								</div>
							</div>
						</div>
					</div>


				</div>
				<div class="span6">
					<div class="box">
						<div class="box-header">
							<span class="title">Payment info</span>
						</div>
						<div class="box-content">
							<form id="restaurant-payment-info" class="fill-up" onsubmit="return false;">
								<ul class="box-list">
									<li>
										<span>Charge Credit Fees?</span>
										<span class="pull-right">
										<input type="checkbox" name="charge_credit_fee" id="charge_credit_fee" class="iButton-icons" <?=$this->payment->charge_credit_fee ? 'checked' : ''?>>
										</span>
									</li>
									<li>
										<span>Waive Fee 1st Month?</span>
										<span class="pull-right">
										<input type="checkbox" name="waive_fee_first_month" id="waive_fee_first_month" class="iButton-icons" <?=$this->payment->waive_fee_first_month ? 'checked' : ''?>>
										</span>
									</li>
									<li>
										<span>Pay For Apology Credits?</span>
										<span class="pull-right">
											<input type="checkbox" name="pay_apology_credits" id="pay_apology_credits" class="iButton-icons" <?=$this->payment->pay_apology_credits ? 'checked' : ''?>>
										</span>
									</li>
									<li class="input">
										<span>Max Apology Credit</span>
										<span class="pull-right">
											<input type="number" class="fill-up" name="max_apology_credit" maxlength="5" id="max_apology_credit" value="<?php echo $this->payment->max_apology_credit;?>" />
										</span>
									</li>
									<li>
										<span>Max Promotion Paying</span>
											<span class="pull-right">
											<input type="number" class="fill-up" name="max_pay_promotion" maxlength="5" id="max_pay_promotion" value="<?php echo $this->payment->max_pay_promotion;?>" />
										</span>
									</li>
									<li class="input">
										<span>Contact Name</span>
										<span class="pull-right span9">
											<input type="text" name="contact_name" maxlength="255" id="contact_name" value="<?php echo $this->payment->contact_name;?>" />
										</span>
									</li>
									<li class="input">
										<span>Check Address</span>
										<span class="pull-right span9">
											<input type="text" class="fill-up" name="check_address" maxlength="255" id="check_address" value="<?php echo $this->payment->check_address;?>" />
										</span>
									</li>
									<li class="input">
										<span>Check Address City</span>
										<span class="pull-right span9">
											<input type="text" class="fill-up" name="check_address_city" maxlength="50" id="check_address_city" value="<?php echo $this->payment->check_address_city;?>" />
										</span>
									</li>
									<li class="input">
										<span>Check Address State</span>
										<span class="pull-right span9">
											<input type="text" class="fill-up" name="check_address_state" maxlength="50" id="check_address_state" value="<?php echo $this->payment->check_address_state;?>" />
										</span>
									</li>
									<li class="input">
										<span>Check Address Zip</span>
										<span class="pull-right span9">
											<input type="text" class="fill-up" name="check_address_zip" maxlength="20" id="check_address_zip" value="<?php echo $this->payment->check_address_zip;?>" />
										</span>
									</li>
									<li class="input">
										<span>Check Address Country</span>
										<span class="pull-right span9">
											<input type="text" class="fill-up" name="check_address_country" maxlength="3" id="check_address_country" value="<?php echo $this->payment->check_address_country;?>" />
										</span>
									</li>
									<li class="input">
										<span>Summary Fax</span>
										<span class="pull-right span9">
											<input type="text" name="summary_fax" maxlength="255" id="summary_fax" value="<?php echo $this->payment->summary_fax;?>" />
										</span>
									</li>
									<li class="input">
										<span>Summary Email</span>
										<span class="pull-right span9">
											<input type="text" name="summary_email" maxlength="255" id="summary_email" value="<?php echo $this->payment->summary_email;?>" />
										</span>
									</li>
									<li class="input">
										<span>Summary Frequency</span>
										<span class="pull-right span9">
											<input type="number" name="summary_frequency" maxlength="5" id="summary_frequency" value="<?php echo $this->payment->summary_frequency;?>" />
										</span>
									</li>
									<li class="input">
										<span>Summary Method</span>
										<span class="pull-right span9">
												<?php $options = array( 'fax', 'email', 'no summary' ); ?>
											<select name="summary_method" id="summary_method" class="uniform">
												<option value="">None</option>
												<? foreach ($options as $option) {
													$selected = ( $option == $this->payment->summary_method ) ? 'selected="selected"' : ''; ?>
												<option <?=$selected?> value="<?=$option?>"><?=$option?></option>
												<? } ?>
											</select>
										</span>
									</li>

									<li class="input">
										<span>Legal Name for Payment</span>
										<span class="pull-right span9">
											<input type="text" name="legal_name_payment" maxlength="255" id="legal_name_payment" value="<?php echo $this->payment->legal_name_payment;?>" />
										</span>
									</li>
									<li class="input">
										<span>Tax ID # </span>
										<span class="pull-right span9">
											<input type="text" name="tax_id" maxlength="255" id="tax_id" value="<?php echo $this->payment->tax_id;?>" />
										</span>
									</li>
									<div style="clear: both;"></div>
									<li class="input">
										<span>Payment Method</span>
										<span class="pull-right">
											<?php $options = array( 'check', 'deposit', 'no payment' ); ?>
											<select name="payment_method" id="payment_method" class="uniform">
												<? foreach ($options as $option) {
													$selected = ( $option == $this->payment->payment_method ) ? 'selected="selected"' : ''; ?>
												<option <?=$selected?> value="<?=$option?>"><?=$option?></option>
												<? } ?>
											</select>
										</span>
									</li>
									<li class="input">
										<button type="button" class="btn btn-blue payment-info-button"><i class="icon-money"></i>  Save Payment changes</button>
										<span class="pull-right">
											<div class="alert-payment-info" style="display:none">
												<span class="alert-message"><strong>Ok!</strong> Payment info saved!</span>
											</div>
										</span>
									</li>
								</ul>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="box">
			<div class="box-header"><span class="title">Recent Payments</span></div>
			<div class="box-content">
				<table class="table table-normal">
					<thead>
						<tr>
							<td>Date</td>
							<td>Amount</td>
							<td>Note</td>
							<td>Type</td>
							<td>Info</td>
						</tr>
					</thead>
					<? foreach ($this->restaurant->payments() as $payment) : ?>
					<tr>
						<td><?=$payment->date?></td>
						<td>$<?=$payment->amount?></td>
						<td><?=$payment->note?></td>
						<td><?=$payment->type()?></td>
						<td><?php
						if( $payment->type() == 'stripe' ) {
							echo '<a style="text-decoration:underline;" target="_blank" href="https://manage.stripe.com/transfers/' . $payment->stripe_id . '">' . $payment->stripe_id . '</a>';
						} else {
							echo $payment->balanced_id;
						}
							?></td>
					</tr>
					<? endforeach; ?>
				</table>
			</div>
		</div>
	</div>
</div>

<script>
	$(function() {

		$('.restaurant-merchant-button').click(function() {
			var form = $(this).closest('form');
			$.post('/api/restaurant/<?=$this->payment->id_restaurant?>/merchant', {
				type: 'person', /* form.find('[name="type"]').val() */
				name: form.find('[name="name"]').val(),
				address: form.find('[name="address"]').val(),
				zip: form.find('[name="zip"]').val(),
/*				person: form.find('[name="person"]').val(),
				taxid: form.find('[name="taxid"]').val(), */
				dob: form.find('[name="dob"]').val()
			}, function() {
				location.href = location.href;
			});
		});


		/* Form payment info */
		$( document ).on( 'click', '.payment-info-button', function(){

			var parent = $( this ).parent();
			var button = parent.html();

			parent.html( '<i class="icon-spinner icon-spin"></i> Processing' );

			$.post('/api/restaurant/<?=$this->payment->id_restaurant?>/paymentinfo', {
				payment_method : ( $( '#payment_method' ).val() ),
				check_address : ( $( '#check_address' ).val() ),
				check_address_city : ( $( '#check_address_city' ).val() ),
				check_address_state : ( $( '#check_address_state' ).val() ),
				check_address_country : ( $( '#check_address_country' ).val() ),
				check_address_zip : ( $( '#check_address_zip' ).val() ),
				contact_name : ( $( '#contact_name' ).val() ),
				summary_fax : ( $( '#summary_fax' ).val() ),
				summary_email : ( $( '#summary_email' ).val() ),
				summary_frequency : ( $( '#summary_frequency' ).val() ),
				legal_name_payment : ( $( '#legal_name_payment' ).val() ),
				summary_method : ( $( '#summary_method' ).val() ),
				max_apology_credit : ( $( '#max_apology_credit' ).val() ),
				tax_id : ( $( '#tax_id' ).val() ),
				charge_credit_fee : ( $( '#charge_credit_fee' ).is( ':checked' ) ? '1' : 0 ),
				waive_fee_first_month : ( $( '#waive_fee_first_month' ).is( ':checked' ) ? '1' : 0 ),
				max_pay_promotion : ( $( '#max_pay_promotion' ).val() ),
				pay_apology_credits : ( $( '#pay_apology_credits' ).is( ':checked' ) ? '1' : 0 )
			}, function( ) {
				$( '.alert-payment-info' ).show();
				setTimeout( function(){
					parent.html( button );
					$( '.alert-payment-info' ).show();
					setTimeout( function(){
						$( '.alert-payment-info' ).hide();
					}, 2500 );
				}, 500 );
			} );

		} );

		$('.restaurant-merchant-button-fake').click(function() {
			$.post('/api/restaurant/<?=$this->payment->id_restaurant?>/fake-merchant', function() {
				location.href = location.href;
			});
		});

		$('.restaurant-stripe-recipient-remove').click(function() {
			if( confirm( 'Confirm remove recipient?' ) ){
				$.post('/api/restaurant/<?=$this->payment->id_restaurant?>/remove-stripe-recipient', function() {
					location.href = location.href;
				});
			}
		});

		$('.restaurant-merchant-button-fakeremove').click(function() {
			$.post('/api/restaurant/<?=$this->payment->id_restaurant?>/fakeremove-merchant', function() {
				location.href = location.href;
			});
		});

		$('.restaurant-merchant-button-accountremove').click(function() {
			$.post('/api/restaurant/<?=$this->payment->id_restaurant?>/remove-bankinfo', function() {
				location.href = location.href;
			});
		});

		$('.restaurant-bank-info-button').click(function() {
			var form = $(this).closest('form');
			$( '.restaurant-bank-info-button-loading' ).show();
			$.ajax({
				type: 'POST',
				url: '/api/restaurant/<?=$this->payment->id_restaurant?>/bankinfo',
				data: {
								routing: form.find('[name="routing"]').val(),
								account: form.find('[name="account"]').val(),
								type: form.find('[name="type"]').val(),
								name: form.find('[name="name"]').val()
							}
			}).done(function( data ) {
				if( data.success ){
					location.href = location.href;
				} else {
					$( '.restaurant-bank-info-button-loading' ).hide();
					alert( 'Error: see the console!'  );
					console.log('Err:', data );
				}
			}).fail(function(jqXHR, textStatus) {
				$( '.restaurant-bank-info-button-loading' ).hide();
				alert( 'Error: see the console!'  );
				console.log('Err:', jqXHR.responseText);
			});
		});

	$('.restaurant-pay-stripe-button').click(function() {
			var amount = $( '[name=stripe-amount]' ).val();
			if( $.trim( amount ) == '' ){
				alert( 'Please type the amount!' );
				$( '[name=stripe-amount]' ).focus();
				return;
			}
			var note = $( '[name=stripe-note]' ).val();
			if( $.trim( note ) == '' ){
				alert( 'Please type the note!' );
				$( '[name=stripe-note]' ).focus();
				return;
			}
			$.ajax({
				type: 'POST',
				url: '/api/restaurant/<?=$this->payment->id_restaurant?>/stripe-credit',
				data: { amount: amount, note : note },
				complete: function( data ){
					if( data.success ){
						alert( 'Paid!' );
						location.href=location.href;

					} else {
						alert( "ERROR ERROR ERROR ERROR ERROR\n\n please see the console.");
						console.log(data);
					}
				}
			})
		});

		$('.restaurant-pay-button').click(function() {
			var form = $(this).closest('form');
			$.ajax({
				type: 'POST',
				url: '/api/restaurant/<?=$this->payment->id_restaurant?>/credit',
				data: { amount: form.find('[name="amount"]').val(), note: form.find('[name="note"]').val() },
				complete: function(data){
					try {
						var json = JSON.parse(data.responseText);
					} catch (e) {
						var json = data.responseText;
					}

					if (json.success) {
						alert( 'Paid!' );
						location.href=location.href;

					} else {
						alert( "ERROR ERROR ERROR ERROR ERROR\n\n please see the console.");
						console.log(json);
					}
				}
			})
		});


		$('.stripe-recipient-info').click(function() {

			var name = $('[name=stripe-name]').val();
			var type = $('[name=stripe-type]').val();
			var tax_id = $('[name=stripe-tax-id]').val();

			if( $.trim( name ) == '' ){
				alert( 'Please type the Name!' );
				$('[name=stripe-name]').focus();
				return;
			}

			if( $.trim( type ) == '' ){
				alert( 'Please choose the Type!' );
				$('[name=stripe-type]').focus();
				return;
			}

			$.ajax({
				type: 'POST',
				url: '/api/restaurant/<?=$this->payment->id_restaurant?>/stripe-recipient',
				data: { name: name, type: type, tax_id: tax_id }
			}).done(function( data ) {
				if( data.success ){
					location.href = location.href;
				} else {
					$( '.restaurant-bank-info-button-loading' ).hide();
					alert( 'Error: see the console!'  );
					console.log('Err:', data );
				}
			})

		} );

		$('.stripe-account-add').click(function() {

			var routingNumber = $('[name=stripe-routing-number]').val();
			var accountNumber = $('[name=stripe-account-number]').val();
			var country = 'US';

			if( $.trim( routingNumber ) == '' ){
				alert( 'Please type the Routing!' );
				$('[name=stripe-routing-number]').focus();
				return;
			}

			if( !Stripe.bankAccount.validateRoutingNumber( routingNumber, country )  ){
				alert( 'Please type a valid Routing!' );
				$('[name=stripe-routing-number]').focus();
				return;
			}

			if( $.trim( accountNumber ) == '' ){
				alert( 'Please type the Account!' );
				$('[name=stripe-account-number]').focus();
				return;
			}

			if( !Stripe.bankAccount.validateAccountNumber( accountNumber, country )  ){
				alert( 'Please type a valid Account!' );
				$('[name=stripe-account-number]').focus();
				return;
			}

			Stripe.bankAccount.createToken({
				country: country,
				routingNumber: routingNumber,
				accountNumber: accountNumber,
			}, function( status, response ){
				$.ajax({
					type: 'POST',
					url: '/api/restaurant/<?=$this->payment->id_restaurant?>/stripe-account',
					data: { bank_account: response.id },
				}).done(function( data ) {
				if( data.success ){
					location.href = location.href;
				} else {
					$( '.restaurant-bank-info-button-loading' ).hide();
					alert( 'Error: see the console!'  );
					console.log('Err:', data );
				}
			}).fail(function(jqXHR, textStatus) {
				$( '.restaurant-bank-info-button-loading' ).hide();
				alert( 'Error: see the console!'  );
				console.log('Err:', jqXHR.responseText);
			});
			});


		} );

	});
</script>
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">Stripe.setPublishableKey('<?=c::config()->stripe->{c::getEnv()}->{'public'}?>');</script>
