⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 285521 in webkit


Ignore:
Timestamp:
Nov 9, 2021, 12:04:19 PM (5 years ago)
Author:
Devin Rousso
Message:

REGRESSION(r271735): PaymentShippingOption.selected ignored
​https://bugs.webkit.org/show_bug.cgi?id=221960
<rdar://problem/73464404>

Reviewed by Tim Horton.

Source/WebCore:

Leverage new PKShippingMethods SPI to provide both the general list of PKShippingMethod
and the default selected PKShippingMethods when creating/updating a payment request.

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

(WebCore::ApplePayShippingMethod::encode const):
(WebCore::ApplePayShippingMethod::decode):
Add new selected boolean property.

  • Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:

(WebCore::ApplePayPaymentHandler::computeShippingMethods const):

  • Modules/paymentrequest/PaymentRequest.cpp:

(WebCore::checkAndCanonicalizeDetails):

Source/WebCore/PAL:

Leverage new PKShippingMethods SPI to provide both the general list of PKShippingMethod
and the default selected PKShippingMethods when creating/updating a payment request.

  • pal/cocoa/PassKitSoftLink.h:
  • pal/cocoa/PassKitSoftLink.mm:
  • pal/spi/cocoa/PassKitSPI.h:

Source/WebKit:

Leverage new PKShippingMethods SPI to provide both the general list of PKShippingMethod
and the default selected PKShippingMethods when creating/updating a payment request.

  • Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h:
  • Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:

(WebKit::toPKShippingMethods): Added.
(WebKit::WebPaymentCoordinatorProxy::platformPaymentRequest):
Add new helper to generate the PKShippingMethods from WebCore objects.

  • Platform/cocoa/PaymentAuthorizationPresenter.mm:

(WebKit::PaymentAuthorizationPresenter::completePaymentMethodSelection):
(WebKit::PaymentAuthorizationPresenter::completeShippingContactSelection):
(WebKit::PaymentAuthorizationPresenter::completeShippingMethodSelection):
(WebKit::PaymentAuthorizationPresenter::completeCouponCodeChange):
(WebKit::toPKShippingMethods): Deleted.

  • Platform/cocoa/WKPaymentAuthorizationDelegate.mm:

(-[WKPaymentAuthorizationDelegate completePaymentMethodSelection:]):
(-[WKPaymentAuthorizationDelegate completeShippingContactSelection:]):
(-[WKPaymentAuthorizationDelegate completeShippingMethodSelection:]):
(-[WKPaymentAuthorizationDelegate completeCouponCodeChange:]):
(-[WKPaymentAuthorizationDelegate _initWithRequest:presenter:]):
(toShippingMethod):
(-[WKPaymentAuthorizationDelegate _didSelectShippingMethod:completion:]):
(-[WKPaymentAuthorizationDelegate summaryItems]): Deleted.
(-[WKPaymentAuthorizationDelegate shippingMethods]): Deleted.
Drive-by: Delete unused methods.

Source/WTF:

Leverage new PKShippingMethods SPI to provide both the general list of PKShippingMethod
and the default selected PKShippingMethods when creating/updating a payment request.

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

LayoutTests:

  • http/tests/paymentrequest/payment-request-change-shipping-option.https.html:
  • http/tests/paymentrequest/payment-request-change-shipping-option.https-expected.txt:
  • http/tests/paymentrequest/updateWith-shippingOptions.https.html:
  • http/tests/paymentrequest/updateWith-shippingOptions.https-expected.txt:
