Skip to content

Commit 31b6ac2

Browse files
authored
ApiPaymentMethodResponse: Add wallet (#258)
1 parent eed139b commit 31b6ac2

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

library/src/commonMain/kotlin/com/ioki/passenger/api/models/ApiPaymentMethodResponse.kt

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.ioki.passenger.api.models
22

3+
import com.ioki.passenger.api.models.ApiPaymentMethodResponse.Summary.Brand
34
import com.ioki.passenger.api.models.ApiPaymentMethodResponse.Summary.Kind
5+
import com.ioki.passenger.api.models.ApiPaymentMethodResponse.Summary.Wallet
46
import kotlinx.serialization.KSerializer
57
import kotlinx.serialization.SerialName
68
import 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+
}

library/src/commonTest/kotlin/com/ioki/passenger/api/models/ApiPaymentMethodResponseTest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ internal class ApiPaymentMethodResponseTest : IokiApiModelTest() {
1818
paymentMethodType = ApiPaymentMethodType.STRIPE,
1919
id = "someId",
2020
summary = ApiPaymentMethodResponse.Summary(
21-
ApiPaymentMethodResponse.Summary.Kind.CREDIT_CARD,
21+
kind = ApiPaymentMethodResponse.Summary.Kind.CREDIT_CARD,
22+
wallet = ApiPaymentMethodResponse.Summary.Wallet.GOOGLE_PAY,
23+
brand = ApiPaymentMethodResponse.Summary.Brand.VISA,
2224
title = "Visa (*1234)",
25+
last4 = "1234",
2326
expiration = "11/20",
2427
mandateUrl = null,
2528
),
@@ -43,6 +46,9 @@ private val paymentMethod =
4346
"id": "someId",
4447
"summary": {
4548
"kind": "card",
49+
"wallet": "google_pay",
50+
"brand": "visa",
51+
"last4": "1234",
4652
"title": "Visa (*1234)",
4753
"expiration": "11/20"
4854
}

test/src/commonMain/kotlin/com/ioki/passenger/api/test/models/ApiPaymentMethodResponse.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ public fun createApiPaymentMethodResponse(
1515

1616
public fun createApiPaymentMethodResponseSummary(
1717
kind: ApiPaymentMethodResponse.Summary.Kind = ApiPaymentMethodResponse.Summary.Kind.UNSUPPORTED,
18+
wallet: ApiPaymentMethodResponse.Summary.Wallet? = null,
19+
brand: ApiPaymentMethodResponse.Summary.Brand? = null,
1820
title: String = "",
21+
last4: String? = null,
1922
expiration: String? = null,
2023
mandateUrl: String? = null,
2124
): ApiPaymentMethodResponse.Summary = ApiPaymentMethodResponse.Summary(
2225
kind = kind,
26+
wallet = wallet,
2327
title = title,
28+
brand = brand,
29+
last4 = last4,
2430
expiration = expiration,
2531
mandateUrl = mandateUrl,
2632
)

0 commit comments

Comments
 (0)