Skip to content

Commit

Permalink
Merge branch 'launch-prereg-2023' into misc-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsuta committed Aug 24, 2023
2 parents 6ba08da + 620f4fe commit 7a117b5
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 141 deletions.
14 changes: 10 additions & 4 deletions uber/site_sections/preregistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,13 @@ def prereg_payment(self, session, message='', **params):
charge_receipt, charge_receipt_items = ReceiptManager.create_new_receipt(model, create_model=True)
existing_receipt = session.get_receipt_by_model(model)
if existing_receipt:
# Multiple attendees can have the same transaction during pre-reg,
# so we always cancel any incomplete transactions
incomplete_txn = existing_receipt.get_last_incomplete_txn()
if incomplete_txn:
incomplete_txn.cancelled = datetime.now()
session.add(incomplete_txn)

# If their registration costs changed, close their old receipt
compare_fields = ['amount', 'count', 'desc']
existing_items = [item.to_dict(compare_fields) for item in existing_receipt.receipt_items]
Expand Down Expand Up @@ -701,6 +708,7 @@ def prereg_payment(self, session, message='', **params):
description=cart.description,
amount=sum([receipt.current_amount_owed for receipt in receipts]))
message = charge.create_stripe_intent()
log.debug(charge.intent)

if message:
return {'error': message}
Expand Down Expand Up @@ -1569,7 +1577,7 @@ def purchase_upgrades(self, session, id, **params):
return {'error': "Cannot find your receipt, please contact registration"}

if receipt.open_receipt_items and receipt.current_amount_owed:
return {'error': "You already have an outstanding balance, please pay for your current items or contact registration"}
return {'error': "You already have an outstanding balance, please refresh the page to pay for your current items or contact {}".format(email_only(c.REGDESK_EMAIL))}

receipt_items = ReceiptManager.auto_update_receipt(attendee, session.get_receipt_by_model(attendee), params)
if not receipt_items:
Expand Down Expand Up @@ -1614,10 +1622,8 @@ def finish_pending_payment(self, session, id, txn_id, **params):
else:
stripe_intent = txn.get_stripe_intent()

stripe_intent = txn.get_stripe_intent()

if not stripe_intent:
return {'error': "Something went wrong. Please contact us at {}.".format(c.REGDESK_EMAIL)}
return {'error': "Something went wrong. Please contact us at {}.".format(email_only(c.REGDESK_EMAIL))}

