Changeset 280459 in webkit


Ignore:
Timestamp:
Jul 29, 2021 5:28:45 PM (12 months ago)
Author:
Devin Rousso
Message:

[Payment Request] additionalShippingMethods are not used if a paymentMethodType is provided
https://bugs.webkit.org/show_bug.cgi?id=228599
<rdar://problem/81190366>

Reviewed by Andy Estes.

Source/WebCore:

r275169 made it so that paymentMethodType is no longer required so that additionalShippingMethods
can be specified without having to limit it to a specific payment method type. While this
works in theory, WebKit doesn't know about the user's selected payment method type until the
user actually selects a payment method, meaning that until then the additionalShippingMethods
are not used. Unfortunately (until now) PKPaymentRequestPaymentMethodUpdate did not
support providing a NSArray<PKShippingMethod *> *, so there was no way to update the list
of shipping methods when the user changed their selected payment method, meaning that WebKit
would have to wait/rely on the user to change their shipping address _after_ selecting a
payment method in order for additionalShippingMethods to take effect.

This also fixes an issue with WebKit's implementation of the W3C Payment Request API by
allowing any generic (i.e. things not specific to Apple Pay) shippingOptions provided in
PaymentDetailsUpdate to actually be used and update the Apple Pay sheet accordingly.

Test: http/tests/paymentrequest/ApplePayModifier-paymentMethodType.https.html

  • Modules/applepay/ApplePayModifier.idl:
  • Modules/applepay/ApplePayModifier.h:
  • Modules/applepay/ApplePayPaymentMethodUpdate.idl:
  • Modules/applepay/ApplePayPaymentMethodUpdate.h:

(WebCore::ApplePayPaymentMethodUpdate::encode const):
(WebCore::ApplePayPaymentMethodUpdate::decode):

  • Modules/applepay/ApplePayShippingMethodUpdate.idl:
  • Modules/applepay/ApplePayShippingMethodUpdate.h:

(WebCore::ApplePayShippingMethodUpdate::encode const):
(WebCore::ApplePayShippingMethodUpdate::decode):
Add (or wrap existing) additionalShippingMethods/newShippingMethods properties.

  • Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:

(WebCore::ApplePayPaymentHandler::computeShippingMethods):
(WebCore::ApplePayPaymentHandler::detailsUpdated):
(WebCore::ApplePayPaymentHandler::shippingOptionUpdated):
(WebCore::ApplePayPaymentHandler::paymentMethodUpdated):
Also call computeShippingMethods() and add the result to the update.

  • testing/MockPaymentCoordinator.cpp:

(WebCore::MockPaymentCoordinator::completeShippingMethodSelection):
(WebCore::MockPaymentCoordinator::completeShippingContactSelection):
(WebCore::MockPaymentCoordinator::completePaymentMethodSelection):
(WebCore::MockPaymentCoordinator::completeCouponCodeChange):
Support for testing.

Source/WebCore/PAL:

r275169 made it so that paymentMethodType is no longer required so that additionalShippingMethods
can be specified without having to limit it to a specific payment method type. While this
works in theory, WebKit doesn't know about the user's selected payment method type until the
user actually selects a payment method, meaning that until then the additionalShippingMethods
are not used. Unfortunately (until now) PKPaymentRequestPaymentMethodUpdate did not
support providing a NSArray<PKShippingMethod *> *, so there was no way to update the list
of shipping methods when the user changed their selected payment method, meaning that WebKit
would have to wait/rely on the user to change their shipping address _after_ selecting a
payment method in order for additionalShippingMethods to take effect.

This also fixes an issue with WebKit's implementation of the W3C Payment Request API by
allowing any generic (i.e. things not specific to Apple Pay) shippingOptions provided in
PaymentDetailsUpdate to actually be used and update the Apple Pay sheet accordingly.

  • pal/spi/cocoa/PassKitSPI.h:
    • add the new shippingMethods property on PKPaymentRequestUpdate
    • add the existing errors property on PKPaymentRequestPaymentMethodUpdate

Source/WebKit:

