tip -> reward
This commit is contained in:
parent
84d4e68ab7
commit
183aed4ba5
@ -159,8 +159,8 @@ test("taler refund uri parsing with instance", (t) => {
|
||||
t.is(r1.merchantBaseUrl, "https://merchant.example.com/instances/myinst/");
|
||||
});
|
||||
|
||||
test("taler tip pickup uri", (t) => {
|
||||
const url1 = "taler://tip/merchant.example.com/tipid";
|
||||
test("taler reward pickup uri", (t) => {
|
||||
const url1 = "taler://reward/merchant.example.com/tipid";
|
||||
const r1 = parseRewardUri(url1);
|
||||
if (!r1) {
|
||||
t.fail();
|
||||
@ -169,26 +169,26 @@ test("taler tip pickup uri", (t) => {
|
||||
t.is(r1.merchantBaseUrl, "https://merchant.example.com/");
|
||||
});
|
||||
|
||||
test("taler tip pickup uri with instance", (t) => {
|
||||
const url1 = "taler://tip/merchant.example.com/instances/tipm/tipid";
|
||||
test("taler reward pickup uri with instance", (t) => {
|
||||
const url1 = "taler://reward/merchant.example.com/instances/tipm/tipid";
|
||||
const r1 = parseRewardUri(url1);
|
||||
if (!r1) {
|
||||
t.fail();
|
||||
return;
|
||||
}
|
||||
t.is(r1.merchantBaseUrl, "https://merchant.example.com/instances/tipm/");
|
||||
t.is(r1.merchantTipId, "tipid");
|
||||
t.is(r1.merchantRewardId, "tipid");
|
||||
});
|
||||
|
||||
test("taler tip pickup uri with instance and prefix", (t) => {
|
||||
const url1 = "taler://tip/merchant.example.com/my/pfx/tipm/tipid";
|
||||
test("taler reward pickup uri with instance and prefix", (t) => {
|
||||
const url1 = "taler://reward/merchant.example.com/my/pfx/tipm/tipid";
|
||||
const r1 = parseRewardUri(url1);
|
||||
if (!r1) {
|
||||
t.fail();
|
||||
return;
|
||||
}
|
||||
t.is(r1.merchantBaseUrl, "https://merchant.example.com/my/pfx/tipm/");
|
||||
t.is(r1.merchantTipId, "tipid");
|
||||
t.is(r1.merchantRewardId, "tipid");
|
||||
});
|
||||
|
||||
test("taler peer to peer push URI", (t) => {
|
||||
|
@ -63,7 +63,7 @@ export interface RefundUriResult {
|
||||
export interface RewardUriResult {
|
||||
type: TalerUriAction.Reward;
|
||||
merchantBaseUrl: string;
|
||||
merchantTipId: string;
|
||||
merchantRewardId: string;
|
||||
}
|
||||
|
||||
export interface ExchangeUri {
|
||||
@ -408,7 +408,7 @@ export function parseRewardUri(s: string): RewardUriResult | undefined {
|
||||
return undefined;
|
||||
}
|
||||
const host = parts[0].toLowerCase();
|
||||
const tipId = parts[parts.length - 1];
|
||||
const rewardId = parts[parts.length - 1];
|
||||
const pathSegments = parts.slice(1, parts.length - 1);
|
||||
const hostAndSegments = [host, ...pathSegments].join("/");
|
||||
const merchantBaseUrl = canonicalizeBaseUrl(
|
||||
@ -418,7 +418,7 @@ export function parseRewardUri(s: string): RewardUriResult | undefined {
|
||||
return {
|
||||
type: TalerUriAction.Reward,
|
||||
merchantBaseUrl,
|
||||
merchantTipId: tipId,
|
||||
merchantRewardId: rewardId,
|
||||
};
|
||||
}
|
||||
|
||||
@ -701,10 +701,10 @@ export function stringifyRefundUri({
|
||||
}
|
||||
export function stringifyRewardUri({
|
||||
merchantBaseUrl,
|
||||
merchantTipId,
|
||||
merchantRewardId,
|
||||
}: Omit<RewardUriResult, "type">): string {
|
||||
const { proto, path } = getUrlInfo(merchantBaseUrl);
|
||||
return `${proto}://reward/${path}${merchantTipId}`;
|
||||
return `${proto}://reward/${path}${merchantRewardId}`;
|
||||
}
|
||||
|
||||
export function stringifyExchangeUri({
|
||||
|
@ -150,14 +150,14 @@ export async function prepareTip(
|
||||
.mktx((x) => [x.rewards])
|
||||
.runReadOnly(async (tx) => {
|
||||
return tx.rewards.indexes.byMerchantTipIdAndBaseUrl.get([
|
||||
res.merchantTipId,
|
||||
res.merchantRewardId,
|
||||
res.merchantBaseUrl,
|
||||
]);
|
||||
});
|
||||
|
||||
if (!tipRecord) {
|
||||
const tipStatusUrl = new URL(
|
||||
`tips/${res.merchantTipId}`,
|
||||
`rewards/${res.merchantRewardId}`,
|
||||
res.merchantBaseUrl,
|
||||
);
|
||||
logger.trace("checking tip status from", tipStatusUrl.href);
|
||||
@ -204,7 +204,7 @@ export async function prepareTip(
|
||||
next_url: tipPickupStatus.next_url,
|
||||
merchantBaseUrl: res.merchantBaseUrl,
|
||||
createdTimestamp: TalerPreciseTimestamp.now(),
|
||||
merchantRewardId: res.merchantTipId,
|
||||
merchantRewardId: res.merchantRewardId,
|
||||
rewardAmountEffective: Amounts.stringify(selectedDenoms.totalCoinValue),
|
||||
denomsSel: selectedDenoms,
|
||||
pickedUpTimestamp: undefined,
|
||||
|
Loading…
Reference in New Issue
Block a user