mirror of
https://github.com/itflow-org/itflow
synced 2026-12-03 09:39:02 +00:00
170 lines
9.9 KiB
PHP
170 lines
9.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* A new card in place of one on autopay running out - no sign-in. The link in the email a client
|
|
* gets a month before their card runs out, and in its month (cardExpiryNightly(),
|
|
* functions/card_expiry.php), opens it: the card, what it pays, then their name, email and
|
|
* agreement, and Stripe's form for the new card, on the page (js/guest_autopay_stripe.js).
|
|
* Stripe sends them back through guest_post.php (guest_card_update_done), which puts the new card
|
|
* in place on every recurring invoice the old one paid, and comes back here. The link then stops.
|
|
*/
|
|
|
|
require_once "includes/inc_all_guest.php";
|
|
|
|
$card_id = intval($_GET['card'] ?? 0);
|
|
$key = is_string($_GET['key'] ?? null) ? $_GET['key'] : '';
|
|
$card = cardUpdateRow($card_id, $key);
|
|
$company = billingCompany();
|
|
// How to reach us, for the pages that send them to us - "billing@example.com or (412) 555-0100"
|
|
$reach = array_filter([trim((string) ($company['company_email'] ?? '')), (string) ($company['phone_display'] ?? '')]);
|
|
$contact = $reach ? ' - ' . implode(' or ', $reach) : '';
|
|
|
|
// Done just now - the key went with it
|
|
if (!$card && !empty($_GET['done'])) { ?>
|
|
<div class="itflow-asset-empty mt-5" data-card-update-done>
|
|
<i class="fas fa-check-circle fa-3x mb-3 text-success opacity-75"></i>
|
|
<h1 class="h4">Your card is updated</h1>
|
|
<p>Autopay charges your new card from now on - nothing else to do.</p>
|
|
<p class="small text-body-secondary"><?= escapeHtml(autopayChangeText()) ?></p>
|
|
</div>
|
|
<?php
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php';
|
|
exit();
|
|
}
|
|
|
|
if (!$card) {
|
|
echo guestDeadEndHtml('fa-credit-card', "This link isn't working", "Your card may have been updated already, or the link replaced by a newer email. Get in touch if your card still needs changing$contact.");
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php';
|
|
exit();
|
|
}
|
|
|
|
$entry = cardAutopayCards($card_id)[$card_id] ?? null;
|
|
if (!$entry) {
|
|
echo guestDeadEndHtml('fa-check-circle', 'Nothing to change', "This card doesn't pay any invoices automatically now, so there's nothing to update. Get in touch if you think it should$contact.");
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php';
|
|
exit();
|
|
}
|
|
|
|
$provider = billingStripeProvider();
|
|
if (!$provider || billingStripeCustomer($card['saved_payment_client_id']) === '') {
|
|
echo guestDeadEndHtml('fa-credit-card', "Your card can't be changed here just now", "Get in touch and we'll change it with you$contact.");
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php';
|
|
exit();
|
|
}
|
|
|
|
$client_id = intval($card['saved_payment_client_id']);
|
|
$parts = billingCardParts($card['saved_payment_description']);
|
|
$exp = intval($parts['expires']);
|
|
$this_month = intval(date('Ym'));
|
|
$fee = billingCardFeeTerms(billingCardFeeFor($client_id), (string) $entry['recurring'][0]['currency']);
|
|
|
|
// Signed in to the client portal as one of this client's contacts - their name and email to start with
|
|
$name = '';
|
|
$email = '';
|
|
if (!empty($_SESSION['client_logged_in']) && intval($_SESSION['client_id'] ?? 0) === $client_id) {
|
|
$me = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_name, contact_email FROM contacts WHERE contact_id = " . intval($_SESSION['contact_id'] ?? 0) . " AND contact_client_id = $client_id"));
|
|
$name = (string) ($me['contact_name'] ?? '');
|
|
$email = (string) ($me['contact_email'] ?? '');
|
|
}
|
|
|
|
?>
|
|
|
|
<div class="row justify-content-center my-4">
|
|
<div class="col-lg-7 col-xl-6">
|
|
|
|
<div class="card mb-3" data-card-update>
|
|
<div class="card-body p-4">
|
|
|
|
<div class="d-flex align-items-center gap-3 mb-3">
|
|
<span class="itflow-asset-icon bg-primary-subtle text-primary-emphasis" aria-hidden="true"><i class="fas fa-credit-card"></i></span>
|
|
<div>
|
|
<h1 class="h4 mb-0">Update your card</h1>
|
|
<div class="small text-body-secondary"><?= escapeHtml($card['client_name']) ?></div>
|
|
</div>
|
|
</div>
|
|
|
|
<p>
|
|
The card that pays <?= count($entry['recurring']) > 1 ? 'these invoices' : 'this invoice' ?> automatically
|
|
<?php if ($exp && $exp < $this_month) { ?>
|
|
<strong>has expired</strong>, so autopay can't charge it. Add the card you use now and autopay carries on.
|
|
<?php } else { ?>
|
|
<strong>expires <?= $exp === $this_month ? 'at the end of this month' : 'at the end of ' . escapeHtml(cardExpiryMonth($exp)) ?></strong>. Add your new card and autopay carries on as it is.
|
|
<?php } ?>
|
|
</p>
|
|
|
|
<ul class="list-group mb-4">
|
|
<li class="list-group-item d-flex justify-content-between gap-3" data-card-update-old>
|
|
<span class="text-body-secondary">Card on file</span>
|
|
<span class="text-end"><i class="<?= escapeHtml($parts['icon']) ?> me-1"></i><?= escapeHtml($parts['label']) ?>
|
|
<?php if ($parts['exp'] !== '') { ?><span class="badge rounded-pill ms-1 <?= $exp < $this_month ? 'text-bg-danger' : 'bg-warning-subtle text-warning-emphasis border border-warning-subtle' ?>"><?= $exp < $this_month ? 'Expired' : 'Expires' ?> <?= escapeHtml($parts['exp']) ?></span><?php } ?>
|
|
</span>
|
|
</li>
|
|
<?php foreach ($entry['recurring'] as $recurring) { ?>
|
|
<li class="list-group-item d-flex justify-content-between gap-3" data-card-update-recurring="<?= intval($recurring['id']) ?>">
|
|
<span class="text-body-secondary min-w-0"><?= escapeHtml($recurring['title']) ?><?php if ($recurring['title'] !== $recurring['number']) { ?> <span class="small text-nowrap">(<?= escapeHtml($recurring['number']) ?>)</span><?php } ?></span>
|
|
<span class="text-end text-nowrap"><span class="itflow-money fw-semibold"><?= escapeHtml(billingMoney($recurring['amount'], $recurring['currency'])) ?></span> each <?= escapeHtml($recurring['period']) ?></span>
|
|
</li>
|
|
<?php } ?>
|
|
<li class="list-group-item d-flex justify-content-between gap-3">
|
|
<span class="text-body-secondary">Next invoice</span><span><?= escapeHtml(formatDate(min(array_column($entry['recurring'], 'next')))) ?></span>
|
|
</li>
|
|
<?php if ($fee !== '') { ?>
|
|
<li class="list-group-item d-flex justify-content-between gap-3">
|
|
<span class="text-body-secondary">Card fee</span><span class="text-end"><?= escapeHtml(ucfirst($fee)) ?>, added to each charge</span>
|
|
</li>
|
|
<?php } ?>
|
|
</ul>
|
|
|
|
<form data-autopay-form data-checkout-url="guest_ajax.php?guest_card_update_checkout=1" data-stripe-key="<?= escapeHtml((string) $provider['payment_provider_public_key']) ?>" novalidate>
|
|
<input type="hidden" name="card" value="<?= $card_id ?>">
|
|
<input type="hidden" name="key" value="<?= escapeHtml($key) ?>">
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label" for="cardUpdateName">Your name</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-user"></i></span>
|
|
<input type="text" class="form-control" id="cardUpdateName" name="name" maxlength="80" autocomplete="name" required value="<?= escapeHtml($name) ?>">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label" for="cardUpdateEmail">Your email</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-envelope"></i></span>
|
|
<input type="email" class="form-control" id="cardUpdateEmail" name="email" maxlength="120" autocomplete="email" required value="<?= escapeHtml($email) ?>">
|
|
</div>
|
|
<div class="form-text">For the confirmation.</div>
|
|
</div>
|
|
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" id="cardUpdateAgree" name="agree" value="1" required>
|
|
<label class="form-check-label small" for="cardUpdateAgree"><?= escapeHtml(cardUpdateConsentText($card, $entry['recurring'])) ?></label>
|
|
</div>
|
|
|
|
<div class="alert alert-danger small py-2" data-autopay-error role="alert" hidden></div>
|
|
|
|
<button type="submit" class="btn btn-primary btn-lg w-100" data-autopay-submit>
|
|
<span data-autopay-idle><i class="fas fa-credit-card me-2"></i>Continue to card details</span>
|
|
<span data-autopay-busy hidden><span class="spinner-border spinner-border-sm me-2" aria-hidden="true"></span>One moment</span>
|
|
</button>
|
|
</form>
|
|
|
|
<div data-autopay-checkout hidden>
|
|
<div id="autopay-checkout"></div>
|
|
</div>
|
|
|
|
<div class="alert alert-warning small mb-0" data-autopay-unavailable hidden>The card form couldn't load - check your connection and reload this page, or get in touch.</div>
|
|
|
|
<p class="small text-body-secondary mb-0 mt-3"><i class="fas fa-lock me-1"></i>Your card goes straight to Stripe, our payment processor - we never see its number. <?= escapeHtml(autopayChangeText()) ?></p>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://js.stripe.com/v3/"></script>
|
|
<script src="<?= staticFileUrl('/js/guest_autopay_stripe.js') ?>"></script>
|
|
|
|
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php';
|