function PaymentRequest(methodData, details, opt_options) {
  __gCrWeb.EventTarget.call(this);

  if (window.top != window.self) {
    throw new DOMException(
        'Failed to construct \'PaymentRequest\': Must be in top-level context',
        'SecurityError');
  }

  // https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
  var isOriginPotentiallyTrustworthy = window.location.origin !== 'null' &&
      (window.location.protocol === 'https:' ||
       window.location.hostname === '127.0.0.1' ||
       window.location.hostname === '::1' ||
       window.location.hostname === 'localhost' ||
       window.location.protocol === 'file:');

  if (!__gCrWeb['paymentRequestManager'].isContextSecure ||
      !isOriginPotentiallyTrustworthy) {
    throw new DOMException(
        'Failed to construct \'PaymentRequest\': Must be in a secure context',
        'SecurityError');
  }

  // Initialize these properties to make them own (vs. inherited) properties.
  this.shippingAddress = null;
  this.shippingOption = null;
  this.shippingType = null;

  // Tracks the event handler registered via
  // PaymentRequest.prototype.onshippingaddresschange.
  this.shippingAddressChangeHandler = null;

  Object.defineProperty(this, 'onshippingaddresschange', {
    set(handler) {
      if (this.shippingAddressChangeHandler) {
        this.removeEventListener(
            'shippingaddresschange', this.shippingAddressChangeHandler);
      }
      this.shippingAddressChangeHandler = handler;
      this.addEventListener('shippingaddresschange', handler);
    },
    configurable: true
  });

  // Tracks the event handler registered via
  // PaymentRequest.prototype.onshippingoptionchange.
  this.shippingOptionChangeHandler = null;

  Object.defineProperty(this, 'onshippingoptionchange', {
    set(handler) {
      if (this.shippingOptionChangeHandler) {
        this.removeEventListener(
            'shippingoptionchange', this.shippingOptionChangeHandler);
      }
      this.shippingOptionChangeHandler = handler;
      this.addEventListener('shippingoptionchange', handler);
    },
    configurable: true
  });

  /**
   * The state of this request, used to govern its lifecycle.
   * @type {PaymentRequestState}
   * @private
   */
  this.state = PaymentRequestState.CREATED;

  /**
   * True if there is a pending updateWith call to update the payment request
   * and false otherwise.
   * @type {boolean}
   * @private
   */
  this.updating = false;

  // Validate methodData.
  __gCrWeb['paymentRequestManager'].validatePaymentMethodData(methodData);

  /**
   * @type {!Array<!window.PaymentMethodData>}
   * @private
   */
  this.methodData = methodData;

  // Validate details and update the shipping options.
  var validatedShippingOptions =
      __gCrWeb['paymentRequestManager'].validatePaymentDetailsInit(
          details, opt_options);
  details.shippingOptions = validatedShippingOptions;

  this.id = details.id ? details.id : __gCrWeb['paymentRequestManager'].guid();

  /**
   * @type {!window.PaymentDetails}
   * @private
   */
  this.details = details;

  // Pick the last selected shipping option as the selected shipping option.
  if (opt_options && opt_options.requestShipping) {
    for (var i = 0; i < validatedShippingOptions.length; i++) {
      if (validatedShippingOptions[i].selected)
        this.shippingOption = validatedShippingOptions[i].id;
    }
  }

  // Validate the opt_options.shippingType.
  if (opt_options && opt_options.shippingType &&
      opt_options.shippingType != PaymentShippingType.SHIPPING &&
      opt_options.shippingType != PaymentShippingType.DELIVERY &&
      opt_options.shippingType != PaymentShippingType.PICKUP) {
    throw new TypeError(
        'The provided shipping type is not a valid enum value of type ' +
        'PaymentShippingType');
  }

  // Use the provided shipping type. Otherwise default to "shipping".
  if (opt_options && opt_options.requestShipping) {
    this.shippingType = opt_options.shippingType ? opt_options.shippingType :
                                                   PaymentShippingType.SHIPPING;
  }

  /**
   * @type {?window.PaymentOptions}
   * @private
   */
  this.options = opt_options || null;

  var message = {
    'command': 'paymentRequest.createPaymentRequest',
    'payment_request':
        __gCrWeb['paymentRequestManager'].serializePaymentRequest(this),
  };
  __gCrWeb.message.invokeOnHost(message);
}
/**
 * A request to make a payment.
 * @param {!Array<!window.PaymentMethodData>} methodData Payment method
 *     identifiers for the payment methods that the web site accepts and any
 *     associated payment method specific data.
 * @param {!window.PaymentDetails} details Information about the transaction
 *     that the user is being asked to complete such as the line items in an
 *     order.
 * @param {window.PaymentOptions=} opt_options Information about what
 *     options the web page wishes to use from the payment request system.
 * @constructor
 * @implements {EventTarget}
 * @extends {__gCrWeb.EventTarget}
 * @throws {DOMException|TypeError|RangeError}
 * @suppress {checkTypes} Required for DOMException's constructor.
 */
