Skip to content

Commit

Permalink
Merge pull request #62 from wilburt/dev
Browse files Browse the repository at this point in the history
Changes for v1.0.4
  • Loading branch information
Wilberforce Uwadiegwu committed Aug 23, 2020
2 parents e090ca4 + 2f13157 commit 815cb50
Show file tree
Hide file tree
Showing 31 changed files with 285 additions and 315 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.0.4
* Implemented support for V2 Android embedding
* Removed instances of deprecated Flutter APIs
* Updated dependencies
* Fixed issues #47 and #48
* Deprecated callbacks in the `chargeCard` function.


## 1.0.3+1
* Fixed issue with wrong plugin class in pubspec.yaml (#45)
* Added spaces to initial string for card number field
Expand Down
48 changes: 6 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,56 +97,20 @@ You can then create a `Charge` object with the access code and card details. The
expiryMonth: expiryMonth,
expiryYear: expiryYear,
);
// Using Cascade notation (similar to Java's builder pattern)
// return PaymentCard(
// number: cardNumber,
// cvc: cvv,
// expiryMonth: expiryMonth,
// expiryYear: expiryYear)
// ..name = 'Segun Chukwuma Adamu'
// ..country = 'Nigeria'
// ..addressLine1 = 'Ikeja, Lagos'
// ..addressPostalCode = '100001';
// Using optional parameters
// return PaymentCard(
// number: cardNumber,
// cvc: cvv,
// expiryMonth: expiryMonth,
// expiryYear: expiryYear,
// name: 'Ismail Adebola Emeka',
// addressCountry: 'Nigeria',
// addressLine1: '90, Nnebisi Road, Asaba, Deleta State');
}
_chargeCard(String accessCode) {
_chargeCard(String accessCode) async {
var charge = Charge()
..accessCode = accessCode
..card = _getCardFromUI();
PaystackPlugin.chargeCard(context,
charge: charge,
beforeValidate: (transaction) => handleBeforeValidate(transaction),
onSuccess: (transaction) => handleOnSuccess(transaction),
onError: (error, transaction) => handleOnError(error, transaction));
}
handleBeforeValidate(Transaction transaction) {
// This is called only before requesting OTP
// Save reference so you may send to server if error occurs with OTP
}
handleOnError(Object e, Transaction transaction) {
// If an access code has expired, simply ask your server for a new one
// and restart the charge instead of displaying error
}
handleOnSuccess(Transaction transaction) {
// This is called only after transaction is successful
final response = await PaystackPlugin.chargeCard(context, charge: charge);
// Use the response
}
```
The transaction is successful if `response.status` is true. Please, see the documentation
of [CheckoutResponse](https://pub.dev/documentation/flutter_paystack/latest/flutter_paystack/CheckoutResponse-class.html)
for more information.



Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'co.paystack.flutterpaystack'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down Expand Up @@ -44,5 +44,5 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'com.google.android.material:material:1.3.0-alpha02'
}
4 changes: 2 additions & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.paystack.flutterpaystack">
package="co.paystack.flutterpaystack">

<application>
<activity
android:name=".AuthActivity"
android:theme="@style/Paystack.Dialog"/>
android:theme="@style/Paystack.Dialog" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,54 +1,52 @@
package co.paystack.flutterpaystack

import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.provider.Settings
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar

class FlutterPaystackPlugin(val appContext: Context, val authDelegate: AuthDelegate) : MethodCallHandler {
companion object {
@JvmStatic
fun registerWith(registrar: Registrar) {
val activity = registrar.activity() ?: return
val channel = MethodChannel(registrar.messenger(), "flutter_paystack")
val authDelegate = AuthDelegate(activity = activity)
val plugin = FlutterPaystackPlugin(appContext = registrar.context(), authDelegate = authDelegate)
channel.setMethodCallHandler(plugin)
import android.app.Activity
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.PluginRegistry


class FlutterPaystackPlugin : FlutterPlugin, ActivityAware {

private var pluginBinding: FlutterPlugin.FlutterPluginBinding? = null
private var methodCallHandler: MethodCallHandlerImpl? = null

override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
pluginBinding = binding
}
}

@SuppressLint("HardwareIds")
override fun onMethodCall(call: MethodCall, result: Result) {

when (call.method) {
"getDeviceId" -> {
result.success("androidsdk_" + Settings.Secure.getString(appContext.contentResolver,
Settings.Secure.ANDROID_ID))
}
"getUserAgent" -> {
result.success("Android_" + Build.VERSION.SDK_INT + "_Paystack_" + BuildConfig.VERSION_NAME)
}

"getVersionCode" -> {
result.success(BuildConfig.VERSION_CODE.toString())
}

"getAuthorization" -> {
authDelegate.handleAuthorization(result, call)
}
"getEncryptedData" -> {
val encryptedData = Crypto.encrypt(call.argument<String>("stringData").toString())
result.success(encryptedData)
}

else -> result.notImplemented()

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
pluginBinding = null
}

}
private fun setupMethodHandler(messenger: BinaryMessenger?, activity: Activity) {
methodCallHandler = MethodCallHandlerImpl(messenger, activity)
}


override fun onDetachedFromActivity() {
methodCallHandler?.disposeHandler()
methodCallHandler = null
}


override fun onAttachedToActivity(binding: ActivityPluginBinding) {
setupMethodHandler(pluginBinding?.binaryMessenger, binding.activity)
}

override fun onDetachedFromActivityForConfigChanges() = onDetachedFromActivity()

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) = onAttachedToActivity(binding)

companion object {

@JvmStatic
fun registerWith(registrar: PluginRegistry.Registrar) {
val plugin = FlutterPaystackPlugin()
plugin.setupMethodHandler(registrar.messenger(), registrar.activity())
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package co.paystack.flutterpaystack

import android.annotation.SuppressLint
import android.app.Activity
import android.os.Build
import android.provider.Settings
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler

class MethodCallHandlerImpl(messenger: BinaryMessenger?, private val activity: Activity?) : MethodCallHandler {
private var channel: MethodChannel? = null
private var authDelegate: AuthDelegate? = null

init {
activity!!.let {
authDelegate = AuthDelegate(it)
channel = MethodChannel(messenger, channelName)
channel?.setMethodCallHandler(this)
}
}

@SuppressLint("HardwareIds")
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
when (call.method) {
"getDeviceId" -> {
val deviceId = Settings.Secure.getString(activity?.contentResolver, Settings.Secure.ANDROID_ID)
result.success("androidsdk_$deviceId")
}
"getUserAgent" -> {
result.success("Android_" + Build.VERSION.SDK_INT + "_Paystack_" + BuildConfig.VERSION_NAME)
}

"getVersionCode" -> {
result.success(BuildConfig.VERSION_CODE.toString())
}

"getAuthorization" -> {
authDelegate?.handleAuthorization(result, call)
}
"getEncryptedData" -> {
val encryptedData = Crypto.encrypt(call.argument<String>("stringData").toString())
result.success(encryptedData)
}

else -> result.notImplemented()
}
}

fun disposeHandler() {
channel?.setMethodCallHandler(null)
channel = null
}
}

private const val channelName = "plugins.wilburt/flutter_paystack"
5 changes: 1 addition & 4 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ android {
defaultConfig {
applicationId "co.paystack.flutterpaystack"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -48,7 +48,4 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
18 changes: 11 additions & 7 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
Expand All @@ -14,14 +14,14 @@
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Flutter Paystack"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:label="Flutter Paystack">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
Expand All @@ -31,9 +31,13 @@
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package co.paystack.flutterpaystackexample

import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity

import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity(): FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
}
}
class MainActivity: FlutterActivity()
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
4 changes: 2 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Oct 25 11:04:03 WAT 2018
#Fri Aug 21 21:56:56 WAT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
1 change: 1 addition & 0 deletions example/ios/Flutter/.last_build_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
85f89a72efc4102d6ce4c0a159895eef
Loading

0 comments on commit 815cb50

Please sign in to comment.