admin charge and view in stripe
This commit is contained in:
84
index.php
84
index.php
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Bramus\Router\Router;
|
use Bramus\Router\Router;
|
||||||
|
use Postmark\PostmarkClient;
|
||||||
use RedBeanPHP\R;
|
use RedBeanPHP\R;
|
||||||
use Stripe\Charge;
|
use Stripe\Charge;
|
||||||
use Stripe\Customer;
|
use Stripe\Customer;
|
||||||
@@ -176,6 +177,89 @@ $router->get('/admin/guest/checkout/{id}', function ($id) {
|
|||||||
include 'views/common/footer.php';
|
include 'views/common/footer.php';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$router->post('/admin/guest/checkout/{id}', function ($id) {
|
||||||
|
$guest = R::load('guests', $id);
|
||||||
|
$totalChargeCents = convertPossibleFloatToCents($_POST['totalCharge']);
|
||||||
|
$guest->checkout_cents = $totalChargeCents;
|
||||||
|
Stripe::setApiKey($_SERVER['STRIPE_API_SECRET_KEY']);
|
||||||
|
|
||||||
|
if (isset($_POST['sendViaStripe']) && $_POST['sendViaStripe'] == 'on') {
|
||||||
|
if (empty($guest->stripe_id)) {
|
||||||
|
$customer = Customer::create([
|
||||||
|
'description' => $guest->name . ' - ' . $guest->email,
|
||||||
|
'email' => $guest->email,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$customer = $guest->stripe_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoiceItem = \Stripe\InvoiceItem::create([
|
||||||
|
'customer' => $customer,
|
||||||
|
'amount' => $guest->checkout_cents,
|
||||||
|
'currency' => 'usd',
|
||||||
|
'description' => 'Dinner in the Woods ' . date('Y'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** @var $invoice \Stripe\Invoice*/
|
||||||
|
$invoice = \Stripe\Invoice::create([
|
||||||
|
'customer' => $customer,
|
||||||
|
'billing' => 'send_invoice',
|
||||||
|
'days_until_due' => 1,
|
||||||
|
'description' => 'Dinner in the Woods ' . date('Y'),
|
||||||
|
]);
|
||||||
|
$invoice->finalizeInvoice();
|
||||||
|
|
||||||
|
$client = new Postmark\PostmarkClient($_SERVER['POSTMARK_API_KEY']);
|
||||||
|
$client->sendEmailWithTemplate(
|
||||||
|
$_SERVER['POSTMARK_FROM'],
|
||||||
|
$guest->email,
|
||||||
|
$_SERVER['POSTMARK_TEMPLATE_STRIPE_INVOICE'],
|
||||||
|
[
|
||||||
|
'name' => $guest->name,
|
||||||
|
'product_name' => 'Dinner in the Woods ' . date('Y'),
|
||||||
|
'action_receipt_url' => $invoice->hosted_invoice_url,
|
||||||
|
],
|
||||||
|
true, //inline css
|
||||||
|
null, //tag
|
||||||
|
true, //track opens
|
||||||
|
null, //reply to
|
||||||
|
null //cc
|
||||||
|
);
|
||||||
|
|
||||||
|
R::store($guest);
|
||||||
|
header('Location: /admin/guest/list/?action=success&msg=Invoice created for ' . $guest->name);
|
||||||
|
} else {
|
||||||
|
if (!empty($guest->stripe_id)) {
|
||||||
|
$charge = \Stripe\Charge::create([
|
||||||
|
'amount' => $guest->checkout_cents,
|
||||||
|
'currency' => 'usd',
|
||||||
|
'customer' => $guest->stripe_id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = new Postmark\PostmarkClient($_SERVER['POSTMARK_API_KEY']);
|
||||||
|
$client->sendEmailWithTemplate(
|
||||||
|
$_SERVER['POSTMARK_FROM'],
|
||||||
|
$guest->email,
|
||||||
|
$_SERVER['POSTMARK_TEMPLATE_STRIPE_RECEIPT'],
|
||||||
|
[
|
||||||
|
'name' => $guest->name,
|
||||||
|
'total' => $guest->checkout_cents/100,
|
||||||
|
'product_name' => 'Dinner in the Woods ' . date('Y'),
|
||||||
|
],
|
||||||
|
true, //inline css
|
||||||
|
null, //tag
|
||||||
|
true, //track opens
|
||||||
|
null, //reply to
|
||||||
|
null //cc
|
||||||
|
);
|
||||||
|
|
||||||
|
header('Location: /admin/guest/list/?action=success&msg=Charge created for ' . $guest->name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
$router->post('/admin/guest/add-card/{id}', function ($id) {
|
$router->post('/admin/guest/add-card/{id}', function ($id) {
|
||||||
$guest = R::load('guests', $_POST['guestId']);
|
$guest = R::load('guests', $_POST['guestId']);
|
||||||
$guest->name = $_POST['name'];
|
$guest->name = $_POST['name'];
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ TABLE_TICKET_PRICE_2="450"
|
|||||||
EVENT_TICKET_PRICE_3="75"
|
EVENT_TICKET_PRICE_3="75"
|
||||||
TABLE_TICKET_PRICE_3="500"
|
TABLE_TICKET_PRICE_3="500"
|
||||||
ENHANCER_TICKET_PRICE="20"
|
ENHANCER_TICKET_PRICE="20"
|
||||||
|
ENHANCER_TICKET_PRICE_SINGLE="2"
|
||||||
CHILDCARE_PRICE="25"
|
CHILDCARE_PRICE="25"
|
||||||
CABANA_PRICE="250"
|
CABANA_PRICE="250"
|
||||||
DB_HOST="localhost"
|
DB_HOST="localhost"
|
||||||
@@ -13,6 +14,8 @@ DB_USER="root"
|
|||||||
DB_PASS="root"
|
DB_PASS="root"
|
||||||
POSTMARK_API_KEY="special"
|
POSTMARK_API_KEY="special"
|
||||||
POSTMARK_TEMPLATE="identifier_for_template"
|
POSTMARK_TEMPLATE="identifier_for_template"
|
||||||
|
POSTMARK_TEMPLATE_STRIPE_INVOICE="identifier_for_template"
|
||||||
|
POSTMARK_TEMPLATE_STRIPE_RECEIPT="id_for_template"
|
||||||
POSTMARK_REMINDER_TEMPLATE="identifier_for_reminder_template"
|
POSTMARK_REMINDER_TEMPLATE="identifier_for_reminder_template"
|
||||||
POSTMARK_GUEST_TEMPLATE="identifier_for_template"
|
POSTMARK_GUEST_TEMPLATE="identifier_for_template"
|
||||||
POSTMARK_FROM="sender@email.com"
|
POSTMARK_FROM="sender@email.com"
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<div class="input-group-text">$</div>
|
<div class="input-group-text">$</div>
|
||||||
</div>
|
</div>
|
||||||
<input name="enhancerCharge" type="text" class="form-control txtCal" id="inlineFormInputGroup" value="<?=$guest->enhancer_qty * $_SERVER['ENHANCER_TICKET_PRICE']?>">
|
<input name="enhancerCharge" type="text" class="form-control txtCal" id="inlineFormInputGroup" value="<?=$guest->enhancer_qty * $_SERVER['ENHANCER_TICKET_PRICE_SINGLE']?>">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@@ -48,9 +48,16 @@
|
|||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<div class="input-group-text">$</div>
|
<div class="input-group-text">$</div>
|
||||||
</div>
|
</div>
|
||||||
<input name="totalCharge" type="text" class="form-control" id="totalCharge" value="<?=$guest->enhancer_qty * $_SERVER['ENHANCER_TICKET_PRICE']?>" readonly>
|
<input name="totalCharge" type="text" class="form-control" id="totalCharge" value="<?=$guest->enhancer_qty * $_SERVER['ENHANCER_TICKET_PRICE_SINGLE']?>" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php
|
||||||
|
if (empty($guest->stripe_id)) {?>
|
||||||
|
<div class="form-group form-check">
|
||||||
|
<input type="checkbox" class="form-check-input" id="sendViaStripe" name="sendViaStripe">
|
||||||
|
<label class="form-check-label" for="sendViaStripe">Send invoice via stripe?</label>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="submit" class="btn btn-primary">Checkout</button>
|
<button type="submit" class="btn btn-primary">Checkout</button>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="inputEnhancers">How many enhancers packs are given (10 per pack)?</label>
|
<label for="inputEnhancers">How many enhancers sold (these are single tickets)?</label>
|
||||||
<input type="number" class="form-control" id="inputEnhancers" name="enhancerQty" value="0">
|
<input type="number" class="form-control" id="inputEnhancers" name="enhancerQty" value="0">
|
||||||
<input type="hidden" class="form-control" id="inputGuestId" name="guestId" value="0">
|
<input type="hidden" class="form-control" id="inputGuestId" name="guestId" value="0">
|
||||||
</div>
|
</div>
|
||||||
@@ -79,6 +79,7 @@
|
|||||||
<a class="dropdown-item" href="/admin/guest/add-card/<?=$guest->id?>">Add Credit Card</a>
|
<a class="dropdown-item" href="/admin/guest/add-card/<?=$guest->id?>">Add Credit Card</a>
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
<a class="dropdown-item" href="/admin/guest/delete-card/<?=$guest->id?>">Delete Credit Card</a>
|
<a class="dropdown-item" href="/admin/guest/delete-card/<?=$guest->id?>">Delete Credit Card</a>
|
||||||
|
<a class="dropdown-item" href="https://dashboard.stripe.com/customers/<?=$guest->stripe_id?>">View in Stripe</a>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<a class="dropdown-item" href="/admin/guest/checkout/<?=$guest->id?>">Checkout</a>
|
<a class="dropdown-item" href="/admin/guest/checkout/<?=$guest->id?>">Checkout</a>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user