A request to make a payment.
@param {!Array} methodData Payment method
identifiers for the payment methods that the web site accepts and any
associated payment method specific data.
@param {!window.PaymentDetails} details Information about the transaction
that the user is being asked to complete such as the line items in an
order.
@param {window.PaymentOptions=} opt_options Information about what
options the web page wishes to use from the payment request system.
A request to make a payment . @param { !Array } methodData Payment method identifiers for the payment methods that the web site accepts and any associated payment method specific data . @param { !window . PaymentDetails } details Information about the transaction that the user is being asked to complete such as the line items in an order . @param { window . PaymentOptions = } opt_options Information about what options the web page wishes to use from the payment request system .
function PaymentRequest(methodData, details, opt_options) {
  __gCrWeb.EventTarget.call(this);
  if (window.top != window.self) {
    throw new DOMException(
        'Failed to construct \'PaymentRequest\': Must be in top-level context',
        'SecurityError');
  }
  var isOriginPotentiallyTrustworthy = window.location.origin !== 'null' &&
      (window.location.protocol === 'https:' ||
       window.location.hostname === '127.0.0.1' ||
       window.location.hostname === '::1' ||
       window.location.hostname === 'localhost' ||
       window.location.protocol === 'file:');
  if (!__gCrWeb['paymentRequestManager'].isContextSecure ||
      !isOriginPotentiallyTrustworthy) {
    throw new DOMException(
        'Failed to construct \'PaymentRequest\': Must be in a secure context',
        'SecurityError');
  }
  this.shippingAddress = null;
  this.shippingOption = null;
  this.shippingType = null;
  this.shippingAddressChangeHandler = null;
  Object.defineProperty(this, 'onshippingaddresschange', {
    set(handler) {
      if (this.shippingAddressChangeHandler) {
        this.removeEventListener(
            'shippingaddresschange', this.shippingAddressChangeHandler);
      }
      this.shippingAddressChangeHandler = handler;
      this.addEventListener('shippingaddresschange', handler);
    },
    configurable: true
  });
  this.shippingOptionChangeHandler = null;
  Object.defineProperty(this, 'onshippingoptionchange', {
    set(handler) {
      if (this.shippingOptionChangeHandler) {
        this.removeEventListener(
            'shippingoptionchange', this.shippingOptionChangeHandler);
      }
      this.shippingOptionChangeHandler = handler;
      this.addEventListener('shippingoptionchange', handler);
    },
    configurable: true
  });
  this.state = PaymentRequestState.CREATED;
  this.updating = false;
  __gCrWeb['paymentRequestManager'].validatePaymentMethodData(methodData);
  this.methodData = methodData;
  var validatedShippingOptions =
      __gCrWeb['paymentRequestManager'].validatePaymentDetailsInit(
          details, opt_options);
  details.shippingOptions = validatedShippingOptions;
  this.id = details.id ? details.id : __gCrWeb['paymentRequestManager'].guid();
  this.details = details;
  if (opt_options && opt_options.requestShipping) {
    for (var i = 0; i < validatedShippingOptions.length; i++) {
      if (validatedShippingOptions[i].selected)
        this.shippingOption = validatedShippingOptions[i].id;
    }
  }
  if (opt_options && opt_options.shippingType &&
      opt_options.shippingType != PaymentShippingType.SHIPPING &&
      opt_options.shippingType != PaymentShippingType.DELIVERY &&
      opt_options.shippingType != PaymentShippingType.PICKUP) {
    throw new TypeError(
        'The provided shipping type is not a valid enum value of type ' +
        'PaymentShippingType');
  }
  if (opt_options && opt_options.requestShipping) {
    this.shippingType = opt_options.shippingType ? opt_options.shippingType :
                                                   PaymentShippingType.SHIPPING;
  }
  this.options = opt_options || null;
  var message = {
    'command': 'paymentRequest.createPaymentRequest',
    'payment_request':
        __gCrWeb['paymentRequestManager'].serializePaymentRequest(this),
  };
  __gCrWeb.message.invokeOnHost(message);
}
function PaymentRequest ( methodData , details , opt_options ) { __gCrWeb . EventTarget . call ( this ) ; if ( window . top != window . self ) { throw new DOMException ( 'Failed to construct \'PaymentRequest\': Must be in top-level context' , 'SecurityError' ) ; } var isOriginPotentiallyTrustworthy = window . location . origin !== 'null' && ( window . location . protocol === 'https:' || window . location . hostname === '127.0.0.1' || window . location . hostname === '::1' || window . location . hostname === 'localhost' || window . location . protocol === 'file:' ) ; if ( ! __gCrWeb [ 'paymentRequestManager' ] . isContextSecure || ! isOriginPotentiallyTrustworthy ) { throw new DOMException ( 'Failed to construct \'PaymentRequest\': Must be in a secure context' , 'SecurityError' ) ; } this . shippingAddress = null ; this . shippingOption = null ; this . shippingType = null ; this . shippingAddressChangeHandler = null ; Object . defineProperty ( this , 'onshippingaddresschange' , { set ( handler ) { if ( this . shippingAddressChangeHandler ) { this . removeEventListener ( 'shippingaddresschange' , this . shippingAddressChangeHandler ) ; } this . shippingAddressChangeHandler = handler ; this . addEventListener ( 'shippingaddresschange' , handler ) ; } , configurable : true } ) ; this . shippingOptionChangeHandler = null ; Object . defineProperty ( this , 'onshippingoptionchange' , { set ( handler ) { if ( this . shippingOptionChangeHandler ) { this . removeEventListener ( 'shippingoptionchange' , this . shippingOptionChangeHandler ) ; } this . shippingOptionChangeHandler = handler ; this . addEventListener ( 'shippingoptionchange' , handler ) ; } , configurable : true } ) ; this . state = PaymentRequestState . CREATED ; this . updating = false ; __gCrWeb [ 'paymentRequestManager' ] . validatePaymentMethodData ( methodData ) ; this . methodData = methodData ; var validatedShippingOptions = __gCrWeb [ 'paymentRequestManager' ] . validatePaymentDetailsInit ( details , opt_options ) ; details . shippingOptions = validatedShippingOptions ; this . id = details . id ? details . id : __gCrWeb [ 'paymentRequestManager' ] . guid ( ) ; this . details = details ; if ( opt_options && opt_options . requestShipping ) { for ( var i = 0 ; i < validatedShippingOptions . length ; i ++ ) { if ( validatedShippingOptions [ i ] . selected ) this . shippingOption = validatedShippingOptions [ i ] . id ; } } if ( opt_options && opt_options . shippingType && opt_options . shippingType != PaymentShippingType . SHIPPING && opt_options . shippingType != PaymentShippingType . DELIVERY && opt_options . shippingType != PaymentShippingType . PICKUP ) { throw new TypeError ( 'The provided shipping type is not a valid enum value of type ' + 'PaymentShippingType' ) ; } if ( opt_options && opt_options . requestShipping ) { this . shippingType = opt_options . shippingType ? opt_options . shippingType : PaymentShippingType . SHIPPING ; } this . options = opt_options || null ; var message = { 'command' : 'paymentRequest.createPaymentRequest' , 'payment_request' : __gCrWeb [ 'paymentRequestManager' ] . serializePaymentRequest ( this ) , } ; __gCrWeb . message . invokeOnHost ( message ) ; }
A request to make a payment.
A request to make a payment .
// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy // Initialize these properties to make them own (vs. inherited) properties. // Tracks the event handler registered via // PaymentRequest.prototype.onshippingaddresschange. // Tracks the event handler registered via // PaymentRequest.prototype.onshippingoptionchange. /**
   * The state of this request, used to govern its lifecycle.
   * @type {PaymentRequestState}
   * @private
   */ /**
   * True if there is a pending updateWith call to update the payment request
   * and false otherwise.
   * @type {boolean}
   * @private
   */ // Validate methodData. /**
   * @type {!Array<!window.PaymentMethodData>}
   * @private
   */ // Validate details and update the shipping options. /**
   * @type {!window.PaymentDetails}
   * @private
   */ // Pick the last selected shipping option as the selected shipping option. // Validate the opt_options.shippingType. // Use the provided shipping type. Otherwise default to "shipping". /**
   * @type {?window.PaymentOptions}
   * @private
   */