@@ -57,6 +57,8 @@ class StripeCheckoutCustom extends StripeCheckout {
57
57
*/
58
58
public $ closedFunction ;
59
59
60
+ private static $ handlerRegistered = false ;
61
+
60
62
/**
61
63
* @see Init extension default
62
64
*/
@@ -92,11 +94,18 @@ private function registerScripts() {
92
94
93
95
$ view ->registerJsFile ($ this ->stripeJs , ['position ' => \yii \web \View::POS_END ]);
94
96
95
- $ js = "var handler = StripeCheckout.configure({
96
- key: ' " . Yii::$ app ->stripe ->publicKey . "',
97
- token: " . $ this ->tokenFunction . "
98
- }); " ;
99
- $ view ->registerJs ($ js );
97
+ if (!self ::$ handlerRegistered ) {
98
+ $ js = "var handler = StripeCheckout.configure({
99
+ key: ' " . Yii::$ app ->stripe ->publicKey . "'
100
+ }); " ;
101
+ $ view ->registerJs ($ js );
102
+ $ js = 'jQuery("window").on("popstate", function(e) {
103
+ handler.close();
104
+ }); ' ;
105
+ $ view ->registerJs ($ js );
106
+
107
+ self ::$ handlerRegistered = true ;
108
+ }
100
109
101
110
$ js = 'jQuery("# ' . $ this ->buttonOptions ['id ' ] . '").on("click", function(e) {
102
111
handler.open({
@@ -109,17 +118,14 @@ private function registerScripts() {
109
118
zipCode: " ' . $ this ->validateZipCode . '",
110
119
email: " ' . $ this ->userEmail . '",
111
120
allowRememberMe: " ' . $ this ->allowRemember . '",
121
+ token: ' . $ this ->tokenFunction . ',
112
122
opened: ' . $ this ->openedFunction . ',
113
- closed: ' . $ this ->closedFunction . ',
123
+ closed: ' . $ this ->closedFunction . '
114
124
});
115
125
e.preventDefault();
116
126
}); ' ;
117
127
$ view ->registerJs ($ js );
118
128
119
- $ js = 'jQuery("window").on("popstate", function(e) {
120
- handler.close();
121
- }); ' ;
122
- $ view ->registerJs ($ js );
123
129
}
124
130
125
131
/**
0 commit comments