solution/app/scripts/modules/payment-api.js
/*
   * Creates the PaymentDetails dictionary inside the PaymentRequest.
   * This can change as the user selects shipping options.
   */
Creates the PaymentDetails dictionary inside the PaymentRequest.
This can change as the user selects shipping options.
Creates the PaymentDetails dictionary inside the PaymentRequest . This can change as the user selects shipping options .
buildPaymentDetails(cart, shippingOptions, shippingOptionId) {
    let displayItems = cart.cart.map(item => {
      return {
        label: `${item.quantity}x ${item.title}`,
        amount: {currency: 'USD', value: String(item.total)},
        selected: false
      };
    });
    let total = cart.total;
    let displayedShippingOptions = [];
    if (shippingOptions.length > 0) {
      let selectedOption = shippingOptions[shippingOptionId];
      displayedShippingOptions = shippingOptions.map(option => {
        return {
          id: option.id,
          label: option.label,
          amount: {currency: 'USD', value: String(option.price)},
          selected: option === selectedOption
        };
      });
      if (selectedOption) total += selectedOption.price;
    }
    let details = {
      displayItems: displayItems,
      total: {
        label: 'Total due',
        amount: {currency: 'USD', value: String(total)}
      },
      shippingOptions: displayedShippingOptions
    };
    return details;
  }
buildPaymentDetails ( cart , shippingOptions , shippingOptionId ) { let displayItems = cart . cart . map ( item => { return { label : ` ${ item . quantity } ${ item . title } ` , amount : { currency : 'USD' , value : String ( item . total ) } , selected : false } ; } ) ; let total = cart . total ; let displayedShippingOptions = [ ] ; if ( shippingOptions . length > 0 ) { let selectedOption = shippingOptions [ shippingOptionId ] ; displayedShippingOptions = shippingOptions . map ( option => { return { id : option . id , label : option . label , amount : { currency : 'USD' , value : String ( option . price ) } , selected : option === selectedOption } ; } ) ; if ( selectedOption ) total += selectedOption . price ; } let details = { displayItems : displayItems , total : { label : 'Total due' , amount : { currency : 'USD' , value : String ( total ) } } , shippingOptions : displayedShippingOptions } ; return details ; }
Creates the PaymentDetails dictionary inside the PaymentRequest.
Creates the PaymentDetails dictionary inside the PaymentRequest .
// Start with the cart items