blob: 6491f3af37803a4c10d448e706c6d2850bae4fa6 [file] [log] [blame]
andersca@apple.com4bcf0a02017-03-09 22:34:52 +00001/*
2 * Copyright (C) 2017 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
drousso@apple.com69adf6c2021-02-19 17:38:37 +000030#include "ApplePayDetailsUpdateBase.h"
andersca@apple.com4bcf0a02017-03-09 22:34:52 +000031#include "ApplePayError.h"
andersca@apple.com4bcf0a02017-03-09 22:34:52 +000032#include "ApplePayShippingMethod.h"
drousso@apple.com69adf6c2021-02-19 17:38:37 +000033#include <wtf/RefPtr.h>
34#include <wtf/Vector.h>
andersca@apple.com4bcf0a02017-03-09 22:34:52 +000035
36namespace WebCore {
37
drousso@apple.com69adf6c2021-02-19 17:38:37 +000038struct ApplePayShippingContactUpdate final : public ApplePayDetailsUpdateBase {
andersca@apple.com4bcf0a02017-03-09 22:34:52 +000039 Vector<RefPtr<ApplePayError>> errors;
40
41 Vector<ApplePayShippingMethod> newShippingMethods;
drousso@apple.com69adf6c2021-02-19 17:38:37 +000042
43 template<class Encoder> void encode(Encoder&) const;
darin@apple.coma4ddc782021-05-30 16:11:40 +000044 template<class Decoder> static std::optional<ApplePayShippingContactUpdate> decode(Decoder&);
andersca@apple.com4bcf0a02017-03-09 22:34:52 +000045};
46
drousso@apple.com69adf6c2021-02-19 17:38:37 +000047template<class Encoder>
48void ApplePayShippingContactUpdate::encode(Encoder& encoder) const
49{
50 ApplePayDetailsUpdateBase::encode(encoder);
51 encoder << errors;
52 encoder << newShippingMethods;
andersca@apple.com4bcf0a02017-03-09 22:34:52 +000053}
54
drousso@apple.com69adf6c2021-02-19 17:38:37 +000055template<class Decoder>
darin@apple.coma4ddc782021-05-30 16:11:40 +000056std::optional<ApplePayShippingContactUpdate> ApplePayShippingContactUpdate::decode(Decoder& decoder)
drousso@apple.com69adf6c2021-02-19 17:38:37 +000057{
58 ApplePayShippingContactUpdate result;
59
60 if (!result.decodeBase(decoder))
darin@apple.com7c840b62021-05-28 01:26:23 +000061 return std::nullopt;
drousso@apple.com69adf6c2021-02-19 17:38:37 +000062
63#define DECODE(name, type) \
darin@apple.coma4ddc782021-05-30 16:11:40 +000064 std::optional<type> name; \
drousso@apple.com69adf6c2021-02-19 17:38:37 +000065 decoder >> name; \
66 if (!name) \
darin@apple.com7c840b62021-05-28 01:26:23 +000067 return std::nullopt; \
drousso@apple.com69adf6c2021-02-19 17:38:37 +000068 result.name = WTFMove(*name); \
69
70 DECODE(errors, Vector<RefPtr<ApplePayError>>)
71 DECODE(newShippingMethods, Vector<ApplePayShippingMethod>)
72
73#undef DECODE
74
75 return result;
76}
77
78} // namespace WebCore
79
andersca@apple.com4bcf0a02017-03-09 22:34:52 +000080#endif