2020-03-02 08:06:54 +03:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
config: service(),
|
|
|
|
ghostPaths: service(),
|
|
|
|
ajax: service(),
|
|
|
|
|
|
|
|
billingEndpoint: computed.reads('config.billingUrl'),
|
|
|
|
|
|
|
|
didRender() {
|
|
|
|
let iframe = this.element.querySelector('#billing-frame');
|
|
|
|
window.addEventListener('message', (event) => {
|
|
|
|
if (event && event.data && event.data.request === 'token') {
|
2020-03-12 15:15:54 +03:00
|
|
|
const ghostIdentityUrl = this.get('ghostPaths.url').api('identities');
|
2020-03-02 08:06:54 +03:00
|
|
|
|
2020-03-12 15:15:54 +03:00
|
|
|
this.ajax.request(ghostIdentityUrl).then((response) => {
|
|
|
|
const token = response && response.identities && response.identities[0] && response.identities[0].token;
|
2020-03-02 08:06:54 +03:00
|
|
|
iframe.contentWindow.postMessage({
|
|
|
|
request: 'token',
|
|
|
|
response: token
|
|
|
|
}, '*');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|