You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.7 KiB

9 years ago
  1. $(function () {
  2. var clientTokenRequested = false;
  3. function requestClientToken() {
  4. if (!clientTokenRequested) {
  5. clientTokenRequested = true;
  6. $.getJSON("/pricing/get_client_token/", setupDropin);
  7. }
  8. }
  9. function setupDropin(data) {
  10. braintree.dropin.create({
  11. authorization: data.client_token,
  12. container: "#dropin",
  13. paypal: { flow: 'vault' }
  14. }, function(createErr, instance) {
  15. $("#payment-form-submit").click(function() {
  16. instance.requestPaymentMethod(function (requestPaymentMethodErr, payload) {
  17. $("#pmm-nonce").val(payload.nonce);
  18. $("#payment-form").submit();
  19. });
  20. }).prop("disabled", false);
  21. });
  22. }
  23. $(".btn-create-payment-method").hover(requestClientToken);
  24. $(".btn-update-payment-method").hover(requestClientToken);
  25. $(".btn-create-payment-method").click(function() {
  26. requestClientToken();
  27. $("#plan_id").val(this.dataset.planId);
  28. $("#payment-form").attr("action", this.dataset.action);
  29. $("#payment-form-submit").text("Set Up Subscription and Pay $" + this.dataset.planPay);
  30. $("#payment-method-modal").modal("show");
  31. });
  32. $(".btn-update-payment-method").click(function() {
  33. requestClientToken();
  34. $("#payment-form").attr("action", this.dataset.action);
  35. $("#payment-form-submit").text("Update Payment Method");
  36. $("#payment-method-modal").modal("show");
  37. });
  38. $("#period-controls :input").change(function() {
  39. $("#monthly").toggleClass("hide", this.value != "monthly");
  40. $("#annual").toggleClass("hide", this.value != "annual");
  41. });
  42. });