if stripe_intent.charges:
return {'error': "This payment has already been finalized!"}
Expand Down
4 changes: 3 additions & 1 deletion uber/templates/preregistration/confirm.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@
<div class="alert alert-warning" role="alert">
You currently have an outstanding balance of <strong>{{ (receipt.current_amount_owed / 100)|format_currency }}</strong>
with an incomplete payment of {{ (incomplete_txn.amount / 100)|format_currency }}.
Please contact us at {{ c.REGDESK_EMAIL|email_only|email_to_link }} if you need to change your purchases or if you have any questions.
<br/><br/>Click here to complete your payment: {{ stripe_form('finish_pending_payment', attendee, txn_id=incomplete_txn.id, stripe_button_id="complete_txn") }}
</div>
{% else %}
<div class="alert alert-danger" role="alert">
You currently have an outstanding balance of <strong>{{ (receipt.current_amount_owed / 100)|format_currency }}</strong>.
Please <a href="" data-bs-toggle="modal" data-bs-target="#receiptModal">check your receipt here</a> to pay.
Please <a href="" data-bs-toggle="modal" data-bs-target="#receiptModal">check your receipt here</a> to pay or
contact us at {{ c.REGDESK_EMAIL|email_only|email_to_link }} if you need to change your purchases or if you have any questions.
</div>
{% endif %}
{% elif attendee.badge_status == c.PENDING_STATUS %}
Expand Down
44 changes: 32 additions & 12 deletions uber/templates/preregistration/receipt_table.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<table class="table table-striped" id="upgrade-preview">
<tbody>
{% for item in receipt.all_sorted_items_and_txns|rejectattr("cancelled") %}
{% for item in receipt.all_sorted_items_and_txns|rejectattr("cancelled")|rejectattr("is_pending_charge") %}
<tr>
<td><span class='pull-right'>{{ item.desc }}{{ ": " if item.desc else "" }}</span></td>
<td>
{% if item.method %}
{{ (item.amount / 100)|format_currency(true) }} {{ "Paid" if item.amount > 0 else "Refunded" }} ({{ item.method_label }})
{{ (item.amount / 100)|format_currency(true) }} {{ "Paid" if item.amount > 0 else "Refunded" }}
{% else %}
{{ (item.amount / 100)|format_currency }}
{% endif %}
Expand All @@ -15,17 +15,37 @@
</td>
</tr>
{% endfor %}
{% if receipt.current_amount_owed %}
<tr><td colspan="2"></td></tr>
<tr>
<td colspan="2">
<span class='pull-right'>
<strong>Total: {{ (receipt.current_amount_owed / 100)|format_currency }}
{% if receipt.item_total > 0 %}
<tr><td colspan="2"></td></tr>
<tr>
<td>
<span class='pull-right'>
<strong>Total</strong>
</span>
</td>
<td> {{ (receipt.item_total / 100)|format_currency }} </td>
</tr>
<tr>
<td>
<span class='pull-right'>
<strong>Paid</strong>
</span>
</td>
<td> {{ ((receipt.payment_total - receipt.refund_total) / 100)|format_currency }} </td>
</tr>
{% if receipt.current_amount_owed %}
<tr>
<td>
<span class='pull-right'>
<strong>Owed</strong>
</span>
</td>
<td>
{{ (receipt.current_receipt_amount / 100)|format_currency }}
{% if receipt.pending_total %}({{ (receipt.pending_total / 100)|format_currency }} pending){% endif %}
</strong>
</span>
</td>
</tr>
</td>
</tr>
{% endif %}
{% endif %}
</tbody>
</table>
Expand Down
182 changes: 58 additions & 124 deletions uber/templates/preregistration/stripeForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@
background-color: #fefde5 !important;
}
</style>
{% if not stripe_loaded %}
{% if c.AUTHORIZENET_LOGIN_ID %}
<script type="text/javascript"
src="https://js{{ 'test' if 'test' in c.AUTHORIZENET_ENDPOINT else '' }}.authorize.net/v1/Accept.js"
charset="utf-8">
</script>
{% else %}
<script src="https://js.stripe.com/v3/" async></script>
{% endif %}
{% set stripe_loaded = true %}
<button type="button"
class="AcceptUI d-none"
id="authNetPayButton"
data-billingAddressOptions='{"show":true, "required":true}'
data-apiLoginID="{{ c.AUTHORIZENET_LOGIN_ID }}"
data-clientKey="{{ c.AUTHORIZENET_PUBLIC_KEY }}"
data-acceptUIFormBtnTxt="Pay"
data-acceptUIFormHeaderTxt="Payment to {{ c.ORGANIZATION_NAME }}"
data-paymentOptions='{"showCreditCard": true}'
data-responseHandler="handleAuthNetResponse">Pay
</button>
{% elif not stripe_loaded %}
<script src="https://js.stripe.com/v3/" async></script>
{% set stripe_loaded = true %}
{% endif %}
<button class="btn btn-info stripe-btn"{% if 'stripe_button_id' in params %} id="{{ params['stripe_button_id'] }}"{% endif %} onClick="callStripeAction();">
<span class="display: block; min-height: 30px;">Pay with Card</span>
</button>
{% if not stripeModal %}
<div id="stripeModal" class="modal" style="color:black;" tabindex="-1" role="dialog" data-bs-backdrop="static">
{% if not c.AUTHORIZENET_LOGIN_ID %}
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body text-start jumbotron">
Expand All @@ -59,83 +65,7 @@
<div class="form-text">Payment description</div><div class="h5" id="chargeDesc"></div>
</div>
</div>
{% if c.AUTHORIZENET_LOGIN_ID %}
<form id="payment-form" class="d-none"
method="POST"
action="index">
<div class="row g-3">
<div class="col-12">
<label for="fullName" class="form-text">Name on card</label>
<input type="text" class="form-control" name="fullName" id="fullName"
autocomplete="name" autocorrect="off" value="{{ cc_full_name }}" />
</div>
</div>

<div class="row g-3">
<div class="col-12">
<label for="cardNumber" class="form-text">Card number</label>
<input type="text" class="form-control" name="cardNumber" id="cardNumber"
inputmode="numeric" autocomplete="cc-number" autocorrect="off" />
</div>
</div>
<div class="row g-3">
<div class="col-6">
<span class="form-text">Expires</span>
<div class="input-group">
<input type="text" maxlength="2" class="form-control" name="expMonth" id="expMonth" placeholder="MM"
inputmode="numeric" autocomplete="cc-exp-month" autocorrect="off" />
<label for="expMonth" class="visually-hidden">Two-digit credit or debit card expiration month</label>
<span class="input-group-text">/</span>
<label for="expYear" class="visually-hidden">Two-digit credit or debit card expiration year</label>
<input type="text" maxlength="2" class="form-control" name="expYear" id="expYear" placeholder="YY"
inputmode="numeric" autocomplete="cc-exp-year" autocorrect="off" />
</div>
</div>
<div class="col-6">
<label for="cardCode" class="form-text">Security code</label>
<input type="text" class="form-control" name="cardCode" id="cardCode" placeholder="CVC"
inputmode="numeric" autocomplete="cc-csc" autocorrect="off" />
</div>
</div>
<div class="row g-3">
<div class="col-12">
<label for="zip" class="form-text">Zip Code</label>
<input type="text" class="form-control" name="zip" id="zip"
autocomplete="cc-number" autocorrect="off" value="{{ cc_zip_code }}" />
</div>
</div>
<div class="row g-3 mt-2">
<div class="col-12">
<button class="btn btn-success">Submit Payment</button>
<button class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
</div>
</div>
</form>
<script type="text/javascript">
var forceNumbers = function() {
if (this.value) {
numberVal = this.value.replace(/\D/g,'');
this.value = numberVal;
}
}
$("#cardNumber").on("input", forceNumbers);
$("#expMonth").on("input", function() {
if (this.value.length >= 2) {
$("#expYear").focus()
} else {
forceNumbers();
}
});
$("#expYear").on("input", function() {
if (this.value.length >= 2) {
$("#cardCode").focus()
} else {
forceNumbers();
}
});
$("#cardCode").on("input", forceNumbers);
</script>
{% else %}

