Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

develop with flutter_v3 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ coverage/

pubspec.lock
.flutter-plugins
.flutter-plugins-dependencies
.flutter-plugins-dependencies

example
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# analyzer:
# enable-experiment:
# - non-nullable
include: package:flutter_lints/flutter.yaml
14 changes: 7 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'jp.pokepay.pokepay_sdk'
version '1.0.0'
version '1.0.6'

buildscript {
repositories {
Expand All @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.1.3'
}
}

Expand All @@ -22,7 +22,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion 31

defaultConfig {
minSdkVersion 21
Expand All @@ -33,8 +33,8 @@ android {
}

dependencies {
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.7'
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.7'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.7'
implementation 'jp.pocket-change.pokepay.android-sdk:pokepaylib:1.5.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.11.1'
implementation 'com.fasterxml.jackson.core:jackson-core:2.11.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.11.1'
implementation 'jp.pocket-change.pokepay.android-sdk:pokepaylib:1.6.0'
}
5 changes: 3 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Jun 10 16:11:04 JST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
zipStoreBase=GRADLE_USER_HOME
85 changes: 54 additions & 31 deletions android/src/main/java/jp/pokepay/pokepay_sdk/PokepaySdkPlugin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jp.pokepay.pokepay_sdk;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import androidx.annotation.NonNull;

Expand All @@ -21,7 +21,6 @@
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;
import jp.pokepay.pokepaylib.BankAPI.Account.CreateAccount;
import jp.pokepay.pokepaylib.BankAPI.Account.CreateAccountCpmToken;
import jp.pokepay.pokepaylib.BankAPI.Account.GetAccount;
Expand All @@ -45,7 +44,6 @@
import jp.pokepay.pokepaylib.BankAPI.Check.GetCheck;
import jp.pokepay.pokepaylib.BankAPI.Check.UpdateCheck;
import jp.pokepay.pokepaylib.BankAPI.CpmToken.GetCpmToken;
import jp.pokepay.pokepaylib.BankAPI.Account.PatchAccountCouponDetail;
import jp.pokepay.pokepaylib.BankAPI.PrivateMoney.GetPrivateMoneyCoupons;
import jp.pokepay.pokepaylib.BankAPI.PrivateMoney.SearchPrivateMoneys;
import jp.pokepay.pokepaylib.BankAPI.Terminal.AddTerminalPublicKey;
Expand Down Expand Up @@ -76,8 +74,8 @@
import jp.pokepay.pokepaylib.OAuthAPI.OAuthRequestError;
import jp.pokepay.pokepaylib.OAuthAPI.Token.ExchangeAuthCode;
import jp.pokepay.pokepaylib.OAuthAPI.Token.RefreshAccessToken;
import jp.pokepay.pokepaylib.Parameters.Product;
import jp.pokepay.pokepaylib.Parameters.Metadata;
import jp.pokepay.pokepaylib.Parameters.Product;
import jp.pokepay.pokepaylib.Pokepay;
import jp.pokepay.pokepaylib.Response;
import jp.pokepay.pokepaylib.Responses.AccessToken;
Expand All @@ -103,35 +101,24 @@
import jp.pokepay.pokepaylib.Responses.Terminal;
import jp.pokepay.pokepaylib.Responses.User;
import jp.pokepay.pokepaylib.Responses.UserTransaction;
import jp.pokepay.pokepaylib.TokenInfo;

/** PokepaySdkPlugin */

/** PokepayFlutterSdkPlugin */
public class PokepaySdkPlugin implements FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private MethodChannel channel;
private static Context context;

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "jp.pokepay/pokepay_sdk");
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "jp.pokepay/pokepay_sdk");
context = flutterPluginBinding.getApplicationContext();
channel.setMethodCallHandler(this);
}

// This static function is optional and equivalent to onAttachedToEngine. It supports the old
// pre-Flutter-1.12 Android projects. You are encouraged to continue supporting
// plugin registration via this function while apps migrate to use the new Android APIs
// post-flutter-1.12 via https://flutter.dev/go/android-project-migration.
//
// It is encouraged to share logic between onAttachedToEngine and registerWith to keep
// them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called
// depending on the user's project. onAttachedToEngine or registerWith must both be defined
// in the same class.
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "jp.pokepay/pokepay_sdk");
channel.setMethodCallHandler(new PokepaySdkPlugin());
}

