blob: 71cbc167e65049e93d6416ed0b6f5b40173aad42 (
plain)
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
|
package ch.bfh.habej2.wallee_c2ec.client.c2ec
import ch.bfh.habej2.wallee_c2ec.config.CURRENT_EXCHANGE
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Response
class C2ECClient {
companion object {
const val WITHDRAWAL_OP = "/c2ec/withdrawal-operation"
const val WITHDRAWAL_STATUS = "$WITHDRAWAL_OP/:wopid"
const val WITHDRAWAL_PAYMENT = "$WITHDRAWAL_OP/:wopid/payment"
}
init {
var client = OkHttpClient.Builder()
.addInterceptor(C2ECBasicAuthInterceptor())
.build();
}
fun retrieveWithdrawalStatus(wopid: String, longPollMs: Int): C2ECWithdrawalOperationStatus {
println("retrieving withdrawal operation status...")
return C2ECWithdrawalOperationStatus()
}
fun sendPaymentNotification(payment: C2ECPaymentNotification) {
println("sending payment notification...")
}
private class C2ECBasicAuthInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val base64EncodedCredentials = java.util.Base64
.getUrlEncoder()
.encode("${CURRENT_EXCHANGE!!.terminalId}:${CURRENT_EXCHANGE!!.accessToken}".toByteArray())
.toString()
return chain.proceed(
chain.request().newBuilder()
.header("Authorization", base64EncodedCredentials)
.build()
)
}
}
}
|