Location:
trunk
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r285505 r285521  
     12021-11-09  Devin Rousso  <drousso@apple.com>
     2
     3        REGRESSION(r271735): PaymentShippingOption.selected ignored
     4        https://bugs.webkit.org/show_bug.cgi?id=221960
     5        <rdar://problem/73464404>
     6
     7        Reviewed by Tim Horton.
     8
     9        * http/tests/paymentrequest/payment-request-change-shipping-option.https.html:
     10        * http/tests/paymentrequest/payment-request-change-shipping-option.https-expected.txt:
     11        * http/tests/paymentrequest/updateWith-shippingOptions.https.html:
     12        * http/tests/paymentrequest/updateWith-shippingOptions.https-expected.txt:
     13
    1142021-11-09  Rob Buis  <rbuis@igalia.com>
    215
  • trunk/LayoutTests/http/tests/paymentrequest/payment-request-change-shipping-option.https-expected.txt

    r271735 r285521  
    11CONSOLE MESSAGE: WebKit currently uses the first shipping option even if other shipping options are marked as selected.
    22
    3 PASS Test for PaymentRequest shippingOption attribute
     3FAIL Test for PaymentRequest shippingOption attribute assert_equals: Must be 'initially-selected', as the selected member is true expected "initially-selected" but got "valid-1"
    44
  • trunk/LayoutTests/http/tests/paymentrequest/payment-request-change-shipping-option.https.html

    r273562 r285521  
    6464        internals.mockPaymentCoordinator.changeShippingOption("valid-1");
    6565    };
    66     // FIXME: <rdar://problem/73464404>
    67     // assert_equals(request.shippingOption, "initially-selected", "Must be 'initially-selected', as the selected member is true");
    68     assert_equals(request.shippingOption, "valid-1", "Must be the first shipping option regardless of the selected property.");
     66    assert_equals(
     67      request.shippingOption,
     68      "initially-selected",
     69      "Must be 'initially-selected', as the selected member is true"
     70    );
    6971    const listenerPromise = new Promise(resolve => {
    7072      request.addEventListener("shippingoptionchange", () => {
  • trunk/LayoutTests/http/tests/paymentrequest/updateWith-shippingOptions.https-expected.txt

    r271735 r285521  
    22
    33PASS Calling `updateWith` with a new `shippingOptions` without `requestShipping` should not update any values.
    4 PASS Calling `updateWith` with a new `shippingOptions` should not update any other values.
     4FAIL Calling `updateWith` with a new `shippingOptions` should not update any other values. assert_equals: selected shipping option should change expected "shippingId4" but got "shippingId3"
    55
  • trunk/LayoutTests/http/tests/paymentrequest/updateWith-shippingOptions.https.html

    r274012 r285521  
    9494        assert_equals(internals.mockPaymentCoordinator.shippingMethods[i].amount, detailsUpdate.shippingOptions[i].amount.value, `shipping option ${i} amount should change`);
    9595    }
    96     // FIXME: <rdar://problem/73464404>
    97     // assert_equals(request.shippingOption, detailsUpdate.shippingOptions.find((shippingOption) => shippingOption.selected).id, "selected shipping option should change");
     96    assert_equals(request.shippingOption, detailsUpdate.shippingOptions.findLast((shippingOption) => shippingOption.selected).id, "selected shipping option should change");
    9897    assert_equals(request.shippingOption, detailsUpdate.shippingOptions[0].id, "selected shipping option should change");
    9998    assert_equals(response.shippingOption, request.shippingOption, "selected shipping option should also be exposed on the response");
  • trunk/Source/WTF/ChangeLog

    r285480 r285521  
     12021-11-09  Devin Rousso  <drousso@apple.com>
     2
     3        REGRESSION(r271735): PaymentShippingOption.selected ignored
     4        https://bugs.webkit.org/show_bug.cgi?id=221960
     5        <rdar://problem/73464404>
     6
     7        Reviewed by Tim Horton.
     8
     9        Leverage new `PKShippingMethods` SPI to provide both the general list of `PKShippingMethod`
     10        and the default selected `PKShippingMethods` when creating/updating a payment request.
     11
     12        * wtf/PlatformEnableCocoa.h:
     13        * wtf/PlatformHave.h:
     14
    1152021-11-08  Myles C. Maxfield  <mmaxfield@apple.com>
    216
  • trunk/Source/WTF/wtf/PlatformEnableCocoa.h

    r285242 r285521  
    7676#endif
    7777
     78#if !defined(ENABLE_APPLE_PAY_SELECTED_SHIPPING_METHOD) && HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     79#define ENABLE_APPLE_PAY_SELECTED_SHIPPING_METHOD 1
     80#endif
     81
    7882#if !defined(ENABLE_APPLE_PAY_SHIPPING_CONTACT_EDITING_MODE) && HAVE(PASSKIT_SHIPPING_CONTACT_EDITING_MODE)
    7983#define ENABLE_APPLE_PAY_SHIPPING_CONTACT_EDITING_MODE 1
    … …  
    447451#endif
    448452
     453#if !defined(ENABLE_PAYMENT_REQUEST_SELECTED_SHIPPING_OPTION) && HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     454#define ENABLE_PAYMENT_REQUEST_SELECTED_SHIPPING_OPTION 1
     455#endif
     456
    449457#if !defined(ENABLE_PICTURE_IN_PICTURE_API) && !PLATFORM(MACCATALYST) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
    450458#define ENABLE_PICTURE_IN_PICTURE_API 1
  • trunk/Source/WTF/wtf/PlatformHave.h

    r285019 r285521  
    650650#endif
    651651
     652#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 120400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 150400)
     653#define HAVE_PASSKIT_DEFAULT_SHIPPING_METHOD 1
     654#endif
     655
    652656#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
    653657#define HAVE_QUICKLOOK_THUMBNAILING 1
  • trunk/Source/WebCore/ChangeLog

    r285520 r285521  
     12021-11-09  Devin Rousso  <drousso@apple.com>
     2
     3        REGRESSION(r271735): PaymentShippingOption.selected ignored
     4        https://bugs.webkit.org/show_bug.cgi?id=221960
     5        <rdar://problem/73464404>
     6
     7        Reviewed by Tim Horton.
     8
     9        Leverage new `PKShippingMethods` SPI to provide both the general list of `PKShippingMethod`
     10        and the default selected `PKShippingMethods` when creating/updating a payment request.
     11
     12        * Modules/applepay/ApplePayShippingMethod.idl:
     13        * Modules/applepay/ApplePayShippingMethod.h:
     14        (WebCore::ApplePayShippingMethod::encode const):
     15        (WebCore::ApplePayShippingMethod::decode):
     16        Add new `selected` boolean property.
     17
     18        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
     19        (WebCore::ApplePayPaymentHandler::computeShippingMethods const):
     20
     21        * Modules/paymentrequest/PaymentRequest.cpp:
     22        (WebCore::checkAndCanonicalizeDetails):
     23
    1242021-11-09  Sihui Liu  <sihui_liu@apple.com>
    225
  • trunk/Source/WebCore/Modules/applepay/ApplePayShippingMethod.h

    r278630 r285521  
    4444#endif
    4545
     46#if ENABLE(APPLE_PAY_SELECTED_SHIPPING_METHOD)
     47    bool selected { false };
     48#endif
     49
    4650    template<class Encoder> void encode(Encoder&) const;
    4751    template<class Decoder> static std::optional<ApplePayShippingMethod> decode(Decoder&);
    … …  
    5761#if ENABLE(APPLE_PAY_SHIPPING_METHOD_DATE_COMPONENTS_RANGE)
    5862    encoder << dateComponentsRange;
     63#endif
     64#if ENABLE(APPLE_PAY_SELECTED_SHIPPING_METHOD)
     65    encoder << selected;
    5966#endif
    6067}
    … …  
    7683    DECODE(dateComponentsRange, std::optional<ApplePayDateComponentsRange>)
    7784#endif
     85#if ENABLE(APPLE_PAY_SELECTED_SHIPPING_METHOD)
     86    DECODE(selected, bool)
     87#endif
    7888
    7989#undef DECODE
    … …  
    8797        WTFMove(*dateComponentsRange),
    8898#endif
     99#if ENABLE(APPLE_PAY_SELECTED_SHIPPING_METHOD)
     100        WTFMove(*selected),
     101#endif
    89102    } };
    90103}
  • trunk/Source/WebCore/Modules/applepay/ApplePayShippingMethod.idl

    r278630 r285521  
    3535
    3636    [Conditional=APPLE_PAY_SHIPPING_METHOD_DATE_COMPONENTS_RANGE] ApplePayDateComponentsRange dateComponentsRange;
     37
     38    [Conditional=APPLE_PAY_SELECTED_SHIPPING_METHOD] boolean selected = false;
    3739};
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp

    r285444 r285521  
    300300        shippingOptions.reserveInitialCapacity(details.shippingOptions->size());
    301301        for (auto& shippingOption : *details.shippingOptions) {
    302             auto shippingMethod = convertAndValidate(shippingOption, currency);
    303             if (shippingMethod.hasException())
    304                 return shippingMethod.releaseException();
    305             shippingOptions.uncheckedAppend(shippingMethod.releaseReturnValue());
     302            auto shippingMethodOrException = convertAndValidate(shippingOption, currency);
     303            if (shippingMethodOrException.hasException())
     304                return shippingMethodOrException.releaseException();
     305
     306            auto shippingMethod = shippingMethodOrException.releaseReturnValue();
     307
     308#if ENABLE(APPLE_PAY_SELECTED_SHIPPING_METHOD)
     309            if (shippingMethod.identifier == m_paymentRequest->shippingOption())
     310                shippingMethod.selected = true;
     311#endif
     312
     313            shippingOptions.uncheckedAppend(WTFMove(shippingMethod));
    306314        }
    307315    }
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp

    r285444 r285521  
    219219                    return Exception { TypeError, "Shipping option IDs must be unique." };
    220220
    221                 // FIXME: <rdar://problem/73464404>
     221#if ENABLE(PAYMENT_REQUEST_SELECTED_SHIPPING_OPTION)
     222                if (shippingOption.selected)
     223                    selectedShippingOption = shippingOption.id;
     224                UNUSED_PARAM(context);
     225                UNUSED_VARIABLE(didLog);
     226#else
    222227                if (!selectedShippingOption)
    223228                    selectedShippingOption = shippingOption.id;
    … …  
    226231                    didLog = true;
    227232                }
     233#endif
    228234            }
    229235        } else if (isUpdate == IsUpdate::No)
  • trunk/Source/WebCore/PAL/ChangeLog

    r285513 r285521  
     12021-11-09  Devin Rousso  <drousso@apple.com>
     2
     3        REGRESSION(r271735): PaymentShippingOption.selected ignored
     4        https://bugs.webkit.org/show_bug.cgi?id=221960
     5        <rdar://problem/73464404>
     6
     7        Reviewed by Tim Horton.
     8
     9        Leverage new `PKShippingMethods` SPI to provide both the general list of `PKShippingMethod`
     10        and the default selected `PKShippingMethods` when creating/updating a payment request.
     11
     12        * pal/cocoa/PassKitSoftLink.h:
     13        * pal/cocoa/PassKitSoftLink.mm:
     14        * pal/spi/cocoa/PassKitSPI.h:
     15
    1162021-11-09  Commit Queue  <commit-queue@webkit.org>
    217
  • trunk/Source/WebCore/PAL/pal/cocoa/PassKitSoftLink.h

    r278630 r285521  
    6161#endif
    6262
     63#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     64SOFT_LINK_CLASS_FOR_HEADER(PAL, PKShippingMethods)
     65#endif
     66
    6367#if HAVE(PASSKIT_SHIPPING_METHOD_DATE_COMPONENTS_RANGE)
    6468SOFT_LINK_CLASS_FOR_HEADER(PAL, PKDateComponentsRange)
  • trunk/Source/WebCore/PAL/pal/cocoa/PassKitSoftLink.mm

    r278630 r285521  
    6565#endif
    6666
     67#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     68SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT(PAL, PassKit, PKShippingMethods, PAL_EXPORT)
     69#endif
     70
    6771#if HAVE(PASSKIT_SHIPPING_METHOD_DATE_COMPONENTS_RANGE)
    6872SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT(PAL, PassKit, PKDateComponentsRange, PAL_EXPORT)
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/PassKitSPI.h

    r283431 r285521  
    7272#endif
    7373
     74#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     75#import <PassKitCore/PKShippingMethods.h>
     76#endif
     77
    7478#if HAVE(PASSKIT_SHIPPING_METHOD_DATE_COMPONENTS_RANGE)
    7579#import <PassKitCore/PKDateComponentsRange.h>
    … …  
    256260@property (nonatomic, copy) NSString *label;
    257261@property (nonatomic, copy) NSDecimalNumber *amount;
     262@end
     263#endif
     264
     265#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     266@interface PKShippingMethods : NSObject
     267- (instancetype)initWithMethods:(NSArray<PKShippingMethod *> *)methods defaultMethod:(nullable PKShippingMethod *)defaultMethod;
    258268@end
    259269#endif
    … …  
    305315#endif
    306316
     317#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     318@property (nonatomic, copy) PKShippingMethods *availableShippingMethods;
     319#endif
     320
    307321#if HAVE(PASSKIT_SHIPPING_CONTACT_EDITING_MODE)
    308322@property (nonatomic, assign) PKShippingContactEditingMode shippingContactEditingMode;
    … …  
    460474@property (nonatomic, copy) NSArray<PKShippingMethod *> *shippingMethods;
    461475#endif
     476#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     477@property (nonatomic, copy) PKShippingMethods *availableShippingMethods;
     478#endif
    462479@end
    463480
    464481@interface PKPaymentRequestPaymentMethodUpdate : PKPaymentRequestUpdate
    465 - (instancetype)initWithErrors:(nullable NSArray<NSError *> *)errors paymentSummaryItems:(nonnull NSArray<PKPaymentSummaryItem *> *)summaryItems;
    466482@property (null_resettable, nonatomic, copy) NSArray<NSError *> *errors;
    467483@end
    468484
    469485@interface PKPaymentRequestShippingContactUpdate : PKPaymentRequestUpdate
    470 - (instancetype)initWithErrors:(nullable NSArray<NSError *> *)errors paymentSummaryItems:(nonnull NSArray<PKPaymentSummaryItem *> *)summaryItems shippingMethods:(nonnull NSArray<PKShippingMethod *> *)shippingMethods;
    471486@property (nonatomic, copy) NSArray<PKShippingMethod *> *shippingMethods;
     487@property (nonatomic, copy, null_resettable) NSArray<NSError *> *errors;
    472488@end
    473489
    … …  
    477493#if HAVE(PASSKIT_COUPON_CODE)
    478494@interface PKPaymentRequestCouponCodeUpdate : PKPaymentRequestUpdate
    479 - (instancetype)initWithErrors:(nullable NSArray<NSError *> *)errors paymentSummaryItems:(NSArray<PKPaymentSummaryItem *> *)paymentSummaryItems shippingMethods:(NSArray<PKShippingMethod *> *)shippingMethods;
     495@property (nonatomic, copy, null_resettable) NSArray<NSError *> *errors;
    480496@end
    481497#endif
  • trunk/Source/WebKit/ChangeLog

    r285520 r285521  
     12021-11-09  Devin Rousso  <drousso@apple.com>
     2
     3        REGRESSION(r271735): PaymentShippingOption.selected ignored
     4        https://bugs.webkit.org/show_bug.cgi?id=221960
     5        <rdar://problem/73464404>
     6
     7        Reviewed by Tim Horton.
     8
     9        Leverage new `PKShippingMethods` SPI to provide both the general list of `PKShippingMethod`
     10        and the default selected `PKShippingMethods` when creating/updating a payment request.
     11
     12        * Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h:
     13        * Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
     14        (WebKit::toPKShippingMethods): Added.
     15        (WebKit::WebPaymentCoordinatorProxy::platformPaymentRequest):
     16        Add new helper to generate the `PKShippingMethods` from WebCore objects.
     17
     18        * Platform/cocoa/PaymentAuthorizationPresenter.mm:
     19        (WebKit::PaymentAuthorizationPresenter::completePaymentMethodSelection):
     20        (WebKit::PaymentAuthorizationPresenter::completeShippingContactSelection):
     21        (WebKit::PaymentAuthorizationPresenter::completeShippingMethodSelection):
     22        (WebKit::PaymentAuthorizationPresenter::completeCouponCodeChange):
     23        (WebKit::toPKShippingMethods): Deleted.
     24
     25        * Platform/cocoa/WKPaymentAuthorizationDelegate.mm:
     26        (-[WKPaymentAuthorizationDelegate completePaymentMethodSelection:]):
     27        (-[WKPaymentAuthorizationDelegate completeShippingContactSelection:]):
     28        (-[WKPaymentAuthorizationDelegate completeShippingMethodSelection:]):
     29        (-[WKPaymentAuthorizationDelegate completeCouponCodeChange:]):
     30        (-[WKPaymentAuthorizationDelegate _initWithRequest:presenter:]):
     31        (toShippingMethod):
     32        (-[WKPaymentAuthorizationDelegate _didSelectShippingMethod:completion:]):
     33        (-[WKPaymentAuthorizationDelegate summaryItems]): Deleted.
     34        (-[WKPaymentAuthorizationDelegate shippingMethods]): Deleted.
     35        Drive-by: Delete unused methods.
     36
    1372021-11-09  Sihui Liu  <sihui_liu@apple.com>
    238
  • trunk/Source/WebKit/Platform/cocoa/PaymentAuthorizationPresenter.mm

    r282464 r285521  
    196196}
    197197
    198 static RetainPtr<NSArray> toPKShippingMethods(const Vector<WebCore::ApplePayShippingMethod>& shippingMethods)
    199 {
    200     return createNSArray(shippingMethods, [] (auto& method) {
    201         return toPKShippingMethod(method);
    202     });
    203 }
    204 
    205198void PaymentAuthorizationPresenter::completeMerchantValidation(const WebCore::PaymentMerchantSession& merchantSession)
    206199{
    … …  
    224217#if HAVE(PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS)
    225218    [paymentMethodUpdate setErrors:toNSErrors(WTFMove(update->errors)).get()];
    226     [paymentMethodUpdate setShippingMethods:toPKShippingMethods(WTFMove(update->newShippingMethods)).get()];
     219#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     220    [paymentMethodUpdate setAvailableShippingMethods:toPKShippingMethods(WTFMove(update->newShippingMethods))];
     221#else
     222    [paymentMethodUpdate setShippingMethods:createNSArray(WTFMove(update->newShippingMethods), [] (auto& method) {
     223        return toPKShippingMethod(method);
     224    }).get()];
     225#endif
    227226#endif
    228227#if HAVE(PASSKIT_INSTALLMENTS) && ENABLE(APPLE_PAY_INSTALLMENTS)
    … …  
    249248    }
    250249
    251     auto shippingContactUpdate = adoptNS([PAL::allocPKPaymentRequestShippingContactUpdateInstance() initWithErrors:toNSErrors(WTFMove(update->errors)).get()
    252         paymentSummaryItems:WebCore::platformSummaryItems(WTFMove(update->newTotal), WTFMove(update->newLineItems))
    253         shippingMethods:toPKShippingMethods(WTFMove(update->newShippingMethods)).get()]);
     250    auto shippingContactUpdate = adoptNS([PAL::allocPKPaymentRequestShippingContactUpdateInstance() initWithPaymentSummaryItems:WebCore::platformSummaryItems(WTFMove(update->newTotal), WTFMove(update->newLineItems))]);
     251    [shippingContactUpdate setErrors:toNSErrors(WTFMove(update->errors)).get()];
     252#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     253    [shippingContactUpdate setAvailableShippingMethods:toPKShippingMethods(WTFMove(update->newShippingMethods))];
     254#else
     255    [shippingContactUpdate setShippingMethods:createNSArray(WTFMove(update->newShippingMethods), [] (auto& method) {
     256        return toPKShippingMethod(method);
     257    }).get()];
     258#endif
    254259    merge(shippingContactUpdate.get(), *update);
    255260    [platformDelegate() completeShippingContactSelection:shippingContactUpdate.get()];
    … …  
    265270
    266271    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()];
     272#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     273    [shippingMethodUpdate setAvailableShippingMethods:toPKShippingMethods(WTFMove(update->newShippingMethods))];
     274#elif HAVE(PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS)
     275    [shippingMethodUpdate setShippingMethods:createNSArray(WTFMove(update->newShippingMethods), [] (auto& method) {
     276        return toPKShippingMethod(method);
     277    }).get()];
    269278#endif
    270279    merge(shippingMethodUpdate.get(), *update);
    … …  
    282291    }
    283292
    284     auto couponCodeUpdate = adoptNS([PAL::allocPKPaymentRequestCouponCodeUpdateInstance() initWithErrors:toNSErrors(WTFMove(update->errors)).get() paymentSummaryItems:WebCore::platformSummaryItems(WTFMove(update->newTotal), WTFMove(update->newLineItems)) shippingMethods:toPKShippingMethods(WTFMove(update->newShippingMethods)).get()]);
     293    auto couponCodeUpdate = adoptNS([PAL::allocPKPaymentRequestCouponCodeUpdateInstance() initWithPaymentSummaryItems:WebCore::platformSummaryItems(WTFMove(update->newTotal), WTFMove(update->newLineItems))]);
     294#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     295    [couponCodeUpdate setAvailableShippingMethods:toPKShippingMethods(WTFMove(update->newShippingMethods))];
     296#else
     297    [couponCodeUpdate setShippingMethods:createNSArray(WTFMove(update->newShippingMethods), [] (auto& method) {
     298        return toPKShippingMethod(method);
     299    }).get()];
     300#endif
    285301    merge(couponCodeUpdate.get(), *update);
    286302    [platformDelegate() completeCouponCodeChange:couponCodeUpdate.get()];
  • trunk/Source/WebKit/Platform/cocoa/WKPaymentAuthorizationDelegate.mm

    r284142 r285521  
    3636@implementation WKPaymentAuthorizationDelegate {
    3737    RetainPtr<NSArray<PKPaymentSummaryItem *>> _summaryItems;
     38#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     39    RetainPtr<PKShippingMethods> _availableShippingMethods;
     40#else
    3841    RetainPtr<NSArray<PKShippingMethod *>> _shippingMethods;
     42#endif
    3943    RetainPtr<NSError> _sessionError;
    4044    WebKit::DidAuthorizePaymentCompletion _didAuthorizePaymentCompletion;
    … …  
    4852}
    4953
    50 - (NSArray<PKPaymentSummaryItem *> *)summaryItems
    51 {
    52     return _summaryItems.get();
    53 }
    54 
    55 - (NSArray<PKShippingMethod *> *)shippingMethods
    56 {
    57     return _shippingMethods.get();
    58 }
    59 
    6054- (void)completeMerchantValidation:(PKPaymentMerchantSession *)session error:(NSError *)error
    6155{
    … …  
    6559- (void)completePaymentMethodSelection:(PKPaymentRequestPaymentMethodUpdate *)paymentMethodUpdate
    6660{
    67     auto update = paymentMethodUpdate ? retainPtr(paymentMethodUpdate) : adoptNS([PAL::allocPKPaymentRequestPaymentMethodUpdateInstance() initWithPaymentSummaryItems:_summaryItems.get()]);
    68     _summaryItems = adoptNS([[update paymentSummaryItems] copy]);
     61    RetainPtr update = paymentMethodUpdate;
     62    if (update) {
     63        _summaryItems = adoptNS([[update paymentSummaryItems] copy]);
     64#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     65        _availableShippingMethods = adoptNS([[update availableShippingMethods] copy]);
     66#elif HAVE(PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS)
     67        _shippingMethods = adoptNS([[update shippingMethods] copy]);
     68#endif
     69    } else {
     70        update = adoptNS([PAL::allocPKPaymentRequestPaymentMethodUpdateInstance() initWithPaymentSummaryItems:_summaryItems.get()]);
     71#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     72        [update setAvailableShippingMethods:_availableShippingMethods.get()];
     73#elif HAVE(PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS)
     74        [update setShippingMethods:_shippingMethods.get()];
     75#endif
     76    }
     77
    6978    std::exchange(_didSelectPaymentMethodCompletion, nil)(update.get());
    7079}
    … …  
    7786- (void)completeShippingContactSelection:(PKPaymentRequestShippingContactUpdate *)shippingContactUpdate
    7887{
    79     auto update = shippingContactUpdate ? retainPtr(shippingContactUpdate) : adoptNS([PAL::allocPKPaymentRequestShippingContactUpdateInstance() initWithErrors:@[] paymentSummaryItems:_summaryItems.get() shippingMethods:_shippingMethods.get()]);
    80     _summaryItems = adoptNS([[update paymentSummaryItems] copy]);
    81     _shippingMethods = adoptNS([[update shippingMethods] copy]);
     88    RetainPtr update = shippingContactUpdate;
     89    if (update) {
     90        _summaryItems = adoptNS([[update paymentSummaryItems] copy]);
     91#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     92        _availableShippingMethods = adoptNS([[update availableShippingMethods] copy]);
     93#else
     94        _shippingMethods = adoptNS([[update shippingMethods] copy]);
     95#endif
     96    } else {
     97        update = adoptNS([PAL::allocPKPaymentRequestShippingContactUpdateInstance() initWithPaymentSummaryItems:_summaryItems.get()]);
     98#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     99        [update setAvailableShippingMethods:_availableShippingMethods.get()];
     100#else
     101        [update setShippingMethods:_shippingMethods.get()];
     102#endif
     103    }
     104
    82105    std::exchange(_didSelectShippingContactCompletion, nil)(update.get());
    83106}
    … …  
    85108- (void)completeShippingMethodSelection:(PKPaymentRequestShippingMethodUpdate *)shippingMethodUpdate
    86109{
    87     auto update = shippingMethodUpdate ? retainPtr(shippingMethodUpdate) : adoptNS([PAL::allocPKPaymentRequestShippingMethodUpdateInstance() initWithPaymentSummaryItems:_summaryItems.get()]);
    88     _summaryItems = adoptNS([[update paymentSummaryItems] copy]);
     110    RetainPtr update = shippingMethodUpdate;
     111    if (update) {
     112        _summaryItems = adoptNS([[update paymentSummaryItems] copy]);
     113#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     114        _availableShippingMethods = adoptNS([[update availableShippingMethods] copy]);
     115#elif HAVE(PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS)
     116        _shippingMethods = adoptNS([[update shippingMethods] copy]);
     117#endif
     118    } else {
     119        update = adoptNS([PAL::allocPKPaymentRequestShippingMethodUpdateInstance() initWithPaymentSummaryItems:_summaryItems.get()]);
     120#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     121        [update setAvailableShippingMethods:_availableShippingMethods.get()];
     122#elif HAVE(PASSKIT_UPDATE_SHIPPING_METHODS_WHEN_CHANGING_SUMMARY_ITEMS)
     123        [update setShippingMethods:_shippingMethods.get()];
     124#endif
     125    }
     126
    89127    std::exchange(_didSelectShippingMethodCompletion, nil)(update.get());
    90128}
    … …  
    94132- (void)completeCouponCodeChange:(PKPaymentRequestCouponCodeUpdate *)couponCodeUpdate
    95133{
    96     PKPaymentRequestCouponCodeUpdate *update = couponCodeUpdate ?: adoptNS([PAL::allocPKPaymentRequestCouponCodeUpdateInstance() initWithErrors:@[] paymentSummaryItems:_summaryItems.get() shippingMethods:_shippingMethods.get()]).autorelease();
    97     _summaryItems = adoptNS([update.paymentSummaryItems copy]);
    98     _shippingMethods = adoptNS([update.shippingMethods copy]);
    99     std::exchange(_didChangeCouponCodeCompletion, nil)(update);
     134    RetainPtr update = couponCodeUpdate;
     135    if (update) {
     136        _summaryItems = adoptNS([[update paymentSummaryItems] copy]);
     137#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     138        _availableShippingMethods = adoptNS([[update availableShippingMethods] copy]);
     139#else
     140        _shippingMethods = adoptNS([[update shippingMethods] copy]);
     141#endif
     142    } else {
     143        update = adoptNS([PAL::allocPKPaymentRequestCouponCodeUpdateInstance() initWithPaymentSummaryItems:_summaryItems.get()]);
     144#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     145        [update setAvailableShippingMethods:_availableShippingMethods.get()];
     146#else
     147        [update setShippingMethods:_shippingMethods.get()];
     148#endif
     149    }
     150
     151    std::exchange(_didChangeCouponCodeCompletion, nil)(update.get());
    100152}
    101153
    … …  
    119171    _presenter = presenter;
    120172    _request = request;
     173#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     174    _availableShippingMethods = request.availableShippingMethods;
     175#else
    121176    _shippingMethods = request.shippingMethods;
     177#endif
    122178    _summaryItems = request.paymentSummaryItems;
    123179    return self;
    … …  
    215271#endif // HAVE(PASSKIT_SHIPPING_METHOD_DATE_COMPONENTS_RANGE)
    216272
    217 static WebCore::ApplePayShippingMethod toShippingMethod(PKShippingMethod *shippingMethod)
     273static WebCore::ApplePayShippingMethod toShippingMethod(PKShippingMethod *shippingMethod, bool selected)
    218274{
    219275    ASSERT(shippingMethod);
    … …  
    228284        result.dateComponentsRange = toDateComponentsRange(shippingMethod.dateComponentsRange);
    229285#endif
     286#if ENABLE(APPLE_PAY_SELECTED_SHIPPING_METHOD)
     287    result.selected = selected;
     288#else
     289    UNUSED_PARAM(selected);
     290#endif
    230291    return result;
    231292}
    … …  
    240301        return [self completeShippingMethodSelection:nil];
    241302
    242     presenter->client().presenterDidSelectShippingMethod(*presenter, toShippingMethod(shippingMethod));
     303    presenter->client().presenterDidSelectShippingMethod(*presenter, toShippingMethod(shippingMethod, true));
    243304}
    244305
  • trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h

    r273143 r285521  
    2929
    3030OBJC_CLASS PKShippingMethod;
     31OBJC_CLASS PKShippingMethods;
    3132
    3233namespace WebCore {
    … …  
    4041NSDecimalNumber *toDecimalNumber(const String& amount);
    4142PKShippingMethod *toPKShippingMethod(const WebCore::ApplePayShippingMethod&);
     43#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     44PKShippingMethods *toPKShippingMethods(const Vector<WebCore::ApplePayShippingMethod>&);
     45#endif
    4246
    4347} // namespace WebKit
  • trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm

    r283431 r285521  
    202202}
    203203
     204#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     205
     206PKShippingMethods *toPKShippingMethods(const Vector<WebCore::ApplePayShippingMethod>& webShippingMethods)
     207{
     208    RetainPtr<PKShippingMethod> defaultMethod;
     209    auto methods = createNSArray(webShippingMethods, [&defaultMethod] (const auto& webShippingMethod) {
     210        auto pkShippingMethod = toPKShippingMethod(webShippingMethod);
     211        if (webShippingMethod.selected)
     212            defaultMethod = pkShippingMethod;
     213        return pkShippingMethod;
     214    });
     215    return [PAL::allocPKShippingMethodsInstance() initWithMethods:methods.get() defaultMethod:defaultMethod.get()];
     216}
     217
     218#endif // HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     219
    204220#if HAVE(PASSKIT_SHIPPING_CONTACT_EDITING_MODE)
    205221
    … …  
    268284    [result setShippingType:toPKShippingType(paymentRequest.shippingType())];
    269285
     286#if HAVE(PASSKIT_DEFAULT_SHIPPING_METHOD)
     287    [result setAvailableShippingMethods:toPKShippingMethods(paymentRequest.shippingMethods())];
     288#else
    270289    [result setShippingMethods:createNSArray(paymentRequest.shippingMethods(), [] (auto& method) {
    271290        return toPKShippingMethod(method);
    272291    }).get()];
     292#endif
    273293
    274294    [result setPaymentSummaryItems:WebCore::platformSummaryItems(paymentRequest.total(), paymentRequest.lineItems())];
Note: See TracChangeset for help on using the changeset viewer.