From e07946bcb5c861f004b6b92a1e632dd1622ad15d Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 13 Dec 2016 12:13:13 -0500 Subject: [PATCH] Various fixes to the PaymentRequest constructor - Fixes #373: align ordering of steps with Blink's implementation, except check for allowed-to-use first since that makes more sense - Fixes #334: properly get the total.amount.value instead of pretending total is a string - Fixes #333 and fixes #335: do not assume various dictionaries are present - Fixes part of #321: use proper dictionary terminology - Ensures request.[[details]].shippingOptions/modifiers is always a sequence, instead of sometimes left as not present - Fixes various algorithm structure and typographic issues --- index.html | 301 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 199 insertions(+), 102 deletions(-) diff --git a/index.html b/index.html index 243571cd..4936663a 100644 --- a/index.html +++ b/index.html @@ -346,21 +346,6 @@

  • If a paymentRequestID was not provided during construction, generate a paymentRequestID.
  • -
  • If the length of the methodData sequence is zero, then - throw a TypeError; optionally informing the developer - that at least one payment method is required. -
  • -
  • For each paymentMethod of methodData: -
      -
    1. If the length of the supportedMethods - sequence is zero, then throw a TypeError; - optionally informing the developer that each payment - method needs to include at least one payment method - identifier. -
    2. -
    -
  • If the current settings object has a responsible browsing context that is not a top-level browsing context, then @@ -379,70 +364,200 @@

  • -
  • If the details argument does not contain a value for - total, then throw a - TypeError; optionally informing the developer that including a - total is required. -
  • -
  • If details.total.amount.value is not a - valid decimal monetary value, then throw a TypeError; - optionally informing the developer that the value is invalid. -
  • -
  • If the first character of details.total.amount.value is - U+002D HYPHEN-MINUS, then throw a TypeError; optionally - informing the developer that total can't be a negative amount - value. -
  • -
  • If the sequence of details.displayItems contains any - PaymentItem objects with an amount that is not a valid decimal - monetary value, then throw a TypeError; optionally - informing the developer that the value is invalid. -
  • -
  • If the sequence of details.shippingOptions contains - any PaymentShippingOption objects with an amount that is not a valid - decimal monetary value, then throw a TypeError; optionally - informing the developer that the value is invalid. -
  • -
  • If details contains a value for error, - then throw a TypeError. -
  • -
  • For each paymentMethod in the methodData - argument, if the data field - is supplied but is not a JSON-serializable object, then - throw a TypeError. -
  • -
  • For each paymentDetailsModifier in details.modifiers: +
  • Process payment methods: +
      +
    1. If the length of the methodData sequence is zero, + then throw a TypeError, optionally informing the + developer that at least one payment method is required. +
    2. +
    3. For each paymentMethod of methodData: +
        +
      1. If the length of the + paymentMethod.supportedMethods + sequence is zero, then throw a TypeError, + optionally informing the developer that each payment + method needs to include at least one payment method + identifier. +
      2. +
      3. If the data + member of paymentMethod is present, but + paymentMethod.data is not a + JSON-serializable object, then throw a + TypeError. +
      4. +
      +
    4. +
    +
  • +
  • Process the total: +
      +
    1. If the total member of + details is not present, then throw a + TypeError, optionally informing the developer that + including total is + required. +
    2. +
    3. If details.total.amount.value is not a valid decimal + monetary value, then throw a TypeError; + optionally informing the developer that the value is invalid. +
    4. +
    5. If the first character of details.total.amount.value is U+002D HYPHEN-MINUS, + then throw a TypeError, optionally informing the + developer that the total can't be negative. +
    6. +
    +
  • +
  • If the displayItems + member of details is present, then for each + item in details.displayItems: +
      +
    1. If item.amount.value is not a valid decimal + monetary value, then throw a TypeError, + optionally informing the developer that the value is invalid. +
    2. +
    +
  • +
  • Let selectedShippingOption be null. +
  • +
  • Process shipping options:
      -
    1. If the total field is - supplied and is not a valid decimal monetary value, then - throw a TypeError; optionally informing the developer that - the value is invalid. +
    2. Let options be an empty + sequence<PaymentShippingOption>.
    3. -
    4. If the total field is - supplied and the first character of - total.amount.value is U+002D HYPHEN-MINUS, then - throw a TypeError; optionally informing the developer that - the value can't be non-negative amount. +
    5. If the shippingOptions member of + details is present, then: +
        +
      1. Let seenIDs be an empty list. +
      2. +
      3. Set options to + details.shippingOptions. +
      4. +
      5. For each option in options: +
          +
        1. If option.amount.value is not a valid + decimal monetary value, then throw a + TypeError, optionally informing the developer that + the value is invalid. +
        2. +
        3. If seenIDs contains + option.id, then set + options to an empty sequence and break. +
        4. +
        5. Append option.id to seenIDs. +
        6. +
        +
      6. +
      7. For each option in options (which + may have been reset to the empty sequence in the previous + step): +
          +
        1. If option.selected is true, + then set selectedShippingOption to + option.id. +
        2. +
        +
      8. +
    6. -
    7. If the sequence of additionalDisplayItems - contains any PaymentItem objects with an amount that is not a valid decimal - monetary value, then throw a TypeError; optionally - informing the developer that the value is invalid. +
    8. Set details.shippingOptions to + options.
  • +
  • Process payment details modifiers: +
      +
    1. Let modifiers be an empty + sequence<PaymentDetailsModifier>. +
    2. +
    3. If the modifiers + member of details is present, then: +
        +
      1. Set modifiers to + details.modifiers. +
      2. +
      3. For each modifier of modifiers: +
          +
        1. If the total member of + modifier is present, then: +
            +
          1. Let value be + modifier.total.amount.value. +
          2. +
          3. If value is not a valid decimal + monetary value, then throw a TypeError, + optionally informing the developer that the value is + invalid. +
          4. +
          5. If the first character of value is + U+002D HYPHEN-MINUS, then throw a TypeError, + optionally informing the developer that the value + can't be negative. +
          6. +
          +
        2. +
        3. If the additionalDisplayItems + member of modifier is present, then for each + item of modifier.additionalDisplayItems: +
            +
          1. Let value be + item.amount.value. +
          2. +
          3. If value is not a valid decimal + monetary value, then throw a TypeError, + optionally informing the developer that the value is + invalid. +
          4. +
          +
        4. +
        +
      4. +
      5. Set details.modifiers to + modifiers. +
      6. +
      +
    4. +
    +
  • +
  • If the error member of + details is present, then throw a TypeError, + optionally informing the developer that an error message cannot be + specified in the constructor. +
  • Let request be a new PaymentRequest.
  • +
  • Set request.[[\options]] to options. +
  • +
  • Set request.[[\state]] to created. +
  • +
  • Set request.[[\updating]] to false. +
  • +
  • Set request.[[\details]] to details. +
  • Set request.[[\methodData]] to @@ -456,30 +571,28 @@

    presenting payment methods.

  • -
  • Set request.[[\details]] to details. -
  • -
  • Set request.[[\options]] to options. -
  • -
  • Set request.[[\state]] to created. +
  • Set the value of request's shippingOption attribute to + selectedShippingOption.
  • Set the value of the shippingAddress attribute on request to null.
  • -
  • Set the value of the - shippingOption attribute on request to null. -
  • Set the value of the shippingType attribute on request to null.
  • -
  • If options.requestShipping is set to true, then set - the value of the If options.requestShipping is set to true, + then set the value of the shippingType attribute on - request to options.shippingType. If - options.shippingType is not a valid - PaymentShippingType value then set the shippingType attribute on - request to "shipping". + request to options.shippingType. If + options.shippingType is not a valid + PaymentShippingType value then set the value of the + shippingType attribute + on request to "shipping".
    This behavior allows a page to detect if it supplied an unsupported shipping type. This will be important if new shipping @@ -487,22 +600,6 @@

    page is run in a user agent supporting an earlier version.

  • -
  • If the details.shippingOptions sequence contains - multiple PaymentShippingOption objects that have the same - id, then set the shippingOptions field of - request.[[\details]] to an empty sequence. -
  • -
  • If request.[[\details]] contains a - shippingOptions sequence and if any - PaymentShippingOption in the sequence has the - selected field set to true, then set shippingOption to the - id of the last PaymentShippingOption in the - sequence with selected set to true. -
  • -
  • Set request.[[\updating]] to false. -
  • Return request.