-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApiPaymentMethodResponse.kt
More file actions
181 lines (151 loc) · 5.55 KB
/
Copy pathApiPaymentMethodResponse.kt
File metadata and controls
181 lines (151 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package com.ioki.passenger.api.models
import com.ioki.passenger.api.models.ApiPaymentMethodResponse.Summary.Brand
import com.ioki.passenger.api.models.ApiPaymentMethodResponse.Summary.Kind
import com.ioki.passenger.api.models.ApiPaymentMethodResponse.Summary.Wallet
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializable
public data class ApiPaymentMethodResponse(
@SerialName(value = "payment_method_type")
val paymentMethodType: ApiPaymentMethodType = ApiPaymentMethodType.UNSUPPORTED,
@SerialName(value = "requires_paypal_secure_element")
val requiresPaypalSecureElement: Boolean,
val id: String?,
val summary: Summary?,
) {
@Serializable
public data class Summary(
val kind: Kind = Kind.UNSUPPORTED,
val wallet: Wallet?,
val brand: Brand?,
val title: String,
val last4: String?,
val expiration: String?,
@SerialName(value = "mandate_url")
val mandateUrl: String?,
) {
@Serializable(with = ApiPaymentMethodResponseKindSerializer::class)
public enum class Kind {
@SerialName(value = "card")
CREDIT_CARD,
@SerialName(value = "sepa_debit")
SEPA_DEBIT,
@SerialName(value = "paypal")
PAYPAL,
@SerialName(value = "cash")
CASH,
@SerialName(value = "service_credits")
SERVICE_CREDITS,
@SerialName(value = "pos_payment")
POS_PAYMENT,
@SerialName(value = "external_payment")
EXTERNAL_PAYMENT,
UNSUPPORTED,
}
@Serializable(with = ApiPaymentMethodResponseWalletSerializer::class)
public enum class Wallet {
@SerialName(value = "google_pay")
GOOGLE_PAY,
@SerialName(value = "apple_pay")
APPLE_PAY,
UNSUPPORTED,
}
@Serializable(with = ApiPaymentMethodResponseBrandSerializer::class)
public enum class Brand {
@SerialName(value = "visa")
VISA,
@SerialName(value = "mastercard")
MASTERCARD,
@SerialName(value = "amex")
AMEX,
@SerialName(value = "cartes_bancaires")
CARTES_BANCAIRES,
@SerialName(value = "diners_club")
DINERS_CLUB,
@SerialName(value = "discover")
DISCOVER,
@SerialName(value = "jcb")
JCB,
@SerialName(value = "unionpay")
UNIONPAY,
UNSUPPORTED,
}
}
}
internal object ApiPaymentMethodResponseKindSerializer : KSerializer<Kind> {
override val descriptor = String.serializer().descriptor
override fun serialize(encoder: Encoder, value: Kind) {
encoder.encodeString(
when (value) {
Kind.CREDIT_CARD -> "card"
Kind.SEPA_DEBIT -> "sepa_debit"
Kind.PAYPAL -> "paypal"
Kind.CASH -> "cash"
Kind.SERVICE_CREDITS -> "service_credits"
Kind.POS_PAYMENT -> "pos_payment"
Kind.EXTERNAL_PAYMENT -> "external_payment"
Kind.UNSUPPORTED -> "unsupported"
},
)
}
override fun deserialize(decoder: Decoder): Kind = when (decoder.decodeString()) {
"card" -> Kind.CREDIT_CARD
"sepa_debit" -> Kind.SEPA_DEBIT
"paypal" -> Kind.PAYPAL
"cash" -> Kind.CASH
"service_credits" -> Kind.SERVICE_CREDITS
"pos_payment" -> Kind.POS_PAYMENT
"external_payment" -> Kind.EXTERNAL_PAYMENT
else -> Kind.UNSUPPORTED
}
}
internal object ApiPaymentMethodResponseWalletSerializer : KSerializer<Wallet> {
override val descriptor = String.serializer().descriptor
override fun serialize(encoder: Encoder, value: Wallet) {
encoder.encodeString(
when (value) {
Wallet.GOOGLE_PAY -> "google_pay"
Wallet.APPLE_PAY -> "apple_pay"
Wallet.UNSUPPORTED -> "unsupported"
},
)
}
override fun deserialize(decoder: Decoder): Wallet = when (decoder.decodeString()) {
"google_pay" -> Wallet.GOOGLE_PAY
"apple_pay" -> Wallet.APPLE_PAY
else -> Wallet.UNSUPPORTED
}
}
internal object ApiPaymentMethodResponseBrandSerializer : KSerializer<Brand> {
override val descriptor = String.serializer().descriptor
override fun serialize(encoder: Encoder, value: Brand) {
encoder.encodeString(
when (value) {
Brand.VISA -> "visa"
Brand.MASTERCARD -> "mastercard"
Brand.AMEX -> "amex"
Brand.CARTES_BANCAIRES -> "cartes_bancaires"
Brand.DINERS_CLUB -> "diners_club"
Brand.DISCOVER -> "discover"
Brand.JCB -> "jcb"
Brand.UNIONPAY -> "unionpay"
Brand.UNSUPPORTED -> "unsupported"
},
)
}
override fun deserialize(decoder: Decoder): Brand = when (decoder.decodeString()) {
"visa" -> Brand.VISA
"mastercard" -> Brand.MASTERCARD
"amex" -> Brand.AMEX
"cartes_bancaires" -> Brand.CARTES_BANCAIRES
"diners_club" -> Brand.DINERS_CLUB
"discover" -> Brand.DISCOVER
"jcb" -> Brand.JCB
"unionpay" -> Brand.UNIONPAY
else -> Brand.UNSUPPORTED
}
}