Browse Source

Notify user about first charge, show "Pricing" in top nav again.

pull/20/head
Pēteris Caune 9 years ago
parent
commit
2f0e6b5672
5 changed files with 26 additions and 7 deletions
  1. +0
    -2
      hc/payments/models.py
  2. +10
    -1
      hc/payments/views.py
  3. +4
    -0
      static/js/pricing.js
  4. +1
    -1
      templates/base.html
  5. +11
    -3
      templates/payments/pricing.html

+ 0
- 2
hc/payments/models.py View File

@ -11,14 +11,12 @@ class Subscription(models.Model):
def _get_braintree_sub(self): def _get_braintree_sub(self):
if not hasattr(self, "_sub"): if not hasattr(self, "_sub"):
print("getting subscription over network")
self._sub = braintree.Subscription.find(self.subscription_id) self._sub = braintree.Subscription.find(self.subscription_id)
return self._sub return self._sub
def _get_braintree_payment_method(self): def _get_braintree_payment_method(self):
if not hasattr(self, "_pm"): if not hasattr(self, "_pm"):
print("getting payment method over network")
self._pm = braintree.PaymentMethod.find(self.payment_method_token) self._pm = braintree.PaymentMethod.find(self.payment_method_token)
return self._pm return self._pm


+ 10
- 1
hc/payments/views.py View File

@ -27,9 +27,15 @@ def pricing(request):
sub = Subscription(user=request.user) sub = Subscription(user=request.user)
sub.save() sub.save()
first_charge = False
if "first_charge" in request.session:
first_charge = True
del request.session["first_charge"]
ctx = { ctx = {
"page": "pricing", "page": "pricing",
"sub": sub
"sub": sub,
"first_charge": first_charge
} }
return render(request, "payments/pricing.html", ctx) return render(request, "payments/pricing.html", ctx)
@ -38,6 +44,8 @@ def pricing(request):
def log_and_bail(request, result): def log_and_bail(request, result):
for error in result.errors.deep_errors: for error in result.errors.deep_errors:
messages.error(request, error.message) messages.error(request, error.message)
else:
messages.error(request, result.message)
return redirect("hc-pricing") return redirect("hc-pricing")
@ -83,6 +91,7 @@ def create_plan(request):
sub.subscription_id = result.subscription.id sub.subscription_id = result.subscription.id
sub.save() sub.save()
request.session["first_charge"] = True
return redirect("hc-pricing") return redirect("hc-pricing")


+ 4
- 0
static/js/pricing.js View File

@ -53,4 +53,8 @@ $(function () {
}) })
}); });
$("#payment-method-cancel").click(function() {
location.reload();
});
}); });

+ 1
- 1
templates/base.html View File

@ -81,7 +81,7 @@
{% endif %} {% endif %}
{% if USE_PAYMENTS and False %}
{% if USE_PAYMENTS %}
<li {% if page == 'pricing' %} class="active" {% endif %}> <li {% if page == 'pricing' %} class="active" {% endif %}>
<a href="{% url 'hc-pricing' %}">Pricing</a> <a href="{% url 'hc-pricing' %}">Pricing</a>
</li> </li>


+ 11
- 3
templates/payments/pricing.html View File

@ -12,7 +12,7 @@
<div class="alert alert-danger"> <div class="alert alert-danger">
<p> <p>
<strong>We're sorry!</strong> There was a problem setting <strong>We're sorry!</strong> There was a problem setting
up the subscription. Response from payment processor:</p>
up the subscription. Response from payment gateway:</p>
{% for message in messages %} {% for message in messages %}
<p class="error-message">{{ message }}</p> <p class="error-message">{{ message }}</p>
@ -25,7 +25,11 @@
<div class="col-md-12"> <div class="col-md-12">
<div id="subscription-status" class="jumbotron"> <div id="subscription-status" class="jumbotron">
<p> <p>
{% if first_charge %}
You just paid <strong>${{ sub.price }}</strong>
{% else %}
You are currently paying <strong>${{ sub.price }}/month</strong> You are currently paying <strong>${{ sub.price }}/month</strong>
{% endif %}
{% if sub.pm_is_credit_card %} {% if sub.pm_is_credit_card %}
using {{ sub.card_type }} card using {{ sub.card_type }} card
@ -178,8 +182,12 @@
<div id="payment-form"></div> <div id="payment-form"></div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Set Up Subscription</button>
<button id="payment-method-cancel" type="button" class="btn btn-default">
Cancel
</button>
<button type="submit" class="btn btn-primary">
Set Up Subscription
</button>
</div> </div>
</div> </div>
</form> </form>


Loading…
Cancel
Save