static private class MethodCallAsyncTask extends AsyncTask<String, Void, MethodCallAsyncTask.TaskResult> {

Expand All @@ -157,7 +144,6 @@ private Env flutterEnvToSDKEnv(int env) {
case 0: return Env.PRODUCTION;
case 1: return Env.SANDBOX;
case 2: return Env.QA;
case 3: return Env.DEVELOPMENT;
default: return Env.DEVELOPMENT;
}
}
Expand Down Expand Up @@ -197,7 +183,8 @@ private TaskResult invokeMethod() {
String accessToken = call.argument("accessToken");
String name = call.argument("name");
String privateMoneyId = call.argument("privateMoneyId");
CreateAccount req = new CreateAccount(name, privateMoneyId);
String externalId = call.argument("externalId");
CreateAccount req = new CreateAccount(name, privateMoneyId,externalId);
Pokepay.setEnv(env);
Account res = req.send(accessToken);
return new TaskResult(null, res.toString());
Expand Down Expand Up @@ -512,6 +499,17 @@ private TaskResult invokeMethod() {
Terminal res = req.send(accessToken);
return new TaskResult(null, res.toString());
}
// case "getTokenInfo": {
// Env env = flutterEnvToSDKEnv((int) call.argument("env"));
// String accessToken = call.argument("accessToken");
// String token = call.argument("token");
// Pokepay.setEnv(env);
// Pokepay.Client client = new Pokepay.Client(accessToken,null);
// TokenInfo tokenInfo = client.getTokenInfo(token);
// MyTokenInfo myTokenInfo = new MyTokenInfo(tokenInfo);
// Log.v("hello",myTokenInfo.toString());
// return new TaskResult(null,myTokenInfo.toString());
// }
case "getUserAccounts": {
Env env = flutterEnvToSDKEnv((int)call.argument("env"));
String accessToken = call.argument("accessToken");
Expand Down Expand Up @@ -563,7 +561,8 @@ private TaskResult invokeMethod() {
String accountId = call.argument("accountId");
String couponId = call.argument("couponId");
boolean isReceived = call.argument("is_received");
PatchAccountCouponDetail req = new PatchAccountCouponDetail(accountId,couponId,isReceived);
String code = call.argument("code");
PatchAccountCouponDetail req = new PatchAccountCouponDetail(accountId,couponId,isReceived,code);
CouponDetail res = req.send(accessToken);
return new TaskResult(null, res.toString());
}
Expand Down Expand Up @@ -599,13 +598,34 @@ private TaskResult invokeMethod() {
Env env = flutterEnvToSDKEnv((int) call.argument("env"));
String accessToken = call.argument("accessToken");
String scanToken = call.argument("scanToken");
double amount = call.argument("amount");
String accountId = call.argument("accountId");
Product[] products = call.argument("products");
String couponId = call.argument("couponId");
Pokepay.setEnv(env);
Pokepay.Client client = new Pokepay.Client(accessToken, null);
UserTransaction userTransaction = client.scanToken(scanToken,amount,accountId,products,couponId);

double amount = 0.0;
if(call.argument("amount")!=null){
amount = call.argument("amount");
}
String accountId=null;
if(call.argument("accountId")!=null){
accountId = call.argument("accountId");
}
Product[] products = new Product[0];
if(call.argument("products")!=null) {
products = call.argument("products");
}
String couponId=null;
if(call.argument("couponId")!=null){
couponId = call.argument("couponId");
}
Pokepay.setEnv(env);
Pokepay.Client client = new Pokepay.Client(accessToken, context);
UserTransaction userTransaction;
if(amount==0.0){
userTransaction = client.scanToken(scanToken);
}else{
userTransaction = client.scanToken(scanToken,amount,accountId,products,couponId);
}



return new TaskResult(null, userTransaction.toString());
}
case "searchPrivateMoneys": {
Expand Down Expand Up @@ -758,7 +778,7 @@ protected void onPostExecute(TaskResult res) {
try {
jsonObj.put("message", message);
} catch (JSONException e) {
Log.e("pokepay_sdk", e.getMessage());
// Log.e("pokepay_sdk", e.getMessage());
}
String errorMessage = jsonObj.toString();
result.error("ProcessingError", errorMessage, null);
Expand All @@ -769,6 +789,9 @@ protected void onPostExecute(TaskResult res) {
}
}




@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
new MethodCallAsyncTask(call, result).execute("");
Expand Down
51 changes: 36 additions & 15 deletions ios/Classes/SwiftPokepaySdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import APIKit
import Result
import Pokepay


private class APIJSONEncoder : JSONEncoder {
override init() {
super.init()
Expand Down Expand Up @@ -83,6 +84,7 @@ private class MethodCallTask {
)
}
private func after<T: Codable>(_ ret: Result<T, PokepayError>) -> Void {

switch ret {
case .success(let ret):
let bytes = try! APIJSONEncoder().encode(ret)
Expand Down Expand Up @@ -135,16 +137,18 @@ private class MethodCallTask {
let client = Pokepay.Client(accessToken: accessToken, env: env)
let name = args["name"] as? String
let privateMoneyId = args["privateMoneyId"] as? String
client.send(BankAPI.Account.Create(name: name, privateMoneyId: privateMoneyId), handler: self.after)
let externalId = args["externalId"] as? String
client.send(BankAPI.Account.Create(name: name, privateMoneyId: privateMoneyId,externalId: externalId), handler: self.after)
case "createAccountCpmToken":
let env = flutterEnvToSDKEnv(ienv: args["env"] as! Int32)
let accessToken = args["accessToken"] as! String
let client = Pokepay.Client(accessToken: accessToken, env: env)
let accountId = args["accountId"] as! String
let scopes = args["scopes"] as! Int
let expiresIn = args["expiresIn"] as? Int
let metadataMap = args["metadata"] as? [String:String]
client.send(BankAPI.Account.CreateAccountCpmToken(accountId: accountId, scopes: BankAPI.Account.CreateAccountCpmToken.Scope(rawValue: scopes)!, expiresIn: expiresIn, metadata: metadataMap), handler: self.after)
let env = flutterEnvToSDKEnv(ienv: args["env"] as! Int32)
let accessToken = args["accessToken"] as! String
let client = Pokepay.Client(accessToken: accessToken, env: env)
let accountId = args["accountId"] as! String
let scopes = args["scopes"] as! Int
let expiresIn = args["expiresIn"] as? Int
let metadataMap = args["metadata"] as? [String:String]

client.send(BankAPI.Account.CreateAccountCpmToken(accountId: accountId, scopes: BankAPI.Account.CreateAccountCpmToken.Scope(rawValue: scopes)!, expiresIn: expiresIn,metadata: metadataMap), handler: self.after)
case "createBill":
let env = flutterEnvToSDKEnv(ienv: args["env"] as! Int32)
let accessToken = args["accessToken"] as! String
Expand Down Expand Up @@ -183,13 +187,21 @@ private class MethodCallTask {
case "createToken":
let env = flutterEnvToSDKEnv(ienv: args["env"] as! Int32)
let accessToken = args["accessToken"] as! String
let isMerchant = args["isMerchan"] as! Bool
let isMerchant = args["isMerchant"] as! Bool
let amount = args["amount"] as! Double
let description = args["description"] as! String
let expiresIn = args["expiresIn"] as? Int32
let accountId = args["accountId"] as? String
let productsString = (args["products"] as! String).data(using: .utf8)!
let products = try! BankAPIJSONDecoder().decode([Product]?.self, from: productsString)
let productsString = (args["products"] as? String)
var products:[Product]?;
if(productsString==nil){
products = nil;
}else{
let productData=productsString?.data(using: .utf8)
products = try! BankAPIJSONDecoder().decode([Product]?.self, from: productData!)
}


let client = Pokepay.Client(accessToken: accessToken,isMerchant: isMerchant,env: env)
client.createToken(amount,description: description, expiresIn: expiresIn, accountId: accountId, products: products, handler: self.after)
case "createUserTransactionWithBill":
Expand Down Expand Up @@ -264,7 +276,7 @@ private class MethodCallTask {
let code = args["code"] as! String
let clientId = args["clientId"] as! String
let clientSecret = args["clientSecret"] as! String
let grantType = args["grantType"] as! String
//let grantType = args["grantType"] as! String
let client = Pokepay.OAuthClient(clientId: clientId, clientSecret: clientSecret, env: env)
client.send(OAuthAPI.Token.ExchangeAuthCode(code: code, clientId: clientId, clientSecret: clientSecret), handler: self.after)
case "getAccount":
Expand Down Expand Up @@ -429,8 +441,17 @@ private class MethodCallTask {
let token = args["scanToken"] as! String
let amount = args["amount"] as? Double
let accountId = args["accountId"] as? String
let productsString = (args["products"] as! String).data(using: .utf8)!
let products = try! BankAPIJSONDecoder().decode([Product]?.self, from: productsString)
// let productsString = (args["products"] as! String).data(using: .utf8)!
let productsString = (args["products"] as? String)
var products:[Product]?;
if(productsString==nil){
products = nil;
}else{
let productData=productsString?.data(using: .utf8)
products = try! BankAPIJSONDecoder().decode([Product]?.self, from: productData!)
}

// let products = try! BankAPIJSONDecoder().decode([Product]?.self, from: productsString)
let couponId = args["couponId"] as? String
let client = Pokepay.Client(accessToken: accessToken,env: env)
client.scanToken(token,amount:amount,accountId:accountId,products:products,couponId:couponId,handler: self.after)
Expand Down
4 changes: 2 additions & 2 deletions ios/pokepay_flutter_sdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'pokepay_flutter_sdk'
s.version = '1.0.4'
s.version = '1.0.6'
s.summary = 'Pokepay flutter SDK'
s.description = <<-DESC
Pokepay flutter SDK
Expand All @@ -15,7 +15,7 @@ Pokepay flutter SDK
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'Pokepay', '1.5.2'
s.dependency 'Pokepay', '1.6.0'
s.platform = :ios, '12.0'

# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
Expand Down
Loading