diff options
Diffstat (limited to 'Source/WebCore/Modules/applepay')
45 files changed, 3735 insertions, 0 deletions
diff --git a/Source/WebCore/Modules/applepay/ApplePayLineItem.h b/Source/WebCore/Modules/applepay/ApplePayLineItem.h new file mode 100644 index 000000000..e3ec6f605 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayLineItem.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2016 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) + +#include "PaymentRequest.h" + +namespace WebCore { + +struct ApplePayLineItem { + using Type = PaymentRequest::LineItem::Type; + + Type type { Type::Final }; + String label; + String amount; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayLineItem.idl b/Source/WebCore/Modules/applepay/ApplePayLineItem.idl new file mode 100644 index 000000000..2c58037ec --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayLineItem.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2016 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, +] enum ApplePayLineItemType { + "pending", + "final" +}; + +[ + Conditional=APPLE_PAY, +] dictionary ApplePayLineItem { + ApplePayLineItemType type = "final"; + DOMString label; + DOMString amount; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayPayment.h b/Source/WebCore/Modules/applepay/ApplePayPayment.h new file mode 100644 index 000000000..31f4cef82 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPayment.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2016 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) + +#include "ApplePayPaymentContact.h" +#include "ApplePayPaymentMethod.h" + +namespace WebCore { + +struct ApplePayPayment { + struct Token { + ApplePayPaymentMethod paymentMethod; + String transactionIdentifier; + String paymentData; + }; + + Token token; + std::optional<ApplePayPaymentContact> billingContact; + std::optional<ApplePayPaymentContact> shippingContact; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayPayment.idl b/Source/WebCore/Modules/applepay/ApplePayPayment.idl new file mode 100644 index 000000000..25bb0e96b --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPayment.idl @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016 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, + JSGenerateToJSObject +] dictionary ApplePayPayment { + required ApplePayPaymentToken token; + ApplePayPaymentContact billingContact; + ApplePayPaymentContact shippingContact; +}; + +[ + Conditional=APPLE_PAY, + JSGenerateToJSObject +] dictionary ApplePayPaymentToken { + required ApplePayPaymentMethod paymentMethod; + DOMString transactionIdentifier; + JSON paymentData; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentAuthorizedEvent.cpp b/Source/WebCore/Modules/applepay/ApplePayPaymentAuthorizedEvent.cpp new file mode 100644 index 000000000..42b7d5dc8 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentAuthorizedEvent.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016 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. + */ + +#include "config.h" +#include "ApplePayPaymentAuthorizedEvent.h" + +#if ENABLE(APPLE_PAY) + +#include "Payment.h" + +namespace WebCore { + +ApplePayPaymentAuthorizedEvent::ApplePayPaymentAuthorizedEvent(const AtomicString& type, const Payment& payment) + : Event(type, false, false) + , m_payment(payment.toApplePayPayment()) +{ +} + +ApplePayPaymentAuthorizedEvent::~ApplePayPaymentAuthorizedEvent() +{ +} + +EventInterface ApplePayPaymentAuthorizedEvent::eventInterface() const +{ + return ApplePayPaymentAuthorizedEventInterfaceType; +} + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentAuthorizedEvent.h b/Source/WebCore/Modules/applepay/ApplePayPaymentAuthorizedEvent.h new file mode 100644 index 000000000..d07a24160 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentAuthorizedEvent.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2016 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) + +#include "ApplePayPayment.h" +#include "Event.h" + +namespace WebCore { + +class Payment; + +class ApplePayPaymentAuthorizedEvent final : public Event { +public: + static Ref<ApplePayPaymentAuthorizedEvent> create(const AtomicString& type, const Payment& payment) + { + return adoptRef(*new ApplePayPaymentAuthorizedEvent(type, payment)); + } + + virtual ~ApplePayPaymentAuthorizedEvent(); + + const ApplePayPayment& payment() const { return m_payment; } + +private: + ApplePayPaymentAuthorizedEvent(const AtomicString& type, const Payment&); + + // Event. + EventInterface eventInterface() const override; + + const ApplePayPayment m_payment; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentAuthorizedEvent.idl b/Source/WebCore/Modules/applepay/ApplePayPaymentAuthorizedEvent.idl new file mode 100644 index 000000000..eeeb32a5f --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentAuthorizedEvent.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015, 2016 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, + NoInterfaceObject, +] interface ApplePayPaymentAuthorizedEvent : Event { + [CachedAttribute] readonly attribute ApplePayPayment payment; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentContact.h b/Source/WebCore/Modules/applepay/ApplePayPaymentContact.h new file mode 100644 index 000000000..1e389d440 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentContact.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 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) + +#include <wtf/Optional.h> +#include <wtf/Vector.h> +#include <wtf/text/WTFString.h> + +namespace WebCore { + +struct ApplePayPaymentContact { + String phoneNumber; + String emailAddress; + String givenName; + String familyName; + std::optional<Vector<String>> addressLines; + String locality; + String postalCode; + String administrativeArea; + String country; + String countryCode; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentContact.idl b/Source/WebCore/Modules/applepay/ApplePayPaymentContact.idl new file mode 100644 index 000000000..62be98b16 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentContact.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016 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, + JSGenerateToJSObject +] dictionary ApplePayPaymentContact { + DOMString phoneNumber; + DOMString emailAddress; + DOMString givenName; + DOMString familyName; + sequence<DOMString> addressLines; + DOMString locality; + DOMString postalCode; + DOMString administrativeArea; + DOMString country; + DOMString countryCode; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentMethod.h b/Source/WebCore/Modules/applepay/ApplePayPaymentMethod.h new file mode 100644 index 000000000..7bf917c93 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentMethod.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 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) + +#include "ApplePayPaymentPass.h" +#include <wtf/Optional.h> + +namespace WebCore { + +enum class ApplePayPaymentMethodType { Debit, Credit, Prepaid, Store }; + +struct ApplePayPaymentMethod { + using Type = ApplePayPaymentMethodType; + + String displayName; + String network; + std::optional<Type> type; + std::optional<ApplePayPaymentPass> paymentPass; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentMethod.idl b/Source/WebCore/Modules/applepay/ApplePayPaymentMethod.idl new file mode 100644 index 000000000..82c4ec21a --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentMethod.idl @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2016 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, +] enum ApplePayPaymentMethodType { + "debit", + "credit", + "prepaid", + "store" +}; + +[ + Conditional=APPLE_PAY, + JSGenerateToJSObject +] dictionary ApplePayPaymentMethod { + DOMString displayName; + DOMString network; + ApplePayPaymentMethodType type; + ApplePayPaymentPass paymentPass; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentMethodSelectedEvent.cpp b/Source/WebCore/Modules/applepay/ApplePayPaymentMethodSelectedEvent.cpp new file mode 100644 index 000000000..4c38c5f3d --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentMethodSelectedEvent.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016 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. + */ + +#include "config.h" +#include "ApplePayPaymentMethodSelectedEvent.h" + +#if ENABLE(APPLE_PAY) + +#include "PaymentMethod.h" + +namespace WebCore { + +ApplePayPaymentMethodSelectedEvent::ApplePayPaymentMethodSelectedEvent(const AtomicString& type, const PaymentMethod& paymentMethod) + : Event(type, false, false) + , m_paymentMethod(paymentMethod.toApplePayPaymentMethod()) +{ +} + +ApplePayPaymentMethodSelectedEvent::~ApplePayPaymentMethodSelectedEvent() +{ +} + +EventInterface ApplePayPaymentMethodSelectedEvent::eventInterface() const +{ + return ApplePayPaymentMethodSelectedEventInterfaceType; +} + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentMethodSelectedEvent.h b/Source/WebCore/Modules/applepay/ApplePayPaymentMethodSelectedEvent.h new file mode 100644 index 000000000..d51832407 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentMethodSelectedEvent.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2016 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) + +#include "ApplePayPaymentMethod.h" +#include "Event.h" + +namespace WebCore { + +class PaymentMethod; + +class ApplePayPaymentMethodSelectedEvent final : public Event { +public: + static Ref<ApplePayPaymentMethodSelectedEvent> create(const AtomicString& type, const PaymentMethod& paymentMethod) + { + return adoptRef(*new ApplePayPaymentMethodSelectedEvent(type, paymentMethod)); + } + + virtual ~ApplePayPaymentMethodSelectedEvent(); + + const ApplePayPaymentMethod& paymentMethod() { return m_paymentMethod; } + +private: + ApplePayPaymentMethodSelectedEvent(const AtomicString& type, const PaymentMethod&); + + // Event. + EventInterface eventInterface() const override; + + const ApplePayPaymentMethod m_paymentMethod; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentMethodSelectedEvent.idl b/Source/WebCore/Modules/applepay/ApplePayPaymentMethodSelectedEvent.idl new file mode 100644 index 000000000..06fcb0847 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentMethodSelectedEvent.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015, 2016 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, + NoInterfaceObject, +] interface ApplePayPaymentMethodSelectedEvent : Event { + [CachedAttribute] readonly attribute ApplePayPaymentMethod paymentMethod; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentPass.h b/Source/WebCore/Modules/applepay/ApplePayPaymentPass.h new file mode 100644 index 000000000..2f058af7b --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentPass.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2016 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) + +#include <wtf/text/WTFString.h> + +namespace WebCore { + +struct ApplePayPaymentPass { + enum class ActivationState { Activated, RequiresActivation, Activating, Suspended, Deactivated }; + + String primaryAccountIdentifier; + String primaryAccountNumberSuffix; + String deviceAccountIdentifier; + String deviceAccountNumberSuffix; + ActivationState activationState; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentPass.idl b/Source/WebCore/Modules/applepay/ApplePayPaymentPass.idl new file mode 100644 index 000000000..43f6d7882 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentPass.idl @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2016 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, +] enum ApplePayPaymentPassActivationState { + "activated", + "requiresActivation", + "activating", + "suspended", + "deactivated" +}; + +[ + Conditional=APPLE_PAY, + JSGenerateToJSObject +] dictionary ApplePayPaymentPass { + required DOMString primaryAccountIdentifier; + required DOMString primaryAccountNumberSuffix; + DOMString deviceAccountIdentifier; + DOMString deviceAccountNumberSuffix; + required ApplePayPaymentPassActivationState activationState; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.h b/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.h new file mode 100644 index 000000000..1203ad8b5 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016 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) + +#include "ApplePayLineItem.h" +#include "ApplePayPaymentContact.h" +#include "ApplePayShippingMethod.h" +#include "PaymentRequest.h" + +namespace WebCore { + +struct ApplePayPaymentRequest { + enum class MerchantCapability { Supports3DS, SupportsEMV, SupportsCredit, SupportsDebit }; + enum class ContactField { Email, Name, Phone, PostalAddress }; + + using ShippingType = PaymentRequest::ShippingType; + + Vector<MerchantCapability> merchantCapabilities; + Vector<String> supportedNetworks; + String countryCode; + String currencyCode; + + std::optional<Vector<ContactField>> requiredBillingContactFields; + std::optional<ApplePayPaymentContact> billingContact; + + std::optional<Vector<ContactField>> requiredShippingContactFields; + std::optional<ApplePayPaymentContact> shippingContact; + + ShippingType shippingType { ShippingType::Shipping }; + std::optional<Vector<ApplePayShippingMethod>> shippingMethods; + + ApplePayLineItem total; + std::optional<Vector<ApplePayLineItem>> lineItems; + + String applicationData; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.idl b/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.idl new file mode 100644 index 000000000..322bf0f2e --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.idl @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2016 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, +] enum ApplePayMerchantCapability { + "supports3DS", + "supportsEMV", + "supportsCredit", + "supportsDebit" +}; + +[ + Conditional=APPLE_PAY, +] enum ApplePayContactField { + "email", + "name", + "phone", + "postalAddress" +}; + +[ + Conditional=APPLE_PAY, +] enum ApplePayShippingType { + "shipping", + "delivery", + "storePickup", + "servicePickup" +}; + +[ + Conditional=APPLE_PAY, +] dictionary ApplePayPaymentRequest { + required ApplePayLineItem total; + sequence<ApplePayLineItem> lineItems; + + required sequence<ApplePayMerchantCapability> merchantCapabilities; + required sequence<DOMString> supportedNetworks; // FIXME: Should this be an sequence of enums? + required DOMString countryCode; + required DOMString currencyCode; + + sequence<ApplePayContactField> requiredBillingContactFields; + ApplePayPaymentContact billingContact; + + sequence<ApplePayContactField> requiredShippingContactFields; + ApplePayPaymentContact shippingContact; + + ApplePayShippingType shippingType = "shipping"; + sequence<ApplePayShippingMethod> shippingMethods; + + DOMString applicationData; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePaySession.cpp b/Source/WebCore/Modules/applepay/ApplePaySession.cpp new file mode 100644 index 000000000..e5225062a --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePaySession.cpp @@ -0,0 +1,1032 @@ +/* + * Copyright (C) 2015, 2016 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. + */ + +#include "config.h" +#include "ApplePaySession.h" + +#if ENABLE(APPLE_PAY) + +#include "ApplePayLineItem.h" +#include "ApplePayPaymentAuthorizedEvent.h" +#include "ApplePayPaymentMethodSelectedEvent.h" +#include "ApplePayPaymentRequest.h" +#include "ApplePayShippingContactSelectedEvent.h" +#include "ApplePayShippingMethod.h" +#include "ApplePayShippingMethodSelectedEvent.h" +#include "ApplePayValidateMerchantEvent.h" +#include "Document.h" +#include "DocumentLoader.h" +#include "EventNames.h" +#include "JSDOMPromise.h" +#include "LinkIconCollector.h" +#include "LinkIconType.h" +#include "MainFrame.h" +#include "Page.h" +#include "PageConsoleClient.h" +#include "PaymentAuthorizationStatus.h" +#include "PaymentContact.h" +#include "PaymentCoordinator.h" +#include "PaymentMerchantSession.h" +#include "PaymentMethod.h" +#include "PaymentRequestValidator.h" +#include "ScriptController.h" +#include "SecurityOrigin.h" +#include "Settings.h" + +namespace WebCore { + +static bool parseDigit(UChar digit, bool isNegative, int64_t& amount) +{ + if (!isASCIIDigit(digit)) + return false; + + int64_t digitValue = (digit - '0'); + + const int64_t maxMultiplier = std::numeric_limits<int64_t>::max() / 10; + + // Check overflow. + if (amount > maxMultiplier || (amount == maxMultiplier && digitValue > (std::numeric_limits<int64_t>::max() % 10) + isNegative)) + return false; + + amount = amount * 10 + digitValue; + return true; +} + +// The amount follows the regular expression -?[0-9]+(\.[0-9][0-9])?. +static std::optional<int64_t> parseAmount(const String& amountString) +{ + int64_t amount = 0; + + bool isNegative = false; + + enum class State { + Start, + Sign, + Digit, + Dot, + DotDigit, + End, + }; + + State state = State::Start; + + for (unsigned i = 0; i < amountString.length(); ++i) { + UChar c = amountString[i]; + + switch (state) { + case State::Start: + if (c == '-') { + isNegative = true; + state = State::Sign; + break; + } + + if (!parseDigit(c, isNegative, amount)) + return std::nullopt; + state = State::Digit; + break; + + case State::Sign: + if (!parseDigit(c, isNegative, amount)) + return std::nullopt; + state = State::Digit; + break; + + case State::Digit: + if (c == '.') { + state = State::Dot; + break; + } + + if (!parseDigit(c, isNegative, amount)) + return std::nullopt; + break; + + case State::Dot: + if (!parseDigit(c, isNegative, amount)) + return std::nullopt; + + state = State::DotDigit; + break; + + case State::DotDigit: + if (!parseDigit(c, isNegative, amount)) + return std::nullopt; + + state = State::End; + break; + + case State::End: + return std::nullopt; + } + } + + if (state != State::Digit && state != State::DotDigit && state != State::End) + return std::nullopt; + + if (state == State::DotDigit) { + // There was a single digit after the decimal point. + // FIXME: Handle this overflowing. + amount *= 10; + } else if (state == State::Digit) { + // There was no decimal point. + // FIXME: Handle this overflowing. + amount *= 100; + } + + if (isNegative) + amount = -amount; + + return amount; +} + +static ExceptionOr<PaymentRequest::LineItem> convertAndValidateTotal(ApplePayLineItem&& lineItem) +{ + auto amount = parseAmount(lineItem.amount); + if (!amount) + return Exception { TypeError, makeString("\"" + lineItem.amount, "\" is not a valid amount.") }; + + PaymentRequest::LineItem result; + result.amount = *amount; + result.type = lineItem.type; + result.label = lineItem.label; + + return WTFMove(result); +} + +static ExceptionOr<PaymentRequest::LineItem> convertAndValidate(ApplePayLineItem&& lineItem) +{ + PaymentRequest::LineItem result; + + // It is OK for pending types to not have an amount. + if (lineItem.type != PaymentRequest::LineItem::Type::Pending) { + auto amount = parseAmount(lineItem.amount); + if (!amount) + return Exception { TypeError, makeString("\"" + lineItem.amount, "\" is not a valid amount.") }; + + result.amount = *amount; + } + + result.type = lineItem.type; + result.label = lineItem.label; + + return WTFMove(result); +} + +static ExceptionOr<Vector<PaymentRequest::LineItem>> convertAndValidate(std::optional<Vector<ApplePayLineItem>>&& lineItems) +{ + Vector<PaymentRequest::LineItem> result; + if (!lineItems) + return WTFMove(result); + + result.reserveInitialCapacity(lineItems->size()); + + for (auto lineItem : lineItems.value()) { + auto convertedLineItem = convertAndValidate(WTFMove(lineItem)); + if (convertedLineItem.hasException()) + return convertedLineItem.releaseException(); + result.uncheckedAppend(convertedLineItem.releaseReturnValue()); + } + + return WTFMove(result); +} + +static ExceptionOr<PaymentRequest::MerchantCapabilities> convertAndValidate(Vector<ApplePayPaymentRequest::MerchantCapability>&& merchantCapabilities) +{ + if (merchantCapabilities.isEmpty()) + return Exception { TypeError, "At least one merchant capability must be provided." }; + + PaymentRequest::MerchantCapabilities result; + + for (auto& merchantCapability : merchantCapabilities) { + switch (merchantCapability) { + case ApplePayPaymentRequest::MerchantCapability::Supports3DS: + result.supports3DS = true; + break; + case ApplePayPaymentRequest::MerchantCapability::SupportsEMV: + result.supportsEMV = true; + break; + case ApplePayPaymentRequest::MerchantCapability::SupportsCredit: + result.supportsCredit = true; + break; + case ApplePayPaymentRequest::MerchantCapability::SupportsDebit: + result.supportsDebit = true; + break; + } + } + + return WTFMove(result); +} + +static ExceptionOr<Vector<String>> convertAndValidate(unsigned version, Vector<String>&& supportedNetworks) +{ + if (supportedNetworks.isEmpty()) + return Exception { TypeError, "At least one supported network must be provided." }; + + for (auto& supportedNetwork : supportedNetworks) { + if (!PaymentRequest::isValidSupportedNetwork(version, supportedNetwork)) + return Exception { TypeError, makeString("\"" + supportedNetwork, "\" is not a valid payment network.") }; + } + + return WTFMove(supportedNetworks); +} + +static ExceptionOr<PaymentRequest::ContactFields> convertAndValidate(Vector<ApplePayPaymentRequest::ContactField>&& contactFields) +{ + if (contactFields.isEmpty()) + return Exception { TypeError, "At least one contact field must be provided." }; + + PaymentRequest::ContactFields result; + + for (auto& contactField : contactFields) { + switch (contactField) { + case ApplePayPaymentRequest::ContactField::Email: + result.email = true; + break; + case ApplePayPaymentRequest::ContactField::Name: + result.name = true; + break; + case ApplePayPaymentRequest::ContactField::Phone: + result.phone = true; + break; + case ApplePayPaymentRequest::ContactField::PostalAddress: + result.postalAddress = true; + break; + } + } + + return WTFMove(result); +} + +static ExceptionOr<PaymentRequest::ShippingMethod> convertAndValidate(ApplePayShippingMethod&& shippingMethod) +{ + auto amount = parseAmount(shippingMethod.amount); + if (!amount) + return Exception { TypeError, makeString("\"" + shippingMethod.amount, "\" is not a valid amount.") }; + + PaymentRequest::ShippingMethod result; + result.amount = *amount; + result.label = shippingMethod.label; + result.detail = shippingMethod.detail; + result.identifier = shippingMethod.identifier; + + return WTFMove(result); +} + +static ExceptionOr<Vector<PaymentRequest::ShippingMethod>> convertAndValidate(Vector<ApplePayShippingMethod>&& shippingMethods) +{ + if (shippingMethods.isEmpty()) + return Exception { TypeError, "At least one shipping method must be provided." }; + + Vector<PaymentRequest::ShippingMethod> result; + result.reserveInitialCapacity(shippingMethods.size()); + + for (auto& shippingMethod : shippingMethods) { + auto convertedShippingMethod = convertAndValidate(WTFMove(shippingMethod)); + if (convertedShippingMethod.hasException()) + return convertedShippingMethod.releaseException(); + result.uncheckedAppend(convertedShippingMethod.releaseReturnValue()); + } + + return WTFMove(result); +} + +static ExceptionOr<PaymentRequest> convertAndValidate(unsigned version, ApplePayPaymentRequest&& paymentRequest) +{ + PaymentRequest result; + + auto total = convertAndValidateTotal(WTFMove(paymentRequest.total)); + if (total.hasException()) + return total.releaseException(); + result.setTotal(total.releaseReturnValue()); + + auto lineItems = convertAndValidate(WTFMove(paymentRequest.lineItems)); + if (lineItems.hasException()) + return lineItems.releaseException(); + result.setLineItems(lineItems.releaseReturnValue()); + + result.setCountryCode(paymentRequest.countryCode); + result.setCurrencyCode(paymentRequest.currencyCode); + + auto merchantCapabilities = convertAndValidate(WTFMove(paymentRequest.merchantCapabilities)); + if (merchantCapabilities.hasException()) + return merchantCapabilities.releaseException(); + result.setMerchantCapabilities(merchantCapabilities.releaseReturnValue()); + + auto supportedNetworks = convertAndValidate(version, WTFMove(paymentRequest.supportedNetworks)); + if (supportedNetworks.hasException()) + return supportedNetworks.releaseException(); + result.setSupportedNetworks(supportedNetworks.releaseReturnValue()); + + if (paymentRequest.requiredBillingContactFields) { + auto requiredBillingContactFields = convertAndValidate(WTFMove(*paymentRequest.requiredBillingContactFields)); + if (requiredBillingContactFields.hasException()) + return requiredBillingContactFields.releaseException(); + result.setRequiredBillingContactFields(requiredBillingContactFields.releaseReturnValue()); + } + + if (paymentRequest.billingContact) + result.setBillingContact(PaymentContact::fromApplePayPaymentContact(paymentRequest.billingContact.value())); + + if (paymentRequest.requiredShippingContactFields) { + auto requiredShippingContactFields = convertAndValidate(WTFMove(*paymentRequest.requiredShippingContactFields)); + if (requiredShippingContactFields.hasException()) + return requiredShippingContactFields.releaseException(); + result.setRequiredShippingContactFields(requiredShippingContactFields.releaseReturnValue()); + } + + if (paymentRequest.shippingContact) + result.setShippingContact(PaymentContact::fromApplePayPaymentContact(paymentRequest.shippingContact.value())); + + result.setShippingType(paymentRequest.shippingType); + + if (paymentRequest.shippingMethods) { + auto shippingMethods = convertAndValidate(WTFMove(*paymentRequest.shippingMethods)); + if (shippingMethods.hasException()) + return shippingMethods.releaseException(); + result.setShippingMethods(shippingMethods.releaseReturnValue()); + } + + result.setApplicationData(paymentRequest.applicationData); + + // FIXME: Merge this validation into the validation we are doing above. + auto validatedPaymentRequest = PaymentRequestValidator::validate(result); + if (validatedPaymentRequest.hasException()) + return validatedPaymentRequest.releaseException(); + + return WTFMove(result); +} + +static bool isSecure(DocumentLoader& documentLoader) +{ + if (!documentLoader.response().url().protocolIs("https")) + return false; + + if (!documentLoader.response().certificateInfo() || documentLoader.response().certificateInfo()->containsNonRootSHA1SignedCertificate()) + return false; + + return true; +} + +static ExceptionOr<void> canCallApplePaySessionAPIs(Document& document) +{ + if (!isSecure(*document.loader())) + return Exception { INVALID_ACCESS_ERR, "Trying to call an ApplePaySession API from an insecure document." }; + + auto& topDocument = document.topDocument(); + if (&document != &topDocument) { + auto& topOrigin = topDocument.topOrigin(); + + if (!document.securityOrigin().isSameSchemeHostPort(topOrigin)) + return Exception { INVALID_ACCESS_ERR, "Trying to call an ApplePaySession API from a document with an different security origin than its top-level frame." }; + + for (auto* ancestorDocument = document.parentDocument(); ancestorDocument != &topDocument; ancestorDocument = ancestorDocument->parentDocument()) { + if (!isSecure(*ancestorDocument->loader())) + return Exception { INVALID_ACCESS_ERR, "Trying to call an ApplePaySession API from a document with an insecure parent frame." }; + + if (!ancestorDocument->securityOrigin().isSameSchemeHostPort(topOrigin)) + return Exception { INVALID_ACCESS_ERR, "Trying to call an ApplePaySession API from a document with an different security origin than its top-level frame." }; + } + } + + return { }; +} + +ExceptionOr<Ref<ApplePaySession>> ApplePaySession::create(Document& document, unsigned version, ApplePayPaymentRequest&& paymentRequest) +{ + auto canCall = canCallApplePaySessionAPIs(document); + if (canCall.hasException()) + return canCall.releaseException(); + + if (!ScriptController::processingUserGesture()) + return Exception { INVALID_ACCESS_ERR, "Must create a new ApplePaySession from a user gesture handler." }; + + auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator(); + + if (!version || !paymentCoordinator.supportsVersion(version)) + return Exception { INVALID_ACCESS_ERR, makeString("\"" + String::number(version), "\" is not a supported version.") }; + + auto convertedPaymentRequest = convertAndValidate(version, WTFMove(paymentRequest)); + if (convertedPaymentRequest.hasException()) + return convertedPaymentRequest.releaseException(); + + return adoptRef(*new ApplePaySession(document, convertedPaymentRequest.releaseReturnValue())); +} + +ApplePaySession::ApplePaySession(Document& document, PaymentRequest&& paymentRequest) + : ActiveDOMObject(&document) + , m_paymentRequest(WTFMove(paymentRequest)) +{ + suspendIfNeeded(); +} + +ApplePaySession::~ApplePaySession() +{ +} + +ExceptionOr<bool> ApplePaySession::supportsVersion(ScriptExecutionContext& scriptExecutionContext, unsigned version) +{ + if (!version) + return Exception { INVALID_ACCESS_ERR }; + + auto& document = downcast<Document>(scriptExecutionContext); + + auto canCall = canCallApplePaySessionAPIs(document); + if (canCall.hasException()) + return canCall.releaseException(); + + return document.frame()->mainFrame().paymentCoordinator().supportsVersion(version); +} + +static bool shouldDiscloseApplePayCapability(Document& document) +{ + auto* page = document.page(); + if (!page || page->usesEphemeralSession()) + return false; + + return document.settings().applePayCapabilityDisclosureAllowed(); +} + +ExceptionOr<bool> ApplePaySession::canMakePayments(ScriptExecutionContext& scriptExecutionContext) +{ + auto& document = downcast<Document>(scriptExecutionContext); + + auto canCall = canCallApplePaySessionAPIs(document); + if (canCall.hasException()) + return canCall.releaseException(); + + return document.frame()->mainFrame().paymentCoordinator().canMakePayments(); +} + +ExceptionOr<void> ApplePaySession::canMakePaymentsWithActiveCard(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise) +{ + auto& document = downcast<Document>(scriptExecutionContext); + + auto canCall = canCallApplePaySessionAPIs(document); + if (canCall.hasException()) + return canCall.releaseException(); + + RefPtr<DeferredPromise> promise(WTFMove(passedPromise)); + if (!shouldDiscloseApplePayCapability(document)) { + auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator(); + bool canMakePayments = paymentCoordinator.canMakePayments(); + + RunLoop::main().dispatch([promise, canMakePayments]() mutable { + promise->resolve<IDLBoolean>(canMakePayments); + }); + return { }; + } + + auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator(); + + paymentCoordinator.canMakePaymentsWithActiveCard(merchantIdentifier, document.domain(), [promise](bool canMakePayments) mutable { + promise->resolve<IDLBoolean>(canMakePayments); + }); + return { }; +} + +ExceptionOr<void> ApplePaySession::openPaymentSetup(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredPromise>&& passedPromise) +{ + auto& document = downcast<Document>(scriptExecutionContext); + + auto canCall = canCallApplePaySessionAPIs(document); + if (canCall.hasException()) + return canCall.releaseException(); + + if (!ScriptController::processingUserGesture()) + return Exception { INVALID_ACCESS_ERR, "Must call ApplePaySession.openPaymentSetup from a user gesture handler." }; + + RefPtr<DeferredPromise> promise(WTFMove(passedPromise)); + auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator(); + + paymentCoordinator.openPaymentSetup(merchantIdentifier, document.domain(), [promise](bool result) mutable { + promise->resolve<IDLBoolean>(result); + }); + + return { }; +} + +ExceptionOr<void> ApplePaySession::begin() +{ + if (!canBegin()) + return Exception { INVALID_ACCESS_ERR, "Payment session is already active." }; + + if (paymentCoordinator().hasActiveSession()) + return Exception { INVALID_ACCESS_ERR, "Page already has an active payment session." }; + + auto& document = *downcast<Document>(scriptExecutionContext()); + + Vector<URL> linkIconURLs; + for (auto& icon : LinkIconCollector { document }.iconsOfTypes({ LinkIconType::TouchIcon, LinkIconType::TouchPrecomposedIcon })) + linkIconURLs.append(icon.url); + + if (!paymentCoordinator().beginPaymentSession(*this, document.url(), linkIconURLs, m_paymentRequest)) + return Exception { INVALID_ACCESS_ERR, "There is already has an active payment session." }; + + m_state = State::Active; + + setPendingActivity(this); + + return { }; +} + +ExceptionOr<void> ApplePaySession::abort() +{ + if (!canAbort()) + return Exception { INVALID_ACCESS_ERR }; + + m_state = State::Aborted; + paymentCoordinator().abortPaymentSession(); + + didReachFinalState(); + + return { }; +} + +ExceptionOr<void> ApplePaySession::completeMerchantValidation(JSC::ExecState& state, JSC::JSValue merchantSessionValue) +{ + if (!canCompleteMerchantValidation()) + return Exception { INVALID_ACCESS_ERR }; + + if (!merchantSessionValue.isObject()) + return Exception { TypeError }; + + auto& document = *downcast<Document>(scriptExecutionContext()); + auto& window = *document.domWindow(); + + String errorMessage; + auto merchantSession = PaymentMerchantSession::fromJS(state, asObject(merchantSessionValue), errorMessage); + if (!merchantSession) { + window.printErrorMessage(errorMessage); + return Exception { INVALID_ACCESS_ERR }; + } + + m_merchantValidationState = MerchantValidationState::ValidationComplete; + paymentCoordinator().completeMerchantValidation(*merchantSession); + + return { }; +} + +static std::optional<PaymentAuthorizationStatus> toPaymentAuthorizationStatus(unsigned short status) +{ + switch (status) { + case ApplePaySession::STATUS_SUCCESS: + return PaymentAuthorizationStatus::Success; + + case ApplePaySession::STATUS_FAILURE: + return PaymentAuthorizationStatus::Failure; + + case ApplePaySession::STATUS_INVALID_BILLING_POSTAL_ADDRESS: + return PaymentAuthorizationStatus::InvalidBillingPostalAddress; + + case ApplePaySession::STATUS_INVALID_SHIPPING_POSTAL_ADDRESS: + return PaymentAuthorizationStatus::InvalidShippingPostalAddress; + + case ApplePaySession::STATUS_INVALID_SHIPPING_CONTACT: + return PaymentAuthorizationStatus::InvalidShippingContact; + + case ApplePaySession::STATUS_PIN_REQUIRED: + return PaymentAuthorizationStatus::PINRequired; + + case ApplePaySession::STATUS_PIN_INCORRECT: + return PaymentAuthorizationStatus::PINIncorrect; + + case ApplePaySession::STATUS_PIN_LOCKOUT: + return PaymentAuthorizationStatus::PINLockout; + + default: + return std::nullopt; + } +} + +ExceptionOr<void> ApplePaySession::completeShippingMethodSelection(unsigned short status, ApplePayLineItem&& newTotal, Vector<ApplePayLineItem>&& newLineItems) +{ + if (!canCompleteShippingMethodSelection()) + return Exception { INVALID_ACCESS_ERR }; + + auto authorizationStatus = toPaymentAuthorizationStatus(status); + if (!authorizationStatus) + return Exception { INVALID_ACCESS_ERR }; + + auto convertedNewTotal = convertAndValidateTotal(WTFMove(newTotal)); + if (convertedNewTotal.hasException()) + return convertedNewTotal.releaseException(); + + PaymentRequest::TotalAndLineItems totalAndLineItems; + totalAndLineItems.total = convertedNewTotal.releaseReturnValue(); + + // FIXME: Merge this validation into the validation we are doing above. + auto validatedTotal = PaymentRequestValidator::validateTotal(totalAndLineItems.total); + if (validatedTotal.hasException()) + return validatedTotal.releaseException(); + + auto convertedNewLineItems = convertAndValidate(WTFMove(newLineItems)); + if (convertedNewLineItems.hasException()) + return convertedNewLineItems.releaseException(); + + totalAndLineItems.lineItems = convertedNewLineItems.releaseReturnValue(); + + m_state = State::Active; + paymentCoordinator().completeShippingMethodSelection(*authorizationStatus, totalAndLineItems); + + return { }; +} + +ExceptionOr<void> ApplePaySession::completeShippingContactSelection(unsigned short status, Vector<ApplePayShippingMethod>&& newShippingMethods, ApplePayLineItem&& newTotal, Vector<ApplePayLineItem>&& newLineItems) +{ + if (!canCompleteShippingContactSelection()) + return Exception { INVALID_ACCESS_ERR }; + + auto authorizationStatus = toPaymentAuthorizationStatus(status); + if (!authorizationStatus) + return Exception { INVALID_ACCESS_ERR }; + + auto convertedNewShippingMethods = convertAndValidate(WTFMove(newShippingMethods)); + if (convertedNewShippingMethods.hasException()) + return convertedNewShippingMethods.releaseException(); + + auto convertedNewTotal = convertAndValidateTotal(WTFMove(newTotal)); + if (convertedNewTotal.hasException()) + return convertedNewTotal.releaseException(); + + PaymentRequest::TotalAndLineItems totalAndLineItems; + totalAndLineItems.total = convertedNewTotal.releaseReturnValue(); + + // FIXME: Merge this validation into the validation we are doing above. + auto validatedTotal = PaymentRequestValidator::validateTotal(totalAndLineItems.total); + if (validatedTotal.hasException()) + return validatedTotal.releaseException(); + + auto convertedNewLineItems = convertAndValidate(WTFMove(newLineItems)); + if (convertedNewLineItems.hasException()) + return convertedNewLineItems.releaseException(); + + totalAndLineItems.lineItems = convertedNewLineItems.releaseReturnValue(); + + m_state = State::Active; + paymentCoordinator().completeShippingContactSelection(*authorizationStatus, convertedNewShippingMethods.releaseReturnValue(), totalAndLineItems); + + return { }; +} + +ExceptionOr<void> ApplePaySession::completePaymentMethodSelection(ApplePayLineItem&& newTotal, Vector<ApplePayLineItem>&& newLineItems) +{ + if (!canCompletePaymentMethodSelection()) + return Exception { INVALID_ACCESS_ERR }; + + auto convertedNewTotal = convertAndValidateTotal(WTFMove(newTotal)); + if (convertedNewTotal.hasException()) + return convertedNewTotal.releaseException(); + + PaymentRequest::TotalAndLineItems totalAndLineItems; + totalAndLineItems.total = convertedNewTotal.releaseReturnValue(); + + // FIXME: Merge this validation into the validation we are doing above. + auto validatedTotal = PaymentRequestValidator::validateTotal(totalAndLineItems.total); + if (validatedTotal.hasException()) + return validatedTotal.releaseException(); + + auto convertedNewLineItems = convertAndValidate(WTFMove(newLineItems)); + if (convertedNewLineItems.hasException()) + return convertedNewLineItems.releaseException(); + + totalAndLineItems.lineItems = convertedNewLineItems.releaseReturnValue(); + + m_state = State::Active; + paymentCoordinator().completePaymentMethodSelection(totalAndLineItems); + + return { }; +} + +ExceptionOr<void> ApplePaySession::completePayment(unsigned short status) +{ + if (!canCompletePayment()) + return Exception { INVALID_ACCESS_ERR }; + + auto authorizationStatus = toPaymentAuthorizationStatus(status); + if (!authorizationStatus) + return Exception { INVALID_ACCESS_ERR }; + + paymentCoordinator().completePaymentSession(*authorizationStatus); + + if (!isFinalStateStatus(*authorizationStatus)) { + m_state = State::Active; + return { }; + } + + m_state = State::Completed; + unsetPendingActivity(this); + return { }; +} + +void ApplePaySession::validateMerchant(const URL& validationURL) +{ + if (m_state == State::Aborted) { + // ApplePaySession::abort has been called. + return; + } + + ASSERT(m_merchantValidationState == MerchantValidationState::Idle); + ASSERT(m_state == State::Active); + + if (validationURL.isNull()) { + // Something went wrong when getting the validation URL. + // FIXME: Maybe we should send an error event here instead? + return; + } + + m_merchantValidationState = MerchantValidationState::ValidatingMerchant; + + auto event = ApplePayValidateMerchantEvent::create(eventNames().validatemerchantEvent, validationURL); + dispatchEvent(event.get()); +} + +void ApplePaySession::didAuthorizePayment(const Payment& payment) +{ + ASSERT(m_state == State::Active); + + m_state = State::Authorized; + + auto event = ApplePayPaymentAuthorizedEvent::create(eventNames().paymentauthorizedEvent, payment); + dispatchEvent(event.get()); +} + +void ApplePaySession::didSelectShippingMethod(const PaymentRequest::ShippingMethod& shippingMethod) +{ + ASSERT(m_state == State::Active); + + if (!hasEventListeners(eventNames().shippingmethodselectedEvent)) { + paymentCoordinator().completeShippingMethodSelection(PaymentAuthorizationStatus::Success, { }); + return; + } + + m_state = State::ShippingMethodSelected; + auto event = ApplePayShippingMethodSelectedEvent::create(eventNames().shippingmethodselectedEvent, shippingMethod); + dispatchEvent(event.get()); +} + +void ApplePaySession::didSelectShippingContact(const PaymentContact& shippingContact) +{ + ASSERT(m_state == State::Active); + + if (!hasEventListeners(eventNames().shippingcontactselectedEvent)) { + paymentCoordinator().completeShippingContactSelection(PaymentAuthorizationStatus::Success, { }, { }); + return; + } + + m_state = State::ShippingContactSelected; + auto event = ApplePayShippingContactSelectedEvent::create(eventNames().shippingcontactselectedEvent, shippingContact); + dispatchEvent(event.get()); +} + +void ApplePaySession::didSelectPaymentMethod(const PaymentMethod& paymentMethod) +{ + ASSERT(m_state == State::Active); + + if (!hasEventListeners(eventNames().paymentmethodselectedEvent)) { + paymentCoordinator().completePaymentMethodSelection({ }); + return; + } + + m_state = State::PaymentMethodSelected; + auto event = ApplePayPaymentMethodSelectedEvent::create(eventNames().paymentmethodselectedEvent, paymentMethod); + dispatchEvent(event.get()); +} + +void ApplePaySession::didCancelPayment() +{ + ASSERT(canCancel()); + + m_state = State::Canceled; + + auto event = Event::create(eventNames().cancelEvent, false, false); + dispatchEvent(event.get()); + + didReachFinalState(); +} + +const char* ApplePaySession::activeDOMObjectName() const +{ + return "ApplePaySession"; +} + +bool ApplePaySession::canSuspendForDocumentSuspension() const +{ + switch (m_state) { + case State::Idle: + case State::Aborted: + case State::Completed: + case State::Canceled: + return true; + + case State::Active: + case State::Authorized: + case State::ShippingMethodSelected: + case State::ShippingContactSelected: + case State::PaymentMethodSelected: + return false; + } +} + +void ApplePaySession::stop() +{ + if (!canAbort()) + return; + + m_state = State::Aborted; + paymentCoordinator().abortPaymentSession(); + + didReachFinalState(); +} + +PaymentCoordinator& ApplePaySession::paymentCoordinator() const +{ + return downcast<Document>(*scriptExecutionContext()).frame()->mainFrame().paymentCoordinator(); +} + +bool ApplePaySession::canBegin() const +{ + switch (m_state) { + case State::Idle: + return true; + + case State::Active: + case State::Aborted: + case State::Authorized: + case State::Completed: + case State::Canceled: + case State::ShippingMethodSelected: + case State::ShippingContactSelected: + case State::PaymentMethodSelected: + return false; + } +} + +bool ApplePaySession::canAbort() const +{ + switch (m_state) { + case State::Idle: + case State::Aborted: + case State::Completed: + case State::Canceled: + return false; + + case State::Active: + case State::Authorized: + case State::ShippingMethodSelected: + case State::ShippingContactSelected: + case State::PaymentMethodSelected: + return true; + } +} + +bool ApplePaySession::canCancel() const +{ + switch (m_state) { + case State::Idle: + case State::Aborted: + case State::Completed: + case State::Canceled: + return false; + + case State::Active: + case State::Authorized: + case State::ShippingMethodSelected: + case State::ShippingContactSelected: + case State::PaymentMethodSelected: + return true; + } +} + +bool ApplePaySession::canCompleteMerchantValidation() const +{ + if (m_state != State::Active) + return false; + + if (m_merchantValidationState != MerchantValidationState::ValidatingMerchant) + return false; + + return true; +} + +bool ApplePaySession::canCompleteShippingMethodSelection() const +{ + switch (m_state) { + case State::Idle: + case State::Aborted: + case State::Active: + case State::Completed: + case State::Canceled: + case State::Authorized: + case State::PaymentMethodSelected: + case State::ShippingContactSelected: + return false; + + case State::ShippingMethodSelected: + return true; + } +} + +bool ApplePaySession::canCompleteShippingContactSelection() const +{ + switch (m_state) { + case State::Idle: + case State::Aborted: + case State::Active: + case State::Completed: + case State::Canceled: + case State::Authorized: + case State::PaymentMethodSelected: + case State::ShippingMethodSelected: + return false; + + case State::ShippingContactSelected: + return true; + } +} + +bool ApplePaySession::canCompletePaymentMethodSelection() const +{ + switch (m_state) { + case State::Idle: + case State::Aborted: + case State::Active: + case State::Completed: + case State::Canceled: + case State::Authorized: + case State::ShippingMethodSelected: + case State::ShippingContactSelected: + return false; + + case State::PaymentMethodSelected: + return true; + } +} + +bool ApplePaySession::canCompletePayment() const +{ + switch (m_state) { + case State::Idle: + case State::Aborted: + case State::Active: + case State::Completed: + case State::Canceled: + case State::ShippingMethodSelected: + case State::ShippingContactSelected: + case State::PaymentMethodSelected: + return false; + + case State::Authorized: + return true; + } +} + +bool ApplePaySession::isFinalState() const +{ + switch (m_state) { + case State::Idle: + case State::Active: + case State::ShippingMethodSelected: + case State::ShippingContactSelected: + case State::PaymentMethodSelected: + case State::Authorized: + return false; + + case State::Completed: + case State::Aborted: + case State::Canceled: + return true; + } +} + +void ApplePaySession::didReachFinalState() +{ + ASSERT(isFinalState()); + unsetPendingActivity(this); +} + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePaySession.h b/Source/WebCore/Modules/applepay/ApplePaySession.h new file mode 100644 index 000000000..ef759ded0 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePaySession.h @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2015, 2016 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) + +#include "ActiveDOMObject.h" +#include "ApplePayPaymentRequest.h" +#include "EventTarget.h" +#include "ExceptionOr.h" +#include <wtf/Ref.h> +#include <wtf/RefCounted.h> + +namespace JSC { +class ExecState; +class JSValue; +} + +namespace WebCore { + +class DeferredPromise; +class Document; +class Payment; +class PaymentContact; +class PaymentCoordinator; +class PaymentMethod; +class URL; + +struct ApplePayLineItem; +struct ApplePayPaymentRequest; +struct ApplePayShippingMethod; + +class ApplePaySession final : public RefCounted<ApplePaySession>, public ActiveDOMObject, public EventTargetWithInlineData { +public: + static ExceptionOr<Ref<ApplePaySession>> create(Document&, unsigned version, ApplePayPaymentRequest&&); + virtual ~ApplePaySession(); + + static const unsigned short STATUS_SUCCESS = 0; + static const unsigned short STATUS_FAILURE = 1; + static const unsigned short STATUS_INVALID_BILLING_POSTAL_ADDRESS = 2; + static const unsigned short STATUS_INVALID_SHIPPING_POSTAL_ADDRESS = 3; + static const unsigned short STATUS_INVALID_SHIPPING_CONTACT = 4; + static const unsigned short STATUS_PIN_REQUIRED = 5; + static const unsigned short STATUS_PIN_INCORRECT = 6; + static const unsigned short STATUS_PIN_LOCKOUT = 7; + + static ExceptionOr<bool> supportsVersion(ScriptExecutionContext&, unsigned version); + static ExceptionOr<bool> canMakePayments(ScriptExecutionContext&); + static ExceptionOr<void> canMakePaymentsWithActiveCard(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&); + static ExceptionOr<void> openPaymentSetup(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&); + + ExceptionOr<void> begin(); + ExceptionOr<void> abort(); + ExceptionOr<void> completeMerchantValidation(JSC::ExecState&, JSC::JSValue merchantSession); + ExceptionOr<void> completeShippingMethodSelection(unsigned short status, ApplePayLineItem&& newTotal, Vector<ApplePayLineItem>&& newLineItems); + ExceptionOr<void> completeShippingContactSelection(unsigned short status, Vector<ApplePayShippingMethod>&& newShippingMethods, ApplePayLineItem&& newTotal, Vector<ApplePayLineItem>&& newLineItems); + ExceptionOr<void> completePaymentMethodSelection(ApplePayLineItem&& newTotal, Vector<ApplePayLineItem>&& newLineItems); + ExceptionOr<void> completePayment(unsigned short status); + + const PaymentRequest& paymentRequest() const { return m_paymentRequest; } + + void validateMerchant(const URL&); + void didAuthorizePayment(const Payment&); + void didSelectShippingMethod(const PaymentRequest::ShippingMethod&); + void didSelectShippingContact(const PaymentContact&); + void didSelectPaymentMethod(const PaymentMethod&); + void didCancelPayment(); + + using RefCounted<ApplePaySession>::ref; + using RefCounted<ApplePaySession>::deref; + +private: + ApplePaySession(Document&, PaymentRequest&&); + + // ActiveDOMObject. + const char* activeDOMObjectName() const override; + bool canSuspendForDocumentSuspension() const override; + void stop() override; + + // EventTargetWithInlineData. + EventTargetInterface eventTargetInterface() const override { return ApplePaySessionEventTargetInterfaceType; } + ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); } + void refEventTarget() override { ref(); } + void derefEventTarget() override { deref(); } + + PaymentCoordinator& paymentCoordinator() const; + + bool canBegin() const; + bool canAbort() const; + bool canCancel() const; + bool canCompleteMerchantValidation() const; + bool canCompleteShippingMethodSelection() const; + bool canCompleteShippingContactSelection() const; + bool canCompletePaymentMethodSelection() const; + bool canCompletePayment() const; + + bool isFinalState() const; + void didReachFinalState(); + + enum class State { + Idle, + + Active, + ShippingMethodSelected, + ShippingContactSelected, + PaymentMethodSelected, + Authorized, + Completed, + + Aborted, + Canceled, + } m_state { State::Idle }; + + enum class MerchantValidationState { + Idle, + ValidatingMerchant, + ValidationComplete, + } m_merchantValidationState { MerchantValidationState::Idle }; + + const PaymentRequest m_paymentRequest; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePaySession.idl b/Source/WebCore/Modules/applepay/ApplePaySession.idl new file mode 100644 index 000000000..802f3c3f0 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePaySession.idl @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015, 2016 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. + */ + +[ + ActiveDOMObject, + Conditional=APPLE_PAY, + Constructor(unsigned long version, ApplePayPaymentRequest paymentRequest), + ConstructorCallWith=Document, + ConstructorMayThrowException, + EnabledBySetting=ApplePay, +] interface ApplePaySession : EventTarget { + const unsigned short STATUS_SUCCESS = 0; + const unsigned short STATUS_FAILURE = 1; + const unsigned short STATUS_INVALID_BILLING_POSTAL_ADDRESS = 2; + const unsigned short STATUS_INVALID_SHIPPING_POSTAL_ADDRESS = 3; + const unsigned short STATUS_INVALID_SHIPPING_CONTACT = 4; + const unsigned short STATUS_PIN_REQUIRED = 5; + const unsigned short STATUS_PIN_INCORRECT = 6; + const unsigned short STATUS_PIN_LOCKOUT = 7; + + [CallWith=ScriptExecutionContext, MayThrowException] static boolean supportsVersion(unsigned long version); + [CallWith=ScriptExecutionContext, MayThrowException] static boolean canMakePayments(); + [CallWith=ScriptExecutionContext, MayThrowException] static Promise<boolean> canMakePaymentsWithActiveCard(DOMString merchantIdentifier); + [CallWith=ScriptExecutionContext, MayThrowException] static Promise<boolean> openPaymentSetup(DOMString merchantIdentifier); + + [MayThrowException] void begin(); + [MayThrowException] void abort(); + [MayThrowException, CallWith=ScriptState] void completeMerchantValidation(any merchantSession); + [MayThrowException] void completeShippingMethodSelection(unsigned short status, ApplePayLineItem newTotal, sequence<ApplePayLineItem> newLineItems); + [MayThrowException] void completeShippingContactSelection(unsigned short status, sequence<ApplePayShippingMethod> newShippingMethods, ApplePayLineItem newTotal, sequence<ApplePayLineItem> newLineItems); + [MayThrowException] void completePaymentMethodSelection(ApplePayLineItem newTotal, sequence<ApplePayLineItem> newLineItems); + [MayThrowException] void completePayment(unsigned short status); + + attribute EventHandler onvalidatemerchant; + attribute EventHandler onpaymentmethodselected; + attribute EventHandler onpaymentauthorized; + attribute EventHandler onshippingmethodselected; + attribute EventHandler onshippingcontactselected; + attribute EventHandler oncancel; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayShippingContactSelectedEvent.cpp b/Source/WebCore/Modules/applepay/ApplePayShippingContactSelectedEvent.cpp new file mode 100644 index 000000000..41a8447c4 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayShippingContactSelectedEvent.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016 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. + */ + +#include "config.h" +#include "ApplePayShippingContactSelectedEvent.h" + +#if ENABLE(APPLE_PAY) + +#include "PaymentContact.h" + +namespace WebCore { + +ApplePayShippingContactSelectedEvent::ApplePayShippingContactSelectedEvent(const AtomicString& type, const PaymentContact& shippingContact) + : Event(type, false, false) + , m_shippingContact(shippingContact.toApplePayPaymentContact()) +{ +} + +ApplePayShippingContactSelectedEvent::~ApplePayShippingContactSelectedEvent() +{ +} + +EventInterface ApplePayShippingContactSelectedEvent::eventInterface() const +{ + return ApplePayShippingContactSelectedEventInterfaceType; +} + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayShippingContactSelectedEvent.h b/Source/WebCore/Modules/applepay/ApplePayShippingContactSelectedEvent.h new file mode 100644 index 000000000..2e7e6f7ef --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayShippingContactSelectedEvent.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016 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) + +#include "ApplePayPaymentContact.h" +#include "Event.h" + +namespace WebCore { + +class PaymentContact; + +class ApplePayShippingContactSelectedEvent final : public Event { +public: + static Ref<ApplePayShippingContactSelectedEvent> create(const AtomicString& type, const PaymentContact& shippingContact) + { + return adoptRef(*new ApplePayShippingContactSelectedEvent(type, shippingContact)); + } + + virtual ~ApplePayShippingContactSelectedEvent(); + + const ApplePayPaymentContact& shippingContact() const { return m_shippingContact; } + +private: + ApplePayShippingContactSelectedEvent(const AtomicString& type, const PaymentContact&); + + // Event. + EventInterface eventInterface() const override; + + const ApplePayPaymentContact m_shippingContact; +}; + +} +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayShippingContactSelectedEvent.idl b/Source/WebCore/Modules/applepay/ApplePayShippingContactSelectedEvent.idl new file mode 100644 index 000000000..7ff4dfd21 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayShippingContactSelectedEvent.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 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, + NoInterfaceObject, +] interface ApplePayShippingContactSelectedEvent : Event { + [CachedAttribute] readonly attribute ApplePayPaymentContact shippingContact; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayShippingMethod.h b/Source/WebCore/Modules/applepay/ApplePayShippingMethod.h new file mode 100644 index 000000000..593521af4 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayShippingMethod.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2016 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) + +#include <wtf/text/WTFString.h> + +namespace WebCore { + +struct ApplePayShippingMethod { + String label; + String detail; + String amount; + String identifier; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayShippingMethod.idl b/Source/WebCore/Modules/applepay/ApplePayShippingMethod.idl new file mode 100644 index 000000000..36f3af754 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayShippingMethod.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2016 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, + JSGenerateToJSObject +] dictionary ApplePayShippingMethod { + required DOMString label; + required DOMString detail; + required DOMString amount; + required DOMString identifier; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayShippingMethodSelectedEvent.cpp b/Source/WebCore/Modules/applepay/ApplePayShippingMethodSelectedEvent.cpp new file mode 100644 index 000000000..6c4fff9f3 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayShippingMethodSelectedEvent.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 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. + */ + +#include "config.h" +#include "ApplePayShippingMethodSelectedEvent.h" + +#if ENABLE(APPLE_PAY) + +#include <wtf/text/StringBuilder.h> + +namespace WebCore { + +static inline String convert(int64_t amount) +{ + StringBuilder amountString; + amountString.appendNumber(amount / 100); + amountString.append('.'); + + unsigned decimals = amount % 100; + if (decimals < 10) + amountString.append('0'); + amountString.appendNumber(decimals); + + return amountString.toString(); +} + +static inline ApplePayShippingMethod convert(const PaymentRequest::ShippingMethod& shippingMethod) +{ + ApplePayShippingMethod convertedMethod; + convertedMethod.label = shippingMethod.label; + convertedMethod.detail = shippingMethod.detail; + convertedMethod.identifier = shippingMethod.identifier; + convertedMethod.amount = convert(shippingMethod.amount); + + return convertedMethod; +} + +ApplePayShippingMethodSelectedEvent::ApplePayShippingMethodSelectedEvent(const AtomicString& type, const PaymentRequest::ShippingMethod& shippingMethod) + : Event(type, false, false) + , m_shippingMethod(convert(shippingMethod)) +{ +} + +ApplePayShippingMethodSelectedEvent::~ApplePayShippingMethodSelectedEvent() +{ +} + +EventInterface ApplePayShippingMethodSelectedEvent::eventInterface() const +{ + return ApplePayShippingMethodSelectedEventInterfaceType; +} + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayShippingMethodSelectedEvent.h b/Source/WebCore/Modules/applepay/ApplePayShippingMethodSelectedEvent.h new file mode 100644 index 000000000..0693487de --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayShippingMethodSelectedEvent.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016 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) + +#include "ApplePayShippingMethod.h" +#include "Event.h" +#include "PaymentRequest.h" + +namespace WebCore { + +class ApplePayShippingMethodSelectedEvent final : public Event { +public: + static Ref<ApplePayShippingMethodSelectedEvent> create(const AtomicString& type, const PaymentRequest::ShippingMethod& shippingMethod) + { + return adoptRef(*new ApplePayShippingMethodSelectedEvent(type, shippingMethod)); + } + + virtual ~ApplePayShippingMethodSelectedEvent(); + + const ApplePayShippingMethod& shippingMethod() const { return m_shippingMethod; } + +private: + ApplePayShippingMethodSelectedEvent(const AtomicString& type, const PaymentRequest::ShippingMethod&); + + // Event. + EventInterface eventInterface() const override; + + const ApplePayShippingMethod m_shippingMethod; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayShippingMethodSelectedEvent.idl b/Source/WebCore/Modules/applepay/ApplePayShippingMethodSelectedEvent.idl new file mode 100644 index 000000000..935a17927 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayShippingMethodSelectedEvent.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 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, + NoInterfaceObject, +] interface ApplePayShippingMethodSelectedEvent : Event { + [CachedAttribute] readonly attribute ApplePayShippingMethod shippingMethod; +}; diff --git a/Source/WebCore/Modules/applepay/ApplePayValidateMerchantEvent.cpp b/Source/WebCore/Modules/applepay/ApplePayValidateMerchantEvent.cpp new file mode 100644 index 000000000..c6c863748 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayValidateMerchantEvent.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2016 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. + */ + +#include "config.h" +#include "ApplePayValidateMerchantEvent.h" + +#if ENABLE(APPLE_PAY) + +namespace WebCore { + +ApplePayValidateMerchantEvent::ApplePayValidateMerchantEvent(const AtomicString& type, const URL& validationURL) + : Event(type, false, false) + , m_validationURL(validationURL) +{ +} + +ApplePayValidateMerchantEvent::~ApplePayValidateMerchantEvent() +{ +} + +EventInterface ApplePayValidateMerchantEvent::eventInterface() const +{ + return ApplePayValidateMerchantEventInterfaceType; +} + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayValidateMerchantEvent.h b/Source/WebCore/Modules/applepay/ApplePayValidateMerchantEvent.h new file mode 100644 index 000000000..451559831 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayValidateMerchantEvent.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2016 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) + +#include "Event.h" +#include "URL.h" + +namespace WebCore { + +class ApplePayValidateMerchantEvent final : public Event { +public: + static Ref<ApplePayValidateMerchantEvent> create(const AtomicString& type, const URL& validationURL) + { + return adoptRef(*new ApplePayValidateMerchantEvent(type, validationURL)); + } + + virtual ~ApplePayValidateMerchantEvent(); + + const String& validationURL() const { return m_validationURL.string(); } + +private: + ApplePayValidateMerchantEvent(const AtomicString& type, const URL& validationURL); + + // Event. + EventInterface eventInterface() const override; + + const URL m_validationURL; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/ApplePayValidateMerchantEvent.idl b/Source/WebCore/Modules/applepay/ApplePayValidateMerchantEvent.idl new file mode 100644 index 000000000..3b2a85bf1 --- /dev/null +++ b/Source/WebCore/Modules/applepay/ApplePayValidateMerchantEvent.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 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, + NoInterfaceObject, +] interface ApplePayValidateMerchantEvent : Event { + readonly attribute DOMString validationURL; +}; diff --git a/Source/WebCore/Modules/applepay/Payment.h b/Source/WebCore/Modules/applepay/Payment.h new file mode 100644 index 000000000..f8b7da25e --- /dev/null +++ b/Source/WebCore/Modules/applepay/Payment.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2016 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) + +#include <wtf/RetainPtr.h> + +OBJC_CLASS PKPayment; + +namespace WebCore { + +struct ApplePayPayment; + +class Payment { +public: + Payment() + { + } + + explicit Payment(PKPayment *pkPayment) + : m_pkPayment(pkPayment) + { + } + + ~Payment() + { + } + + ApplePayPayment toApplePayPayment() const; + + PKPayment *pkPayment() const { return m_pkPayment.get(); } + +private: + RetainPtr<PKPayment> m_pkPayment; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentAuthorizationStatus.h b/Source/WebCore/Modules/applepay/PaymentAuthorizationStatus.h new file mode 100644 index 000000000..97c77842a --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentAuthorizationStatus.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2016 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) + +namespace WebCore { + +enum class PaymentAuthorizationStatus { + Success, + Failure, + InvalidBillingPostalAddress, + InvalidShippingPostalAddress, + InvalidShippingContact, + PINRequired, + PINIncorrect, + PINLockout, +}; + +static inline bool isFinalStateStatus(PaymentAuthorizationStatus status) +{ + switch (status) { + case PaymentAuthorizationStatus::Success: + case PaymentAuthorizationStatus::Failure: + return true; + + case PaymentAuthorizationStatus::InvalidBillingPostalAddress: + case PaymentAuthorizationStatus::InvalidShippingPostalAddress: + case PaymentAuthorizationStatus::InvalidShippingContact: + case PaymentAuthorizationStatus::PINRequired: + case PaymentAuthorizationStatus::PINIncorrect: + case PaymentAuthorizationStatus::PINLockout: + return false; + } +} + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentContact.h b/Source/WebCore/Modules/applepay/PaymentContact.h new file mode 100644 index 000000000..a8e3d0140 --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentContact.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016 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) + +#include <wtf/Forward.h> +#include <wtf/RetainPtr.h> + +OBJC_CLASS PKContact; + +namespace WebCore { + +struct ApplePayPaymentContact; + +class PaymentContact { +public: + PaymentContact() = default; + explicit PaymentContact(PKContact *pkContact) + : m_pkContact(pkContact) + { + } + + static PaymentContact fromApplePayPaymentContact(const ApplePayPaymentContact&); + ApplePayPaymentContact toApplePayPaymentContact() const; + + PKContact *pkContact() const { return m_pkContact.get(); } + +private: + RetainPtr<PKContact> m_pkContact; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp b/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp new file mode 100644 index 000000000..154a6d05c --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2015, 2016 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. + */ + +#include "config.h" +#include "PaymentCoordinator.h" + +#if ENABLE(APPLE_PAY) + +#include "ApplePaySession.h" +#include "PaymentAuthorizationStatus.h" +#include "PaymentCoordinatorClient.h" +#include "URL.h" + +namespace WebCore { + +PaymentCoordinator::PaymentCoordinator(PaymentCoordinatorClient& client) + : m_client(client) +{ +} + +PaymentCoordinator::~PaymentCoordinator() +{ + m_client.paymentCoordinatorDestroyed(); +} + +bool PaymentCoordinator::supportsVersion(unsigned version) +{ + return m_client.supportsVersion(version); +} + +bool PaymentCoordinator::canMakePayments() +{ + return m_client.canMakePayments(); +} + +void PaymentCoordinator::canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler) +{ + m_client.canMakePaymentsWithActiveCard(merchantIdentifier, domainName, WTFMove(completionHandler)); +} + +void PaymentCoordinator::openPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler) +{ + m_client.openPaymentSetup(merchantIdentifier, domainName, WTFMove(completionHandler)); +} + +bool PaymentCoordinator::beginPaymentSession(ApplePaySession& paymentSession, const URL& originatingURL, const Vector<URL>& linkIconURLs, const PaymentRequest& paymentRequest) +{ + ASSERT(!m_activeSession); + + if (!m_client.showPaymentUI(originatingURL, linkIconURLs, paymentRequest)) + return false; + + m_activeSession = &paymentSession; + return true; +} + +void PaymentCoordinator::completeMerchantValidation(const PaymentMerchantSession& paymentMerchantSession) +{ + ASSERT(m_activeSession); + + m_client.completeMerchantValidation(paymentMerchantSession); +} + +void PaymentCoordinator::completeShippingMethodSelection(PaymentAuthorizationStatus status, std::optional<PaymentRequest::TotalAndLineItems> newTotalAndItems) +{ + ASSERT(m_activeSession); + + m_client.completeShippingMethodSelection(status, WTFMove(newTotalAndItems)); +} + +void PaymentCoordinator::completeShippingContactSelection(PaymentAuthorizationStatus status, const Vector<PaymentRequest::ShippingMethod>& newShippingMethods, std::optional<PaymentRequest::TotalAndLineItems> newTotalAndItems) +{ + ASSERT(m_activeSession); + + m_client.completeShippingContactSelection(status, newShippingMethods, WTFMove(newTotalAndItems)); +} + +void PaymentCoordinator::completePaymentMethodSelection(std::optional<PaymentRequest::TotalAndLineItems> newTotalAndItems) +{ + ASSERT(m_activeSession); + + m_client.completePaymentMethodSelection(WTFMove(newTotalAndItems)); +} + +void PaymentCoordinator::completePaymentSession(PaymentAuthorizationStatus status) +{ + ASSERT(m_activeSession); + + m_client.completePaymentSession(status); + + if (!isFinalStateStatus(status)) + return; + + m_activeSession = nullptr; +} + +void PaymentCoordinator::abortPaymentSession() +{ + ASSERT(m_activeSession); + + m_client.abortPaymentSession(); + m_activeSession = nullptr; +} + +void PaymentCoordinator::validateMerchant(const URL& validationURL) +{ + if (!m_activeSession) { + // It's possible that the payment has been aborted already. + return; + } + + m_activeSession->validateMerchant(validationURL); +} + +void PaymentCoordinator::didAuthorizePayment(const Payment& payment) +{ + if (!m_activeSession) { + // It's possible that the payment has been aborted already. + return; + } + + m_activeSession->didAuthorizePayment(payment); +} + +void PaymentCoordinator::didSelectPaymentMethod(const PaymentMethod& paymentMethod) +{ + if (!m_activeSession) { + // It's possible that the payment has been aborted already. + return; + } + + m_activeSession->didSelectPaymentMethod(paymentMethod); +} + +void PaymentCoordinator::didSelectShippingMethod(const PaymentRequest::ShippingMethod& shippingMethod) +{ + if (!m_activeSession) { + // It's possible that the payment has been aborted already. + return; + } + + m_activeSession->didSelectShippingMethod(shippingMethod); +} + +void PaymentCoordinator::didSelectShippingContact(const PaymentContact& shippingContact) +{ + if (!m_activeSession) { + // It's possible that the payment has been aborted already. + return; + } + + m_activeSession->didSelectShippingContact(shippingContact); +} + +void PaymentCoordinator::didCancelPayment() +{ + if (!m_activeSession) { + // It's possible that the payment has been aborted already. + return; + } + + m_activeSession->didCancelPayment(); + m_activeSession = nullptr; +} + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentCoordinator.h b/Source/WebCore/Modules/applepay/PaymentCoordinator.h new file mode 100644 index 000000000..500ae16d1 --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentCoordinator.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2015, 2016 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) + +#include "PaymentRequest.h" +#include <functional> + +namespace WebCore { + +class ApplePaySession; +class Payment; +class PaymentCoordinatorClient; +class PaymentContact; +class PaymentMerchantSession; +class PaymentMethod; +class URL; +enum class PaymentAuthorizationStatus; + +class PaymentCoordinator { +public: + explicit PaymentCoordinator(PaymentCoordinatorClient&); + ~PaymentCoordinator(); + + bool supportsVersion(unsigned version); + bool canMakePayments(); + void canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler); + void openPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler); + + bool hasActiveSession() const { return m_activeSession; } + + bool beginPaymentSession(ApplePaySession&, const URL& originatingURL, const Vector<URL>& linkIconURLs, const PaymentRequest&); + void completeMerchantValidation(const PaymentMerchantSession&); + void completeShippingMethodSelection(PaymentAuthorizationStatus, std::optional<PaymentRequest::TotalAndLineItems> newItems); + void completeShippingContactSelection(PaymentAuthorizationStatus, const Vector<PaymentRequest::ShippingMethod>& newShippingMethods, std::optional<PaymentRequest::TotalAndLineItems> newItems); + void completePaymentMethodSelection(std::optional<PaymentRequest::TotalAndLineItems> newItems); + void completePaymentSession(PaymentAuthorizationStatus); + void abortPaymentSession(); + + WEBCORE_EXPORT void validateMerchant(const URL& validationURL); + WEBCORE_EXPORT void didAuthorizePayment(const Payment&); + WEBCORE_EXPORT void didSelectPaymentMethod(const PaymentMethod&); + WEBCORE_EXPORT void didSelectShippingMethod(const PaymentRequest::ShippingMethod&); + WEBCORE_EXPORT void didSelectShippingContact(const PaymentContact&); + WEBCORE_EXPORT void didCancelPayment(); + +private: + PaymentCoordinatorClient& m_client; + + RefPtr<ApplePaySession> m_activeSession; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentCoordinatorClient.h b/Source/WebCore/Modules/applepay/PaymentCoordinatorClient.h new file mode 100644 index 000000000..3d6ecc073 --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentCoordinatorClient.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015, 2016 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) + +#include "PaymentRequest.h" +#include <functional> +#include <wtf/Forward.h> + +namespace WebCore { + +class PaymentMerchantSession; +class URL; +enum class PaymentAuthorizationStatus; + +class PaymentCoordinatorClient { +public: + virtual bool supportsVersion(unsigned version) = 0; + virtual bool canMakePayments() = 0; + virtual void canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler) = 0; + virtual void openPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler) = 0; + + virtual bool showPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLs, const PaymentRequest&) = 0; + virtual void completeMerchantValidation(const PaymentMerchantSession&) = 0; + virtual void completeShippingMethodSelection(PaymentAuthorizationStatus, std::optional<PaymentRequest::TotalAndLineItems> newTotalAndItems) = 0; + virtual void completeShippingContactSelection(PaymentAuthorizationStatus, const Vector<PaymentRequest::ShippingMethod>& newShippingMethods, std::optional<PaymentRequest::TotalAndLineItems> newTotalAndItems) = 0; + virtual void completePaymentMethodSelection(std::optional<WebCore::PaymentRequest::TotalAndLineItems> newTotalAndItems) = 0; + virtual void completePaymentSession(PaymentAuthorizationStatus) = 0; + virtual void abortPaymentSession() = 0; + virtual void paymentCoordinatorDestroyed() = 0; + +protected: + virtual ~PaymentCoordinatorClient() { } +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentHeaders.h b/Source/WebCore/Modules/applepay/PaymentHeaders.h new file mode 100644 index 000000000..99bcb8bc2 --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentHeaders.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2016 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 + +#include "Payment.h" +#include "PaymentContact.h" +#include "PaymentMerchantSession.h" +#include "PaymentMethod.h" +#include "PaymentRequest.h" + diff --git a/Source/WebCore/Modules/applepay/PaymentMerchantSession.h b/Source/WebCore/Modules/applepay/PaymentMerchantSession.h new file mode 100644 index 000000000..a5c6dddce --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentMerchantSession.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2016 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) + +#include <wtf/Forward.h> +#include <wtf/RetainPtr.h> + +namespace JSC { +class ExecState; +class JSValue; +} + +OBJC_CLASS PKPaymentMerchantSession; + +namespace WebCore { + +class PaymentMerchantSession { +public: + PaymentMerchantSession() + { + } + + explicit PaymentMerchantSession(PKPaymentMerchantSession *pkPaymentMerchantSession) + : m_pkPaymentMerchantSession(pkPaymentMerchantSession) + { + } + + ~PaymentMerchantSession() + { + } + + static std::optional<PaymentMerchantSession> fromJS(JSC::ExecState&, JSC::JSValue, String& errorMessage); + + PKPaymentMerchantSession *pkPaymentMerchantSession() const { return m_pkPaymentMerchantSession.get(); } + +private: + RetainPtr<PKPaymentMerchantSession> m_pkPaymentMerchantSession; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentMethod.h b/Source/WebCore/Modules/applepay/PaymentMethod.h new file mode 100644 index 000000000..69a3770c7 --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentMethod.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2016 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) + +#include <wtf/RetainPtr.h> + +OBJC_CLASS PKPaymentMethod; + +namespace WebCore { + +struct ApplePayPaymentMethod; + +class PaymentMethod { +public: + PaymentMethod() + { + } + + explicit PaymentMethod(PKPaymentMethod *pkPaymentMethod) + : m_pkPaymentMethod(pkPaymentMethod) + { + } + + ApplePayPaymentMethod toApplePayPaymentMethod() const; + + PKPaymentMethod *pkPaymentMethod() const { return m_pkPaymentMethod.get(); } + +private: + RetainPtr<PKPaymentMethod> m_pkPaymentMethod; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentRequest.cpp b/Source/WebCore/Modules/applepay/PaymentRequest.cpp new file mode 100644 index 000000000..06e5244ae --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentRequest.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2015, 2016 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. + */ + +#include "config.h" +#include "PaymentRequest.h" + +#if ENABLE(APPLE_PAY) + +#include "SoftLinking.h" + +namespace WebCore { + +PaymentRequest::PaymentRequest() +{ +} + +PaymentRequest::~PaymentRequest() +{ +} + +#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/PaymentRequestAdditions.cpp>) +#include <WebKitAdditions/PaymentRequestAdditions.cpp> +#else +static inline bool isAdditionalValidSupportedNetwork(unsigned, const String&) +{ + return false; +} +#endif + +bool PaymentRequest::isValidSupportedNetwork(unsigned version, const String& supportedNetwork) +{ + if (supportedNetwork == "amex") + return true; + if (supportedNetwork == "chinaUnionPay") + return true; + if (supportedNetwork == "discover") + return true; + if (supportedNetwork == "interac") + return true; + if (supportedNetwork == "masterCard") + return true; + if (supportedNetwork == "privateLabel") + return true; + if (supportedNetwork == "visa") + return true; + + return isAdditionalValidSupportedNetwork(version, supportedNetwork); +} + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentRequest.h b/Source/WebCore/Modules/applepay/PaymentRequest.h new file mode 100644 index 000000000..ec3ee1faf --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentRequest.h @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2015, 2016 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) + +#include "PaymentContact.h" +#include <wtf/Optional.h> +#include <wtf/Vector.h> +#include <wtf/text/WTFString.h> + +namespace WebCore { + +class PaymentRequest { +public: + WEBCORE_EXPORT PaymentRequest(); + WEBCORE_EXPORT ~PaymentRequest(); + + const String& countryCode() const { return m_countryCode; } + void setCountryCode(const String& countryCode) { m_countryCode = countryCode; } + + const String& currencyCode() const { return m_currencyCode; } + void setCurrencyCode(const String& currencyCode) { m_currencyCode = currencyCode; } + + struct ContactFields { + bool postalAddress { false }; + bool phone { false }; + bool email { false }; + bool name { false }; + }; + + const ContactFields& requiredBillingContactFields() const { return m_requiredBillingContactFields; } + void setRequiredBillingContactFields(const ContactFields& requiredBillingContactFields) { m_requiredBillingContactFields = requiredBillingContactFields; } + + const PaymentContact& billingContact() const { return m_billingContact; } + void setBillingContact(const PaymentContact& billingContact) { m_billingContact = billingContact; } + + const ContactFields& requiredShippingContactFields() const { return m_requiredShippingContactFields; } + void setRequiredShippingContactFields(const ContactFields& requiredShippingContactFields) { m_requiredShippingContactFields = requiredShippingContactFields; } + + const PaymentContact& shippingContact() const { return m_shippingContact; } + void setShippingContact(const PaymentContact& shippingContact) { m_shippingContact = shippingContact; } + + static bool isValidSupportedNetwork(unsigned version, const String&); + + const Vector<String>& supportedNetworks() const { return m_supportedNetworks; } + void setSupportedNetworks(const Vector<String>& supportedNetworks) { m_supportedNetworks = supportedNetworks; } + + struct MerchantCapabilities { + bool supports3DS { false }; + bool supportsEMV { false }; + bool supportsCredit { false }; + bool supportsDebit { false }; + }; + + const MerchantCapabilities& merchantCapabilities() const { return m_merchantCapabilities; } + void setMerchantCapabilities(const MerchantCapabilities& merchantCapabilities) { m_merchantCapabilities = merchantCapabilities; } + + struct LineItem { + enum class Type { + Pending, + Final, + } type { Type::Final }; + + // Stored as a fixed point decimal number with two decimals: + // 1.23 -> 123. + // 0.01 -> 1. + std::optional<int64_t> amount; + String label; + }; + + enum class ShippingType { + Shipping, + Delivery, + StorePickup, + ServicePickup, + }; + ShippingType shippingType() const { return m_shippingType; } + void setShippingType(ShippingType shippingType) { m_shippingType = shippingType; } + + struct ShippingMethod { + String label; + String detail; + int64_t amount; + + String identifier; + }; + const Vector<ShippingMethod>& shippingMethods() const { return m_shippingMethods; } + void setShippingMethods(const Vector<ShippingMethod>& shippingMethods) { m_shippingMethods = shippingMethods; } + + const Vector<LineItem>& lineItems() const { return m_lineItems; } + void setLineItems(const Vector<LineItem>& lineItems) { m_lineItems = lineItems; } + + const LineItem& total() const { return m_total; }; + void setTotal(const LineItem& total) { m_total = total; } + + struct TotalAndLineItems { + PaymentRequest::LineItem total; + Vector<PaymentRequest::LineItem> lineItems; + }; + + const String& applicationData() const { return m_applicationData; } + void setApplicationData(const String& applicationData) { m_applicationData = applicationData; } + +private: + String m_countryCode; + String m_currencyCode; + + ContactFields m_requiredBillingContactFields; + PaymentContact m_billingContact; + + ContactFields m_requiredShippingContactFields; + PaymentContact m_shippingContact; + + Vector<String> m_supportedNetworks; + MerchantCapabilities m_merchantCapabilities; + + ShippingType m_shippingType { ShippingType::Shipping }; + Vector<ShippingMethod> m_shippingMethods; + + Vector<LineItem> m_lineItems; + LineItem m_total; + + String m_applicationData; +}; + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentRequestValidator.cpp b/Source/WebCore/Modules/applepay/PaymentRequestValidator.cpp new file mode 100644 index 000000000..9245841bf --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentRequestValidator.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2015, 2016 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. + */ + +#include "config.h" +#include "PaymentRequestValidator.h" + +#if ENABLE(APPLE_PAY) + +#include "ExceptionCode.h" +#include "PaymentRequest.h" +#include <unicode/ucurr.h> +#include <unicode/uloc.h> + +namespace WebCore { + +static ExceptionOr<void> validateCountryCode(const String&); +static ExceptionOr<void> validateCurrencyCode(const String&); +static ExceptionOr<void> validateMerchantCapabilities(const PaymentRequest::MerchantCapabilities&); +static ExceptionOr<void> validateSupportedNetworks(const Vector<String>&); +static ExceptionOr<void> validateShippingMethods(const Vector<PaymentRequest::ShippingMethod>&); +static ExceptionOr<void> validateShippingMethod(const PaymentRequest::ShippingMethod&); + + +ExceptionOr<void> PaymentRequestValidator::validate(const PaymentRequest& paymentRequest) +{ + auto validatedCountryCode = validateCountryCode(paymentRequest.countryCode()); + if (validatedCountryCode.hasException()) + return validatedCountryCode.releaseException(); + + auto validatedCurrencyCode = validateCurrencyCode(paymentRequest.currencyCode()); + if (validatedCurrencyCode.hasException()) + return validatedCurrencyCode.releaseException(); + + auto validatedSupportedNetworks = validateSupportedNetworks(paymentRequest.supportedNetworks()); + if (validatedSupportedNetworks.hasException()) + return validatedSupportedNetworks.releaseException(); + + auto validatedMerchantCapabilities = validateMerchantCapabilities(paymentRequest.merchantCapabilities()); + if (validatedMerchantCapabilities.hasException()) + return validatedMerchantCapabilities.releaseException(); + + auto validatedTotal = validateTotal(paymentRequest.total()); + if (validatedTotal.hasException()) + return validatedTotal.releaseException(); + + auto validatedShippingMethods = validateShippingMethods(paymentRequest.shippingMethods()); + if (validatedShippingMethods.hasException()) + return validatedShippingMethods.releaseException(); + + return { }; +} + +ExceptionOr<void> PaymentRequestValidator::validateTotal(const PaymentRequest::LineItem& total) +{ + if (!total.label) + return Exception { TypeError, "Missing total label." }; + + if (!total.amount) + return Exception { TypeError, "Missing total amount." }; + + if (*total.amount <= 0) + return Exception { TypeError, "Total amount must be greater than zero." }; + + if (*total.amount > 10000000000) + return Exception { TypeError, "Total amount is too big." }; + + return { }; +} + +static ExceptionOr<void> validateCountryCode(const String& countryCode) +{ + if (!countryCode) + return Exception { TypeError, "Missing country code." }; + + for (auto *countryCodePtr = uloc_getISOCountries(); *countryCodePtr; ++countryCodePtr) { + if (countryCode == *countryCodePtr) + return { }; + } + + return Exception { TypeError, makeString("\"" + countryCode, "\" is not a valid country code.") }; +} + +static ExceptionOr<void> validateCurrencyCode(const String& currencyCode) +{ + if (!currencyCode) + return Exception { TypeError, "Missing currency code." }; + + UErrorCode errorCode = U_ZERO_ERROR; + auto currencyCodes = std::unique_ptr<UEnumeration, void (*)(UEnumeration*)>(ucurr_openISOCurrencies(UCURR_ALL, &errorCode), uenum_close); + + int32_t length; + while (auto *currencyCodePtr = uenum_next(currencyCodes.get(), &length, &errorCode)) { + if (currencyCodePtr == currencyCode) + return { }; + } + + return Exception { TypeError, makeString("\"" + currencyCode, "\" is not a valid currency code.") }; +} + +static ExceptionOr<void> validateMerchantCapabilities(const PaymentRequest::MerchantCapabilities& merchantCapabilities) +{ + if (!merchantCapabilities.supports3DS && !merchantCapabilities.supportsEMV && !merchantCapabilities.supportsCredit && !merchantCapabilities.supportsDebit) + return Exception { TypeError, "Missing merchant capabilities." }; + + return { }; +} + +static ExceptionOr<void> validateSupportedNetworks(const Vector<String>& supportedNetworks) +{ + if (supportedNetworks.isEmpty()) + return Exception { TypeError, "Missing supported networks." }; + + return { }; +} + +static ExceptionOr<void> validateShippingMethod(const PaymentRequest::ShippingMethod& shippingMethod) +{ + if (shippingMethod.amount < 0) + return Exception { TypeError, "Shipping method amount must be greater than or equal to zero." }; + + return { }; +} + +static ExceptionOr<void> validateShippingMethods(const Vector<PaymentRequest::ShippingMethod>& shippingMethods) +{ + for (const auto& shippingMethod : shippingMethods) { + auto validatedShippingMethod = validateShippingMethod(shippingMethod); + if (validatedShippingMethod.hasException()) + return validatedShippingMethod.releaseException(); + } + + return { }; +} + +} + +#endif diff --git a/Source/WebCore/Modules/applepay/PaymentRequestValidator.h b/Source/WebCore/Modules/applepay/PaymentRequestValidator.h new file mode 100644 index 000000000..bcd618595 --- /dev/null +++ b/Source/WebCore/Modules/applepay/PaymentRequestValidator.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2015, 2016 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) + +#include "ExceptionOr.h" +#include "PaymentRequest.h" + +namespace WebCore { + +class PaymentRequestValidator { +public: + static ExceptionOr<void> validate(const PaymentRequest&); + static ExceptionOr<void> validateTotal(const PaymentRequest::LineItem&); +}; + +} + +#endif |