Created
January 8, 2014 11:32
-
-
Save tatey/8315517 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (typeof window.EDH === 'undefined') { | |
| window.EDH = {}; | |
| } | |
| if (typeof window.EDH.Donation === 'undefined') { | |
| window.EDH.Donation = {}; | |
| } | |
| var Donation = window.EDH.Donation; | |
| jQuery(function($) { | |
| braintree.onSubmitEncryptForm($form, function(event) { | |
| disableSubmitButton(true); | |
| event.preventDefault(); | |
| Donation.MakePayment.make($form.serialize()) | |
| .done(function(status) { | |
| window.location = status.thankYouURL; | |
| }) | |
| .fail(function(status) { | |
| // update form | |
| }); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| var Payment = window.EDH.Donation.Payment, | |
| Poll = window.EDH.Donation.Poll; | |
| var MakePayment = { | |
| make: function(props) { | |
| var payment = new Payment(props), | |
| poll = new Poll(); | |
| payment.save() | |
| .done(function() { | |
| return poll.ready(payment.getPollURL()); | |
| }); | |
| } | |
| }; | |
| })(); | |
| MakePayment.make(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| var Payment = function(props) { | |
| this.props = {}; | |
| this.props.url = '<%= asset_url %>'; | |
| var prop; | |
| for (prop in props) { | |
| this.props = [prop] = props[prop]; | |
| } | |
| return this; | |
| }; | |
| Payment.prototype.save = function() { | |
| var deferred = new $.Deferred(); | |
| var _this = this; | |
| $.post(this.getURL(), this.props, {dataType: 'json'}) | |
| .done(function(data) { | |
| _this.props = data; | |
| deferred.resolve({thankYouURL: _this.props.thank_you_url}); | |
| }); | |
| return deferred; | |
| }; | |
| Payment.prototype.getURL = function() { | |
| var retry_order_url = this.props.retry_order_url; | |
| if (retry_order_url) { | |
| return retry_order_url; | |
| } else { | |
| return this.url; | |
| } | |
| }; | |
| Payment.prototype.getPollURL = function() { | |
| return this.props.poll_url; | |
| }; | |
| window.EDH.Payment = Payment; | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| var Poll = function(props) { | |
| }; | |
| Poll.prototype.ready = function(url) { | |
| var deferred = new $.Deferred(); | |
| $.get(url, 'json') | |
| .done(function(data) { | |
| if (data.state === 'payment_successful') { | |
| deferred.resolve(); | |
| } else { | |
| deferred.reject(); | |
| } | |
| }) | |
| .fail(function() { | |
| // TODO | |
| }); | |
| return deferred; | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment