-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Apple Pay] Support for PKDisbursementRequest on WebKit
https://bugs.webkit.org/show_bug.cgi?id=267428 rdar://115776022 Reviewed by Alex Christensen. Originally authored by Robin Malhotra. This patch adds support for `PKDisbursementRequest` and associated classes. Since `PKDisbursementPaymentRequest` is a subclass and not a property, the code paths may sometimes diverge from convention. * LayoutTests/http/tests/paymentrequest/ApplePayModifier-disbursementPaymentRequest.https-expected.txt: Added. * LayoutTests/http/tests/paymentrequest/ApplePayModifier-disbursementPaymentRequest.https.html: Added. * LayoutTests/platform/ios-wk2/TestExpectations: * LayoutTests/platform/mac-wk2/TestExpectations: * Source/WTF/wtf/PlatformEnableCocoa.h: * Source/WebCore/DerivedSources-input.xcfilelist: * Source/WebCore/DerivedSources-output.xcfilelist: * Source/WebCore/DerivedSources.make: * Source/WebCore/Modules/applepay/ApplePayDetailsUpdateBase.h: * Source/WebCore/Modules/applepay/ApplePayDetailsUpdateBase.idl: * Source/WebCore/Modules/applepay/ApplePayDisbursementPaymentRequest.h: Copied from Source/WebCore/Modules/applepay/ApplePayMerchantCapability.h. * Source/WebCore/Modules/applepay/ApplePayDisbursementPaymentRequest.idl: Copied from Source/WebCore/Modules/applepay/ApplePayMerchantCapability.idl. * Source/WebCore/Modules/applepay/ApplePayFeature.h: * Source/WebCore/Modules/applepay/ApplePayFeature.idl: * Source/WebCore/Modules/applepay/ApplePayLineItem.h: * Source/WebCore/Modules/applepay/ApplePayLineItem.idl: * Source/WebCore/Modules/applepay/ApplePayMerchantCapability.cpp: (WebCore::convertAndValidate): * Source/WebCore/Modules/applepay/ApplePayMerchantCapability.h: * Source/WebCore/Modules/applepay/ApplePayMerchantCapability.idl: * Source/WebCore/Modules/applepay/ApplePayPaymentRequest.h: * Source/WebCore/Modules/applepay/ApplePayPaymentRequest.idl: * Source/WebCore/Modules/applepay/ApplePaySession.cpp: (WebCore::convertAndValidate): * Source/WebCore/Modules/applepay/ApplePaySessionPaymentRequest.h: (WebCore::ApplePaySessionPaymentRequest::disbursementPaymentRequest const): (WebCore::ApplePaySessionPaymentRequest::setDisbursementPaymentRequest): * Source/WebCore/Modules/applepay/PaymentSummaryItems.h: * Source/WebCore/Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm: (WebCore::platformDisbursementSummaryItem): (WebCore::platformInstantFundsOutFeeSummaryItem): (WebCore::platformSummaryItem): (WebCore::platformDisbursementSummaryItems): * Source/WebCore/Modules/applepay/paymentrequest/ApplePayModifier.h: * Source/WebCore/Modules/applepay/paymentrequest/ApplePayModifier.idl: * Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp: (WebCore::ApplePayPaymentHandler::show): (WebCore::ApplePayPaymentHandler::shippingAddressUpdated): (WebCore::ApplePayPaymentHandler::shippingOptionUpdated): (WebCore::ApplePayPaymentHandler::paymentMethodUpdated): * Source/WebCore/PAL/pal/cocoa/PassKitSoftLink.h: * Source/WebCore/PAL/pal/cocoa/PassKitSoftLink.mm: * Source/WebCore/PAL/pal/spi/cocoa/PassKitSPI.h: * Source/WebCore/SourcesCocoa.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/testing/MockPaymentCoordinator.cpp: (WebCore::MockPaymentCoordinator::showPaymentUI): (WebCore::MockPaymentCoordinator::completeShippingMethodSelection): (WebCore::MockPaymentCoordinator::completeShippingContactSelection): (WebCore::MockPaymentCoordinator::completePaymentMethodSelection): * Source/WebCore/testing/MockPaymentCoordinator.h: * Source/WebCore/testing/MockPaymentCoordinator.idl: * Source/WebKit/Platform/cocoa/PaymentAuthorizationPresenter.mm: (WebKit::PaymentAuthorizationPresenter::completePaymentMethodSelection): (WebKit::PaymentAuthorizationPresenter::completeShippingContactSelection): * Source/WebKit/Shared/ApplePay/DisbursementPaymentRequest.h: Copied from Source/WebCore/Modules/applepay/ApplePayMerchantCapability.h. * Source/WebKit/Shared/ApplePay/cocoa/DisbursementPaymentRequestCocoa.mm: Added. (WebKit::platformDisbursementPaymentRequest): * Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h: * Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm: (WebKit::toPKMerchantCapabilities): * Source/WebKit/Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * Source/WebKit/Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in: * Source/WebKit/SourcesCocoa.txt: * Source/WebKit/WebKit.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/275146@main
- Loading branch information
Showing
46 changed files
with
691 additions
and
16 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
.../http/tests/paymentrequest/ApplePayModifier-disbursementPaymentRequest.https-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
PASS Should have a feature for `disbursementPaymentRequest`. | ||
PASS Should propagate all data as part of the request. | ||
|
116 changes: 116 additions & 0 deletions
116
LayoutTests/http/tests/paymentrequest/ApplePayModifier-disbursementPaymentRequest.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<!doctype html> | ||
<meta charset="utf-8" /> | ||
<title> | ||
Tests for providing `disbursementPaymentRequest` as part of | ||
`ApplePayModifier`. | ||
</title> | ||
<script src="/js-test-resources/ui-helper.js"></script> | ||
<script src="/resources/payment-request.js"></script> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<script> | ||
setup({ explicit_done: true, explicit_timeout: true }); | ||
|
||
test((test) => { | ||
const method = validPaymentMethod(); | ||
method.data.features = ["paymentRequestDisbursements"]; | ||
new PaymentRequest([method], validPaymentDetails()); | ||
}, "Should have a feature for `disbursementPaymentRequest`."); | ||
|
||
const RESOLVED_PROMISE = Promise.resolve({}); | ||
|
||
const lineItems = { | ||
total: { | ||
label: "Chime", | ||
amount: "15.00", | ||
}, | ||
ifo: { | ||
label: "Instant Transfer Fee", | ||
amount: "0.15", | ||
disbursementLineItemType: "instantFundsOutFee", | ||
}, | ||
disbursement: { | ||
label: "Total Amount", | ||
amount: "14.85", | ||
disbursementLineItemType: "disbursement", | ||
}, | ||
}; | ||
|
||
const validLineItems = [ | ||
lineItems.total, | ||
lineItems.ifo, | ||
lineItems.disbursement, | ||
]; | ||
|
||
function modifiersWithData(data, lineItems) { | ||
data.additionalLineItems = lineItems; | ||
return [ | ||
{ supportedMethods: "https://apple.com/apple-pay", data: { ...data } }, | ||
]; | ||
} | ||
|
||
function testValidDisbursementPaymentRequest(description, options) { | ||
const { | ||
initialDisbursementPaymentRequest, | ||
expectedDisbursementPaymentRequest, | ||
} = options; | ||
user_activation_test(async (test) => { | ||
const detailsInit = { | ||
total: { | ||
label: "Disbursement", | ||
amount: { | ||
value: "14.85", | ||
currency: "USD", | ||
}, | ||
}, | ||
}; | ||
if (initialDisbursementPaymentRequest !== undefined) { | ||
detailsInit.modifiers = modifiersWithData( | ||
{ disbursementPaymentRequest: initialDisbursementPaymentRequest }, | ||
validLineItems, | ||
); | ||
} | ||
|
||
const request = new PaymentRequest([validPaymentMethod()], detailsInit); | ||
request.addEventListener("merchantvalidation", (event) => { | ||
event.complete(RESOLVED_PROMISE); | ||
}); | ||
|
||
request.addEventListener("shippingaddresschange", (event) => { | ||
event.updateWith({}); | ||
internals.mockPaymentCoordinator.changePaymentMethod({ | ||
type: "debit", | ||
}); | ||
}); | ||
|
||
request.addEventListener("paymentmethodchange", (event) => { | ||
event.updateWith(RESOLVED_PROMISE); | ||
internals.mockPaymentCoordinator.acceptPayment(); | ||
}); | ||
|
||
const response = await request.show(); | ||
|
||
const { disbursementPaymentRequest } = internals.mockPaymentCoordinator; | ||
const assert = disbursementPaymentRequest | ||
? assert_object_equals | ||
: assert_equals; | ||
assert( | ||
disbursementPaymentRequest, | ||
expectedDisbursementPaymentRequest, | ||
"check that the `DisbursementPaymentRequest` matches", | ||
); | ||
await response.compconste("success"); | ||
}, description + " as part of the request."); | ||
} | ||
|
||
testValidDisbursementPaymentRequest("Should propagate all data", { | ||
initialDisbursementPaymentRequest: {}, | ||
expectedDisbursementPaymentRequest: {}, | ||
}); | ||
|
||
// We don't need invalidation tests since a disbursement request is an empty dictionary. | ||
|
||
done(); | ||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Source/WebCore/Modules/applepay/ApplePayDisbursementPaymentRequest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#if ENABLE(APPLE_PAY_DISBURSEMENTS) | ||
|
||
#include <WebCore/ApplePayLineItem.h> | ||
#include <wtf/WallTime.h> | ||
#include <wtf/text/WTFString.h> | ||
|
||
namespace WebCore { | ||
|
||
template<typename> class ExceptionOr; | ||
|
||
struct ApplePayDisbursementPaymentRequest final { | ||
ExceptionOr<void> validate() const; | ||
ExceptionOr<ApplePayDisbursementPaymentRequest> convertAndValidate() &&; | ||
}; | ||
|
||
} // namespace WebCore | ||
|
||
#endif // ENABLE(APPLE_PAY_DISBURSEMENTS) |
31 changes: 31 additions & 0 deletions
31
Source/WebCore/Modules/applepay/ApplePayDisbursementPaymentRequest.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
[ | ||
Conditional=APPLE_PAY_DISBURSEMENTS, | ||
ExportMacro=WEBCORE_EXPORT, | ||
JSGenerateToJSObject, | ||
] dictionary ApplePayDisbursementPaymentRequest { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.