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