1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/components/gh-billing-iframe.js
Nazar Gargol f70e1b1e29 Added billing "update" CTA button
no issue

- Added billing update button to navigation menu. Ghost-Admin communicates with billing iframe and displays this button based on the plan data that iframe returns
- Ghost-Admin communicates with an iframe using same mechanism as with token exchange - throu `window.postMessage` API
2020-04-21 18:54:29 +12:00

26 lines
945 B
JavaScript

import Component from '@ember/component';
import {inject as service} from '@ember/service';
export default Component.extend({
billing: service(),
config: service(),
ghostPaths: service(),
ajax: service(),
didRender() {
let iframe = this.element.querySelector('#billing-frame');
window.addEventListener('message', (event) => {
if (event && event.data && event.data.request === 'token') {
const ghostIdentityUrl = this.get('ghostPaths.url').api('identities');
this.ajax.request(ghostIdentityUrl).then((response) => {
const token = response && response.identities && response.identities[0] && response.identities[0].token;
iframe.contentWindow.postMessage({
request: 'token',
response: token
}, '*');
});
}
});
}
});