-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PaymentService implementation and related support classes
- Loading branch information
Eric M. Lee
committed
Jul 27, 2017
1 parent
c714c98
commit 19b5c96
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/deliveryhero/android/braintreesample/feature/payment/RetrieveToken.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.deliveryhero.android.braintreesample.feature.payment | ||
|
||
import com.deliveryhero.android.braintreesample.model.ClientToken | ||
import io.reactivex.Single | ||
|
||
interface RetrieveToken { | ||
|
||
operator fun invoke(): Single<ClientToken> | ||
} |
8 changes: 8 additions & 0 deletions
8
...c/main/java/com/deliveryhero/android/braintreesample/feature/payment/RetrieveTokenImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.deliveryhero.android.braintreesample.feature.payment | ||
|
||
import com.deliveryhero.android.braintreesample.BraintreeSampleApplication.Companion.paymentService | ||
|
||
class RetrieveTokenImpl : RetrieveToken { | ||
|
||
override operator fun invoke() = paymentService.getClientToken(null, null) | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/deliveryhero/android/braintreesample/model/PaymentModels.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.deliveryhero.android.braintreesample.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class ClientToken(@SerializedName("client_token") val value: String = "") |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/deliveryhero/android/braintreesample/service/PaymentService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.deliveryhero.android.braintreesample.service | ||
|
||
import com.deliveryhero.android.braintreesample.model.ClientToken | ||
import io.reactivex.Single | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface PaymentService { | ||
|
||
@GET("/client_token") | ||
fun getClientToken(@Query("customer_id") customerId: String?, | ||
@Query("merchant_account_id") merchantAccountId: String?) | ||
: Single<ClientToken> | ||
} | ||
|
||
object ApiClientRequestInterceptor : Interceptor { | ||
|
||
override fun intercept(chain: Interceptor.Chain): Response { | ||
val request = chain.request() | ||
.newBuilder() | ||
.addHeader("User-Agent", "braintree/android-demo-app/2.5.5-SNAPSHOT") | ||
.addHeader("Accept", "application/json") | ||
.build() | ||
return chain.proceed(request) | ||
} | ||
} |