<div class="charge_desc" style="margin-bottom:10px;"></div>
<form action="/charge" method="post" id="payment-form" class="d-none">
<div class="form-row">
Expand All @@ -152,10 +82,10 @@
<div style="margin-top:10px;"><button class="btn btn-success">Submit Payment</button>
<button class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button></div>
</form>
{% endif %}
</div>
</div>
</div>
{% endif %}
</div>
<script type="text/javascript">
$('#stripeModal').detach().appendTo("body");
Expand Down Expand Up @@ -220,21 +150,45 @@
}
}

var loadJS = function(src, callback) {
$('script[src="' + src + '"]').remove();

var script = document.createElement( "script" )
script.type = "text/javascript";
script.src = src;
script.onload = function() {
callback();
};
document.getElementsByTagName( "head" )[0].appendChild( script );
}

{% if c.AUTHORIZENET_LOGIN_ID %}
let authnet_ref_id = '';
let authnet_amount = 0;
let authnet_email = '';
let authnet_desc = '';
let authnet_customer_id = '';
let authnet_success_url = '';
let authnet_cancel_url = '';

var collectAuthNetPayment = function (ref_id, email, desc, customer_id, success_url, cancel_url, amount) {
var form = $('#payment-form');
form.removeClass('d-none');
var authData = {
clientKey: "{{ c.AUTHORIZENET_PUBLIC_KEY }}",
apiLoginID: "{{ c.AUTHORIZENET_LOGIN_ID }}"
};
authnet_ref_id = ref_id;
authnet_amount = amount;
authnet_email = email;
authnet_desc = desc;
authnet_customer_id = customer_id;
authnet_success_url = success_url;
authnet_cancel_url = cancel_url;

stripeModal = new bootstrap.Modal($('#stripeModal'))
$('#authNetPayButton').attr("data-acceptUIFormBtnTxt", "Pay $" + (amount / 100).toFixed(2));

stripeModal.show();
hideMessageBox("cc-message-alert");
loadJS("https://js{{ 'test' if 'test' in c.AUTHORIZENET_ENDPOINT else '' }}.authorize.net/v3/AcceptUI.js", function() {
$('#authNetPayButton').trigger("click");
}
);
}

var handleAuthNetResponse = function (response) {
var handleAuthNetResponse = function (response) {
if (response.messages.resultCode === "Error") {
showErrorMessage(response.messages.message[0].text, "cc-message-alert")

Expand All @@ -248,45 +202,25 @@
}
} else {
$.post("../preregistration/submit_authnet_charge", {
ref_id: ref_id,
amount: amount,
email: email,
desc: desc,
customer_id: customer_id,
ref_id: authnet_ref_id,
amount: authnet_amount,
email: authnet_email,
desc: authnet_desc,
customer_id: authnet_customer_id,
token_desc: response.opaqueData.dataDescriptor,
token_val: response.opaqueData.dataValue,
csrf_token: csrf_token
},
function(result) {
if (result.error) {
showErrorMessage(result.error, "cc-message-alert");
showErrorMessage(result.error);
} else {
// The payment has been processed!
processSuccessUrl(success_url);
processSuccessUrl(authnet_success_url);
};
});
}
}

form.on('submit', function(event) {
event.preventDefault();
var cardData = {
fullName: $("#fullName").val(),
cardNumber: $("#cardNumber").val(),
month: $("#expMonth").val(),
year: $("#expYear").val(),
cardCode: $("#cardCode").val(),
zip: $("#zip").val()
};

var secureData = {
authData: authData,
cardData: cardData
};

Accept.dispatchData(secureData, handleAuthNetResponse);
});
}
{% else %}
var collectStripePayment = function (client_secret, stripe_id, success_url, cancel_url) {
var stripeModal = bootstrap.Modal.getOrCreateInstance($('#stripeModal'));
Expand Down

0 comments on commit 7a117b5

Please sign in to comment.