embeds.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. function BxStripeConnectEmbeds(oOptions) {
  2. this._sActionsUri = oOptions.sActionUri;
  3. this._sActionsUrl = oOptions.sActionUrl;
  4. this._sObjName = oOptions.sObjName == undefined ? 'oStripeConnectEmbeds' : oOptions.sObjName;
  5. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'slide' : oOptions.sAnimationEffect;
  6. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  7. this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
  8. this._sPublicKey = oOptions.sPublicKey;
  9. this._iProfileId = oOptions.iProfileId;
  10. this._oStripeConnect = null;
  11. this.init();
  12. }
  13. BxStripeConnectEmbeds.prototype.init = function() {
  14. var $this = this;
  15. window.StripeConnect = window.StripeConnect || {};
  16. StripeConnect.onLoad = () => {
  17. $this._oStripeConnect = StripeConnect.init({
  18. publishableKey: $this._sPublicKey,
  19. fetchClientSecret: function() {
  20. var sSecret = '';
  21. $.ajax({
  22. url: $this._sActionsUrl + 'account_session_create/' + $this._iProfileId,
  23. async: false,
  24. dataType: 'json',
  25. success: function (oData) {
  26. if(parseInt(oData.code) != 0)
  27. return;
  28. sSecret = oData.secret
  29. }
  30. });
  31. return sSecret;
  32. }
  33. });
  34. };
  35. };
  36. BxStripeConnectEmbeds.prototype.load = function(sEmbed) {
  37. var $this = this;
  38. var oContainer = $('#' + this._aHtmlIds[sEmbed]);
  39. this.loadingInContainer(oContainer, true);
  40. var fCreate = function() {
  41. if(!$this._oStripeConnect) {
  42. setTimeout(fCreate, 1000);
  43. return;
  44. }
  45. oContainer.html($this._oStripeConnect.create(sEmbed));
  46. };
  47. $(document).ready(fCreate);
  48. };
  49. BxStripeConnectEmbeds.prototype.loadingInButton = function(e, bShow) {
  50. if($(e).length)
  51. bx_loading_btn($(e), bShow);
  52. else
  53. bx_loading($('body'), bShow);
  54. };
  55. BxStripeConnectEmbeds.prototype.loadingInBlock = function(e, bShow) {
  56. var oParent = $(e).length ? $(e).parents('.bx-db-container:first') : $('body');
  57. bx_loading(oParent, bShow);
  58. };
  59. BxStripeConnectEmbeds.prototype.loadingInContainer = function(e, bShow) {
  60. var oContainer = $(e).length ? $(e) : $('body');
  61. bx_loading(oContainer, bShow);
  62. };