Remove bindings generation support for legacy WebCore::Dictionary
[WebKit-https.git] / Source / WebCore / Modules / applepay / ApplePaySession.h
1 /*
2  * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #if ENABLE(APPLE_PAY)
29
30 #include "ActiveDOMObject.h"
31 #include "EventTarget.h"
32 #include "ExceptionOr.h"
33 #include "PaymentRequest.h"
34 #include <wtf/Ref.h>
35 #include <wtf/RefCounted.h>
36
37 namespace WebCore {
38
39 class ArrayValue;
40 class DeferredPromise;
41 class Dictionary;
42 class Document;
43 class Payment;
44 class PaymentContact;
45 class PaymentCoordinator;
46 class PaymentMethod;
47 class URL;
48
49 class ApplePaySession final : public RefCounted<ApplePaySession>, public ActiveDOMObject, public EventTargetWithInlineData {
50 public:
51     static ExceptionOr<Ref<ApplePaySession>> create(JSC::ExecState&, Document&, unsigned version, JSC::JSValue);
52     virtual ~ApplePaySession();
53
54     // DOM API.
55     static const unsigned short STATUS_SUCCESS = 0;
56     static const unsigned short STATUS_FAILURE = 1;
57     static const unsigned short STATUS_INVALID_BILLING_POSTAL_ADDRESS = 2;
58     static const unsigned short STATUS_INVALID_SHIPPING_POSTAL_ADDRESS = 3;
59     static const unsigned short STATUS_INVALID_SHIPPING_CONTACT = 4;
60     static const unsigned short STATUS_PIN_REQUIRED = 5;
61     static const unsigned short STATUS_PIN_INCORRECT = 6;
62     static const unsigned short STATUS_PIN_LOCKOUT = 7;
63
64     static ExceptionOr<bool> supportsVersion(ScriptExecutionContext&, unsigned version);
65     static ExceptionOr<bool> canMakePayments(ScriptExecutionContext&);
66     static ExceptionOr<void> canMakePaymentsWithActiveCard(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&);
67     static ExceptionOr<void> openPaymentSetup(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredPromise>&&);
68
69     ExceptionOr<void> begin();
70     ExceptionOr<void> abort();
71     ExceptionOr<void> completeMerchantValidation(JSC::ExecState&, JSC::JSValue merchantSessionDictionary);
72     ExceptionOr<void> completeShippingMethodSelection(unsigned short status, const Dictionary& newTotal, const ArrayValue& newLineItems);
73     ExceptionOr<void> completeShippingContactSelection(unsigned short status, const ArrayValue& newShippingMethods, const Dictionary& newTotal, const ArrayValue& newLineItems);
74     ExceptionOr<void> completePaymentMethodSelection(const Dictionary& newTotal, const ArrayValue& newLineItems);
75     ExceptionOr<void> completePayment(unsigned short status);
76
77     const PaymentRequest& paymentRequest() const { return m_paymentRequest; }
78
79     void validateMerchant(const URL&);
80     void didAuthorizePayment(const Payment&);
81     void didSelectShippingMethod(const PaymentRequest::ShippingMethod&);
82     void didSelectShippingContact(const PaymentContact&);
83     void didSelectPaymentMethod(const PaymentMethod&);
84     void didCancelPayment();
85
86     using RefCounted<ApplePaySession>::ref;
87     using RefCounted<ApplePaySession>::deref;
88
89 private:
90     ApplePaySession(Document&, PaymentRequest&&);
91
92     // ActiveDOMObject.
93     const char* activeDOMObjectName() const override;
94     bool canSuspendForDocumentSuspension() const override;
95     void stop() override;
96
97     // EventTargetWithInlineData.
98     EventTargetInterface eventTargetInterface() const override { return ApplePaySessionEventTargetInterfaceType; }
99     ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); }
100     void refEventTarget() override { ref(); }
101     void derefEventTarget() override { deref(); }
102
103     PaymentCoordinator& paymentCoordinator() const;
104
105     bool canBegin() const;
106     bool canAbort() const;
107     bool canCancel() const;
108     bool canCompleteMerchantValidation() const;
109     bool canCompleteShippingMethodSelection() const;
110     bool canCompleteShippingContactSelection() const;
111     bool canCompletePaymentMethodSelection() const;
112     bool canCompletePayment() const;
113
114     bool isFinalState() const;
115     void didReachFinalState();
116
117     enum class State {
118         Idle,
119
120         Active,
121         ShippingMethodSelected,
122         ShippingContactSelected,
123         PaymentMethodSelected,
124         Authorized,
125         Completed,
126
127         Aborted,
128         Canceled,
129     } m_state { State::Idle };
130
131     enum class MerchantValidationState {
132         Idle,
133         ValidatingMerchant,
134         ValidationComplete,
135     } m_merchantValidationState { MerchantValidationState::Idle };
136
137     const PaymentRequest m_paymentRequest;
138 };
139
140 }
141
142 #endif