-
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.
* Added iPay88 wrapper
- Loading branch information
Showing
34 changed files
with
335 additions
and
185 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ allprojects { | |
repositories { | ||
google() | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
} | ||
|
||
|
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,6 +1,6 @@ | ||
ext { | ||
Versions = [ | ||
appCompat : "1.3.0", | ||
playServices: "17.6.0" | ||
appCompat: "1.3.0", | ||
iPay88Sdk : "1.0.0" | ||
] | ||
} |
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
Binary file not shown.
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,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> |
3 changes: 3 additions & 0 deletions
3
ipay88/src/main/java/io/primer/ipay88/api/exceptions/IPayConnectionErrorException.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,3 @@ | ||
package io.primer.ipay88.api.exceptions | ||
|
||
class IPayConnectionErrorException : IllegalStateException() |
3 changes: 3 additions & 0 deletions
3
ipay88/src/main/java/io/primer/ipay88/api/exceptions/IPayPaymentCancelledException.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,3 @@ | ||
package io.primer.ipay88.api.exceptions | ||
|
||
class IPayPaymentCancelledException : IllegalStateException() |
7 changes: 7 additions & 0 deletions
7
ipay88/src/main/java/io/primer/ipay88/api/exceptions/IPayPaymentFailedException.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,7 @@ | ||
package io.primer.ipay88.api.exceptions | ||
|
||
class IPayPaymentFailedException( | ||
val transactionId: String?, | ||
val refNo: String?, | ||
val errorDescription: String? | ||
) : IllegalStateException() |
19 changes: 19 additions & 0 deletions
19
ipay88/src/main/java/io/primer/ipay88/api/ui/IPay88LauncherParams.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,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
119
ipay88/src/main/java/io/primer/ipay88/api/ui/NativeIPay88Activity.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,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) | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
ipay88/src/main/java/io/primer/ipay88/internal/IPayStateHolder.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,6 @@ | ||
package io.primer.ipay88.internal | ||
|
||
internal object IPayStateHolder { | ||
|
||
var currentState: IPayPaymentState? = null | ||
} |
Oops, something went wrong.