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

Added initialize call and fetch token support for android with flutter #84

Open
wants to merge 4 commits into
base: fix/kotlin-mismatch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ android {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0'

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.4'
//TODO: Add Library folder path in implementation's dir
// compileOnly fileTree(include: ['*.aar'], dir: '/Users/kausthubh.adhikari/Desktop/SDK-Libraries/androidlibs')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.razorpay.ValidateVpaCallback;
import com.razorpay.upi.AccountBalance;
import com.razorpay.upi.BankAccount;
import com.razorpay.upi.TurboSessionDelegate;
import com.razorpay.upi.UpiAccount;
import com.razorpay.upi.Bank;
import com.razorpay.upi.Card;
Expand All @@ -52,11 +53,14 @@
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.ActivityResultListener;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;

import static com.razorpay.flutter_customui.Constants.PAYMENT_DATA;

import com.razorpay.UpiTurboPrefetchLinkAccountsResultListener;
import com.razorpay.upi.AllAccounts;
import com.razorpay.upi.model.Session;

public class RazorpayDelegate implements ActivityResultListener {
private Activity activity;
Expand Down Expand Up @@ -91,6 +95,18 @@ public class RazorpayDelegate implements ActivityResultListener {
Gson gson;
private Handler uiThreadHandler = new Handler(Looper.getMainLooper());

// TurboSessionDelegate
private Function1<? super Session, Unit> sessionCompletion = null;
TurboSessionDelegate turboSessionDelegate = new TurboSessionDelegate() {
@Override
public void fetchToken(@NonNull Function1<? super Session, Unit> completion) {
sessionCompletion = completion;
HashMap<Object, Object> reply = new HashMap<>();
reply.put("responseEvent", "refreshSessionToken");
onEventSuccess(reply);
}
};

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public RazorpayDelegate(Activity activity) {
this.activity = activity;
Expand All @@ -101,6 +117,7 @@ void init(String key, Result result) {
this.key = key;
this.pendingResult = result;
razorpay = new Razorpay(activity, key);
razorpay.upiTurbo.initialize(this.turboSessionDelegate);
}

void submit(final JSONObject payload, Result result) {
Expand Down Expand Up @@ -766,4 +783,10 @@ public void onError(@NonNull JSONObject jsonObject) {
});

}

public void updateToken(String token) {
if (sessionCompletion != null) {
sessionCompletion.invoke(new Session(token));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result)
razorpayDelegate.setPrefetchUPIPinWithUI(bankAccountStr, result, eventSink);
break;

case "refreshSessionToken":
String newToken = call.arguments().toString();
razorpayDelegate.updateToken(newToken);

default:
Log.d(TAG, "no method");
}
Expand Down
138 changes: 68 additions & 70 deletions lib/model/upi_account.dart
Original file line number Diff line number Diff line change
@@ -1,89 +1,87 @@
import 'bank_account.dart';

class UpiAccount {
String? accountNumber;
String? bankLogoUrl;
String? bankName;
String? bankPlaceholderUrl;
String? ifsc;
int? pinLength;
Vpa? vpa;
String? type;
String? accountNumber;
String? bankLogoUrl;
String? bankName;
String? bankId;
String? bankPlaceholderUrl;
String? ifsc;
int? pinLength;
Vpa? vpa;
String? type;


UpiAccount({
this.accountNumber,
this.bankLogoUrl,
this.bankName,
this.bankPlaceholderUrl,
this.ifsc,
this.pinLength,
this.vpa,
this.type
});
UpiAccount(
{this.accountNumber,
this.bankLogoUrl,
this.bankName,
this.bankId,
this.bankPlaceholderUrl,
this.ifsc,
this.pinLength,
this.vpa,
this.type});

factory UpiAccount.fromJson(Map<String, dynamic> json) => UpiAccount(
accountNumber: json['account_number'],
bankLogoUrl: json['bank_logo_url'],
bankName: json['bank_name'],
bankPlaceholderUrl: json['bankPlaceholderUrl'],
ifsc: json['ifsc'],
pinLength: json['pinLength'],
vpa: Vpa.fromJson(json['vpa']),
type: json['type']
);
accountNumber: json['account_number'],
bankLogoUrl: json['bank_logo_url'],
bankName: json['bank_name'],
bankId: json['bank_id'],
bankPlaceholderUrl: json['bankPlaceholderUrl'],
ifsc: json['ifsc'],
pinLength: json['pinLength'],
vpa: Vpa.fromJson(json['vpa']),
type: json['type']);

Map<String, dynamic> toJson() => {
'account_number': accountNumber,
'bank_logo_url': bankLogoUrl,
'bank_name': bankName,
'bankPlaceholderUrl': bankPlaceholderUrl,
'ifsc': ifsc,
'pinLength': pinLength,
'vpa': vpa?.toJson(),
'type': type
};

'account_number': accountNumber,
'bank_logo_url': bankLogoUrl,
'bank_name': bankName,
'bank_id': bankId,
'bankPlaceholderUrl': bankPlaceholderUrl,
'ifsc': ifsc,
'pinLength': pinLength,
'vpa': vpa?.toJson(),
'type': type
};
}

class Vpa {
String? address;
BankAccount? bankAccount;
String? handle;
bool? active;
bool? isDefault;
bool? validated;
String? username;
String? address;
BankAccount? bankAccount;
String? handle;
bool? active;
bool? isDefault;
bool? validated;
String? username;

Vpa({
this.address,
this.bankAccount,
this.handle,
this.active,
this.isDefault,
this.validated,
this.username,
this.address,
this.bankAccount,
this.handle,
this.active,
this.isDefault,
this.validated,
this.username,
});

factory Vpa.fromJson(Map<String, dynamic> json) => Vpa(
address: json['address'],
bankAccount: BankAccount.fromJson(json['bank_account']),
handle: json['handle'],
active: json['active'],
isDefault: json['default'],
validated: json['validated'],
username: json['username'],
);
address: json['address'],
bankAccount: BankAccount.fromJson(json['bank_account']),
handle: json['handle'],
active: json['active'],
isDefault: json['default'],
validated: json['validated'],
username: json['username'],
);

Map<String, dynamic> toJson() => {
'address': address,
'bank_account': bankAccount?.toJson(),
'handle': handle,
'active': active,
'default': isDefault,
'validated': validated,
'username': username,
};
'address': address,
'bank_account': bankAccount?.toJson(),
'handle': handle,
'active': active,
'default': isDefault,
'validated': validated,
'username': username,
};
}


1 change: 1 addition & 0 deletions lib/upi_turbo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ class UpiTurbo {
accountNumber: upiAccount.accountNumber,
bankLogoUrl: upiAccount.bankLogoUrl,
bankName: upiAccount.bankName,
bankId: upiAccount.bankId,
bankPlaceholderUrl: upiAccount.bankPlaceholderUrl,
ifsc: upiAccount.ifsc,
pinLength: upiAccount.pinLength,
Expand Down