Skip to content

Commit

Permalink
Added iPay88 wrapper (#1)
Browse files Browse the repository at this point in the history
* Added iPay88 wrapper
  • Loading branch information
semirp authored Dec 21, 2022
1 parent 8d27831 commit eeee815
Show file tree
Hide file tree
Showing 34 changed files with 335 additions and 185 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea
/.idea/assetWizardSettings.xml
.DS_Store
/build
Expand Down
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions .idea/jarRepositories.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/misc.xml

This file was deleted.

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
}
}

Expand Down
4 changes: 3 additions & 1 deletion config/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ ext {
Dependencies = [
Android: [
appCompat: "androidx.appcompat:appcompat:${Versions.appCompat}",
playServicesBase: "com.google.android.gms:play-services-base:${Versions.playServices}"
],
iPay88 : [
iPay88: "io.primer:ipay88:${Versions.iPay88Sdk}",
],
]
}
4 changes: 2 additions & 2 deletions config/versions.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ext {
Versions = [
appCompat : "1.3.0",
playServices: "17.6.0"
appCompat: "1.3.0",
iPay88Sdk : "1.0.0"
]
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ kotlin.code.style=official
# Publishing values (see publish.gradle)
GROUP=io.primer
POM_ARTIFACT_ID=ipay88-android
VERSION_NAME=0.0.1
POM_NAME=ipay88
VERSION_NAME=1.0.0
POM_NAME=ipay88-android
POM_DESCRIPTION=Primer wrapper for iPay88 SDK for Android
POM_INCEPTION_YEAR=2022
POM_URL=https://github.com/primer-io/primer-ipay88-sdk-android
Expand Down
10 changes: 6 additions & 4 deletions ipay88/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {

buildTypes {
release {
minifyEnabled false
minifyEnabled true
consumerProguardFiles 'consumer-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
Expand All @@ -31,14 +31,16 @@ android {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/java'
}

buildTypes.each {
it.buildConfigField 'String', 'SDK_VERSION_STRING', "\"$VERSION_NAME\""
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation Dependencies.Android.appCompat
implementation Dependencies.Android.playServicesBase
implementation Dependencies.iPay88.iPay88
}
Binary file removed ipay88/libs/classes.jar
Binary file not shown.
33 changes: 33 additions & 0 deletions ipay88/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,36 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-dontusemixedcaseclassnames
-repackageclasses 'io.primer.ipay88.internal'
-allowaccessmodification
-renamesourcefileattribute SourceFile
-keepattributes Signature,Exceptions,*Annotation*,
InnerClasses,PermittedSubclasses,EnclosingMethod,
Deprecated,SourceFile,LineNumberTable

# keep class BuildConfig
-keep public class **.BuildConfig { *; }

-keep class io.primer.ipay88.api.** {
public *;
}

-keep class io.primer.ipay88.api.ui.NativeIPay88Activity {
public protected static <methods>;
*** Companion;
}

-keep class io.primer.ipay88.api.ui.NativeIPay88Activity$Companion {
*;
}

-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
23 changes: 22 additions & 1 deletion ipay88/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.primer.android.ipay88">
xmlns:tools="http://schemas.android.com/tools"
package="io.primer.ipay88">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<application>
<activity
android:name="io.primer.ipay88.api.ui.NativeIPay88Activity"
android:exported="false"
android:label=""
android:launchMode="singleTop"
android:theme="@style/Theme.AppCompat.NoActionBar.FullScreen.IPay" />

<activity
android:name="com.ipay.IPayIHActivity"
android:configChanges="orientation|screenSize"
android:exported="false"
tools:ignore="AppLinkUrlError" />

<activity
android:name="com.ipay.IPayIHAcitivityR"
android:configChanges="orientation|screenSize" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.primer.ipay88.api.exceptions

class IPayConnectionErrorException : IllegalStateException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.primer.ipay88.api.exceptions

class IPayPaymentCancelledException : IllegalStateException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.primer.ipay88.api.exceptions

class IPayPaymentFailedException(
val transactionId: String?,
val refNo: String?,
val errorDescription: String?
) : IllegalStateException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.primer.ipay88.api.ui

import java.io.Serializable

data class IPay88LauncherParams(
val iPayPaymentId: String,
val iPayMethod: Int,
val merchantCode: String,
val amount: String,
val referenceNumber: String,
val prodDesc: String,
val currencyCode: String?,
val countryCode: String?,
val customerName: String?,
val customerEmail: String?,
val backendCallbackUrl: String,
val deeplinkUrl: String,
val errorCode: Int
) : Serializable
119 changes: 119 additions & 0 deletions ipay88/src/main/java/io/primer/ipay88/api/ui/NativeIPay88Activity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package io.primer.ipay88.api.ui

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import com.ipay.IPayIH
import io.primer.ipay88.api.exceptions.IPayConnectionErrorException
import io.primer.ipay88.api.exceptions.IPayPaymentCancelledException
import io.primer.ipay88.api.exceptions.IPayPaymentFailedException
import io.primer.ipay88.internal.IPayPaymentState
import io.primer.ipay88.internal.IPayStateHolder
import io.primer.ipay88.internal.PrimerIPay88Delegate
import io.primer.ipay88.internal.extension.toIPayIHPayment
import io.primer.ipay88.internal.extension.toIPayIHR

class NativeIPay88Activity : AppCompatActivity() {

private val iPayIH by lazy { IPayIH.getInstance() }

private val launcherIntent = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { activityResult ->
when (activityResult.resultCode) {
RESULT_CANCELED -> {
setCancelledResult(IPayPaymentCancelledException())
finish()
}
RESULT_OK -> {
when (val state = IPayStateHolder.currentState) {
is IPayPaymentState.Cancelled -> {
setCancelledResult(IPayPaymentCancelledException())
finish()
}
is IPayPaymentState.ConnectionError -> {
setErrorResult(IPayConnectionErrorException())
finish()
}
is IPayPaymentState.Failed -> {
setErrorResult(
IPayPaymentFailedException(
state.transId,
state.refNo,
state.errorDescription
)
)
finish()
}
is IPayPaymentState.ReQuery -> {
reQuery(
intent.getSerializableExtra(INTENT_PARAMS_EXTRA_KEY) as IPay88LauncherParams
)
}
is IPayPaymentState.Success -> {
setResult(RESULT_OK)
finish()
}
else -> {
setErrorResult(IllegalStateException())
finish()
}
}
}
else -> finish()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
startCheckout(getLauncherParams())
}
}

private fun startCheckout(params: IPay88LauncherParams) {
launcherIntent.launch(
iPayIH.checkout(
params.toIPayIHPayment(),
this,
PrimerIPay88Delegate(),
params.iPayMethod
)
)
}

private fun reQuery(params: IPay88LauncherParams) {
launcherIntent.launch(
iPayIH.requery(
params.toIPayIHR(),
this,
PrimerIPay88Delegate(),
)
)
}

private fun setErrorResult(exception: IllegalStateException) {
val errorCode = getLauncherParams().errorCode
setResult(errorCode, Intent().apply { putExtra(ERROR_KEY, exception) })
}

private fun setCancelledResult(exception: IllegalStateException) {
setResult(RESULT_CANCELED, Intent().apply { putExtra(ERROR_KEY, exception) })
}

private fun getLauncherParams() =
intent.getSerializableExtra(INTENT_PARAMS_EXTRA_KEY) as IPay88LauncherParams

companion object {

private const val INTENT_PARAMS_EXTRA_KEY = "INTENT_PARAMS_EXTRA"
const val ERROR_KEY = "ERROR"

fun getLaunchIntent(context: Context, params: IPay88LauncherParams) =
Intent(context, NativeIPay88Activity::class.java).apply {
putExtra(INTENT_PARAMS_EXTRA_KEY, params)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.primer.ipay88.internal

internal object IPayStateHolder {

var currentState: IPayPaymentState? = null
}
Loading

0 comments on commit eeee815

Please sign in to comment.