11package com.ioki.passenger.api.models
22
3+ import com.ioki.passenger.api.models.ApiPaymentMethodResponse.Summary.Brand
34import com.ioki.passenger.api.models.ApiPaymentMethodResponse.Summary.Kind
5+ import com.ioki.passenger.api.models.ApiPaymentMethodResponse.Summary.Wallet
46import kotlinx.serialization.KSerializer
57import kotlinx.serialization.SerialName
68import kotlinx.serialization.Serializable
@@ -18,7 +20,10 @@ public data class ApiPaymentMethodResponse(
1820 @Serializable
1921 public data class Summary (
2022 val kind : Kind = Kind .UNSUPPORTED ,
23+ val wallet : Wallet ? ,
24+ val brand : Brand ? ,
2125 val title : String ,
26+ val last4 : String? ,
2227 val expiration : String? ,
2328 @SerialName(value = " mandate_url" )
2429 val mandateUrl : String? ,
@@ -48,6 +53,46 @@ public data class ApiPaymentMethodResponse(
4853
4954 UNSUPPORTED ,
5055 }
56+
57+ @Serializable(with = ApiPaymentMethodResponseWalletSerializer ::class )
58+ public enum class Wallet {
59+ @SerialName(value = " google_pay" )
60+ GOOGLE_PAY ,
61+
62+ @SerialName(value = " apple_pay" )
63+ APPLE_PAY ,
64+
65+ UNSUPPORTED ,
66+ }
67+
68+ @Serializable(with = ApiPaymentMethodResponseBrandSerializer ::class )
69+ public enum class Brand {
70+ @SerialName(value = " visa" )
71+ VISA ,
72+
73+ @SerialName(value = " mastercard" )
74+ MASTERCARD ,
75+
76+ @SerialName(value = " amex" )
77+ AMEX ,
78+
79+ @SerialName(value = " cartes_bancaires" )
80+ CARTES_BANCAIRES ,
81+
82+ @SerialName(value = " diners_club" )
83+ DINERS_CLUB ,
84+
85+ @SerialName(value = " discover" )
86+ DISCOVER ,
87+
88+ @SerialName(value = " jcb" )
89+ JCB ,
90+
91+ @SerialName(value = " unionpay" )
92+ UNIONPAY ,
93+
94+ UNSUPPORTED ,
95+ }
5196 }
5297}
5398
@@ -80,3 +125,55 @@ internal object ApiPaymentMethodResponseKindSerializer : KSerializer<Kind> {
80125 else -> Kind .UNSUPPORTED
81126 }
82127}
128+
129+ internal object ApiPaymentMethodResponseWalletSerializer : KSerializer<Wallet> {
130+ override val descriptor = String .serializer().descriptor
131+
132+ override fun serialize (encoder : Encoder , value : Wallet ) {
133+ encoder.encodeString(
134+ when (value) {
135+ Wallet .GOOGLE_PAY -> " google_pay"
136+ Wallet .APPLE_PAY -> " apple_pay"
137+ Wallet .UNSUPPORTED -> " unsupported"
138+ },
139+ )
140+ }
141+
142+ override fun deserialize (decoder : Decoder ): Wallet = when (decoder.decodeString()) {
143+ " google_pay" -> Wallet .GOOGLE_PAY
144+ " apple_pay" -> Wallet .APPLE_PAY
145+ else -> Wallet .UNSUPPORTED
146+ }
147+ }
148+
149+ internal object ApiPaymentMethodResponseBrandSerializer : KSerializer<Brand> {
150+ override val descriptor = String .serializer().descriptor
151+
152+ override fun serialize (encoder : Encoder , value : Brand ) {
153+ encoder.encodeString(
154+ when (value) {
155+ Brand .VISA -> " visa"
156+ Brand .MASTERCARD -> " mastercard"
157+ Brand .AMEX -> " amex"
158+ Brand .CARTES_BANCAIRES -> " cartes_bancaires"
159+ Brand .DINERS_CLUB -> " diners_club"
160+ Brand .DISCOVER -> " discover"
161+ Brand .JCB -> " jcb"
162+ Brand .UNIONPAY -> " unionpay"
163+ Brand .UNSUPPORTED -> " unsupported"
164+ },
165+ )
166+ }
167+
168+ override fun deserialize (decoder : Decoder ): Brand = when (decoder.decodeString()) {
169+ " visa" -> Brand .VISA
170+ " mastercard" -> Brand .MASTERCARD
171+ " amex" -> Brand .AMEX
172+ " cartes_bancaires" -> Brand .CARTES_BANCAIRES
173+ " diners_club" -> Brand .DINERS_CLUB
174+ " discover" -> Brand .DISCOVER
175+ " jcb" -> Brand .JCB
176+ " unionpay" -> Brand .UNIONPAY
177+ else -> Brand .UNSUPPORTED
178+ }
179+ }
0 commit comments