fix(native): Android offers TREK Cloud while orders are closed and says a refused purchase is refunded

The licence testers of the internal test buy from a release build, so the
plan screen no longer hides the purchase on Android before the opening.
Their purchases are Play test purchases, which the cloud serves. A real
purchase made before the opening is refused with ordering-closed and never
acknowledged, so Google Play refunds it after three days; the claim and the
restore now say that instead of a general error. The app still acknowledges
a purchase only after a redeem that returned an instance. iOS is unchanged.
This commit is contained in:
Maurice
2026-11-08 02:31:13 +00:00
parent 796f39fe1f
commit dedbf16f03
31 changed files with 123 additions and 7 deletions
+15 -7
View File
@@ -5,6 +5,7 @@ import { StatusBar, Style } from '@capacitor/status-bar';
import logoUrl from '../public/icons/icon-white.svg';
import logoBlack from '../public/logo-dark.svg'; // #000 wordmark, for light backgrounds
import logoWhite from '../public/logo-light.svg'; // #fff wordmark, for dark backgrounds
import { opensSoon, refundedBeforeOpening } from '../src/native/cloudOrders';
import { fakeIapClient, getIapClient, productIdFor, type Purchase } from '../src/native/iap';
import { CLOUD_TERMS_URL, CLOUD_URL, PRIVACY_URL, SERVER_DOCS_URL, STORE_TERMS_URL } from '../src/native/links';
import { probeDemo, probeServer, type ProbeFailure, type ProbeGet } from '../src/native/serverAddress';
@@ -429,12 +430,14 @@ function offerFor(offer: Offer, plan: CloudPlan, interval: 'month' | 'year'): {
async function loadOffer(list: CloudPlans): Promise<Offer> {
const available = await iapReady;
// Closed: a store purchase would be refused at the cloud, so only a test build may buy.
const opensSoon = available && list.closed && !(await iap.isSandbox().catch(() => false));
const canBuy = available && !opensSoon;
if (!canBuy || iap === fakeIapClient) return { canBuy, storePrices: null, opensSoon };
// Closed: a real purchase is refused at the cloud, so only a test build may buy on iOS;
// Android keeps the button for the licence testers (see cloudOrders.ts).
const sandbox = list.closed && !onPlay ? await iap.isSandbox().catch(() => false) : false;
const soon = opensSoon({ available, closed: list.closed, sandbox, onPlay });
const canBuy = available && !soon;
if (!canBuy || iap === fakeIapClient) return { canBuy, storePrices: null, opensSoon: soon };
const ids = list.plans.flatMap((p) => [productIdFor(p.id, 'month'), productIdFor(p.id, 'year')]);
return { canBuy, storePrices: await iap.prices(ids), opensSoon };
return { canBuy, storePrices: await iap.prices(ids), opensSoon: soon };
}
function planCard(plan: CloudPlan, interval: 'month' | 'year', offer: Offer): HTMLElement {
@@ -526,7 +529,10 @@ function planFooter(offer: Offer, plans: CloudPlan[]): Node[] {
void notify(NotificationType.Error);
restore.disabled = false;
status.className = 'hint bad';
status.textContent = t('native.plans.restoreFailed');
// Bought before the opening: refused, unacknowledged, and refunded by Google Play.
status.textContent = refundedBeforeOpening(redeemed.code, onPlay)
? t('native.claim.closedRefund')
: t('native.plans.restoreFailed');
});
// A payment that was pending (cash, some carrier billing) and has cleared since:
@@ -838,7 +844,9 @@ function showClaim(
slugNote.textContent = t('native.claim.taken');
slugNote.className = 'hint bad';
} else {
error.textContent = t('native.claim.redeemFailed');
error.textContent = refundedBeforeOpening(redeemed.code, onPlay)
? t('native.claim.closedRefund')
: t('native.claim.redeemFailed');
}
});
+35
View File
@@ -0,0 +1,35 @@
import { describe, expect, it } from 'vitest';
import { opensSoon, refundedBeforeOpening } from './cloudOrders';
describe('opensSoon', () => {
const base = { available: true, closed: true, sandbox: false, onPlay: false };
it('FE-NATIVE-ORDERS-001: closed orders hide the purchase from an App Store build', () => {
expect(opensSoon(base)).toBe(true);
});
it('FE-NATIVE-ORDERS-002: a TestFlight build may buy while orders are closed', () => {
expect(opensSoon({ ...base, sandbox: true })).toBe(false);
});
it('FE-NATIVE-ORDERS-003: an Android release build keeps the purchase while orders are closed', () => {
expect(opensSoon({ ...base, onPlay: true })).toBe(false);
});
it('FE-NATIVE-ORDERS-004: open orders and a binary without a store never say "opens soon"', () => {
expect(opensSoon({ ...base, closed: false })).toBe(false);
expect(opensSoon({ ...base, available: false })).toBe(false);
});
});
describe('refundedBeforeOpening', () => {
it('FE-NATIVE-ORDERS-005: a purchase refused as ordering-closed on Android is the refunded one', () => {
expect(refundedBeforeOpening('ordering-closed', true)).toBe(true);
});
it('FE-NATIVE-ORDERS-006: other refusals, and ordering-closed on iOS, keep the general message', () => {
expect(refundedBeforeOpening('ordering-closed', false)).toBe(false);
expect(refundedBeforeOpening('redeem-failed', true)).toBe(false);
expect(refundedBeforeOpening(undefined, true)).toBe(false);
});
});
+26
View File
@@ -0,0 +1,26 @@
/**
* What the app's plan screens do while TREK Cloud's orders are closed, apart
* from the screens themselves so it can be tested.
*
* On iOS only a test build (TestFlight, App Review) may buy then: the App Store
* charges it nothing and the cloud serves it. On Android the button shows in
* every build, so the licence testers of the internal test can buy from a
* release build; their purchases are Play test purchases, which the cloud
* serves. A real purchase made before the opening is refused at the cloud with
* `ordering-closed` and never acknowledged, so Google Play refunds it after
* three days, and the app says so instead of showing a general error.
*/
/** Whether the plans show without a way to buy: orders are closed and this build may not buy before the opening. */
export function opensSoon(opts: { available: boolean; closed: boolean; sandbox: boolean; onPlay: boolean }): boolean {
return opts.available && opts.closed && !opts.sandbox && !opts.onPlay;
}
/**
* Whether the cloud refused a purchase because it came before the opening, on
* Android, where Google Play then refunds it: the app says so rather than
* showing a general error. On iOS no real purchase gets this far.
*/
export function refundedBeforeOpening(code: string | undefined, onPlay: boolean): boolean {
return onPlay && code === 'ordering-closed';
}