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.

115 lines
3.7 KiB

  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. $("#update-payment-method").hover(requestClientToken);
  24. $("#update-payment-method").click(function() {
  25. requestClientToken();
  26. $("#payment-form").attr("action", this.dataset.action);
  27. $("#payment-form-submit").text("Update Payment Method");
  28. $("#payment-method-modal").modal("show");
  29. });
  30. $("#billing-history").load( "/accounts/profile/billing/history/" );
  31. $("#billing-address").load( "/accounts/profile/billing/address/", function() {
  32. $("#billing-address input").each(function(idx, obj) {
  33. $("#" + obj.name).val(obj.value);
  34. });
  35. });
  36. $("#payment-method").load( "/accounts/profile/billing/payment_method/", function() {
  37. $("#next-billing-date").text($("#nbd").val());
  38. });
  39. $("#billing-periods input").click(updateChangePlanForm);
  40. $("#plan-hobbyist").click(function() {
  41. $(".plan").removeClass("selected");
  42. $("#plan-hobbyist").addClass("selected");
  43. updateChangePlanForm();
  44. });
  45. $("#plan-business").click(function() {
  46. $(".plan").removeClass("selected");
  47. $("#plan-business").addClass("selected");
  48. updateChangePlanForm();
  49. });
  50. $("#plan-business-plus").click(function() {
  51. $(".plan").removeClass("selected");
  52. $("#plan-business-plus").addClass("selected");
  53. updateChangePlanForm();
  54. });
  55. function updateChangePlanForm() {
  56. var planId = $("#old-plan-id").val();
  57. // "Monthly" is selected: dispplay monthly prices
  58. if ($("#billing-monthly").is(":checked")) {
  59. var period = "monthly";
  60. $("#business-price").text("$20");
  61. $("#business-plus-price").text("$80");
  62. }
  63. // "Annual" is selected: dispplay annual prices
  64. if ($("#billing-annual").is(":checked")) {
  65. var period = "annual";
  66. $("#business-price").text("$16");
  67. $("#business-plus-price").text("$64");
  68. }
  69. // "Hobbyist" is selected, set planId
  70. if ($("#plan-hobbyist").hasClass("selected")) {
  71. planId = "";
  72. }
  73. // "Business" is selected, set planId
  74. if ($("#plan-business").hasClass("selected")) {
  75. planId = period == "monthly" ? "P20" : "Y192";
  76. }
  77. // "Business Plus" is selected, set planId
  78. if ($("#plan-business-plus").hasClass("selected")) {
  79. planId = period == "monthly" ? "P80" : "Y768";
  80. }
  81. $("#plan-id").val(planId);
  82. if (planId == $("#old-plan-id").val()) {
  83. $("#change-plan-btn")
  84. .attr("disabled", "disabled")
  85. .text("Change Billing Plan");
  86. } else {
  87. var caption = "Change Billing Plan";
  88. if (planId) {
  89. caption += " And Pay $" + planId.substr(1) + " Now";
  90. }
  91. $("#change-plan-btn").removeAttr("disabled").text(caption);
  92. }
  93. }
  94. updateChangePlanForm();
  95. });