Paytabs payment integration using dart, flutter web and api - api

I have a flutter web project and I was trying to implement a payment solution. I found out that paytabs is a good choice for my situation. I wanted to add their api but I kept getting the CORS erorr over my flutter website. So I tried their ready payment page but I am also unable to implement since I have no previous knowledge about web development. I only use dart and flutter. But I would like to implement the api since it gives higher control. This is the url used for post requests https://www.paytabs.com/apiv2/create_pay_page Using the http package I always have the CORS appearing as an error. Documentation for the paytab service: https://dev.paytabs.com/docs/paypage/ Hope you can help

There are not payment plugins available for flutter.
but we can integrate PayTabs by using flutter platform channel.
step 1-> Create the Flutter platform client final Map result = await methodChannel.invokeMethod('getPayTabs');
Exemple :`
Future<void> _getPayTabs() async {
String batteryLevel;
try {
debugPrint("this is dart getPayTabs");
final Map result = await methodChannel.invokeMethod('getPayTabs');
debugPrint("trasiction data $result");
} on PlatformException {
debugPrint("trasiction data Failed");
}
step 2-> Importing the SDK android project
In Android Studio, Right click on the app choose New > Module
Choose the Downloaded paytabs_sdk-v4.0.1.aar. If not, download here
Right click on your App and choose Open Module Settings
Add the Module dependency
Choose the: paytabs_sdk-v4.0.1 module to be included
Confirm the Module import by changing the Android view to Project view in the sidebar
Add below dependencies.
You can start with code changes.
You have to include the following dependencies:
allprojects {
repositories {
...
maven {
url 'https://jitpack.io'
}
}
}
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.github.dbachelder:CreditCardEntry:1.4.9'
step 3-> Add an Android platform-specific implementation
Start by opening the Android host portion of your Flutter app in Android Studio:
Open the file MainActivity.kt located in the kotlin folder in the Project view. (Note: If editing with Android Studio 2.3, note that the kotlin folder is shown as if named java.)
Inside the configureFlutterEngine() method, create a MethodChannel and call setMethodCallHandler(). Make sure to use the same channel name as was used on the Flutter client side.
You need to override your Activity’s onActivityResult

Related

Cannot find name 'SFAuthSession'

I am new to ionic and cordova plugins and I'm trying to implement the sharing of cookies using the cordova-plugin-sfauthenticationsession in my ionic app.
Here is my code based on the documentation provided in this link:
SFAuthSession.start("myScheme://","https://www.facebook.com/",
function(data){
console.log(data);
},function(error){
console.log(error);
}
);
The problem is whenever I try to build my app, the terminal shows an error that it cannot find SFAuthSession. I don't have any idea what I need to import (if any) since it is not included in the documentation. Hope somebody can help me with this.
P.S.
I also tried the safari view controller following this documentation and it is working fine since it provides what is to be imported.
This is a common error. The docs tell you how to install that specific plugin but they don't tell you that you also need to update your module file to include it.
Look at this page:
Ionic Native Community Edition - Ionic Documentation
It explains that you need to import the plugin in a #NgModule and add it to the list of Providers. For Angular, the import path should end with /ngx. Angular's change detection is automatically handled.
To do this you do:
// app.module.ts
import { Camera } from '#ionic-native/camera/ngx';
...
#NgModule({
...
providers: [
...
Camera
...
]
...
})
export class AppModule { }
So just import your Ionic Native module using that technique and you it should work.
When there is no Ionic Native wrapper
However, based on your comments below it is now clear that there isn't an Ionic Native wrapper for this Cordova plugin.
This means that you will have to either:
Access it without Ionic Native
OR write your own Ionic Native wrapper
It seems like this article on Medium has a great introduction to this:
Build your first Cordova plugin for Ionic Native – Sangkhim Khun – Medium
You have passed beyond my personal experience here but I'm trying to figure it out with you.
Part three of the tutorial has an interesting snippet for accessing a Cordova plugin directly:
declare var cordova: any;
var success = function(result) {
alert(JSON.stringify(result, undefined, 2));
}
var failure = function(result) {
alert(JSON.stringify(result, undefined, 2));
}
cordova.plugins.HelloWorld.coolMethod({
_sMessage: "Hello World"
}, success, failure);
You would have to compare the documentation of your Cordova plugin to adapt this yourself to get it working.
Alternatively, if you continue reading that tutorial it explains how to create an Ionic Native wrapper which you could even contribute back to the project so that everyone can use this feature.

Instant app with multivariant base module

I've started to implement instant app feature in my application. I managed to transition to base module and properly build an installable app. The base module has 3 build types:
buildTypes {
release {...}
acceptance {...}
debug {...}
When I try to build instant app as a separate module that has build.gradle file:
apply plugin: 'com.android.instantapp'
dependencies {
implementation project(':base')
}
I'm getting below error message:
Cannot choose between the following variants of project :app:
- inchargeAcceptanceBundleElements
- inchargeAcceptanceRuntime
- inchargeAcceptanceUnitTestCompile
...
(much much longer I can give full stacktrace if needed)
I tried to change instantapp/build.gradle:
implementation project(path: ':base', configuration: 'default')
but then I get:
Unable to resolve dependency for ':instantapp#debug/compileClasspath': Failed to transform file 'base-release.aar' to match attributes {artifactType=processed-aar} using transform IdentityTransform
Then the app module itself has 4 product flavors but it shouldn't matter I believe.
Any advice how to run instantapp module ?

IBM Mobilefirst V8 - Custom Direct update on hybrid application using Ionic v3.20.0 is not happening

I am trying to implement customized direct update in ionic v3.20.0 but while accessing to the below code, am unable to proceed. I can't find any way to do it as the below function is not there in worklight.d.ts file,but can be found at worklight.js file.
The plugin used is cordova-plugin-mfp. The solution provided in the official doc is relevant to only cordova application,that can be done through index.js file which has the function WlCommonInit(). As per the doc the below code is to be called from this function, but unable to do this in ionic-cordova based application.
wl_DirectUpdateChallengeHandler.handleDirectUpdate = function(directUpdateData, directUpdateContext) {
// Implement custom Direct Update logic
};
Pleas refer to the below link for further information.
https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/application-development/direct-update/
Please help me to implement this in ionic v3.20.0 which need to be implemented in typescript. Thanks!.
Presently there is no typescript API for wl_DirectUpdateChallengeHandler in cordova-plugin-mfp to customize direct update in Ionic Applications.
However you can do implementation in the JavaScript and include it in the Ionic Project. Following are the steps :
Create a folder called js inside the path src/assets of the project
Create a new JS file with following code and save it as wldirectudpate.js
function wlCommonInit() {
console.log(">> wlCommonInit() ..." );
wl_DirectUpdateChallengeHandler.handleDirectUpdate = function(directUpdateData, directUpdateContext) {
// Implement custom Direct Update logic
};
};
Add the JS location in index.html file which is located at /src/index.html
<script src="assets/js/wldirectudpate.js"></script>

React Native and Facebook SDK on Android

I can't seem to get React Native FBSDK work on Android. I completed all the steps from registering the app to configuring the manifest file (can be found on this page: https://developers.facebook.com/docs/react-native/configure-android-current)
When I run the app I get the error: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first. I am using the latest version of react-native-fbsdk so the method above is deprecated. Also if I put the call into the main application class, the app crashes on startup.
So I'm kind of stuck here. Everything runs smooth on iOS but Android gives me headaches.
As you haven't shown code it's hard to know, but make sure you have:
#Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
// If you want to use AppEventsLogger to log events:
AppEventsLogger.activateApp(this);
SoLoader.init(this, /* native exopackage */ false);
}
in your MainApplication class (MainApplication.java)--at least, I didn't see that mentioned in the link you provided. Good luck
I have the same issue and I realize that I have to complete all steps to configure the native facebook sdk for android. Its mean you need to have a facebook account for this work.
What you need to do next is:
In your project open yourapp/android/build.gradle
Add the Maven Central Repository to build.gradle before dependencies:
repositories {
mavenCentral()
}
Add compile 'com.facebook.android:facebook-android-sdk:[4,5)'to your build.gradle dependencies
Build project
Open your strings.xml file, for example: /app/src/main/res/values/strings.xml.and add <string name="facebook_app_id">xxxxxxxxx</string>
Open your AndroidManifest.xml and add <uses-permission android:name="android.permission.INTERNET"/>
Add meta to application element <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
Generate a development key hash
You can see detail in quick start of developer facebook page (developers.facebook.com/quickstarts)

IntelliJ run vs running a jar, with a Springboot Kotlin, Multi module Gradle project with Social Oauth2

TL;DR: Why does everything run fine when started via IntelliJ, and why is it broken when call java -jar app.jar. And how do I fix this?
Alright, I have some issues with a backend I am trying to dockerize. I have an application created with Spring Boot (1.4.2.RELEASE) following the Spring Oauth (2.0.12.RELEASE) guide on their page. I follow the Gradle version, since I prefer Gradle over Maven. Also I am using Kotlin instead of Java. Everything is fine, I start via IntelliJ my backend with static front end, I can login via Facebook (and Google and Github), I receive a nice Principal witch holds al the information I need, and I can modify Spring Security to authorize and permit endpoints. So far so good.
Now for the bad part, when I run either ./gradlew clean build app:bootrun or ./gradlew clean build app:jar and run the jar via java -jar (like I will do in my Docker container), my backend comes up. My static front end pops up. Now I want to login via Facebook, I end up on the Facebook login page, I enter my credentials, and... nothing!
I end up back on my homepage, not logged in, no log messages that mean anything to me, just silence. The last thing I see in the log is:Getting user info from: https://graph.facebook.com/me
This Url will give me in my browser:
{
"error": {
"message": "An active access token must be used to query information about the current user.",
"type": "OAuthException",
"code": 2500,
"fbtrace_id": "GV/58H5f4fJ"
}
}
When going to this URL via an IntelliJ start, it will give me credential details. Obviously something is going wrong, but I have no clue what. Especially since a run from IntelliJ works fine. There is some difference between how the jar is started, and how IntelliJ's run config works, but I have no clue where to search for what. I could post trace logging, or all my Gradle files, but perhaps thats too much info to put in 1 question. I will defenitly update this question if someone needs some more details :)
The structure outline of this project is as follows:
root:
- api: is going to be opensourced later, contains rest definitions and DTOs.
- core: contains the meat. Also here is included in the gradle file
spring-boot-starter, -web, -security, spring-security-oauth2, and some jackson stuff.
- rest: contains versioned rest service implementations.
- app: contains angular webjars amongst others, the front end, and
my `#SpringBootApplication`, `#EnableOAuth2Client`
and the impl of `WebSecurityConfigurerAdapter`.
Why does everything run fine when started via IntelliJ, and why is it broken using bootRun or the jar artefact. And how do I fix this?
I found it, the problem was not Multi module Graldle, Spring boot, or Oauth2 related. In fact it was due to a src set config of Gradle, where Java was supposed to be in a Java src set folder, and Kotlin in a Java src set folder:
sourceSets {
main.java.srcDirs += 'src/main/java'
main.kotlin.srcDirs += 'src/main/kotlin'
}
As Will Humphreys stated in his comment above, IntelliJ takes all source sets, and runs the app. However, when building the jar via Gradle, these source sets are stricter. I had a Java file in my Kotlin src set, which is no problem for IntelliJ. But the jar created by Gradle takes into account the source sets as defined in the build.gralde file, which are stricter.
I found my missing bean issue with the code below:
#Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
};
}
The Bean I missed was called AuthenticationController, which is a #RestController, and kinda crucial for my authentication code.