stripe.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup Payment Payment
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. function BxPaymentProviderStripe(oOptions) {
  11. this.init(oOptions);
  12. }
  13. BxPaymentProviderStripe.prototype = new BxPaymentMain();
  14. BxPaymentProviderStripe.prototype.init = function(oOptions) {
  15. this._sProvider = oOptions.sProvider;
  16. this._sActionsUrl = oOptions.sActionUrl;
  17. this._sObjName = oOptions.sObjName == undefined ? 'oPaymentProviderStripe' : oOptions.sObjName;
  18. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
  19. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  20. this._oOptions = oOptions;
  21. this._rHandler = StripeCheckout.configure({
  22. key: oOptions.sPublicKey,
  23. name: oOptions.sVendorName,
  24. amount: oOptions.iAmount == undefined ? '' : oOptions.iAmount,
  25. currency: oOptions.sVendorCurrency,
  26. image: oOptions.sVendorIcon,
  27. locale: 'auto',
  28. email: oOptions.sClientEmail,
  29. description: oOptions.sItemTitle == undefined ? '' : oOptions.sItemTitle
  30. });
  31. //--- For Single payment
  32. this._sObjNameGrid = oOptions.sObjNameGrid;
  33. //--- For Recurring payment
  34. this._sObjNameCart = oOptions.sObjNameCart;
  35. this._iSellerId = oOptions.iSellerId;
  36. this._iModuleId = oOptions.iModuleId;
  37. this._iItemId = oOptions.iItemId;
  38. this._iItemCount = oOptions.iItemCount;
  39. this._sRedirect = oOptions.sRedirect;
  40. this._sCustom = oOptions.sCustom;
  41. };
  42. BxPaymentProviderStripe.prototype.changeAmount = function (iAmount) {
  43. this._rHandler = StripeCheckout.configure({
  44. key: this._oOptions.sPublicKey,
  45. name: this._oOptions.sVendorName,
  46. amount: iAmount,
  47. currency: this._oOptions.sVendorCurrency,
  48. image: this._oOptions.sVendorIcon,
  49. locale: 'auto',
  50. email: this._oOptions.sClientEmail,
  51. description: this._oOptions.sItemTitle == undefined ? '' : this._oOptions.sItemTitle
  52. });
  53. }
  54. BxPaymentProviderStripe.prototype.checkout = function(oLink) {
  55. oLink = jQuery(oLink);
  56. if(oLink.hasClass('bx-btn-disabled'))
  57. return;
  58. oLink.toggleClass('bx-btn-disabled');
  59. var $this = this;
  60. this._rHandler.open({
  61. token: function(token) {
  62. glGrids[$this._sObjNameGrid]._oQueryAppend['provider'] = $this._sProvider;
  63. glGrids[$this._sObjNameGrid]._oQueryAppend['token'] = token.id;
  64. glGrids[$this._sObjNameGrid].actionWithSelected('', 'checkout', {}, '', false, false);
  65. },
  66. closed: function() {
  67. oLink.toggleClass('bx-btn-disabled');
  68. }
  69. });
  70. };
  71. BxPaymentProviderStripe.prototype.subscribe = function(oLink) {
  72. var $this = this;
  73. var oDate = new Date();
  74. oLink = jQuery(oLink);
  75. if(oLink.hasClass('bx-btn-disabled'))
  76. return;
  77. oLink.addClass('bx-btn-disabled');
  78. this._rHandler.open({
  79. token: function(token) {
  80. $this.loadingInPopup(oLink, true);
  81. var oParams = {
  82. seller_id: $this._iSellerId,
  83. seller_provider: $this._sProvider,
  84. module_id: $this._iModuleId,
  85. item_id: $this._iItemId,
  86. item_count: $this._iItemCount,
  87. redirect: $this._sRedirect,
  88. custom: $this._sCustom,
  89. token: token.id,
  90. _t: oDate.getTime()
  91. };
  92. $.post(
  93. $this._sActionsUrl + 'subscribe_json/',
  94. oParams,
  95. function(oData){
  96. $this.loadingInPopup(oLink, true);
  97. processJsonData(oData);
  98. },
  99. 'json'
  100. );
  101. },
  102. closed: function() {
  103. oLink.removeClass('bx-btn-disabled');
  104. }
  105. });
  106. };
  107. /** @} */