tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PMIValidationChromeScript.js (2542B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* Any copyright is dedicated to the Public Domain.
      3   http://creativecommons.org/publicdomain/zero/1.0/ */
      4 
      5 /* eslint-env mozilla/chrome-script */
      6 
      7 "use strict";
      8 
      9 const { XPCOMUtils } = ChromeUtils.importESModule(
     10  "resource://gre/modules/XPCOMUtils.sys.mjs"
     11 );
     12 
     13 const paymentSrv = Cc[
     14  "@mozilla.org/dom/payments/payment-request-service;1"
     15 ].getService(Ci.nsIPaymentRequestService);
     16 
     17 const UIService = {
     18  showPayment(requestId) {
     19    paymentSrv.changeShippingOption(requestId, "");
     20  },
     21  abortPayment(requestId) {
     22    let abortResponse = Cc[
     23      "@mozilla.org/dom/payments/payment-abort-action-response;1"
     24    ].createInstance(Ci.nsIPaymentAbortActionResponse);
     25    abortResponse.init(requestId, Ci.nsIPaymentActionResponse.ABORT_SUCCEEDED);
     26    paymentSrv.respondPayment(
     27      abortResponse.QueryInterface(Ci.nsIPaymentActionResponse)
     28    );
     29  },
     30  completePayment(requestId) {
     31    const completeResponse = Cc[
     32      "@mozilla.org/dom/payments/payment-complete-action-response;1"
     33    ].createInstance(Ci.nsIPaymentCompleteActionResponse);
     34    completeResponse.init(
     35      requestId,
     36      Ci.nsIPaymentActionResponse.COMPLETE_SUCCEEDED
     37    );
     38    paymentSrv.respondPayment(
     39      completeResponse.QueryInterface(Ci.nsIPaymentActionResponse)
     40    );
     41  },
     42  updatePayment(requestId) {
     43    const showResponseData = Cc[
     44      "@mozilla.org/dom/payments/general-response-data;1"
     45    ].createInstance(Ci.nsIGeneralResponseData);
     46    showResponseData.initData({
     47      paymentToken: "6880281f-0df3-4b8e-916f-66575e2457c1",
     48    });
     49 
     50    const showResponse = Cc[
     51      "@mozilla.org/dom/payments/payment-show-action-response;1"
     52    ].createInstance(Ci.nsIPaymentShowActionResponse);
     53    showResponse.init(
     54      requestId,
     55      Ci.nsIPaymentActionResponse.PAYMENT_ACCEPTED,
     56      "https://example.com", // payment method
     57      showResponseData, // payment method data
     58      "Bill A. Pacheco", // payer name
     59      "", // payer email
     60      ""
     61    ); // payer phone
     62    paymentSrv.respondPayment(
     63      showResponse.QueryInterface(Ci.nsIPaymentActionResponse)
     64    );
     65  },
     66  closePayment(requestId) {},
     67  QueryInterface: ChromeUtils.generateQI(["nsIPaymentUIService"]),
     68 };
     69 
     70 function emitTestFail(message) {
     71  sendAsyncMessage("test-fail", message);
     72 }
     73 
     74 addMessageListener("set-ui-service", function () {
     75  paymentSrv.setTestingUIService(
     76    UIService.QueryInterface(Ci.nsIPaymentUIService)
     77  );
     78 });
     79 
     80 addMessageListener("teardown", function () {
     81  sendAsyncMessage("teardown-complete");
     82 });