|
| 1 | +import Component from '@glimmer/component'; |
| 2 | +import { tracked } from '@glimmer/tracking'; |
| 3 | +import { inject as service } from '@ember/service'; |
| 4 | +import { action } from '@ember/object'; |
| 5 | + |
| 6 | +const DRIVER_COPY = { |
| 7 | + taler: { |
| 8 | + name: 'GNU Taler', |
| 9 | + icon: 'wallet', |
| 10 | + type: 'Wallet payment', |
| 11 | + description: 'Privacy-preserving wallet payments, QR checkout, webhook confirmation, refunds, and settlement verification.', |
| 12 | + }, |
| 13 | + stripe: { |
| 14 | + name: 'Stripe', |
| 15 | + icon: 'credit-card', |
| 16 | + type: 'Cards and wallets', |
| 17 | + description: 'Card and digital wallet processing with webhook confirmation and refund support.', |
| 18 | + }, |
| 19 | + cash: { |
| 20 | + name: 'Cash', |
| 21 | + icon: 'money-bill-wave', |
| 22 | + type: 'Manual payment', |
| 23 | + description: 'Record offline or in-person payments without external webhook provisioning.', |
| 24 | + }, |
| 25 | + qpay: { |
| 26 | + name: 'QPay', |
| 27 | + icon: 'qrcode', |
| 28 | + type: 'Regional payment', |
| 29 | + description: 'Regional gateway support for QR and local payment collection flows.', |
| 30 | + }, |
| 31 | +}; |
| 32 | + |
| 33 | +export default class GatewayHubComponent extends Component { |
| 34 | + @service gatewayActions; |
| 35 | + @tracked table; |
| 36 | + |
| 37 | + get gateways() { |
| 38 | + return Array.from(this.args.gateways ?? []); |
| 39 | + } |
| 40 | + |
| 41 | + get summary() { |
| 42 | + return this.args.summary?.summary ?? {}; |
| 43 | + } |
| 44 | + |
| 45 | + get drivers() { |
| 46 | + return Array.from(this.args.drivers ?? []); |
| 47 | + } |
| 48 | + |
| 49 | + get driverCards() { |
| 50 | + const configuredByDriver = new Map(); |
| 51 | + |
| 52 | + this.gateways.forEach((gateway) => { |
| 53 | + const list = configuredByDriver.get(gateway.driver) ?? []; |
| 54 | + list.push(gateway); |
| 55 | + configuredByDriver.set(gateway.driver, list); |
| 56 | + }); |
| 57 | + |
| 58 | + return ['taler', 'stripe', 'cash', 'qpay'].map((code) => { |
| 59 | + const manifest = this.drivers.find((driver) => driver.code === code) ?? {}; |
| 60 | + const copy = DRIVER_COPY[code]; |
| 61 | + const configured = configuredByDriver.get(code) ?? []; |
| 62 | + const active = configured.filter((gateway) => gateway.status === 'active'); |
| 63 | + |
| 64 | + return { |
| 65 | + code, |
| 66 | + name: manifest.name ?? copy.name, |
| 67 | + icon: copy.icon, |
| 68 | + type: copy.type, |
| 69 | + description: copy.description, |
| 70 | + capabilities: manifest.capabilities ?? [], |
| 71 | + configuredCount: configured.length, |
| 72 | + activeCount: active.length, |
| 73 | + primaryGateway: configured[0], |
| 74 | + connected: configured.length > 0, |
| 75 | + }; |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + get hasGatewayConnections() { |
| 80 | + return this.gateways.length > 0; |
| 81 | + } |
| 82 | + |
| 83 | + get warningCount() { |
| 84 | + return Number(this.summary.webhook_warnings ?? 0); |
| 85 | + } |
| 86 | + |
| 87 | + get statusTiles() { |
| 88 | + return [ |
| 89 | + { |
| 90 | + label: 'Active gateways', |
| 91 | + value: this.summary.active_gateways ?? 0, |
| 92 | + caption: 'Ready to collect payments', |
| 93 | + icon: 'plug', |
| 94 | + }, |
| 95 | + { |
| 96 | + label: 'Live ready', |
| 97 | + value: this.summary.live_gateways ?? 0, |
| 98 | + caption: 'Production connections', |
| 99 | + icon: 'bolt', |
| 100 | + }, |
| 101 | + { |
| 102 | + label: 'Webhook issues', |
| 103 | + value: this.warningCount, |
| 104 | + caption: this.warningCount > 0 ? 'Need provisioning review' : 'No open warnings', |
| 105 | + icon: 'link', |
| 106 | + }, |
| 107 | + { |
| 108 | + label: 'Sandbox', |
| 109 | + value: this.summary.sandbox_gateways ?? 0, |
| 110 | + caption: 'Testing connections', |
| 111 | + icon: 'flask', |
| 112 | + }, |
| 113 | + ]; |
| 114 | + } |
| 115 | + |
| 116 | + @action setupTable(table) { |
| 117 | + this.table = table; |
| 118 | + } |
| 119 | + |
| 120 | + @action refresh() { |
| 121 | + if (typeof this.args.refresh === 'function') { |
| 122 | + this.args.refresh(); |
| 123 | + } |
| 124 | + |
| 125 | + return this.gatewayActions.refresh(); |
| 126 | + } |
| 127 | + |
| 128 | + @action openDriver(driver) { |
| 129 | + if (driver.primaryGateway) { |
| 130 | + return this.gatewayActions.transition.view(driver.primaryGateway); |
| 131 | + } |
| 132 | + |
| 133 | + return this.gatewayActions.transition.create(); |
| 134 | + } |
| 135 | +} |
0 commit comments