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.

45 lines
1.5 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. });