changed api

This commit is contained in:
sdarbinyan
2026-05-14 12:26:03 +04:00
parent c15a2317f8
commit f1f2ccc777
2 changed files with 30 additions and 12 deletions

View File

@@ -79,7 +79,8 @@
}
</div>
@if (validId()) {
@if (settingsLoaded()) {
@if (hasPartnerId() && validId()) {
<button class="pay-btn" type="button" (click)="pay()" [disabled]="!canPay()">
<span class="pay-btn__icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor"
@@ -100,6 +101,7 @@
{{ 'fastcheck.share_tg' | translate }}
</button>
}
}
</div>
<div class="card__footer">

View File

@@ -146,9 +146,13 @@ export class FastcheckPage {
const params = new URLSearchParams(window.location.search);
// ?id=<partnerId> — used by the "New" button URL; fallback to default id.
// hasPartnerId is true ONLY when a real ?id was provided AND it is not the
// default fallback. The Pay button is gated on this — without a real
// partner id we never call /settings and always show the Telegram button.
const idParam = params.get('id');
const isRealId = !!idParam && idParam !== this.defaultPartnerId;
this.partnerId.set(idParam ?? this.defaultPartnerId);
this.hasPartnerId.set(!!idParam);
this.hasPartnerId.set(isRealId);
// ?iid=xxxxxx-xxxxxx-xxxxxx — auto-fill and trigger lookup
const iidParam = params.get('iid') ?? '';
@@ -161,8 +165,16 @@ export class FastcheckPage {
if (digits.length === 18) this.lookupFastcheck(masked);
}
// Always call settings on each load — may return active check data to autofill.
// Call /settings on every load when we have a real partner id — it may
// return active check data to autofill, telegramID, and callbackurl.
// Without a real id we skip the request entirely: no Pay button can be
// shown anyway and we don't want a wasted call against the default id.
if (isRealId) {
this.loadSettings(!!created || !!iidParam);
} else {
this.settingsLoaded.set(true);
this.validId.set(false);
}
// Connectivity check — makes visible requests in DevTools and surfaces
// backend availability issues early.
@@ -264,17 +276,13 @@ export class FastcheckPage {
}
/**
* Pay button — redirect to the ready callback URL returned by /settings.
* Falls back to opening the legacy Telegram-accept popup if no URL is set.
* Pay button — run the standard Accept-Fastcheck flow (Telegram login +
* POST /fastcheck with code) and, on success, redirect the user to the
* callbackurl returned by /settings. If no callback was provided we keep
* the legacy return_url query-param behaviour via fireMerchantCallback().
*/
pay(): void {
if (!this.canPay()) return;
const url = this.callbackUrl();
if (url) {
window.location.href = url;
return;
}
// No callback was provided — keep the legacy Telegram-accept flow.
this.error.set('');
this.loginOnly.set(false);
this.openPopup();
@@ -452,6 +460,14 @@ export class FastcheckPage {
}
private fireMerchantCallback(): void {
// Prefer the callbackurl returned by POST /fastcheck/settings/{id}; this
// is the merchant URL the partner expects us to land on after pay.
const cb = this.callbackUrl();
if (cb) {
setTimeout(() => { window.location.href = cb; }, 1500);
return;
}
// Legacy fallback: ?return_url=... query param.
const params = new URLSearchParams(window.location.search);
const returnUrl = params.get('return_url');
if (returnUrl) {