-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address verification for authentication for international cards
* WIP: Address Verification card authentication - Launch verification form when authentication type required is `avs` Signed-off-by: Michael obi <[email protected]> * WIP: AVS - Set test USD card Signed-off-by: Michael obi <[email protected]> * WIP: Address verification system - Submit address to complete charge authentication Signed-off-by: Michael obi <[email protected]> * Complete charge with AVS Signed-off-by: Michael obi <[email protected]> * Remove test helper code some sample app Signed-off-by: Michael obi <[email protected]> * Move mavenCentral repository declaration to project level Signed-off-by: Michael obi <[email protected]> * Bump version code to 18 Signed-off-by: Michael obi <[email protected]> * Revert BASE_URL to https://standard.paystack.co/ Signed-off-by: Michael obi <[email protected]> * Fix issue where PIN responses caused a crash due to absence of `auth` property Signed-off-by: Michael obi <[email protected]> * Handle AVS errors Signed-off-by: Michael obi <[email protected]>
- Loading branch information
1 parent
ecb830c
commit 88b0263
Showing
15 changed files
with
560 additions
and
9 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
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
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 |
---|---|---|
@@ -1,20 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="co.paystack.android"> | ||
package="co.paystack.android"> | ||
|
||
<application> | ||
<activity | ||
android:name=".ui.PinActivity" | ||
android:theme="@style/Paystack.Dialog.PinEntry"/> | ||
android:theme="@style/Paystack.Dialog.PinEntry" /> | ||
<activity | ||
android:name=".ui.OtpActivity" | ||
android:theme="@style/Paystack.Dialog.OtpEntry" /> | ||
<activity | ||
android:name=".ui.AuthActivity" | ||
android:theme="@style/Paystack.Dialog.OtpEntry"/> | ||
android:theme="@style/Paystack.Dialog.OtpEntry" /> | ||
<activity | ||
android:name=".ui.CardActivity" | ||
android:theme="@style/Paystack.Dialog.CardEntry"/> | ||
android:theme="@style/Paystack.Dialog.CardEntry" /> | ||
<activity | ||
android:name=".ui.AddressVerificationActivity" | ||
android:theme="@style/Paystack.Dialog" /> | ||
</application> | ||
|
||
</manifest> |
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
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
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
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
58 changes: 58 additions & 0 deletions
58
paystack/src/main/java/co/paystack/android/api/service/PaystackApiFactory.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,58 @@ | ||
package co.paystack.android.mobilemoney.data.api | ||
|
||
import android.os.Build | ||
import co.paystack.android.BuildConfig | ||
import co.paystack.android.api.service.PaystackApiService | ||
import co.paystack.android.api.service.converter.WrappedResponseConverter | ||
import co.paystack.android.api.utils.TLSSocketFactory | ||
import com.google.gson.GsonBuilder | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import java.security.KeyManagementException | ||
import java.security.KeyStoreException | ||
import java.security.NoSuchAlgorithmException | ||
import java.util.concurrent.TimeUnit | ||
|
||
/* | ||
* Generates an API client for new paystack API (https://api.paystack.co) | ||
* */ | ||
internal object PaystackApiFactory { | ||
private const val BASE_URL = "https://api.paystack.co/" | ||
|
||
@Throws(NoSuchAlgorithmException::class, KeyManagementException::class, KeyStoreException::class) | ||
fun createRetrofitService(): PaystackApiService { | ||
val gson = GsonBuilder() | ||
.setDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'") | ||
.create() | ||
|
||
val tlsV1point2factory = TLSSocketFactory() | ||
val okHttpClient = OkHttpClient.Builder() | ||
.addInterceptor { chain -> | ||
val original = chain.request() | ||
// Add headers so we get Android version and Paystack Library version | ||
val builder = original.newBuilder() | ||
.header("User-Agent", "Android_" + Build.VERSION.SDK_INT + "_Paystack_" + BuildConfig.VERSION_NAME) | ||
.header("X-Paystack-Build", BuildConfig.VERSION_CODE.toString()) | ||
.header("Accept", "application/json") | ||
.method(original.method(), original.body()) | ||
val request = builder.build() | ||
chain.proceed(request) | ||
} | ||
.sslSocketFactory(tlsV1point2factory, tlsV1point2factory.x509TrustManager) | ||
.connectTimeout(1, TimeUnit.MINUTES) | ||
.readTimeout(1, TimeUnit.MINUTES) | ||
.writeTimeout(1, TimeUnit.MINUTES) | ||
.build() | ||
|
||
val retrofit = Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(okHttpClient) | ||
.addConverterFactory(WrappedResponseConverter.Factory()) | ||
.addConverterFactory(GsonConverterFactory.create(gson)) | ||
.build() | ||
|
||
return retrofit.create(PaystackApiService::class.java) | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
paystack/src/main/java/co/paystack/android/api/service/PaystackApiService.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,10 @@ | ||
package co.paystack.android.api.service | ||
|
||
import co.paystack.android.model.AvsState | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
internal interface PaystackApiService { | ||
@GET("/address_verification/states") | ||
suspend fun getAddressVerificationStates(@Query("country") countryCode: String): List<AvsState> | ||
} |
49 changes: 49 additions & 0 deletions
49
paystack/src/main/java/co/paystack/android/api/service/converter/WrappedResponseConverter.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,49 @@ | ||
package co.paystack.android.api.service.converter | ||
|
||
import okhttp3.ResponseBody | ||
import retrofit2.Converter | ||
import retrofit2.Retrofit | ||
import java.lang.reflect.ParameterizedType | ||
import java.lang.reflect.Type | ||
|
||
class WrappedResponseConverter<T>( | ||
private val delegate: Converter<ResponseBody, WrappedResponse<T>> | ||
) : Converter<ResponseBody, T> { | ||
override fun convert(value: ResponseBody): T? { | ||
val response = delegate.convert(value) | ||
return response?.data | ||
} | ||
|
||
|
||
class Factory : Converter.Factory() { | ||
override fun responseBodyConverter( | ||
type: Type, | ||
annotations: Array<Annotation>, | ||
retrofit: Retrofit | ||
): Converter<ResponseBody, *>? { | ||
val wrappedType: Type = object : ParameterizedType { | ||
override fun getRawType(): Type { | ||
return WrappedResponse::class.java | ||
} | ||
|
||
override fun getOwnerType(): Type? { | ||
return null | ||
} | ||
|
||
override fun getActualTypeArguments(): Array<Type> { | ||
return arrayOf(type) | ||
} | ||
} | ||
|
||
val delegate = retrofit.nextResponseBodyConverter<WrappedResponse<Any>>(this, wrappedType, annotations) | ||
return WrappedResponseConverter(delegate) | ||
|
||
} | ||
} | ||
|
||
open class WrappedResponse<T>( | ||
val `data`: T, | ||
val message: String, | ||
val status: Boolean | ||
) | ||
} |
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,7 @@ | ||
package co.paystack.android.model | ||
|
||
data class AvsState( | ||
val name: String, | ||
val slug: String, | ||
val abbreviation: String | ||
) |
Oops, something went wrong.