-
Notifications
You must be signed in to change notification settings - Fork 151
/
stripe_v3.js
100 lines (83 loc) · 2.97 KB
/
stripe_v3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup Payment Payment
* @ingroup UnaModules
*
* @{
*/
function BxPaymentProviderStripeV3(oOptions) {
this.init(oOptions);
}
BxPaymentProviderStripeV3.prototype = new BxPaymentMain();
BxPaymentProviderStripeV3.prototype.init = function(oOptions) {
this._sProvider = oOptions.sProvider;
this._sActionsUrl = oOptions.sActionUrl;
this._sObjName = oOptions.sObjName == undefined ? 'oPaymentProviderStripeV3' : oOptions.sObjName;
this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
//--- For Single payment
this._sObjNameGrid = oOptions.sObjNameGrid;
//--- For Recurring payment
this._sObjNameCart = oOptions.sObjNameCart;
this._iSellerId = oOptions.iSellerId;
this._iModuleId = oOptions.iModuleId;
this._iItemId = oOptions.iItemId;
this._iItemCount = oOptions.iItemCount;
this._sRedirect = oOptions.sRedirect;
this._sCustom = oOptions.sCustom;
var $this = this;
if(window.Stripe === undefined) {
$.getScript('https://js.stripe.com/v3/', function() {
$this._rHandler = Stripe(oOptions.sPublicKey);
});
}
else
this._rHandler = Stripe(oOptions.sPublicKey);
};
BxPaymentProviderStripeV3.prototype.onCartCheckout = function(oData) {
this._rHandler.redirectToCheckout({
sessionId: oData.session_id
}).then(function (oResult) {
if(oResult.error)
bx_alert(oResult.error.message);
}).catch(function(oError) {
console.error('Error:', oError);
});
};
BxPaymentProviderStripeV3.prototype.subscribe = function(oLink) {
var oDate = new Date();
oLink = jQuery(oLink);
if(oLink.hasClass('bx-btn-disabled'))
return;
oLink.addClass('bx-btn-disabled');
this.loadingInPopup(oLink, true);
var aParams = {
seller_id: this._iSellerId,
seller_provider: this._sProvider,
module_id: this._iModuleId,
item_id: this._iItemId,
item_count: this._iItemCount,
redirect: this._sRedirect,
custom: this._sCustom,
_t: oDate.getTime()
};
$.post(this._sActionsUrl + 'call/' + this._sProvider + '/get_session_recurring/' + this._iSellerId + '/', aParams, function(oData) {
if(oData && oData.code != undefined && parseInt(oData.code) == 0)
oData.params = aParams;
oLink.removeClass('bx-btn-disabled');
processJsonData(oData);
}, 'json');
};
BxPaymentProviderStripeV3.prototype.onSubscribe = function(oData) {
this._rHandler.redirectToCheckout({
sessionId: oData.session_id
}).then(function (oResult) {
if(oResult.error)
bx_alert(oResult.error.message);
}).catch(function(oError) {
console.error('Error:', oError);
});
};
/** @} */