23
23
</template >
24
24
25
25
<script >
26
- import qs from ' qs'
27
26
import config from ' config'
28
27
import Popup from ' components/Popup.vue'
29
28
import LoaderIcon from ' components/Loader.vue'
@@ -35,13 +34,15 @@ export default {
35
34
editable: { type: Boolean , default: undefined },
36
35
currency: { type: String , default: ' USD' },
37
36
label: { type: String , required: true },
37
+ successMessage: String ,
38
38
opReturn: String ,
39
39
outputs: { type: Array , default : () => [] },
40
40
clientIdentifier: String ,
41
41
buttonId: true ,
42
42
buttonData: true ,
43
43
type: { type: String , default: ' buy' },
44
- devMode: { type: Boolean , default: undefined }
44
+ devMode: { type: Boolean , default: undefined },
45
+ disabled: { type: Boolean , default: undefined }
45
46
},
46
47
47
48
data () {
@@ -51,64 +52,70 @@ export default {
51
52
size: {
52
53
width: ' 280px' ,
53
54
height: ' 50px'
54
- }
55
+ },
56
+ iframeSrc: config .iframeUrl .concat (' ?' , ' format=postmessage' )
55
57
}
56
58
},
57
59
58
60
mounted () {
59
- window .addEventListener (' message' , this .handleMessage , false );
61
+ window .addEventListener (' message' , this .handleMessage , false )
60
62
},
61
63
62
64
destroyed () {
63
- window .removeEventListener (' message' , this .handleMessage , false );
64
- },
65
-
66
- watch: {
67
- iframeSrc (val ) {
68
- this .loading = true ;
69
- }
65
+ window .removeEventListener (' message' , this .handleMessage , false )
70
66
},
71
67
72
68
computed: {
73
- iframeSrc () {
74
- return config .iframeUrl .concat (' ?' , qs .stringify (this .queryParams ));
75
- },
76
-
77
69
queryParams () {
78
70
return {
79
- to: this .to ,
80
- amt: this .amount ,
81
- edt: this .editable ,
82
- ccy: this .outputs .length ? undefined : this .currency ,
83
- lbl: this .label ,
84
- opd: this .opReturn ,
85
- os: this .outputs .length ? JSON .stringify (this .outputs ) : undefined ,
86
- cid: this .clientIdentifier ,
87
- bid: this .buttonId ,
88
- bdt: this .buttonData ,
89
- t: this .type ,
90
- dev: this .devMode
71
+ to: this .to ,
72
+ amt: this .amount ,
73
+ edt: this .editable ,
74
+ ccy: this .outputs .length ? undefined : this .currency ,
75
+ lbl: this .label ,
76
+ scsmsg: this .successMessage ,
77
+ opd: this .opReturn ,
78
+ os: this .outputs .length ? JSON .stringify (this .outputs ) : undefined ,
79
+ cid: this .clientIdentifier ,
80
+ bid: this .buttonId ,
81
+ bdt: this .buttonData ,
82
+ t: this .type ,
83
+ dev: this .devMode ,
84
+ dsbd: this .disabled
91
85
}
92
86
},
93
87
},
94
88
89
+ watch: {
90
+ queryParams (params ) {
91
+ this .postMessage (' attributes-updated' , params)
92
+ }
93
+ },
94
+
95
95
methods: {
96
96
loaded (e ) {
97
+ this .postMessage (' attributes-updated' , this .queryParams )
97
98
setTimeout (() => { this .loading = false }, 2000 )
98
99
},
99
100
101
+ postMessage (topic , payload ) {
102
+ this .$refs .iframe .contentWindow .postMessage ({
103
+ v1: { topic, payload }
104
+ }, config .iframeUrl )
105
+ },
106
+
100
107
handleMessage (e ) {
101
108
if ( this .$refs [' iframe' ] && e .source === this .$refs [' iframe' ].contentWindow ) {
102
109
const { error , size , payment , popup } = e .data ;
103
110
104
111
// Check valid iframe origin
105
112
if ( e .origin !== config .iframeOrigin ) {
106
- console .log (` vue-money-button: postMessage: wrong origin: ${ e .origin } should be ${ config .iframeOrigin } ` );
113
+ console .log (` vue-money-button: postMessage: wrong origin: ${ e .origin } should be ${ config .iframeOrigin } ` )
107
114
return
108
115
}
109
116
110
117
if (process .env .NODE_ENV === ' development' )
111
- console .log (' vue-money-button: Received message' , e .data );
118
+ console .log (' vue-money-button: Received message' , e .data )
112
119
113
120
// If popup
114
121
if ( popup ) {
0 commit comments