File: app-simple.js

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (84 lines) | stat: -rw-r--r-- 2,585 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
self.addEventListener('canmakepayment', event => {
  event.respondWith(true);
});

self.addEventListener('paymentrequest', event => {
  const expectedId = 'test-payment-request-identifier';
  if (event.paymentRequestId !== expectedId) {
    const msg = `Expected payment request identifier "${expectedId}", but got "${
      event.paymentRequestId
    }"`;
    event.respondWith(Promise.reject(new Error(msg)));
    return;
  }

  if (event.methodData.length !== 1) {
    const msg = `Expected one method data, but got ${
      event.methodData.length
    } instead`;
    event.respondWith(Promise.reject(new Error(msg)));
    return;
  }

  const methodData = event.methodData[0];
  const expectedMethodNamePrefix = 'http';
  if (!methodData.supportedMethods.startsWith(expectedMethodNamePrefix)) {
    const msg = `Expected payment method name "${methodData.supportedMethods}" to start with ${expectedMethodNamePrefix}"`;
    event.respondWith(Promise.reject(new Error(msg)));
    return;
  }

  const expectedMethodNameSuffix = '/payment-handler/payment-request-event-manual-manifest.json';
  if (!methodData.supportedMethods.endsWith(expectedMethodNameSuffix)) {
    const msg = `Expected payment method name "${methodData.supportedMethods}" to end with ${expectedMethodNameSuffix}"`;
    event.respondWith(Promise.reject(new Error(msg)));
    return;
  }

  if (methodData.data.supportedNetworks) {
    const msg =
      'Expected no supported networks in payment method specific data';
    event.respondWith(Promise.reject(new Error(msg)));
    return;
  }

  if (methodData.displayItems) {
    const msg = 'Expected no display items';
    event.respondWith(Promise.reject(new Error(msg)));
    return;
  }

  const total = event.total;
  if (!total) {
    const msg = 'Expected total';
    event.respondWith(Promise.reject(new Error(msg)));
    return;
  }

  if (total.label) {
    const msg = 'Expected no total label';
    event.respondWith(Promise.reject(new Error(msg)));
    return;
  }

  const expectedCurrency = 'USD';
  if (total.currency !== expectedCurrency) {
    const msg = `Expected currency "${expectedCurrency}", but got "${
      total.currency
    }"`;
    event.respondWith(Promise.reject(new Error(msg)));
    return;
  }

  const expectedValue = '0.01';
  if (total.value !== expectedValue) {
    const msg = `Expected value "${expectedValue}", but got "${total.value}"`;
    event.respondWith(Promise.reject(new Error(msg)));
    return;
  }

  event.respondWith({
    methodName: methodData.supportedMethods,
    details: {status: 'success'},
  });
});