r275169 made it so that paymentMethodType is no longer required so that additionalShippingMethods
can be specified without having to limit it to a specific payment method type. While this
works in theory, WebKit doesn't know about the user's selected payment method type until the
user actually selects a payment method, meaning that until then the additionalShippingMethods
are not used. Unfortunately (until now) PKPaymentRequestPaymentMethodUpdate did not
support providing a NSArray<PKShippingMethod *> *, so there was no way to update the list
of shipping methods when the user changed their selected payment method, meaning that WebKit
would have to wait/rely on the user to change their shipping address _after_ selecting a
payment method in order for additionalShippingMethods to take effect.

This also fixes an issue with WebKit's implementation of the W3C Payment Request API by
allowing any generic (i.e. things not specific to Apple Pay) shippingOptions provided in
PaymentDetailsUpdate to actually be used and update the Apple Pay sheet accordingly.

  • Platform/cocoa/PaymentAuthorizationPresenter.mm:

(WebKit::PaymentAuthorizationPresenter::completePaymentMethodSelection):
(WebKit::PaymentAuthorizationPresenter::completeShippingMethodSelection):
Also convert and set the shippingMethods on the update.

Source/WTF:

r275169 made it so that paymentMethodType is no longer required so that additionalShippingMethods
can be specified without having to limit it to a specific payment method type. While this
works in theory, WebKit doesn't know about the user's selected payment method type until the
user actually selects a payment method, meaning that until then the additionalShippingMethods
are not used. Unfortunately (until now) PKPaymentRequestPaymentMethodUpdate did not
support providing a NSArray<PKShippingMethod *> *, so there was no way to update the list
of shipping methods when the user changed their selected payment method, meaning that WebKit
would have to wait/rely on the user to change their shipping address _after_ selecting a
payment method in order for additionalShippingMethods to take effect.

This also fixes an issue with WebKit's implementation of the W3C Payment Request API by
allowing any generic (i.e. things not specific to Apple Pay) shippingOptions provided in
PaymentDetailsUpdate to actually be used and update the Apple Pay sheet accordingly.

  • wtf/PlatformHave.h:
  • wtf/PlatformEnableCocoa.h:

Add new compile flags for PassKit supporting modifying shipping methods with any update.

LayoutTests:

  • http/tests/paymentrequest/ApplePayModifier-paymentMethodType.https.html: Added.
  • http/tests/paymentrequest/ApplePayModifier-paymentMethodType.https-expected.txt: Added.
  • platform/ios-14-wk2/TestExpectations:
  • platform/mac-bigsur-wk2/TestExpectations: Added.

Skip on older macOS/iOS since they don't support modifying shipping methods with any update.

