haikuwebkit/Source/WebCore/Modules/applepay
Devin Rousso 0d84a0f413 [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.


Canonical link: https://commits.webkit.org/240094@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@280459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-07-30 00:28:45 +00:00
..
cocoa [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
paymentrequest [Payment Request] `additionalShippingMethods` are not used if a `paymentMethodType` is provided 2021-07-30 00:28:45 +00:00
ApplePayCancelEvent.cpp
ApplePayCancelEvent.h
ApplePayCancelEvent.idl [WebIDL] Realign our IDL extended attribute names with those specified in WebIDL 2020-09-05 17:14:23 +00:00
ApplePayContactField.cpp
ApplePayContactField.h
ApplePayContactField.idl
ApplePayCouponCodeChangedEvent.cpp [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayCouponCodeChangedEvent.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayCouponCodeChangedEvent.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayCouponCodeDetails.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayCouponCodeDetails.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayCouponCodeUpdate.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayCouponCodeUpdate.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayDateComponents.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayDateComponents.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayDateComponentsRange.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayDateComponentsRange.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayDetailsUpdateBase.h Remove WTF::Optional synonym for std::optional, using that class template directly instead 2021-05-30 16:11:40 +00:00
ApplePayDetailsUpdateBase.idl [Payment Request] move added `object data` to `ApplePayModifier` 2021-03-29 20:01:00 +00:00
ApplePayDetailsUpdateData.h Remove WTF::Optional synonym for std::optional, using that class template directly instead 2021-05-30 16:11:40 +00:00
ApplePayDetailsUpdateData.idl [Payment Request] add an `object data` to `PaymentDetailsBase` so that data specific to Apple Pay can be provided 2021-02-19 17:38:37 +00:00
ApplePayError.h Remove <wtf/Optional.h> 2021-06-02 06:45:51 +00:00
ApplePayError.idl [WebIDL] Make Exposed mandatory for IDL interfaces 2020-10-01 00:15:51 +00:00
ApplePayErrorCode.h [Apple Pay] Do not add coupon code `ApplePayErrorCode` values for systems that do not support it 2021-07-24 08:23:15 +00:00
ApplePayErrorCode.idl [Apple Pay] Do not add coupon code `ApplePayErrorCode` values for systems that do not support it 2021-07-24 08:23:15 +00:00
ApplePayErrorContactField.h [Payment Request] add an `object data` to `PaymentDetailsBase` so that data specific to Apple Pay can be provided 2021-02-19 17:38:37 +00:00
ApplePayErrorContactField.idl
ApplePayInstallmentConfiguration.idl
ApplePayInstallmentConfigurationWebCore.h
ApplePayInstallmentItem.h
ApplePayInstallmentItem.idl
ApplePayInstallmentItemType.h
ApplePayInstallmentItemType.idl
ApplePayInstallmentRetailChannel.h
ApplePayInstallmentRetailChannel.idl
ApplePayLineItem.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayLineItem.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayMerchantCapability.cpp
ApplePayMerchantCapability.h
ApplePayMerchantCapability.idl
ApplePayPayment.h Remove WTF::Optional synonym for std::optional, using that class template directly instead 2021-05-30 16:11:40 +00:00
ApplePayPayment.idl
ApplePayPaymentAuthorizationResult.h [Payment Request] add an `object data` to `PaymentDetailsBase` so that data specific to Apple Pay can be provided 2021-02-19 17:38:37 +00:00
ApplePayPaymentAuthorizationResult.idl
ApplePayPaymentAuthorizedEvent.cpp
ApplePayPaymentAuthorizedEvent.h
ApplePayPaymentAuthorizedEvent.idl [WebIDL] Realign our IDL extended attribute names with those specified in WebIDL 2020-09-05 17:14:23 +00:00
ApplePayPaymentContact.h Remove <wtf/Optional.h> 2021-06-02 06:45:51 +00:00
ApplePayPaymentContact.idl
ApplePayPaymentMethod.h Remove <wtf/Optional.h> 2021-06-02 06:45:51 +00:00
ApplePayPaymentMethod.idl
ApplePayPaymentMethodSelectedEvent.cpp
ApplePayPaymentMethodSelectedEvent.h
ApplePayPaymentMethodSelectedEvent.idl [WebIDL] Realign our IDL extended attribute names with those specified in WebIDL 2020-09-05 17:14:23 +00:00
ApplePayPaymentMethodType.h
ApplePayPaymentMethodType.idl
ApplePayPaymentMethodUpdate.h [Payment Request] `additionalShippingMethods` are not used if a `paymentMethodType` is provided 2021-07-30 00:28:45 +00:00
ApplePayPaymentMethodUpdate.idl [Payment Request] `additionalShippingMethods` are not used if a `paymentMethodType` is provided 2021-07-30 00:28:45 +00:00
ApplePayPaymentPass.h
ApplePayPaymentPass.idl
ApplePayPaymentRequest.h Remove WTF::Optional synonym for std::optional, using that class template directly instead 2021-05-30 16:11:40 +00:00
ApplePayPaymentRequest.idl
ApplePayPaymentTiming.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayPaymentTiming.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayRecurringPaymentDateUnit.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayRecurringPaymentDateUnit.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayRequestBase.cpp [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayRequestBase.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayRequestBase.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePaySession.cpp [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePaySession.h Unreviewed, followup to r278630 2021-06-09 02:23:59 +00:00
ApplePaySession.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePaySessionError.h
ApplePaySessionError.idl
ApplePaySessionPaymentRequest.cpp Remove WTF::Optional synonym for std::optional, using that class template directly instead 2021-05-30 16:11:40 +00:00
ApplePaySessionPaymentRequest.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePaySetup.cpp Next step toward using std::optional directly instead of through WTF::Optional typedef 2021-05-28 01:26:23 +00:00
ApplePaySetup.idl [WebIDL] Make Exposed mandatory for IDL interfaces 2020-10-01 00:15:51 +00:00
ApplePaySetupConfiguration.h
ApplePaySetupConfiguration.idl
ApplePaySetupFeature.idl [WebIDL] Make Exposed mandatory for IDL interfaces 2020-10-01 00:15:51 +00:00
ApplePaySetupFeature.mm [Apple Pay] Fix the build on Catalina internal SDKs 2020-07-08 03:21:59 +00:00
ApplePaySetupFeatureState.h
ApplePaySetupFeatureState.idl
ApplePaySetupFeatureType.idl
ApplePaySetupFeatureTypeWebCore.h
ApplePaySetupFeatureWebCore.h
ApplePaySetupWebCore.h Remove WTF::Optional synonym for std::optional, using that class template directly instead 2021-05-30 16:11:40 +00:00
ApplePayShippingContactEditingMode.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayShippingContactEditingMode.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayShippingContactSelectedEvent.cpp
ApplePayShippingContactSelectedEvent.h
ApplePayShippingContactSelectedEvent.idl [WebIDL] Realign our IDL extended attribute names with those specified in WebIDL 2020-09-05 17:14:23 +00:00
ApplePayShippingContactUpdate.h Remove <wtf/Optional.h> 2021-06-02 06:45:51 +00:00
ApplePayShippingContactUpdate.idl [Payment Request] add an `object data` to `PaymentDetailsBase` so that data specific to Apple Pay can be provided 2021-02-19 17:38:37 +00:00
ApplePayShippingMethod.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayShippingMethod.idl [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
ApplePayShippingMethodSelectedEvent.cpp [Payment Request] add an `object data` to `PaymentDetailsBase` so that data specific to Apple Pay can be provided 2021-02-19 17:38:37 +00:00
ApplePayShippingMethodSelectedEvent.h [Payment Request] add an `object data` to `PaymentDetailsBase` so that data specific to Apple Pay can be provided 2021-02-19 17:38:37 +00:00
ApplePayShippingMethodSelectedEvent.idl [WebIDL] Realign our IDL extended attribute names with those specified in WebIDL 2020-09-05 17:14:23 +00:00
ApplePayShippingMethodUpdate.h [Payment Request] `additionalShippingMethods` are not used if a `paymentMethodType` is provided 2021-07-30 00:28:45 +00:00
ApplePayShippingMethodUpdate.idl [Payment Request] `additionalShippingMethods` are not used if a `paymentMethodType` is provided 2021-07-30 00:28:45 +00:00
ApplePayValidateMerchantEvent.cpp
ApplePayValidateMerchantEvent.h
ApplePayValidateMerchantEvent.idl [WebIDL] Realign our IDL extended attribute names with those specified in WebIDL 2020-09-05 17:14:23 +00:00
Payment.h
PaymentAPIVersion.h
PaymentAuthorizationStatus.h
PaymentContact.h
PaymentCoordinator.cpp Enable WebPage's release logging in ephemeral sessions 2021-06-10 18:11:22 +00:00
PaymentCoordinator.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
PaymentCoordinatorClient.cpp
PaymentCoordinatorClient.h Enable WebPage's release logging in ephemeral sessions 2021-06-10 18:11:22 +00:00
PaymentHeaders.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
PaymentInstallmentConfiguration.mm Remove WTF::Optional synonym for std::optional, using that class template directly instead 2021-05-30 16:11:40 +00:00
PaymentInstallmentConfigurationWebCore.h
PaymentMerchantSession.h Remove WTF::Optional synonym for std::optional, using that class template directly instead 2021-05-30 16:11:40 +00:00
PaymentMethod.h
PaymentRequestValidator.h [Payment Request] add an `object data` to `PaymentItem` so that data specific to Apple Pay can be provided 2021-02-19 00:37:33 +00:00
PaymentRequestValidator.mm Use ICUDeleter to encode ucnv_close/uenum_close call into type of deleter of std::unique_ptr 2021-03-26 09:25:21 +00:00
PaymentSession.cpp
PaymentSession.h [Payment Request] upstream new features 2021-06-08 22:15:18 +00:00
PaymentSessionError.h
PaymentSummaryItems.h [Payment Request] add an `object data` to `PaymentDetailsBase` so that data specific to Apple Pay can be provided 2021-02-19 17:38:37 +00:00