project/app/scripts/modules/payment-api.js
/*
   * Creates a PaymentRequest object including the event handlers used to
   * update the payment details as the user makes choices.
   */
Creates a PaymentRequest object including the event handlers used to
update the payment details as the user makes choices.
Creates a PaymentRequest object including the event handlers used to update the payment details as the user makes choices .
buildPaymentRequest(cart) {
    const supportedInstruments = [{
      supportedMethods: (PAYMENT_METHODS)
    }];
    const paymentOptions = {
    };
    let shippingOptions = [];
    let selectedOption = null;
    let details = this.buildPaymentDetails(cart, shippingOptions, selectedOption);
    request.addEventListener('shippingaddresschange', e => {
      e.updateWith(_ => {
        shippingOptions = this.optionsForCountry(request.shippingAddress.country);
        selectedOption = shippingOptions[0].id;
        let details = this.buildPaymentDetails(cart, shippingOptions, selectedOption);
        return Promise.resolve(details);
      });
    });
    request.addEventListener('shippingoptionchange', e => {
      e.updateWith(_ => {
        selectedOption = request.shippingOption;
        let details = this.buildPaymentDetails(cart, shippingOptions, selectedOption);
        return Promise.resolve(details);
      });
    });
    return request;
  }
buildPaymentRequest ( cart ) { const supportedInstruments = [ { supportedMethods : ( PAYMENT_METHODS ) } ] ; const paymentOptions = { } ; let shippingOptions = [ ] ; let selectedOption = null ; let details = this . buildPaymentDetails ( cart , shippingOptions , selectedOption ) ; request . addEventListener ( 'shippingaddresschange' , e => { e . updateWith ( _ => { shippingOptions = this . optionsForCountry ( request . shippingAddress . country ) ; selectedOption = shippingOptions [ 0 ] . id ; let details = this . buildPaymentDetails ( cart , shippingOptions , selectedOption ) ; return Promise . resolve ( details ) ; } ) ; } ) ; request . addEventListener ( 'shippingoptionchange' , e => { e . updateWith ( _ => { selectedOption = request . shippingOption ; let details = this . buildPaymentDetails ( cart , shippingOptions , selectedOption ) ; return Promise . resolve ( details ) ; } ) ; } ) ; return request ; }
Creates a PaymentRequest object including the event handlers used to
 update the payment details as the user makes choices.
Creates a PaymentRequest object including the event handlers used to update the payment details as the user makes choices .
// Supported payment instruments // Payment options // TODO PAY-5 - add payment options // TODO PAY-2 - initialize the PaymentRequest object // When user selects a shipping address, add shipping options to match // Get the shipping options and select the least expensive // When user selects a shipping option, update cost, etc. to match