Location:
trunk
Files:
3 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r280458 r280459  
     12021-07-29  Devin Rousso  <drousso@apple.com>
     2
     3        [Payment Request] `additionalShippingMethods` are not used if a `paymentMethodType` is provided
     4        https://bugs.webkit.org/show_bug.cgi?id=228599
     5        <rdar://problem/81190366>
     6
     7        Reviewed by Andy Estes.
     8
     9        * http/tests/paymentrequest/ApplePayModifier-paymentMethodType.https.html: Added.
     10        * http/tests/paymentrequest/ApplePayModifier-paymentMethodType.https-expected.txt: Added.
     11
     12        * platform/ios-14-wk2/TestExpectations:
     13        * platform/mac-bigsur-wk2/TestExpectations: Added.
     14        Skip on older macOS/iOS since they don't support modifying shipping methods with any update.
     15
    1162021-07-29  Eric Hutchison  <ehutchison@apple.com>
    217
  • trunk/LayoutTests/platform/ios-14-wk2/TestExpectations

    r280246 r280459  
    99# Accessibility text recognition support tests.
    1010accessibility/ios-simulator/image-overlay-elements.html [ Skip ]
     11
     12http/tests/paymentrequest/ApplePayModifier-paymentMethodType.https.html [ Skip ]
  • trunk/Source/WTF/ChangeLog

    r280452 r280459  
     12021-07-29  Devin Rousso  <drousso@apple.com>
     2
     3        [Payment Request] `additionalShippingMethods` are not used if a `paymentMethodType` is provided
     4        https://bugs.webkit.org/show_bug.cgi?id=228599
     5        <rdar://problem/81190366>
     6
     7        Reviewed by Andy Estes.
     8
     9        r275169 made it so that `paymentMethodType` is no longer `required` so that `additionalShippingMethods`
     10        can be specified without having to limit it to a specific payment method type. While this
     11        works in theory, WebKit doesn't know about the user's selected payment method type until the
     12        user actually selects a payment method, meaning that until then the `additionalShippingMethods`
     13        are not used. Unfortunately (until now) `PKPaymentRequestPaymentMethodUpdate` did not
     14        support providing a `NSArray<PKShippingMethod *> *`, so there was no way to update the list
     15        of shipping methods when the user changed their selected payment method, meaning that WebKit
     16        would have to wait/rely on the user to change their shipping address _after_ selecting a
     17        payment method in order for `additionalShippingMethods` to take effect.
     18
     19        This also fixes an issue with WebKit's implementation of the W3C Payment Request API by
     20        allowing any generic (i.e. things not specific to Apple Pay) `shippingOptions` provided in
     21        `PaymentDetailsUpdate` to actually be used and update the Apple Pay sheet accordingly.
     22
     23        * wtf/PlatformHave.h:
     24        * wtf/PlatformEnableCocoa.h:
     25        Add new compile flags for PassKit supporting modifying shipping methods with any update.
     26
    1272021-07-28  Yusuke Suzuki  <ysuzuki@apple.com>
    228
  • trunk/Source/WTF/wtf/PlatformEnableCocoa.h

    r279184 r280459  
    9696#endif
    9797
     98#if !defined(ENABLE_APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS) && HAVE(PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS)
     99#define ENABLE_APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS 1
     100#endif
     101
    98102#if !defined(ENABLE_APPLICATION_MANIFEST)
    99103#define ENABLE_APPLICATION_MANIFEST 1
  • trunk/Source/WTF/wtf/PlatformHave.h

    r280445 r280459  
    726726#define HAVE_PASSKIT_COUPON_CODE 1
    727727#define HAVE_PASSKIT_SHIPPING_CONTACT_EDITING_MODE 1
     728#define HAVE_PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS 1
    728729#endif
    729730
  • trunk/Source/WebCore/ChangeLog

    r280454 r280459  
     12021-07-29  Devin Rousso  <drousso@apple.com>
     2
     3        [Payment Request] `additionalShippingMethods` are not used if a `paymentMethodType` is provided
     4        https://bugs.webkit.org/show_bug.cgi?id=228599
     5        <rdar://problem/81190366>
     6
     7        Reviewed by Andy Estes.
     8
     9        r275169 made it so that `paymentMethodType` is no longer `required` so that `additionalShippingMethods`
     10        can be specified without having to limit it to a specific payment method type. While this
     11        works in theory, WebKit doesn't know about the user's selected payment method type until the
     12        user actually selects a payment method, meaning that until then the `additionalShippingMethods`
     13        are not used. Unfortunately (until now) `PKPaymentRequestPaymentMethodUpdate` did not
     14        support providing a `NSArray<PKShippingMethod *> *`, so there was no way to update the list
     15        of shipping methods when the user changed their selected payment method, meaning that WebKit
     16        would have to wait/rely on the user to change their shipping address _after_ selecting a
     17        payment method in order for `additionalShippingMethods` to take effect.
     18
     19        This also fixes an issue with WebKit's implementation of the W3C Payment Request API by
     20        allowing any generic (i.e. things not specific to Apple Pay) `shippingOptions` provided in
     21        `PaymentDetailsUpdate` to actually be used and update the Apple Pay sheet accordingly.
     22
     23        Test: http/tests/paymentrequest/ApplePayModifier-paymentMethodType.https.html
     24
     25        * Modules/applepay/ApplePayModifier.idl:
     26        * Modules/applepay/ApplePayModifier.h:
     27        * Modules/applepay/ApplePayPaymentMethodUpdate.idl:
     28        * Modules/applepay/ApplePayPaymentMethodUpdate.h:
     29        (WebCore::ApplePayPaymentMethodUpdate::encode const):
     30        (WebCore::ApplePayPaymentMethodUpdate::decode):
     31        * Modules/applepay/ApplePayShippingMethodUpdate.idl:
     32        * Modules/applepay/ApplePayShippingMethodUpdate.h:
     33        (WebCore::ApplePayShippingMethodUpdate::encode const):
     34        (WebCore::ApplePayShippingMethodUpdate::decode):
     35        Add (or wrap existing) `additionalShippingMethods`/`newShippingMethods` properties.
     36
     37        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
     38        (WebCore::ApplePayPaymentHandler::computeShippingMethods):
     39        (WebCore::ApplePayPaymentHandler::detailsUpdated):
     40        (WebCore::ApplePayPaymentHandler::shippingOptionUpdated):
     41        (WebCore::ApplePayPaymentHandler::paymentMethodUpdated):
     42        Also call `computeShippingMethods()` and add the result to the update.
     43
     44        * testing/MockPaymentCoordinator.cpp:
     45        (WebCore::MockPaymentCoordinator::completeShippingMethodSelection):
     46        (WebCore::MockPaymentCoordinator::completeShippingContactSelection):
     47        (WebCore::MockPaymentCoordinator::completePaymentMethodSelection):
     48        (WebCore::MockPaymentCoordinator::completeCouponCodeChange):
     49        Support for testing.
     50
    1512021-07-29  Alex Christensen  <achristensen@webkit.org>
    252
  • trunk/Source/WebCore/Modules/applepay/ApplePayPaymentMethodUpdate.h

    r278340 r280459  
    2929
    3030#include "ApplePayDetailsUpdateBase.h"
     31#include "ApplePayError.h"
     32#include "ApplePayShippingMethod.h"
     33#include <wtf/RefPtr.h>
     34#include <wtf/Vector.h>
    3135#include <wtf/text/WTFString.h>
    3236
     
    3438
    3539struct ApplePayPaymentMethodUpdate final : public ApplePayDetailsUpdateBase {
     40#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
     41    Vector<RefPtr<ApplePayError>> errors;
     42
     43    Vector<ApplePayShippingMethod> newShippingMethods;
     44#endif
     45
    3646#if ENABLE(APPLE_PAY_INSTALLMENTS)
    3747    String installmentGroupIdentifier;
     
    4656{
    4757    ApplePayDetailsUpdateBase::encode(encoder);
     58#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
     59    encoder << errors;
     60    encoder << newShippingMethods;
     61#endif
    4862#if ENABLE(APPLE_PAY_INSTALLMENTS)
    4963    encoder << installmentGroupIdentifier;
     
    6680    result.name = WTFMove(*name); \
    6781
     82#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
     83    DECODE(errors, Vector<RefPtr<ApplePayError>>)
     84    DECODE(newShippingMethods, Vector<ApplePayShippingMethod>)
     85#endif
     86
    6887#if ENABLE(APPLE_PAY_INSTALLMENTS)
    6988    DECODE(installmentGroupIdentifier, String)
  • trunk/Source/WebCore/Modules/applepay/ApplePayPaymentMethodUpdate.idl

    r273143 r280459  
    2727    Conditional=APPLE_PAY,
    2828] dictionary ApplePayPaymentMethodUpdate : ApplePayDetailsUpdateBase {
     29    [Conditional=APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS] sequence<ApplePayError> errors;
     30
     31    [Conditional=APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS] sequence<ApplePayShippingMethod> newShippingMethods;
     32
    2933    [Conditional=APPLE_PAY_INSTALLMENTS] DOMString installmentGroupIdentifier;
    3034};
  • trunk/Source/WebCore/Modules/applepay/ApplePayShippingMethodUpdate.h

    r278253 r280459  
    2929
    3030#include "ApplePayDetailsUpdateBase.h"
     31#include "ApplePayShippingMethod.h"
     32#include <wtf/Vector.h>
    3133
    3234namespace WebCore {
    3335
    3436struct ApplePayShippingMethodUpdate final : public ApplePayDetailsUpdateBase {
     37#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
     38    Vector<ApplePayShippingMethod> newShippingMethods;
     39#endif
     40
    3541    template<class Encoder> void encode(Encoder&) const;
    3642    template<class Decoder> static std::optional<ApplePayShippingMethodUpdate> decode(Decoder&);
     
    4147{
    4248    ApplePayDetailsUpdateBase::encode(encoder);
     49#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
     50    encoder << newShippingMethods;
     51#endif
    4352}
    4453
     
    5160        return std::nullopt;
    5261
     62#define DECODE(name, type) \
     63    std::optional<type> name; \
     64    decoder >> name; \
     65    if (!name) \
     66        return std::nullopt; \
     67    result.name = WTFMove(*name); \
     68
     69#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
     70    DECODE(newShippingMethods, Vector<ApplePayShippingMethod>)
     71#endif
     72
     73#undef DECODE
     74
    5375    return result;
    5476}
  • trunk/Source/WebCore/Modules/applepay/ApplePayShippingMethodUpdate.idl

    r273143 r280459  
    2727    Conditional=APPLE_PAY,
    2828] dictionary ApplePayShippingMethodUpdate : ApplePayDetailsUpdateBase {
     29    [Conditional=APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS] sequence<ApplePayShippingMethod> newShippingMethods;
    2930};
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayModifier.h

    r278437 r280459  
    4242    std::optional<ApplePayLineItem> total;
    4343    Vector<ApplePayLineItem> additionalLineItems;
     44#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
    4445    Vector<ApplePayShippingMethod> additionalShippingMethods;
     46#endif
    4547
    4648#if defined(ApplePayModifierAdditions_members)
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayModifier.idl

    r278437 r280459  
    3030    ApplePayLineItem total;
    3131    sequence<ApplePayLineItem> additionalLineItems;
    32     sequence<ApplePayShippingMethod> additionalShippingMethods;
     32    [Conditional=APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS] sequence<ApplePayShippingMethod> additionalShippingMethods;
    3333};
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp

    r278630 r280459  
    307307    }
    308308
     309#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
    309310    auto modifierException = firstApplicableModifier();
    310311    if (modifierException.hasException())
     
    312313    if (auto modifierData = modifierException.releaseReturnValue())
    313314        shippingOptions.appendVector(WTFMove(std::get<1>(*modifierData).additionalShippingMethods));
     315#endif
    314316
    315317    return WTFMove(shippingOptions);
     
    512514        return shippingOptionUpdated();
    513515    case Reason::PaymentMethodChanged:
    514         return paymentMethodUpdated(computeErrors(paymentMethodErrors));
     516        return paymentMethodUpdated(computeErrors(WTFMove(error), WTFMove(addressErrors), WTFMove(payerErrors), paymentMethodErrors));
    515517    }
    516518
     
    575577    ApplePayShippingMethodUpdate update;
    576578
     579#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
     580    auto newShippingMethods = computeShippingMethods();
     581    if (newShippingMethods.hasException())
     582        return newShippingMethods.releaseException();
     583    update.newShippingMethods = newShippingMethods.releaseReturnValue();
     584#endif
     585
    577586    auto newTotalAndLineItems = computeTotalAndLineItems();
    578587    if (newTotalAndLineItems.hasException())
     
    618627        return { };
    619628    }
     629#endif // ENABLE(APPLE_PAY_COUPON_CODE)
     630
     631    ASSERT(m_updateState == UpdateState::PaymentMethod);
     632    m_updateState = UpdateState::None;
     633
     634    ApplePayPaymentMethodUpdate update;
     635
     636#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
     637    update.errors = WTFMove(errors);
     638
     639    auto newShippingMethods = computeShippingMethods();
     640    if (newShippingMethods.hasException())
     641        return newShippingMethods.releaseException();
     642    update.newShippingMethods = newShippingMethods.releaseReturnValue();
    620643#else
    621644    UNUSED_PARAM(errors);
    622 #endif // ENABLE(APPLE_PAY_COUPON_CODE)
    623 
    624     ASSERT(m_updateState == UpdateState::PaymentMethod);
    625     m_updateState = UpdateState::None;
    626 
    627     ApplePayPaymentMethodUpdate update;
     645#endif
    628646
    629647    auto newTotalAndLineItems = computeTotalAndLineItems();
  • trunk/Source/WebCore/PAL/ChangeLog

    r280441 r280459  
     12021-07-29  Devin Rousso  <drousso@apple.com>
     2
     3        [Payment Request] `additionalShippingMethods` are not used if a `paymentMethodType` is provided
     4        https://bugs.webkit.org/show_bug.cgi?id=228599
     5        <rdar://problem/81190366>
     6
     7        Reviewed by Andy Estes.
     8
     9        r275169 made it so that `paymentMethodType` is no longer `required` so that `additionalShippingMethods`
     10        can be specified without having to limit it to a specific payment method type. While this
     11        works in theory, WebKit doesn't know about the user's selected payment method type until the
     12        user actually selects a payment method, meaning that until then the `additionalShippingMethods`
     13        are not used. Unfortunately (until now) `PKPaymentRequestPaymentMethodUpdate` did not
     14        support providing a `NSArray<PKShippingMethod *> *`, so there was no way to update the list
     15        of shipping methods when the user changed their selected payment method, meaning that WebKit
     16        would have to wait/rely on the user to change their shipping address _after_ selecting a
     17        payment method in order for `additionalShippingMethods` to take effect.
     18
     19        This also fixes an issue with WebKit's implementation of the W3C Payment Request API by
     20        allowing any generic (i.e. things not specific to Apple Pay) `shippingOptions` provided in
     21        `PaymentDetailsUpdate` to actually be used and update the Apple Pay sheet accordingly.
     22
     23        * pal/spi/cocoa/PassKitSPI.h:
     24         - add the new `shippingMethods` property on `PKPaymentRequestUpdate`
     25         - add the existing `errors` property on `PKPaymentRequestPaymentMethodUpdate`
     26
    1272021-07-29  Kate Cheney  <katherine_cheney@apple.com>
    228
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/PassKitSPI.h

    r278834 r280459  
    450450- (instancetype)initWithPaymentSummaryItems:(NSArray<PKPaymentSummaryItem *> *)paymentSummaryItems;
    451451@property (nonatomic, copy) NSArray<PKPaymentSummaryItem *> *paymentSummaryItems;
    452 #if HAVE(PASSKIT_COUPON_CODE)
     452#if HAVE(PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS)
    453453@property (nonatomic, copy) NSArray<PKShippingMethod *> *shippingMethods;
    454454#endif
    455 
    456455@end
    457456
    458457@interface PKPaymentRequestPaymentMethodUpdate : PKPaymentRequestUpdate
     458- (instancetype)initWithErrors:(nullable NSArray<NSError *> *)errors paymentSummaryItems:(nonnull NSArray<PKPaymentSummaryItem *> *)summaryItems;
     459@property (null_resettable, nonatomic, copy) NSArray<NSError *> *errors;
    459460@end
    460461
  • trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp

    r278630 r280459  
    148148    m_total = WTFMove(shippingMethodUpdate->newTotal);
    149149    m_lineItems = WTFMove(shippingMethodUpdate->newLineItems);
     150#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
     151    m_shippingMethods = WTFMove(shippingMethodUpdate->newShippingMethods);
     152#endif
    150153#if defined(MockPaymentCoordinatorAdditions_completeShippingMethodSelection)
    151154    MockPaymentCoordinatorAdditions_completeShippingMethodSelection
     
    170173    m_total = WTFMove(shippingContactUpdate->newTotal);
    171174    m_lineItems = WTFMove(shippingContactUpdate->newLineItems);
     175    m_shippingMethods = WTFMove(shippingContactUpdate->newShippingMethods);
    172176    m_errors = convert(WTFMove(shippingContactUpdate->errors));
    173     m_shippingMethods = WTFMove(shippingContactUpdate->newShippingMethods);
    174177#if defined(MockPaymentCoordinatorAdditions_completeShippingContactSelection)
    175178    MockPaymentCoordinatorAdditions_completeShippingContactSelection
     
    184187    m_total = WTFMove(paymentMethodUpdate->newTotal);
    185188    m_lineItems = WTFMove(paymentMethodUpdate->newLineItems);
     189#if ENABLE(APPLE_PAY_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_LINE_ITEMS)
     190    m_shippingMethods = WTFMove(paymentMethodUpdate->newShippingMethods);
     191    m_errors = convert(WTFMove(paymentMethodUpdate->errors));
     192#endif
    186193#if defined(MockPaymentCoordinatorAdditions_completePaymentMethodSelection)
    187194    MockPaymentCoordinatorAdditions_completePaymentMethodSelection
     
    198205    m_total = WTFMove(couponCodeUpdate->newTotal);
    199206    m_lineItems = WTFMove(couponCodeUpdate->newLineItems);
     207    m_shippingMethods = WTFMove(couponCodeUpdate->newShippingMethods);
    200208    m_errors = convert(WTFMove(couponCodeUpdate->errors));
    201     m_shippingMethods = WTFMove(couponCodeUpdate->newShippingMethods);
    202209#if defined(MockPaymentCoordinatorAdditions_completeCouponCodeChange)
    203210    MockPaymentCoordinatorAdditions_completeCouponCodeChange
  • trunk/Source/WebKit/ChangeLog

    r280451 r280459  
     12021-07-29  Devin Rousso  <drousso@apple.com>
     2
     3        [Payment Request] `additionalShippingMethods` are not used if a `paymentMethodType` is provided
     4        https://bugs.webkit.org/show_bug.cgi?id=228599
     5        <rdar://problem/81190366>
     6
     7        Reviewed by Andy Estes.
     8
     9        r275169 made it so that `paymentMethodType` is no longer `required` so that `additionalShippingMethods`
     10        can be specified without having to limit it to a specific payment method type. While this
     11        works in theory, WebKit doesn't know about the user's selected payment method type until the
     12        user actually selects a payment method, meaning that until then the `additionalShippingMethods`
     13        are not used. Unfortunately (until now) `PKPaymentRequestPaymentMethodUpdate` did not
     14        support providing a `NSArray<PKShippingMethod *> *`, so there was no way to update the list
     15        of shipping methods when the user changed their selected payment method, meaning that WebKit
     16        would have to wait/rely on the user to change their shipping address _after_ selecting a
     17        payment method in order for `additionalShippingMethods` to take effect.
     18
     19        This also fixes an issue with WebKit's implementation of the W3C Payment Request API by
     20        allowing any generic (i.e. things not specific to Apple Pay) `shippingOptions` provided in
     21        `PaymentDetailsUpdate` to actually be used and update the Apple Pay sheet accordingly.
     22
     23        * Platform/cocoa/PaymentAuthorizationPresenter.mm:
     24        (WebKit::PaymentAuthorizationPresenter::completePaymentMethodSelection):
     25        (WebKit::PaymentAuthorizationPresenter::completeShippingMethodSelection):
     26        Also convert and set the `shippingMethods` on the update.
     27
    1282021-07-29  Kate Cheney  <katherine_cheney@apple.com>
    229
  • trunk/Source/WebKit/Platform/cocoa/PaymentAuthorizationPresenter.mm

    r280284 r280459  
    218218
    219219    auto paymentMethodUpdate = adoptNS([PAL::allocPKPaymentRequestPaymentMethodUpdateInstance() initWithPaymentSummaryItems:WebCore::platformSummaryItems(WTFMove(update->newTotal), WTFMove(update->newLineItems))]);
     220#if HAVE(PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS)
     221    [paymentMethodUpdate setErrors:toNSErrors(WTFMove(update->errors)).get()];
     222    [paymentMethodUpdate setShippingMethods:toPKShippingMethods(WTFMove(update->newShippingMethods)).get()];
     223#endif
    220224#if HAVE(PASSKIT_INSTALLMENTS) && ENABLE(APPLE_PAY_INSTALLMENTS)
    221225    [paymentMethodUpdate setInstallmentGroupIdentifier:WTFMove(update->installmentGroupIdentifier)];
     
    261265
    262266    auto shippingMethodUpdate = adoptNS([PAL::allocPKPaymentRequestShippingMethodUpdateInstance() initWithPaymentSummaryItems:WebCore::platformSummaryItems(WTFMove(update->newTotal), WTFMove(update->newLineItems))]);
     267#if HAVE(PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS)
     268    [shippingMethodUpdate setShippingMethods:toPKShippingMethods(WTFMove(update->newShippingMethods)).get()];
     269#endif
    263270#if defined(PaymentAuthorizationPresenterAdditions_completeShippingMethodSelection)
    264271    PaymentAuthorizationPresenterAdditions_completeShippingMethodSelection
Note: See TracChangeset for help on using the changeset viewer.