Skip to content

Commit 815cb50

Browse files
author
Wilberforce Uwadiegwu
authored
Merge pull request #62 from wilburt/dev
Changes for v1.0.4
2 parents e090ca4 + 2f13157 commit 815cb50

File tree

31 files changed

+285
-315
lines changed

31 files changed

+285
-315
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 1.0.4
2+
* Implemented support for V2 Android embedding
3+
* Removed instances of deprecated Flutter APIs
4+
* Updated dependencies
5+
* Fixed issues #47 and #48
6+
* Deprecated callbacks in the `chargeCard` function.
7+
8+
19
## 1.0.3+1
210
* Fixed issue with wrong plugin class in pubspec.yaml (#45)
311
* Added spaces to initial string for card number field

README.md

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -97,56 +97,20 @@ You can then create a `Charge` object with the access code and card details. The
9797
expiryMonth: expiryMonth,
9898
expiryYear: expiryYear,
9999
);
100-
101-
// Using Cascade notation (similar to Java's builder pattern)
102-
// return PaymentCard(
103-
// number: cardNumber,
104-
// cvc: cvv,
105-
// expiryMonth: expiryMonth,
106-
// expiryYear: expiryYear)
107-
// ..name = 'Segun Chukwuma Adamu'
108-
// ..country = 'Nigeria'
109-
// ..addressLine1 = 'Ikeja, Lagos'
110-
// ..addressPostalCode = '100001';
111-
112-
// Using optional parameters
113-
// return PaymentCard(
114-
// number: cardNumber,
115-
// cvc: cvv,
116-
// expiryMonth: expiryMonth,
117-
// expiryYear: expiryYear,
118-
// name: 'Ismail Adebola Emeka',
119-
// addressCountry: 'Nigeria',
120-
// addressLine1: '90, Nnebisi Road, Asaba, Deleta State');
121100
}
122101
123-
_chargeCard(String accessCode) {
102+
_chargeCard(String accessCode) async {
124103
var charge = Charge()
125104
..accessCode = accessCode
126105
..card = _getCardFromUI();
127106
128-
PaystackPlugin.chargeCard(context,
129-
charge: charge,
130-
beforeValidate: (transaction) => handleBeforeValidate(transaction),
131-
onSuccess: (transaction) => handleOnSuccess(transaction),
132-
onError: (error, transaction) => handleOnError(error, transaction));
133-
}
134-
135-
handleBeforeValidate(Transaction transaction) {
136-
// This is called only before requesting OTP
137-
// Save reference so you may send to server if error occurs with OTP
138-
}
139-
140-
handleOnError(Object e, Transaction transaction) {
141-
// If an access code has expired, simply ask your server for a new one
142-
// and restart the charge instead of displaying error
143-
}
144-
145-
146-
handleOnSuccess(Transaction transaction) {
147-
// This is called only after transaction is successful
107+
final response = await PaystackPlugin.chargeCard(context, charge: charge);
108+
// Use the response
148109
}
149110
```
111+
The transaction is successful if `response.status` is true. Please, see the documentation
112+
of [CheckoutResponse](https://pub.dev/documentation/flutter_paystack/latest/flutter_paystack/CheckoutResponse-class.html)
113+
for more information.
150114

151115

152116

android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ group 'co.paystack.flutterpaystack'
22
version '1.0-SNAPSHOT'
33

44
buildscript {
5-
ext.kotlin_version = '1.3.61'
5+
ext.kotlin_version = '1.3.72'
66
repositories {
77
google()
88
jcenter()
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:3.5.3'
12+
classpath 'com.android.tools.build:gradle:4.0.1'
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414
}
1515
}
@@ -44,5 +44,5 @@ android {
4444

4545
dependencies {
4646
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
47-
implementation 'com.google.android.material:material:1.2.0-alpha03'
47+
implementation 'com.google.android.material:material:1.3.0-alpha02'
4848
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="co.paystack.flutterpaystack">
2+
package="co.paystack.flutterpaystack">
33

44
<application>
55
<activity
66
android:name=".AuthActivity"
7-
android:theme="@style/Paystack.Dialog"/>
7+
android:theme="@style/Paystack.Dialog" />
88
</application>
99
</manifest>
Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
11
package co.paystack.flutterpaystack
22

3-
import android.annotation.SuppressLint
4-
import android.content.Context
5-
import android.os.Build
6-
import android.provider.Settings
7-
import io.flutter.plugin.common.MethodCall
8-
import io.flutter.plugin.common.MethodChannel
9-
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
10-
import io.flutter.plugin.common.MethodChannel.Result
11-
import io.flutter.plugin.common.PluginRegistry.Registrar
12-
13-
class FlutterPaystackPlugin(val appContext: Context, val authDelegate: AuthDelegate) : MethodCallHandler {
14-
companion object {
15-
@JvmStatic
16-
fun registerWith(registrar: Registrar) {
17-
val activity = registrar.activity() ?: return
18-
val channel = MethodChannel(registrar.messenger(), "flutter_paystack")
19-
val authDelegate = AuthDelegate(activity = activity)
20-
val plugin = FlutterPaystackPlugin(appContext = registrar.context(), authDelegate = authDelegate)
21-
channel.setMethodCallHandler(plugin)
3+
import android.app.Activity
4+
import io.flutter.embedding.engine.plugins.FlutterPlugin
5+
import io.flutter.embedding.engine.plugins.activity.ActivityAware
6+
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
7+
import io.flutter.plugin.common.BinaryMessenger
8+
import io.flutter.plugin.common.PluginRegistry
9+
10+
11+
class FlutterPaystackPlugin : FlutterPlugin, ActivityAware {
12+
13+
private var pluginBinding: FlutterPlugin.FlutterPluginBinding? = null
14+
private var methodCallHandler: MethodCallHandlerImpl? = null
15+
16+
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
17+
pluginBinding = binding
2218
}
23-
}
24-
25-
@SuppressLint("HardwareIds")
26-
override fun onMethodCall(call: MethodCall, result: Result) {
27-
28-
when (call.method) {
29-
"getDeviceId" -> {
30-
result.success("androidsdk_" + Settings.Secure.getString(appContext.contentResolver,
31-
Settings.Secure.ANDROID_ID))
32-
}
33-
"getUserAgent" -> {
34-
result.success("Android_" + Build.VERSION.SDK_INT + "_Paystack_" + BuildConfig.VERSION_NAME)
35-
}
36-
37-
"getVersionCode" -> {
38-
result.success(BuildConfig.VERSION_CODE.toString())
39-
}
40-
41-
"getAuthorization" -> {
42-
authDelegate.handleAuthorization(result, call)
43-
}
44-
"getEncryptedData" -> {
45-
val encryptedData = Crypto.encrypt(call.argument<String>("stringData").toString())
46-
result.success(encryptedData)
47-
}
48-
49-
else -> result.notImplemented()
19+
20+
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
21+
pluginBinding = null
5022
}
5123

52-
}
24+
private fun setupMethodHandler(messenger: BinaryMessenger?, activity: Activity) {
25+
methodCallHandler = MethodCallHandlerImpl(messenger, activity)
26+
}
27+
28+
29+
override fun onDetachedFromActivity() {
30+
methodCallHandler?.disposeHandler()
31+
methodCallHandler = null
32+
}
33+
34+
35+
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
36+
setupMethodHandler(pluginBinding?.binaryMessenger, binding.activity)
37+
}
38+
39+
override fun onDetachedFromActivityForConfigChanges() = onDetachedFromActivity()
40+
41+
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) = onAttachedToActivity(binding)
42+
43+
companion object {
44+
45+
@JvmStatic
46+
fun registerWith(registrar: PluginRegistry.Registrar) {
47+
val plugin = FlutterPaystackPlugin()
48+
plugin.setupMethodHandler(registrar.messenger(), registrar.activity())
49+
}
50+
}
5351

5452
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package co.paystack.flutterpaystack
2+
3+
import android.annotation.SuppressLint
4+
import android.app.Activity
5+
import android.os.Build
6+
import android.provider.Settings
7+
import io.flutter.plugin.common.BinaryMessenger
8+
import io.flutter.plugin.common.MethodCall
9+
import io.flutter.plugin.common.MethodChannel
10+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
11+
12+
class MethodCallHandlerImpl(messenger: BinaryMessenger?, private val activity: Activity?) : MethodCallHandler {
13+
private var channel: MethodChannel? = null
14+
private var authDelegate: AuthDelegate? = null
15+
16+
init {
17+
activity!!.let {
18+
authDelegate = AuthDelegate(it)
19+
channel = MethodChannel(messenger, channelName)
20+
channel?.setMethodCallHandler(this)
21+
}
22+
}
23+
24+
@SuppressLint("HardwareIds")
25+
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
26+
when (call.method) {
27+
"getDeviceId" -> {
28+
val deviceId = Settings.Secure.getString(activity?.contentResolver, Settings.Secure.ANDROID_ID)
29+
result.success("androidsdk_$deviceId")
30+
}
31+
"getUserAgent" -> {
32+
result.success("Android_" + Build.VERSION.SDK_INT + "_Paystack_" + BuildConfig.VERSION_NAME)
33+
}
34+
35+
"getVersionCode" -> {
36+
result.success(BuildConfig.VERSION_CODE.toString())
37+
}
38+
39+
"getAuthorization" -> {
40+
authDelegate?.handleAuthorization(result, call)
41+
}
42+
"getEncryptedData" -> {
43+
val encryptedData = Crypto.encrypt(call.argument<String>("stringData").toString())
44+
result.success(encryptedData)
45+
}
46+
47+
else -> result.notImplemented()
48+
}
49+
}
50+
51+
fun disposeHandler() {
52+
channel?.setMethodCallHandler(null)
53+
channel = null
54+
}
55+
}
56+
57+
private const val channelName = "plugins.wilburt/flutter_paystack"

example/android/app/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ android {
2929
defaultConfig {
3030
applicationId "co.paystack.flutterpaystack"
3131
minSdkVersion 16
32-
targetSdkVersion 28
32+
targetSdkVersion 29
3333
versionCode 1
3434
versionName "1.0"
3535
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -48,7 +48,4 @@ flutter {
4848

4949
dependencies {
5050
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
51-
testImplementation 'junit:junit:4.12'
52-
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
53-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
5451
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
flutter needs it to communicate with the running application
66
to allow setting breakpoints, to provide hot reload, etc.
77
-->
8-
<uses-permission android:name="android.permission.INTERNET"/>
8+
<uses-permission android:name="android.permission.INTERNET" />
99

1010
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
1111
calls FlutterMain.startInitialization(this); in its onCreate method.
@@ -14,14 +14,14 @@
1414
FlutterApplication and put your custom class here. -->
1515
<application
1616
android:name="io.flutter.app.FlutterApplication"
17-
android:label="Flutter Paystack"
18-
android:icon="@mipmap/ic_launcher">
17+
android:icon="@mipmap/ic_launcher"
18+
android:label="Flutter Paystack">
1919
<activity
2020
android:name=".MainActivity"
21-
android:launchMode="singleTop"
22-
android:theme="@style/LaunchTheme"
2321
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
2422
android:hardwareAccelerated="true"
23+
android:launchMode="singleTop"
24+
android:theme="@style/LaunchTheme"
2525
android:windowSoftInputMode="adjustResize">
2626
<!-- This keeps the window background of the activity showing
2727
until Flutter renders its first frame. It can be removed if
@@ -31,9 +31,13 @@
3131
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
3232
android:value="true" />
3333
<intent-filter>
34-
<action android:name="android.intent.action.MAIN"/>
35-
<category android:name="android.intent.category.LAUNCHER"/>
34+
<action android:name="android.intent.action.MAIN" />
35+
<category android:name="android.intent.category.LAUNCHER" />
3636
</intent-filter>
3737
</activity>
38+
39+
<meta-data
40+
android:name="flutterEmbedding"
41+
android:value="2" />
3842
</application>
3943
</manifest>
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
package co.paystack.flutterpaystackexample
22

3-
import android.os.Bundle
3+
import io.flutter.embedding.android.FlutterActivity
44

5-
import io.flutter.app.FlutterActivity
6-
import io.flutter.plugins.GeneratedPluginRegistrant
75

8-
class MainActivity(): FlutterActivity() {
9-
override fun onCreate(savedInstanceState: Bundle?) {
10-
super.onCreate(savedInstanceState)
11-
GeneratedPluginRegistrant.registerWith(this)
12-
}
13-
}
6+
class MainActivity: FlutterActivity()

example/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
buildscript {
2-
ext.kotlin_version = '1.3.61'
2+
ext.kotlin_version = '1.3.72'
33
repositories {
44
google()
55
jcenter()
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.5.3'
9+
classpath 'com.android.tools.build:gradle:4.0.1'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
}
1212
}

0 commit comments

Comments
 (0)