Skip to content

Commit fb2d628

Browse files
uds5501abhinavk96
authored andcommitted
feat: add invoice download action (#3424)
1 parent e2c71f7 commit fb2d628

File tree

1 file changed

+24
-0
lines changed
  • app/controllers/event-invoice

1 file changed

+24
-0
lines changed

app/controllers/event-invoice/paid.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Controller from '@ember/controller';
2+
import { action } from '@ember/object';
3+
4+
export default class extends Controller {
5+
@action
6+
async downloadEventInvoice(eventName, orderId) {
7+
this.set('isLoading', true);
8+
try {
9+
const result = this.loader.downloadFile(`/events/invoices/${this.orderId}`);
10+
const anchor = document.createElement('a');
11+
anchor.style.display = 'none';
12+
anchor.href = URL.createObjectURL(new Blob([result], { type: 'application/pdf' }));
13+
anchor.download = `${eventName}-EventInvoice-${orderId}.pdf`;
14+
document.body.appendChild(anchor);
15+
anchor.click();
16+
this.notify.success(this.l10n.t('Here is your Event Invoice'));
17+
document.body.removeChild(anchor);
18+
} catch (e) {
19+
console.warn(e);
20+
this.notify.error(this.l10n.t('Unexpected error occurred.'));
21+
}
22+
this.set('isLoading', false);
23+
}
24+
}

0 commit comments

Comments
 (0)