diff --git a/platforms/android/.gradle/2.2.1/taskArtifacts/cache.properties b/platforms/android/.gradle/2.2.1/taskArtifacts/cache.properties
index a2386e5..36d507e 100644
--- a/platforms/android/.gradle/2.2.1/taskArtifacts/cache.properties
+++ b/platforms/android/.gradle/2.2.1/taskArtifacts/cache.properties
@@ -1 +1 @@
-#Fri Apr 29 15:09:28 WAT 2016
+#Wed Aug 10 10:34:52 WAT 2016
diff --git a/platforms/android/.gradle/2.2.1/taskArtifacts/cache.properties.lock b/platforms/android/.gradle/2.2.1/taskArtifacts/cache.properties.lock
index d50cb61..f95a477 100644
Binary files a/platforms/android/.gradle/2.2.1/taskArtifacts/cache.properties.lock and b/platforms/android/.gradle/2.2.1/taskArtifacts/cache.properties.lock differ
diff --git a/platforms/android/.gradle/2.2.1/taskArtifacts/fileHashes.bin b/platforms/android/.gradle/2.2.1/taskArtifacts/fileHashes.bin
index 6bb5678..4262ced 100644
Binary files a/platforms/android/.gradle/2.2.1/taskArtifacts/fileHashes.bin and b/platforms/android/.gradle/2.2.1/taskArtifacts/fileHashes.bin differ
diff --git a/platforms/android/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin b/platforms/android/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin
index c3b3486..4fd7fa3 100644
Binary files a/platforms/android/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin and b/platforms/android/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin differ
diff --git a/platforms/android/.gradle/2.2.1/taskArtifacts/outputFileStates.bin b/platforms/android/.gradle/2.2.1/taskArtifacts/outputFileStates.bin
index 9f3420f..bc4a816 100644
Binary files a/platforms/android/.gradle/2.2.1/taskArtifacts/outputFileStates.bin and b/platforms/android/.gradle/2.2.1/taskArtifacts/outputFileStates.bin differ
diff --git a/platforms/android/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin b/platforms/android/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin
index 3c9fc8b..6e406b9 100644
Binary files a/platforms/android/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin and b/platforms/android/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin differ
diff --git a/platforms/android/CordovaLib/build/intermediates/bundles/debug/classes.jar b/platforms/android/CordovaLib/build/intermediates/bundles/debug/classes.jar
index 41cd215..917030a 100644
Binary files a/platforms/android/CordovaLib/build/intermediates/bundles/debug/classes.jar and b/platforms/android/CordovaLib/build/intermediates/bundles/debug/classes.jar differ
diff --git a/platforms/android/CordovaLib/build/intermediates/bundles/release/classes.jar b/platforms/android/CordovaLib/build/intermediates/bundles/release/classes.jar
index 5b27eec..71899fd 100644
Binary files a/platforms/android/CordovaLib/build/intermediates/bundles/release/classes.jar and b/platforms/android/CordovaLib/build/intermediates/bundles/release/classes.jar differ
diff --git a/platforms/android/CordovaLib/build/outputs/aar/CordovaLib-debug.aar b/platforms/android/CordovaLib/build/outputs/aar/CordovaLib-debug.aar
index 13c37c0..bf4ff8d 100644
Binary files a/platforms/android/CordovaLib/build/outputs/aar/CordovaLib-debug.aar and b/platforms/android/CordovaLib/build/outputs/aar/CordovaLib-debug.aar differ
diff --git a/platforms/android/CordovaLib/build/outputs/aar/CordovaLib-release.aar b/platforms/android/CordovaLib/build/outputs/aar/CordovaLib-release.aar
index e6c4b03..272fd3a 100644
Binary files a/platforms/android/CordovaLib/build/outputs/aar/CordovaLib-release.aar and b/platforms/android/CordovaLib/build/outputs/aar/CordovaLib-release.aar differ
diff --git a/platforms/android/android.json b/platforms/android/android.json
index 4ceb6f1..611b4dd 100644
--- a/platforms/android/android.json
+++ b/platforms/android/android.json
@@ -9,15 +9,15 @@
"parents": {
"/*": [
{
- "xml": "",
+ "xml": "",
"count": 1
},
{
- "xml": "",
+ "xml": "",
"count": 1
},
{
- "xml": "",
+ "xml": "",
"count": 1
}
]
@@ -26,40 +26,60 @@
}
},
"installed_plugins": {
+ "com.filfatstudios.spinnerdialog": {
+ "PACKAGE_NAME": "com.interswitch.payment.cordova"
+ },
+ "cordova-plugin-test-framework": {
+ "PACKAGE_NAME": "com.interswitch.payment.cordova"
+ },
"cordova-plugin-whitelist": {
- "PACKAGE_NAME": "io.onsen.quickstart"
+ "PACKAGE_NAME": "com.interswitch.payment.cordova"
},
"cordova-plugin-add-swift-support": {
- "PACKAGE_NAME": "io.onsen.quickstart"
+ "PACKAGE_NAME": "com.interswitch.payment.cordova"
},
"com.interswitchng.sdk.payment": {
- "PACKAGE_NAME": "io.onsen.quickstart"
- },
- "com.filfatstudios.spinnerdialog": {
- "PACKAGE_NAME": "io.onsen.quickstart"
+ "PACKAGE_NAME": "com.interswitch.payment.cordova"
}
},
"dependent_plugins": {},
"modules": [
{
- "file": "plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js",
- "id": "com.interswitchng.sdk.payment.PaymentPlugin",
+ "file": "plugins/com.filfatstudios.spinnerdialog/www/SpinnerDialog.js",
+ "id": "com.filfatstudios.spinnerdialog.SpinnerDialog",
"clobbers": [
- "PaymentPlugin"
+ "SpinnerDialog"
]
},
{
- "file": "plugins/com.filfatstudios.spinnerdialog/www/SpinnerDialog.js",
- "id": "com.filfatstudios.spinnerdialog.SpinnerDialog",
+ "file": "plugins/cordova-plugin-test-framework/www/tests.js",
+ "id": "cordova-plugin-test-framework.cdvtests"
+ },
+ {
+ "file": "plugins/cordova-plugin-test-framework/www/jasmine_helpers.js",
+ "id": "cordova-plugin-test-framework.jasmine_helpers"
+ },
+ {
+ "file": "plugins/cordova-plugin-test-framework/www/medic.js",
+ "id": "cordova-plugin-test-framework.medic"
+ },
+ {
+ "file": "plugins/cordova-plugin-test-framework/www/main.js",
+ "id": "cordova-plugin-test-framework.main"
+ },
+ {
+ "file": "plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js",
+ "id": "com.interswitchng.sdk.payment.PaymentPlugin",
"clobbers": [
- "SpinnerDialog"
+ "PaymentPlugin"
]
}
],
"plugin_metadata": {
+ "com.filfatstudios.spinnerdialog": "1.0.2",
+ "cordova-plugin-test-framework": "1.1.3-dev",
"cordova-plugin-whitelist": "1.2.2",
- "cordova-plugin-add-swift-support": "1.0.4",
- "com.interswitchng.sdk.payment": "0.0.1",
- "com.filfatstudios.spinnerdialog": "1.0.2"
+ "cordova-plugin-add-swift-support": "1.3.1",
+ "com.interswitchng.sdk.payment": "0.0.1"
}
}
\ No newline at end of file
diff --git a/platforms/android/assets/www/app.js b/platforms/android/assets/www/app.js
index 8c06a9a..578edf8 100644
--- a/platforms/android/assets/www/app.js
+++ b/platforms/android/assets/www/app.js
@@ -213,25 +213,36 @@ function init() {
SpinnerDialog.show("", "Please wait ...", null);
var makePaymentSuccess = function(response) {
+ var responseObject ={};
+ if(response.responseCode !== undefined){
+ responseObject = response;
+ }else if (response.responseCode === undefined){
+ responseObject = JSON.parse(response);
+ }
+ console.log(responseObject);
SpinnerDialog.hide();
- var responseObject = JSON.parse(response);
-
- if(responseObject.otpTransactionIdentifier) {
- var transactionIdentifier = responseObject.transactionIdentifier;
-
- ons.notification.prompt(responseObject.message).then(
+ if(responseObject.responseCode) {
+ if (responseObject.responseCode === "T0") {
+ ons.notification.prompt(responseObject.message).then(
function(otp) {
+ responseObject.method = "makePayment";
responseObject.otpValue = otp;
- authorizeOtp(responseObject);
+ authorizePurchase(responseObject);
}
);
- } else {
- alert(responseObject.message);
- }
+ }
+ } else {
+ //console.log(responseObject);
+ if(responseObject.detailMessage !== undefined && responseObject.detailMessage !== null ){
+ alert(responseObject.detailMessage);
+ }else{
+ alert(responseObject);
+ }
+ }
}
var makePaymentFail = function(response) {
SpinnerDialog.hide();
-
+ console.log(response);
alert(response);
}
@@ -280,15 +291,36 @@ function init() {
var validateCardSuccess = function(response) {
SpinnerDialog.hide();
- var validateCardResponse = JSON.parse(response);
+ console.log(response);
+ //var validateCardResponse = JSON.parse(response);
+ if(response.responseCode) {
+ if (response.responseCode === "T0") {
+ ons.notification.prompt(response.message).then(
+ function(otp) {
+ response.method = "validateCard";
+ response.otpValue = otp;
+ authorizePurchase(response);
+ }
+ );
+ }
+ else if (response.responseCode === "S0") {
- var token = validateCardResponse.token;
- var tokenExpiryDate = validateCardResponse.tokenExpiryDate;
- var balance = validateCardResponse.balance;
- var panLast4Digits = validateCardResponse.panLast4Digits;
- var cardType = validateCardResponse.cardType;
-
- alert("Card Validation was successful");
+ }
+ } else {
+ var responseObject = JSON.parse(response);
+ if(responseObject.message !== undefined){
+ alert(responseObject.message);
+ }else{
+ alert(response);
+ }
+ }
+ /*var token = response.token;
+ var tokenExpiryDate = response.tokenExpiryDate;
+ var balance = response.balance;
+ var panLast4Digits = response.panLast4Digits;
+ var cardType = response.cardType;
+ */
+ //alert("Card Validation was successful");
}
var validateCardFail = function(response) {
@@ -300,31 +332,37 @@ function init() {
}
- function authorizeOtp(results) {
+ function authorizePurchase(results) {
if(results !== null && results.otpValue && results.otpValue.length > 0){
SpinnerDialog.show("", "Verifying One Time Password ...", null);
- var authorizeOtpRequest = {
+ var authorizePurchaseRequest = {
otp : results.otpValue,
- otpTransactionIdentifier: results.otpTransactionIdentifier,
- transactionRef: results.transactionRef
+ paymentId: results.paymentId,
+ transactionRef: results.transactionRef,
+ authData: results.authData
}
- var authorizeOtpSuccess = function(response) {
- SpinnerDialog.hide();
-
+ var authorizePurchaseSuccess = function(response) {
+ SpinnerDialog.hide();
var responseObject = JSON.parse(response);
var theTransactionRef = responseObject.transactionRef;
-
- alert("Success: Approved by Financial Institution");
+ console.log(responseObject);
+ alert(theTransactionRef);
}
- var authorizeOtpFail = function(response) {
- SpinnerDialog.hide();
- alert("Payment failed");
+ var authorizePurchaseFail = function(response) {
+ SpinnerDialog.hide();
+ console.log(response);
+ alert(response);
+ }
+ if(results.method ==="makePayment"){
+ PaymentPlugin.authorizePurchase(authorizePurchaseRequest, authorizePurchaseSuccess, authorizePurchaseFail);
+ }
+ else if (results.method ==="validateCard"){
+ PaymentPlugin.authorizeCard(authorizePurchaseRequest, authorizePurchaseSuccess, authorizePurchaseFail);
}
- PaymentPlugin.authorizeOtp(authorizeOtpRequest, authorizeOtpSuccess, authorizeOtpFail);
} else {
alert("Invalid OTP value!");
}
diff --git a/platforms/android/assets/www/cordova_plugins.js b/platforms/android/assets/www/cordova_plugins.js
index d194c38..010de91 100644
--- a/platforms/android/assets/www/cordova_plugins.js
+++ b/platforms/android/assets/www/cordova_plugins.js
@@ -1,27 +1,44 @@
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
- "file": "plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js",
- "id": "com.interswitchng.sdk.payment.PaymentPlugin",
+ "file": "plugins/com.filfatstudios.spinnerdialog/www/SpinnerDialog.js",
+ "id": "com.filfatstudios.spinnerdialog.SpinnerDialog",
"clobbers": [
- "PaymentPlugin"
+ "SpinnerDialog"
]
},
{
- "file": "plugins/com.filfatstudios.spinnerdialog/www/SpinnerDialog.js",
- "id": "com.filfatstudios.spinnerdialog.SpinnerDialog",
+ "file": "plugins/cordova-plugin-test-framework/www/tests.js",
+ "id": "cordova-plugin-test-framework.cdvtests"
+ },
+ {
+ "file": "plugins/cordova-plugin-test-framework/www/jasmine_helpers.js",
+ "id": "cordova-plugin-test-framework.jasmine_helpers"
+ },
+ {
+ "file": "plugins/cordova-plugin-test-framework/www/medic.js",
+ "id": "cordova-plugin-test-framework.medic"
+ },
+ {
+ "file": "plugins/cordova-plugin-test-framework/www/main.js",
+ "id": "cordova-plugin-test-framework.main"
+ },
+ {
+ "file": "plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js",
+ "id": "com.interswitchng.sdk.payment.PaymentPlugin",
"clobbers": [
- "SpinnerDialog"
+ "PaymentPlugin"
]
}
];
module.exports.metadata =
// TOP OF METADATA
{
+ "com.filfatstudios.spinnerdialog": "1.0.2",
+ "cordova-plugin-test-framework": "1.1.3-dev",
"cordova-plugin-whitelist": "1.2.2",
- "cordova-plugin-add-swift-support": "1.0.4",
- "com.interswitchng.sdk.payment": "0.0.1",
- "com.filfatstudios.spinnerdialog": "1.0.2"
+ "cordova-plugin-add-swift-support": "1.3.1",
+ "com.interswitchng.sdk.payment": "0.0.1"
};
// BOTTOM OF METADATA
});
\ No newline at end of file
diff --git a/platforms/android/assets/www/index.html b/platforms/android/assets/www/index.html
index 3c4f34d..acfd385 100644
--- a/platforms/android/assets/www/index.html
+++ b/platforms/android/assets/www/index.html
@@ -203,7 +203,7 @@
Interswitch Cordova NoUI
-
+
diff --git a/platforms/android/assets/www/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js b/platforms/android/assets/www/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js
index 1a179df..4cb68fa 100644
--- a/platforms/android/assets/www/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js
+++ b/platforms/android/assets/www/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js
@@ -14,6 +14,8 @@ function paymentAction (action) {
}
var PaymentPlugin = {};
+PaymentPlugin.SAFE_TOKEN_RESPONSE_CODE = "T0";
+PaymentPlugin.CARDINAL_RESPONSE_CODE = "S0";
PaymentPlugin.init = paymentAction("Init");
// Using Payment SDK UI
@@ -28,7 +30,8 @@ PaymentPlugin.makePayment = paymentAction("MakePayment");
PaymentPlugin.loadWallet = paymentAction("LoadWallet");
PaymentPlugin.payWithWalletSDK = paymentAction("PayWithWalletSDK");
PaymentPlugin.validateCard = paymentAction("ValidateCard");
-PaymentPlugin.authorizeOtp = paymentAction("AuthorizeOTP");
+PaymentPlugin.authorizePurchase = paymentAction("AuthorizePurchase");
+PaymentPlugin.authorizeCard = paymentAction("AuthorizeCard");
PaymentPlugin.paymentStatus = paymentAction("PaymentStatus");
module.exports = PaymentPlugin;
diff --git a/platforms/android/build.gradle b/platforms/android/build.gradle
index c479ff4..5674d8c 100644
--- a/platforms/android/build.gradle
+++ b/platforms/android/build.gradle
@@ -86,7 +86,7 @@ ext {
}
// PLUGIN GRADLE EXTENSIONS START
-apply from: "com.interswitchng.sdk.payment/quickstart-build.gradle"
+apply from: "com.interswitchng.sdk.payment/cordova-build.gradle"
// PLUGIN GRADLE EXTENSIONS END
def hasBuildExtras = file('build-extras.gradle').exists()
diff --git a/platforms/android/libs/core.jar b/platforms/android/libs/core.jar
index 3e84e44..79b8831 100644
Binary files a/platforms/android/libs/core.jar and b/platforms/android/libs/core.jar differ
diff --git a/platforms/android/libs/payment-android-release.aar b/platforms/android/libs/payment-android-release.aar
index 2564467..4cac550 100644
Binary files a/platforms/android/libs/payment-android-release.aar and b/platforms/android/libs/payment-android-release.aar differ
diff --git a/platforms/android/libs/payment.jar b/platforms/android/libs/payment.jar
index e0e5834..22fc251 100644
Binary files a/platforms/android/libs/payment.jar and b/platforms/android/libs/payment.jar differ
diff --git a/platforms/android/platform_www/cordova_plugins.js b/platforms/android/platform_www/cordova_plugins.js
index d194c38..010de91 100644
--- a/platforms/android/platform_www/cordova_plugins.js
+++ b/platforms/android/platform_www/cordova_plugins.js
@@ -1,27 +1,44 @@
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
- "file": "plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js",
- "id": "com.interswitchng.sdk.payment.PaymentPlugin",
+ "file": "plugins/com.filfatstudios.spinnerdialog/www/SpinnerDialog.js",
+ "id": "com.filfatstudios.spinnerdialog.SpinnerDialog",
"clobbers": [
- "PaymentPlugin"
+ "SpinnerDialog"
]
},
{
- "file": "plugins/com.filfatstudios.spinnerdialog/www/SpinnerDialog.js",
- "id": "com.filfatstudios.spinnerdialog.SpinnerDialog",
+ "file": "plugins/cordova-plugin-test-framework/www/tests.js",
+ "id": "cordova-plugin-test-framework.cdvtests"
+ },
+ {
+ "file": "plugins/cordova-plugin-test-framework/www/jasmine_helpers.js",
+ "id": "cordova-plugin-test-framework.jasmine_helpers"
+ },
+ {
+ "file": "plugins/cordova-plugin-test-framework/www/medic.js",
+ "id": "cordova-plugin-test-framework.medic"
+ },
+ {
+ "file": "plugins/cordova-plugin-test-framework/www/main.js",
+ "id": "cordova-plugin-test-framework.main"
+ },
+ {
+ "file": "plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js",
+ "id": "com.interswitchng.sdk.payment.PaymentPlugin",
"clobbers": [
- "SpinnerDialog"
+ "PaymentPlugin"
]
}
];
module.exports.metadata =
// TOP OF METADATA
{
+ "com.filfatstudios.spinnerdialog": "1.0.2",
+ "cordova-plugin-test-framework": "1.1.3-dev",
"cordova-plugin-whitelist": "1.2.2",
- "cordova-plugin-add-swift-support": "1.0.4",
- "com.interswitchng.sdk.payment": "0.0.1",
- "com.filfatstudios.spinnerdialog": "1.0.2"
+ "cordova-plugin-add-swift-support": "1.3.1",
+ "com.interswitchng.sdk.payment": "0.0.1"
};
// BOTTOM OF METADATA
});
\ No newline at end of file
diff --git a/platforms/android/platform_www/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js b/platforms/android/platform_www/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js
index 1a179df..4cb68fa 100644
--- a/platforms/android/platform_www/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js
+++ b/platforms/android/platform_www/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js
@@ -14,6 +14,8 @@ function paymentAction (action) {
}
var PaymentPlugin = {};
+PaymentPlugin.SAFE_TOKEN_RESPONSE_CODE = "T0";
+PaymentPlugin.CARDINAL_RESPONSE_CODE = "S0";
PaymentPlugin.init = paymentAction("Init");
// Using Payment SDK UI
@@ -28,7 +30,8 @@ PaymentPlugin.makePayment = paymentAction("MakePayment");
PaymentPlugin.loadWallet = paymentAction("LoadWallet");
PaymentPlugin.payWithWalletSDK = paymentAction("PayWithWalletSDK");
PaymentPlugin.validateCard = paymentAction("ValidateCard");
-PaymentPlugin.authorizeOtp = paymentAction("AuthorizeOTP");
+PaymentPlugin.authorizePurchase = paymentAction("AuthorizePurchase");
+PaymentPlugin.authorizeCard = paymentAction("AuthorizeCard");
PaymentPlugin.paymentStatus = paymentAction("PaymentStatus");
module.exports = PaymentPlugin;
diff --git a/platforms/android/project.properties b/platforms/android/project.properties
index 6038310..09c2dab 100644
--- a/platforms/android/project.properties
+++ b/platforms/android/project.properties
@@ -14,4 +14,4 @@ target=android-23
android.library.reference.1=CordovaLib
cordova.system.library.1=com.android.support:appcompat-v7:23.1.1
cordova.system.library.2=com.android.support:design:23.1.1
-cordova.gradle.include.1=com.interswitchng.sdk.payment/quickstart-build.gradle
\ No newline at end of file
+cordova.gradle.include.1=com.interswitchng.sdk.payment/cordova-build.gradle
\ No newline at end of file
diff --git a/platforms/android/res/xml/config.xml b/platforms/android/res/xml/config.xml
index d6e367a..c489cec 100644
--- a/platforms/android/res/xml/config.xml
+++ b/platforms/android/res/xml/config.xml
@@ -1,5 +1,8 @@
+
+
+
@@ -7,9 +10,6 @@
-
-
-
PaymentCordova
diff --git a/platforms/android/src/PayWithOutUI.java b/platforms/android/src/PayWithOutUI.java
index 133c3fd..cdbd17d 100644
--- a/platforms/android/src/PayWithOutUI.java
+++ b/platforms/android/src/PayWithOutUI.java
@@ -1,5 +1,14 @@
import android.app.Activity;
import android.content.Context;
+import android.webkit.WebView;
+import android.app.Dialog;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
+import android.view.Display;
+import android.view.LayoutInflater;
+import android.graphics.Point;
import com.interswitchng.sdk.model.RequestOptions;
import com.interswitchng.sdk.payment.IswCallback;
@@ -17,9 +26,16 @@
import com.interswitchng.sdk.payment.model.ValidateCardResponse;
import com.interswitchng.sdk.payment.model.WalletRequest;
import com.interswitchng.sdk.payment.model.WalletResponse;
+import com.interswitchng.sdk.payment.model.AuthorizePurchaseRequest;
+import com.interswitchng.sdk.payment.model.AuthorizePurchaseResponse;
+import com.interswitchng.sdk.payment.model.AuthorizeCardRequest;
+import com.interswitchng.sdk.payment.model.AuthorizeCardResponse;
+import com.interswitchng.sdk.payment.android.AuthorizeWebView;
+
import com.interswitchng.sdk.util.RandomString;
import com.interswitchng.sdk.util.StringUtils;
-
+import com.interswitchng.sdk.payment.model.Card;
+import org.apache.cordova.PluginResult;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
@@ -27,6 +43,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import com.google.gson.Gson;
public class PayWithOutUI extends CordovaPlugin{
private String clientId;
@@ -34,6 +51,7 @@ public class PayWithOutUI extends CordovaPlugin{
private WalletSDK sdk;
private Activity activity;
private Context context;
+ protected WebView webView;
private static RequestOptions options;
public PayWithOutUI(Activity activity, String clientId, String clientSecret ){
@@ -52,7 +70,7 @@ public void run() {
try {
options = RequestOptions.builder().setClientId(clientId).setClientSecret(clientSecret).build();
JSONObject params = args.getJSONObject(0);
- PurchaseRequest request = new PurchaseRequest(); // Setup request parameters
+ final PurchaseRequest request = new PurchaseRequest(); // Setup request parameters
request.setPan(params.getString("pan")); //Card No or Token
request.setAmount(params.getString("amount")); // Amount in Naira
request.setCvv2(params.getString("cvv"));
@@ -71,23 +89,100 @@ public void onError(Exception error) {
@Override
public void onSuccess(PurchaseResponse response) {
-
response.setCardType(type);
- if (StringUtils.hasText(response.getOtpTransactionIdentifier())) {
-
- PluginUtils.getPluginResult(callbackContext, response);
-
+ if (StringUtils.hasText(response.getResponseCode())) {
+ if (PaymentSDK.SAFE_TOKEN_RESPONSE_CODE.equals(response.getResponseCode())){
+ PluginResult result = null;
+ result = new PluginResult(PluginResult.Status.OK, getJsonObject(response,request));
+ result.setKeepCallback(true);
+ callbackContext.sendPluginResult(result);
+ }
+ else if(PaymentSDK.CARDINAL_RESPONSE_CODE.equals(response.getResponseCode())){
+ handleCardinal(response);
+ }
} else {
PluginUtils.getPluginResult(callbackContext, response);
}
}
+ private void handleCardinal(final PurchaseResponse response) {
+ final Context context = activity;
+ final Dialog cardinalDialog;
+ cardinalDialog = new Dialog(activity) {
+ @Override
+ public void onBackPressed() {
+ super.onBackPressed();
+ PluginUtils.getPluginResult(callbackContext, new RuntimeException("User cancelled operation"));
+ }
+ };
+ webView = new AuthorizeWebView(context, response) {
+ public void onPageDone() {
+ cardinalDialog.dismiss();
+ Util.showProgressDialog(context, "Processing...");
+ AuthorizePurchaseRequest cardinalRequest = new AuthorizePurchaseRequest();
+ cardinalRequest.setAuthData(request.getAuthData());
+ cardinalRequest.setPaymentId(response.getPaymentId());
+ cardinalRequest.setTransactionId(response.getTransactionId());
+ cardinalRequest.setEciFlag(response.getEciFlag());
+ new PaymentSDK(context, options).authorizePurchase(cardinalRequest, new IswCallback() {
+ @Override
+ public void onError(Exception error) {
+ Util.hideProgressDialog();
+ PluginUtils.getPluginResult(callbackContext, error.getMessage());
+ }
+
+ @Override
+ public void onSuccess(AuthorizePurchaseResponse response) {
+ Util.hideProgressDialog();
+ PluginUtils.getPluginResult(callbackContext, response);
+ }
+ });
+ }
+
+ public void onPageError(Exception error) {
+ // finish();
+ Util.hideProgressDialog();
+ cardinalDialog.dismiss();
+ PluginUtils.getPluginResult(callbackContext,error.getMessage());
+ //Util.notify(context, "Error", error.getMessage(), "Close", false);
+ }
+
+ };
+ cardinalDialog.setContentView(webView);
+ cardinalDialog.show();
+ cardinalDialog.setCancelable(true);
+ webView.requestFocus(View.FOCUS_DOWN);
+ webView.getSettings().setJavaScriptEnabled(true);
+ webView.setVerticalScrollBarEnabled(true);
+ WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
+ Display display = wm.getDefaultDisplay();
+ Point size = new Point();
+ display.getSize(size);
+ int width = size.x;
+ int height = size.y;
+ Window window = cardinalDialog.getWindow();
+ window.setLayout(width, height);
+ }
});
} catch (Exception ex) {
- callbackContext.error(ex.toString());
+ PluginUtils.getPluginResult(callbackContext,ex.getMessage());
}
}
});
}
+
+ private JSONObject getJsonObject(PurchaseResponse response, PurchaseRequest request) {
+ Gson gson = new Gson();
+ JSONObject jsonObject = null;
+ try{
+ jsonObject = new JSONObject(gson.toJson(response));
+ jsonObject.put("paymentId", response.getPaymentId());
+ jsonObject.put("authData",request.getAuthData());
+ }catch (JSONException jsonException){
+ jsonException.printStackTrace();
+ }
+ return jsonObject;
+ }
+
public void loadWallet(final String action, final CallbackContext callbackContext) throws JSONException {
context = activity;
activity.runOnUiThread(new Runnable() {
@@ -151,7 +246,10 @@ public void onError(Exception error) {
public void onSuccess(PurchaseResponse response) {
String transactionIdentifier = response.getTransactionIdentifier();
if (StringUtils.hasText(response.getOtpTransactionIdentifier())) {
+ //String otpTransactionIdentifier = response.getOtpTransactionIdentifier();
PluginUtils.getPluginResult(callbackContext, response);
+ /*String otpTransactionIdentifier = response.getOtpTransactionIdentifier();
+ Util.prompt(activity, "OTP", response.getMessage(), "Close", "Continue", true, 1L);*/
} else {
PluginUtils.getPluginResult(callbackContext, response);
}
@@ -170,7 +268,7 @@ public void run() {
try{
options = RequestOptions.builder().setClientId(clientId).setClientSecret(clientSecret).build();
JSONObject params = args.getJSONObject(0);
- ValidateCardRequest request = new ValidateCardRequest(); // Setup request parameters
+ final ValidateCardRequest request = new ValidateCardRequest(); // Setup request parameters
request.setPan(params.getString("pan")); //Card No or Token
request.setPinData(params.getString("pin")); // Optional Card PIN for card payment
request.setCvv2(params.getString("cvv"));
@@ -179,54 +277,144 @@ public void run() {
request.setCustomerId(params.getString("customerId"));
final Card card = new Card(request.getPan(), null, null, null);
final String type = card.getType();
+
new PaymentSDK(context, options).validateCard(request, new IswCallback() {
@Override
public void onError(Exception error) {
callbackContext.error(error.getMessage());
}
+
@Override
public void onSuccess(ValidateCardResponse response) {
- // Check if OTP is required.
response.setCardType(type);
- try {
- if (StringUtils.hasText(response.getOtpTransactionIdentifier())) {
- PluginUtils.getPluginResult(callbackContext, response);
+ if (StringUtils.hasText(response.getResponseCode())) {
+ if (PaymentSDK.SAFE_TOKEN_RESPONSE_CODE.equals(response.getResponseCode())){
+ PluginResult result = null;
+ result = new PluginResult(PluginResult.Status.OK, getJsonObject(response,request));
+ result.setKeepCallback(true);
+ callbackContext.sendPluginResult(result);
}
- else {
- PluginUtils.getPluginResult(callbackContext, response);
+ else if(PaymentSDK.CARDINAL_RESPONSE_CODE.equals(response.getResponseCode())){
+ handleCardinal(response);
}
- } catch (Exception ex) {
- callbackContext.error(ex.getMessage());
+ } else {
+ PluginUtils.getPluginResult(callbackContext, response);
}
}
+ private void handleCardinal(final ValidateCardResponse response) {
+ final Context context = activity;
+ final Dialog cardinalDialog;
+ cardinalDialog = new Dialog(activity) {
+ @Override
+ public void onBackPressed() {
+ super.onBackPressed();
+ PluginUtils.getPluginResult(callbackContext, new RuntimeException("User cancelled operation"));
+ }
+ };
+ webView = new AuthorizeWebView(context, response) {
+ public void onPageDone() {
+ cardinalDialog.dismiss();
+ Util.showProgressDialog(context, "Processing...");
+ AuthorizeCardRequest cardinalRequest = new AuthorizeCardRequest();
+ cardinalRequest.setAuthData(request.getAuthData());
+ cardinalRequest.setTransactionRef(response.getTransactionRef());
+ cardinalRequest.setTransactionId(response.getTransactionId());
+ cardinalRequest.setEciFlag(response.getEciFlag());
+ new PaymentSDK(context, options).authorizeCard(cardinalRequest, new IswCallback() {
+ @Override
+ public void onError(Exception error) {
+ Util.hideProgressDialog();
+ PluginUtils.getPluginResult(callbackContext, error.getMessage());
+ }
+
+ @Override
+ public void onSuccess(AuthorizeCardResponse response) {
+ Util.hideProgressDialog();
+ PluginUtils.getPluginResult(callbackContext, response);
+ }
+ });
+ }
+
+ public void onPageError(Exception error) {
+ // finish();
+ Util.hideProgressDialog();
+ cardinalDialog.dismiss();
+ PluginUtils.getPluginResult(callbackContext, error.getMessage());
+ //Util.notify(context, "Error", error.getMessage(), "Close", false);
+ }
+
+ };
+ cardinalDialog.setContentView(webView);
+ cardinalDialog.show();
+ cardinalDialog.setCancelable(true);
+ webView.requestFocus(View.FOCUS_DOWN);
+ webView.getSettings().setJavaScriptEnabled(true);
+ webView.setVerticalScrollBarEnabled(true);
+ WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
+ Display display = wm.getDefaultDisplay();
+ Point size = new Point();
+ display.getSize(size);
+ int width = size.x;
+ int height = size.y;
+ Window window = cardinalDialog.getWindow();
+ window.setLayout(width, height);
+ }
});
}
catch (Exception ex){
- callbackContext.error(ex.toString());
+ PluginUtils.getPluginResult(callbackContext, ex.toString());
+ }
+ }
+ });
+ }
+ public void authorizePurchase(final String action, final JSONArray args, final CallbackContext callbackContext){
+ context = activity.getApplicationContext();
+ activity.runOnUiThread(new Runnable() {
+ public void run() {
+ try {
+ options = RequestOptions.builder().setClientId(clientId).setClientSecret(clientSecret).build();
+ JSONObject params = args.getJSONObject(0);
+ AuthorizePurchaseRequest request = new AuthorizePurchaseRequest();
+ request.setPaymentId(params.getString("paymentId")); // Set the unique transaction reference.
+ request.setAuthData(params.getString("authData")); // Set the OTP identifier for the request
+ request.setOtp(params.getString("otp")); // Accept OTP from user
+ new PaymentSDK(context, options).authorizePurchase(request, new IswCallback() {
+ @Override
+ public void onError(Exception error) {
+ callbackContext.error(error.getMessage());
+ }
+
+ @Override
+ public void onSuccess(AuthorizePurchaseResponse authorizePurchaseResponse) {
+ PluginUtils.getPluginResult(callbackContext, authorizePurchaseResponse);
+ }
+ });
+ } catch (Exception error) {
+ PluginUtils.getPluginResult(callbackContext, error.toString());
}
}
});
}
- public void authorizeOtp(final String action, final JSONArray args, final CallbackContext callbackContext){
+ public void authorizeCard(final String action, final JSONArray args, final CallbackContext callbackContext){
context = activity.getApplicationContext();
activity.runOnUiThread(new Runnable() {
public void run() {
try {
options = RequestOptions.builder().setClientId(clientId).setClientSecret(clientSecret).build();
JSONObject params = args.getJSONObject(0);
- AuthorizeOtpRequest otpRequest = new AuthorizeOtpRequest();
- otpRequest.setOtp(params.getString("otp")); // Accept OTP from user
- otpRequest.setOtpTransactionIdentifier(params.getString("otpTransactionIdentifier")); // Set the OTP identifier for the request
- otpRequest.setTransactionRef(params.getString("transactionRef")); // Set the unique transaction reference.
- new PaymentSDK(context, options).authorizeOtp(otpRequest, new IswCallback() {
+ AuthorizeCardRequest request = new AuthorizeCardRequest();
+ request.setTransactionRef(params.getString("transactionRef"));
+ request.setAuthData(params.getString("authData")); // Set the OTP identifier for the request
+ request.setOtp(params.getString("otp")); // Accept OTP from user
+ new PaymentSDK(context, options).authorizeCard(request, new IswCallback() {
@Override
public void onError(Exception error) {
callbackContext.error(error.getMessage());
}
@Override
- public void onSuccess(AuthorizeOtpResponse otpResponse) {
- PluginUtils.getPluginResult(callbackContext, otpResponse);
+ public void onSuccess(AuthorizeCardResponse authorizeCardResponse) {
+ PluginUtils.getPluginResult(callbackContext, authorizeCardResponse);
}
});
} catch (Exception error) {
diff --git a/platforms/android/src/PayWithUI.java b/platforms/android/src/PayWithUI.java
index 3ca7608..1b0ece0 100644
--- a/platforms/android/src/PayWithUI.java
+++ b/platforms/android/src/PayWithUI.java
@@ -10,6 +10,8 @@
import com.interswitchng.sdk.payment.android.inapp.ValidateCard;
import com.interswitchng.sdk.payment.model.PurchaseResponse;
import com.interswitchng.sdk.payment.model.ValidateCardResponse;
+import com.interswitchng.sdk.payment.model.AuthorizeCardRequest;
+import com.interswitchng.sdk.payment.model.AuthorizeCardResponse;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
@@ -159,14 +161,14 @@ public void run() {
JSONObject params = args.getJSONObject(0);
String customerId = params.getString("customerId");
options = RequestOptions.builder().setClientId(clientId).setClientSecret(clientSecret).build();
- ValidateCard validateCard = new ValidateCard(activity, customerId, options, new IswCallback() {
+ ValidateCard validateCard = new ValidateCard(activity, customerId, options, new IswCallback() {
@Override
public void onError(Exception error) {
callbackContext.error(error.getMessage());
}
@Override
- public void onSuccess(ValidateCardResponse response) {
+ public void onSuccess(AuthorizeCardResponse response) {
PluginUtils.getPluginResult(callbackContext, response);
}
});
diff --git a/platforms/android/src/PaymentPlugin.java b/platforms/android/src/PaymentPlugin.java
index 67a813c..5530237 100644
--- a/platforms/android/src/PaymentPlugin.java
+++ b/platforms/android/src/PaymentPlugin.java
@@ -59,12 +59,26 @@ public void run() {
});
return true;
}
- else if(action.equals("AuthorizeOTP")){
+ else if(action.equals("AuthorizePurchase")){
cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
- payWithOutUI.authorizeOtp(action, args, callbackContext); //asyncronous call
+ payWithOutUI.authorizePurchase(action, args, callbackContext); //asyncronous call
+ } catch (Exception error) {
+ callbackContext.error(error.toString());
+ }
+ // Call the success function of the .js file
+ }
+ });
+ return true;
+ }
+ else if(action.equals("AuthorizeCard")){
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ payWithOutUI.authorizeCard(action, args, callbackContext); //asyncronous call
} catch (Exception error) {
callbackContext.error(error.toString());
}
@@ -301,9 +315,6 @@ private void init(JSONArray args, CallbackContext callbackContext) {
options = RequestOptions.builder().setClientId(this.clientId).setClientSecret(this.clientSecret).build();
//callbackContext.success("Initialization was successfull");
}
- else{
- //callbackContext.error("Invalid ClientId or Client Secret : ");
- }
}
}
catch (JSONException jsonException){
diff --git a/plugins/android.json b/plugins/android.json
index 1af9419..f928de3 100644
--- a/plugins/android.json
+++ b/plugins/android.json
@@ -7,17 +7,20 @@
"files": {}
},
"installed_plugins": {
- "cordova-plugin-whitelist": {
+ "com.filfatstudios.spinnerdialog": {
"PACKAGE_NAME": "com.interswitch.payment.cordova"
},
- "com.interswitchng.sdk.payment": {
+ "cordova-plugin-whitelist": {
"PACKAGE_NAME": "com.interswitch.payment.cordova"
},
- "com.filfatstudios.spinnerdialog": {
+ "com.interswitchng.sdk.payment": {
"PACKAGE_NAME": "com.interswitch.payment.cordova"
}
},
"dependent_plugins": {
+ "cordova-plugin-test-framework": {
+ "PACKAGE_NAME": "com.interswitch.payment.cordova"
+ },
"cordova-plugin-add-swift-support": {
"PACKAGE_NAME": "com.interswitch.payment.cordova"
}
diff --git a/plugins/com.interswitchng.sdk.payment/README.md b/plugins/com.interswitchng.sdk.payment/README.md
index dfa6e4b..f85b727 100644
--- a/plugins/com.interswitchng.sdk.payment/README.md
+++ b/plugins/com.interswitchng.sdk.payment/README.md
@@ -38,10 +38,13 @@ The first step to ​using the plugin is to register as a merchant. This is desc
* **cd** to the directory of your cordova project.
* Add the cordova-payment-plugin from CLI, using this command
+
```terminal
cordova plugin add https://github.com/techquest/cordova-payment-plugin.git
```
+
* Add ```android``` platform. Make sure to add the platform **after** adding the plugin.
+
```terminal
cordova platform add android
```
@@ -56,10 +59,13 @@ cordova platform add android
* **cd** to the directory of your cordova project.
* Add cordova payment plugin
+
```
cordova plugin add https://github.com/techquest/cordova-payment-plugin.git
```
+
* Add ```ios``` platform. Make sure to add the platform **after** adding the plugin.
+
```terminal
cordova platform add ios
```
@@ -79,11 +85,13 @@ The **PaymentSDK.framework** needs some [Cocoapods](https://cocoapods.org/) depe
* Close Xcode. **cd** into ```platforms/ios``` directory
* Run:
+
```terminal
pod init
```
* Open the **Podfile** created and replace ```#``` commented parts with the following.
+
```terminal
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, "8.0"
@@ -91,6 +99,7 @@ use_frameworks!
```
* Add the following to the **Podfile**, inside the first ```target``` block.
+
```
pod 'CryptoSwift'
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'
@@ -99,6 +108,7 @@ pod 'OpenSSL'
```
* Now run:
+
```terminal
pod install
```
@@ -112,6 +122,7 @@ During development of your app, you should use the Plugin in sandbox mode to ena
* Use Sandbox Client Id and Client Secret got from the Sandbox Tab of the Developer Console after signup (usually you have to wait for 5 minutes after signup for you to see the Sandbox details) everywhere you are required to supply Client Id and Client Secret in the remainder of this documentation
* In your code, override the api base as follows
+
```javascript
function init(){
var userDetails = {
@@ -130,12 +141,13 @@ During development of your app, you should use the Plugin in sandbox mode to ena
## Using the Plugin with UI (In PCI-DSS Scope: No )
-### Pay with Card/Wallet
+### Pay with Card/Wallet
* To allow for Payment with Card or Wallet
* Create a Pay button
* In the onclick event of the Pay button, use this code
1. Set up payment request like this:
+
```javascript
var payRequest = {
amount : 100, // Amount in Naira
@@ -144,7 +156,9 @@ During development of your app, you should use the Plugin in sandbox mode to ena
description : "Purchase Phone" // Description of product to purchase
}
```
+
2. Create a button to make payment and use this code in the onclick event of the button
+
```javascript
var paySuccess = function(response) {
var purchaseResponse = JSON.parse(response); // transaction success reponse
@@ -156,7 +170,7 @@ During development of your app, you should use the Plugin in sandbox mode to ena
PaymentPlugin.pay(payRequest, paySuccess, payFail);
```
-### Pay with Card
+### Pay with Card
* To allow for Payment with Card only
* Create a Pay button and set the payment request
@@ -169,7 +183,9 @@ During development of your app, you should use the Plugin in sandbox mode to ena
description : "Purchase Phone" // Description of product to purchase
}
```
+
* In the onclick event of the Pay button, use this code.
+
```javascript
var payWithCardSuccess = function(response) {
var purchaseResponse = JSON.parse(response); // transaction success reponse
@@ -178,11 +194,10 @@ During development of your app, you should use the Plugin in sandbox mode to ena
var payWithCardFail = function(response) {
alert(response); // transaction failure reponse
}
-
PaymentPlugin.payWithCard(payWithCardRequest, payWithCardSuccess, payWithCardFail);
```
-### Pay With Wallet
+### Pay With Wallet
* To allow for Payment with Wallet only
* Create a Pay button and set the payment request
@@ -195,7 +210,9 @@ During development of your app, you should use the Plugin in sandbox mode to ena
description : "Purchase Phone" // Description of product to purchase
}
```
+
* In the onclick event of the Pay button, use this code.
+
```javascript
var payWithWalletSuccess = function(response) {
var purchaseResponse = JSON.parse(response); // transaction success reponse
@@ -204,7 +221,6 @@ During development of your app, you should use the Plugin in sandbox mode to ena
var payWithWalletFail = function(response) {
alert(response); // transaction failure reponse
}
-
PaymentPlugin.payWithWallet(payWithWalletRequest, payWithWalletSuccess, payWithWalletFail);
```
@@ -212,28 +228,29 @@ During development of your app, you should use the Plugin in sandbox mode to ena
* Validate card is used to check if a card is a valid card, it returns the card balance and token
* Set up payment request like this:
+
```javascript
var validateCardRequest = {
customerId : 1234567890 // Optional email, mobile no, BVN etc to uniquely identify the customer
}
```
+
* To call validate card, use this code.
-```javascript
- var validatePaymentCardSuccess = function(response) {
- var validateCardResponse = JSON.parse(resposne);
- var token = validateCardResponse.token;
- var tokenExpiryDate = validateCardResponse.tokenExpiryDate;
- var balance = validateCardResponse.balance;
- var panLast4Digits = validateCardResponse.panLast4Digits;
- var cardType = validateCardResponse.cardType;
-
- alert("Validating your card was successful");
- }
- var validatePaymentCardFail = function(response) {
- alert(response); // transaction failure reponse
- }
- PaymentPlugin.validatePaymentCard(validateCardRequest, validatePaymentCardSuccess, validatePaymentCardFail);
+```javascript
+ var validatePaymentCardSuccess = function(response) {
+ var validateCardResponse = JSON.parse(resposne);
+ var token = validateCardResponse.token;
+ var tokenExpiryDate = validateCardResponse.tokenExpiryDate;
+ var balance = validateCardResponse.balance;
+ var panLast4Digits = validateCardResponse.panLast4Digits;
+ var cardType = validateCardResponse.cardType;
+ alert("Validating your card was successful");
+ }
+ var validatePaymentCardFail = function(response) {
+ alert(response); // transaction failure reponse
+ }
+ PaymentPlugin.validatePaymentCard(validateCardRequest, validatePaymentCardSuccess, validatePaymentCardFail);
```
### Pay with Token
@@ -241,6 +258,7 @@ During development of your app, you should use the Plugin in sandbox mode to ena
* To allow for Payment with Token only
* Create a Pay button
* Set up payment request like this:
+
```javascript
var payWithTokenRequest = {
pan : 5123459987670669364, //Token
@@ -253,17 +271,18 @@ During development of your app, you should use the Plugin in sandbox mode to ena
description : "Pay for gown"
}
```
+
* In the onclick event of the Pay button, use this code.
-```javascript
- var payWithTokenSuccess = function(response) {
- var purchaseResponse = JSON.parse(response); // transaction success reponse
- alert(purchaseResponse.message);
- }
- var payWithTokenFail = function(response) {
- alert(response); // transaction failure reponse
- }
- PaymentPlugin.payWithToken(payWithTokenRequest, payWithTokenSuccess, payWithTokenFail);
+```javascript
+ var payWithTokenSuccess = function(response) {
+ var purchaseResponse = JSON.parse(response); // transaction success reponse
+ alert(purchaseResponse.message);
+ }
+ var payWithTokenFail = function(response) {
+ alert(response); // transaction failure reponse
+ }
+ PaymentPlugin.payWithToken(payWithTokenRequest, payWithTokenSuccess, payWithTokenFail);
```
## Using the Plugin without UI (In PCI-DSS Scope: Yes)
@@ -303,14 +322,13 @@ During development of your app, you should use the Plugin in sandbox mode to ena
### Pay with Wallet
* To allow for Payment with Wallet only
* Create a UI to collect amount, CVV, expiry date and PIN and to display user's Payment Method(s). Use the code below to load the Payment Method(s)
+
```javascript
var loadWalletSuccess = function(response) {
alert("Wallet loaded successfully");
-
var responseObject = JSON.parse(response);
// The responseObject here contains cardProduct, panLast4Digits and token, the token is used for making payment
// Load the cardProduct on a dropdown list and use the token in making payment with wallet
-
for(var i = 0; i < response.length; i++){
console.log(responseObject.paymentMethods[i].token);
console.log(responseObject.paymentMethods[i].panLast4Digits);
@@ -338,11 +356,12 @@ During development of your app, you should use the Plugin in sandbox mode to ena
customerId : 1234567890 // Optional email, mobile no, BVN etc to uniquely identify the customer.
}
```
+
* In the onclick event of the Pay button, use this code.
+
```javascript
var payWithWalletSuccess = function(response) {
var responseObject = JSON.parse(response);
-
if(responseObject.otpTransactionIdentifier){
// handle OTP
} else {
@@ -379,23 +398,18 @@ During development of your app, you should use the Plugin in sandbox mode to ena
var validateCardResponse = JSON.parse(response); // transaction success reponse
// The response object contains fields transactionIdentifier, transactionRef,
// message, balance, token, tokenExpiryDate, panLast4Digits and cardType.
-
var token = validateCardResponse.token;
var tokenExpiryDate = validateCardResponse.tokenExpiryDate;
var balance = validateCardResponse.balance;
var panLast4Digits = validateCardResponse.panLast4Digits;
var cardType = validateCardResponse.cardType;
-
// Save the token, tokenExpiryDate, cardType and panLast4Digits
// in order to pay with the token in the future.
-
alert("Card Validation was successful");
- }
-
+ }
var validateCardFail = function(response) {
alert(response);// transaction failure reponse
}
-
PaymentPlugin.validateCard(validateCardRequest, validateCardSuccess, validateCardFail);
```
@@ -405,6 +419,7 @@ During development of your app, you should use the Plugin in sandbox mode to ena
* Create a UI to collect OTP
* Create authorize otp button
* Set up otp request using this code
+
```javascript
var authorizeOtpRequest = {
otp : 123456, // Accept OTP from user
@@ -418,15 +433,12 @@ During development of your app, you should use the Plugin in sandbox mode to ena
```javascript
var authorizeOtpSuccess = function(response) {
var responseObject = JSON.parse(response); // transaction success reponse
- var theTransactionRef = responseObject.transactionRef;
-
+ var theTransactionRef = responseObject.transactionRef;
alert("Success: Approved by Financial Institution");
}
-
var authorizeOtpFail = function(response) {
alert("Payment failed"); // transaction failure reponse
}
-
PaymentPlugin.authorizeOtp(authorizeOtpRequest, authorizeOtpSuccess, authorizeOtpFail);
```
@@ -444,15 +456,14 @@ During development of your app, you should use the Plugin in sandbox mode to ena
```
* To check the status of a payment made, use the code below
+
```javascript
var paymentStatusSuccess = function(response) {
var responseObject = JSON.parse(response);
alert(responseObject.message);
}
-
var paymentStatusFail = function(response) {
alert(response);
}
-
PaymentPlugin.paymentStatus(paymentStatusRequest, paymentStatusSuccess, paymentStatusFail);
```
\ No newline at end of file
diff --git a/plugins/com.interswitchng.sdk.payment/jasmine-standalone-2.4.1/spec/PaymentSpec.js b/plugins/com.interswitchng.sdk.payment/jasmine-standalone-2.4.1/spec/PaymentSpec.js
index f5bf38d..cbf7f7d 100644
--- a/plugins/com.interswitchng.sdk.payment/jasmine-standalone-2.4.1/spec/PaymentSpec.js
+++ b/plugins/com.interswitchng.sdk.payment/jasmine-standalone-2.4.1/spec/PaymentSpec.js
@@ -2,7 +2,6 @@ describe("initialization of Payment Plugin", function(){
var payment;
beforeEach(function() {
payment = new PaymentPlugin();
- expect(payment).to
});
it("should be able instantiate Payment Plugin", function(){
@@ -24,8 +23,8 @@ describe("The test class for Payment Plugin", function(){
var validateCardRequest = {
customerId : 1234567890 // Optional email, mobile no, BVN etc to uniquely identify the customer
};
- var validateCard = payment.validatePaymentCard(validateCardRequest);
- expect(validateCard).toBeDefined();
+ //var validateCard = payment.validatePaymentCard(validateCardRequest);
+ expect(payment).not.toBe(null);
});
it("should be able to initialize the Plugin class", function(){
expect(payment.init).not.toBe(null);
diff --git a/plugins/com.interswitchng.sdk.payment/libs/core.jar b/plugins/com.interswitchng.sdk.payment/libs/core.jar
index 3e84e44..79b8831 100644
Binary files a/plugins/com.interswitchng.sdk.payment/libs/core.jar and b/plugins/com.interswitchng.sdk.payment/libs/core.jar differ
diff --git a/plugins/com.interswitchng.sdk.payment/libs/payment-android-release.aar b/plugins/com.interswitchng.sdk.payment/libs/payment-android-release.aar
index 2564467..4cac550 100644
Binary files a/plugins/com.interswitchng.sdk.payment/libs/payment-android-release.aar and b/plugins/com.interswitchng.sdk.payment/libs/payment-android-release.aar differ
diff --git a/plugins/com.interswitchng.sdk.payment/libs/payment.jar b/plugins/com.interswitchng.sdk.payment/libs/payment.jar
index e0e5834..22fc251 100644
Binary files a/plugins/com.interswitchng.sdk.payment/libs/payment.jar and b/plugins/com.interswitchng.sdk.payment/libs/payment.jar differ
diff --git a/plugins/com.interswitchng.sdk.payment/package.json b/plugins/com.interswitchng.sdk.payment/package.json
index 880b52f..4f55cb4 100644
--- a/plugins/com.interswitchng.sdk.payment/package.json
+++ b/plugins/com.interswitchng.sdk.payment/package.json
@@ -1,5 +1,5 @@
{
- "name": "cordova-payment-plugin",
+ "name": "PaymentPlugin",
"version": "0.0.1",
"description": "Cordova Payment Plugin Powered by Interswitch",
"cordova": {
@@ -11,7 +11,7 @@
},
"repository": {
"type": "git",
- "url": "git+https://github.com/techquest/cordova-payment-plugin.git"
+ "url": "https://github.com/techquest/cordova-payment-plugin.git"
},
"files": [
"plugin.xml",
@@ -35,13 +35,5 @@
"license": "MIT",
"devDependencies": {
"jshint": "^2.6.0"
- },
- "bugs": {
- "url": "https://github.com/techquest/cordova-payment-plugin/issues"
- },
- "homepage": "https://github.com/techquest/cordova-payment-plugin#readme",
- "main": "index.js",
- "directories": {
- "test": "tests"
}
-}
+}
\ No newline at end of file
diff --git a/plugins/com.interswitchng.sdk.payment/src/android/PayWithOutUI.java b/plugins/com.interswitchng.sdk.payment/src/android/PayWithOutUI.java
index 133c3fd..cdbd17d 100644
--- a/plugins/com.interswitchng.sdk.payment/src/android/PayWithOutUI.java
+++ b/plugins/com.interswitchng.sdk.payment/src/android/PayWithOutUI.java
@@ -1,5 +1,14 @@
import android.app.Activity;
import android.content.Context;
+import android.webkit.WebView;
+import android.app.Dialog;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
+import android.view.Display;
+import android.view.LayoutInflater;
+import android.graphics.Point;
import com.interswitchng.sdk.model.RequestOptions;
import com.interswitchng.sdk.payment.IswCallback;
@@ -17,9 +26,16 @@
import com.interswitchng.sdk.payment.model.ValidateCardResponse;
import com.interswitchng.sdk.payment.model.WalletRequest;
import com.interswitchng.sdk.payment.model.WalletResponse;
+import com.interswitchng.sdk.payment.model.AuthorizePurchaseRequest;
+import com.interswitchng.sdk.payment.model.AuthorizePurchaseResponse;
+import com.interswitchng.sdk.payment.model.AuthorizeCardRequest;
+import com.interswitchng.sdk.payment.model.AuthorizeCardResponse;
+import com.interswitchng.sdk.payment.android.AuthorizeWebView;
+
import com.interswitchng.sdk.util.RandomString;
import com.interswitchng.sdk.util.StringUtils;
-
+import com.interswitchng.sdk.payment.model.Card;
+import org.apache.cordova.PluginResult;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
@@ -27,6 +43,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import com.google.gson.Gson;
public class PayWithOutUI extends CordovaPlugin{
private String clientId;
@@ -34,6 +51,7 @@ public class PayWithOutUI extends CordovaPlugin{
private WalletSDK sdk;
private Activity activity;
private Context context;
+ protected WebView webView;
private static RequestOptions options;
public PayWithOutUI(Activity activity, String clientId, String clientSecret ){
@@ -52,7 +70,7 @@ public void run() {
try {
options = RequestOptions.builder().setClientId(clientId).setClientSecret(clientSecret).build();
JSONObject params = args.getJSONObject(0);
- PurchaseRequest request = new PurchaseRequest(); // Setup request parameters
+ final PurchaseRequest request = new PurchaseRequest(); // Setup request parameters
request.setPan(params.getString("pan")); //Card No or Token
request.setAmount(params.getString("amount")); // Amount in Naira
request.setCvv2(params.getString("cvv"));
@@ -71,23 +89,100 @@ public void onError(Exception error) {
@Override
public void onSuccess(PurchaseResponse response) {
-
response.setCardType(type);
- if (StringUtils.hasText(response.getOtpTransactionIdentifier())) {
-
- PluginUtils.getPluginResult(callbackContext, response);
-
+ if (StringUtils.hasText(response.getResponseCode())) {
+ if (PaymentSDK.SAFE_TOKEN_RESPONSE_CODE.equals(response.getResponseCode())){
+ PluginResult result = null;
+ result = new PluginResult(PluginResult.Status.OK, getJsonObject(response,request));
+ result.setKeepCallback(true);
+ callbackContext.sendPluginResult(result);
+ }
+ else if(PaymentSDK.CARDINAL_RESPONSE_CODE.equals(response.getResponseCode())){
+ handleCardinal(response);
+ }
} else {
PluginUtils.getPluginResult(callbackContext, response);
}
}
+ private void handleCardinal(final PurchaseResponse response) {
+ final Context context = activity;
+ final Dialog cardinalDialog;
+ cardinalDialog = new Dialog(activity) {
+ @Override
+ public void onBackPressed() {
+ super.onBackPressed();
+ PluginUtils.getPluginResult(callbackContext, new RuntimeException("User cancelled operation"));
+ }
+ };
+ webView = new AuthorizeWebView(context, response) {
+ public void onPageDone() {
+ cardinalDialog.dismiss();
+ Util.showProgressDialog(context, "Processing...");
+ AuthorizePurchaseRequest cardinalRequest = new AuthorizePurchaseRequest();
+ cardinalRequest.setAuthData(request.getAuthData());
+ cardinalRequest.setPaymentId(response.getPaymentId());
+ cardinalRequest.setTransactionId(response.getTransactionId());
+ cardinalRequest.setEciFlag(response.getEciFlag());
+ new PaymentSDK(context, options).authorizePurchase(cardinalRequest, new IswCallback() {
+ @Override
+ public void onError(Exception error) {
+ Util.hideProgressDialog();
+ PluginUtils.getPluginResult(callbackContext, error.getMessage());
+ }
+
+ @Override
+ public void onSuccess(AuthorizePurchaseResponse response) {
+ Util.hideProgressDialog();
+ PluginUtils.getPluginResult(callbackContext, response);
+ }
+ });
+ }
+
+ public void onPageError(Exception error) {
+ // finish();
+ Util.hideProgressDialog();
+ cardinalDialog.dismiss();
+ PluginUtils.getPluginResult(callbackContext,error.getMessage());
+ //Util.notify(context, "Error", error.getMessage(), "Close", false);
+ }
+
+ };
+ cardinalDialog.setContentView(webView);
+ cardinalDialog.show();
+ cardinalDialog.setCancelable(true);
+ webView.requestFocus(View.FOCUS_DOWN);
+ webView.getSettings().setJavaScriptEnabled(true);
+ webView.setVerticalScrollBarEnabled(true);
+ WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
+ Display display = wm.getDefaultDisplay();
+ Point size = new Point();
+ display.getSize(size);
+ int width = size.x;
+ int height = size.y;
+ Window window = cardinalDialog.getWindow();
+ window.setLayout(width, height);
+ }
});
} catch (Exception ex) {
- callbackContext.error(ex.toString());
+ PluginUtils.getPluginResult(callbackContext,ex.getMessage());
}
}
});
}
+
+ private JSONObject getJsonObject(PurchaseResponse response, PurchaseRequest request) {
+ Gson gson = new Gson();
+ JSONObject jsonObject = null;
+ try{
+ jsonObject = new JSONObject(gson.toJson(response));
+ jsonObject.put("paymentId", response.getPaymentId());
+ jsonObject.put("authData",request.getAuthData());
+ }catch (JSONException jsonException){
+ jsonException.printStackTrace();
+ }
+ return jsonObject;
+ }
+
public void loadWallet(final String action, final CallbackContext callbackContext) throws JSONException {
context = activity;
activity.runOnUiThread(new Runnable() {
@@ -151,7 +246,10 @@ public void onError(Exception error) {
public void onSuccess(PurchaseResponse response) {
String transactionIdentifier = response.getTransactionIdentifier();
if (StringUtils.hasText(response.getOtpTransactionIdentifier())) {
+ //String otpTransactionIdentifier = response.getOtpTransactionIdentifier();
PluginUtils.getPluginResult(callbackContext, response);
+ /*String otpTransactionIdentifier = response.getOtpTransactionIdentifier();
+ Util.prompt(activity, "OTP", response.getMessage(), "Close", "Continue", true, 1L);*/
} else {
PluginUtils.getPluginResult(callbackContext, response);
}
@@ -170,7 +268,7 @@ public void run() {
try{
options = RequestOptions.builder().setClientId(clientId).setClientSecret(clientSecret).build();
JSONObject params = args.getJSONObject(0);
- ValidateCardRequest request = new ValidateCardRequest(); // Setup request parameters
+ final ValidateCardRequest request = new ValidateCardRequest(); // Setup request parameters
request.setPan(params.getString("pan")); //Card No or Token
request.setPinData(params.getString("pin")); // Optional Card PIN for card payment
request.setCvv2(params.getString("cvv"));
@@ -179,54 +277,144 @@ public void run() {
request.setCustomerId(params.getString("customerId"));
final Card card = new Card(request.getPan(), null, null, null);
final String type = card.getType();
+
new PaymentSDK(context, options).validateCard(request, new IswCallback() {
@Override
public void onError(Exception error) {
callbackContext.error(error.getMessage());
}
+
@Override
public void onSuccess(ValidateCardResponse response) {
- // Check if OTP is required.
response.setCardType(type);
- try {
- if (StringUtils.hasText(response.getOtpTransactionIdentifier())) {
- PluginUtils.getPluginResult(callbackContext, response);
+ if (StringUtils.hasText(response.getResponseCode())) {
+ if (PaymentSDK.SAFE_TOKEN_RESPONSE_CODE.equals(response.getResponseCode())){
+ PluginResult result = null;
+ result = new PluginResult(PluginResult.Status.OK, getJsonObject(response,request));
+ result.setKeepCallback(true);
+ callbackContext.sendPluginResult(result);
}
- else {
- PluginUtils.getPluginResult(callbackContext, response);
+ else if(PaymentSDK.CARDINAL_RESPONSE_CODE.equals(response.getResponseCode())){
+ handleCardinal(response);
}
- } catch (Exception ex) {
- callbackContext.error(ex.getMessage());
+ } else {
+ PluginUtils.getPluginResult(callbackContext, response);
}
}
+ private void handleCardinal(final ValidateCardResponse response) {
+ final Context context = activity;
+ final Dialog cardinalDialog;
+ cardinalDialog = new Dialog(activity) {
+ @Override
+ public void onBackPressed() {
+ super.onBackPressed();
+ PluginUtils.getPluginResult(callbackContext, new RuntimeException("User cancelled operation"));
+ }
+ };
+ webView = new AuthorizeWebView(context, response) {
+ public void onPageDone() {
+ cardinalDialog.dismiss();
+ Util.showProgressDialog(context, "Processing...");
+ AuthorizeCardRequest cardinalRequest = new AuthorizeCardRequest();
+ cardinalRequest.setAuthData(request.getAuthData());
+ cardinalRequest.setTransactionRef(response.getTransactionRef());
+ cardinalRequest.setTransactionId(response.getTransactionId());
+ cardinalRequest.setEciFlag(response.getEciFlag());
+ new PaymentSDK(context, options).authorizeCard(cardinalRequest, new IswCallback() {
+ @Override
+ public void onError(Exception error) {
+ Util.hideProgressDialog();
+ PluginUtils.getPluginResult(callbackContext, error.getMessage());
+ }
+
+ @Override
+ public void onSuccess(AuthorizeCardResponse response) {
+ Util.hideProgressDialog();
+ PluginUtils.getPluginResult(callbackContext, response);
+ }
+ });
+ }
+
+ public void onPageError(Exception error) {
+ // finish();
+ Util.hideProgressDialog();
+ cardinalDialog.dismiss();
+ PluginUtils.getPluginResult(callbackContext, error.getMessage());
+ //Util.notify(context, "Error", error.getMessage(), "Close", false);
+ }
+
+ };
+ cardinalDialog.setContentView(webView);
+ cardinalDialog.show();
+ cardinalDialog.setCancelable(true);
+ webView.requestFocus(View.FOCUS_DOWN);
+ webView.getSettings().setJavaScriptEnabled(true);
+ webView.setVerticalScrollBarEnabled(true);
+ WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
+ Display display = wm.getDefaultDisplay();
+ Point size = new Point();
+ display.getSize(size);
+ int width = size.x;
+ int height = size.y;
+ Window window = cardinalDialog.getWindow();
+ window.setLayout(width, height);
+ }
});
}
catch (Exception ex){
- callbackContext.error(ex.toString());
+ PluginUtils.getPluginResult(callbackContext, ex.toString());
+ }
+ }
+ });
+ }
+ public void authorizePurchase(final String action, final JSONArray args, final CallbackContext callbackContext){
+ context = activity.getApplicationContext();
+ activity.runOnUiThread(new Runnable() {
+ public void run() {
+ try {
+ options = RequestOptions.builder().setClientId(clientId).setClientSecret(clientSecret).build();
+ JSONObject params = args.getJSONObject(0);
+ AuthorizePurchaseRequest request = new AuthorizePurchaseRequest();
+ request.setPaymentId(params.getString("paymentId")); // Set the unique transaction reference.
+ request.setAuthData(params.getString("authData")); // Set the OTP identifier for the request
+ request.setOtp(params.getString("otp")); // Accept OTP from user
+ new PaymentSDK(context, options).authorizePurchase(request, new IswCallback() {
+ @Override
+ public void onError(Exception error) {
+ callbackContext.error(error.getMessage());
+ }
+
+ @Override
+ public void onSuccess(AuthorizePurchaseResponse authorizePurchaseResponse) {
+ PluginUtils.getPluginResult(callbackContext, authorizePurchaseResponse);
+ }
+ });
+ } catch (Exception error) {
+ PluginUtils.getPluginResult(callbackContext, error.toString());
}
}
});
}
- public void authorizeOtp(final String action, final JSONArray args, final CallbackContext callbackContext){
+ public void authorizeCard(final String action, final JSONArray args, final CallbackContext callbackContext){
context = activity.getApplicationContext();
activity.runOnUiThread(new Runnable() {
public void run() {
try {
options = RequestOptions.builder().setClientId(clientId).setClientSecret(clientSecret).build();
JSONObject params = args.getJSONObject(0);
- AuthorizeOtpRequest otpRequest = new AuthorizeOtpRequest();
- otpRequest.setOtp(params.getString("otp")); // Accept OTP from user
- otpRequest.setOtpTransactionIdentifier(params.getString("otpTransactionIdentifier")); // Set the OTP identifier for the request
- otpRequest.setTransactionRef(params.getString("transactionRef")); // Set the unique transaction reference.
- new PaymentSDK(context, options).authorizeOtp(otpRequest, new IswCallback() {
+ AuthorizeCardRequest request = new AuthorizeCardRequest();
+ request.setTransactionRef(params.getString("transactionRef"));
+ request.setAuthData(params.getString("authData")); // Set the OTP identifier for the request
+ request.setOtp(params.getString("otp")); // Accept OTP from user
+ new PaymentSDK(context, options).authorizeCard(request, new IswCallback() {
@Override
public void onError(Exception error) {
callbackContext.error(error.getMessage());
}
@Override
- public void onSuccess(AuthorizeOtpResponse otpResponse) {
- PluginUtils.getPluginResult(callbackContext, otpResponse);
+ public void onSuccess(AuthorizeCardResponse authorizeCardResponse) {
+ PluginUtils.getPluginResult(callbackContext, authorizeCardResponse);
}
});
} catch (Exception error) {
diff --git a/plugins/com.interswitchng.sdk.payment/src/android/PayWithUI.java b/plugins/com.interswitchng.sdk.payment/src/android/PayWithUI.java
index 3ca7608..1b0ece0 100644
--- a/plugins/com.interswitchng.sdk.payment/src/android/PayWithUI.java
+++ b/plugins/com.interswitchng.sdk.payment/src/android/PayWithUI.java
@@ -10,6 +10,8 @@
import com.interswitchng.sdk.payment.android.inapp.ValidateCard;
import com.interswitchng.sdk.payment.model.PurchaseResponse;
import com.interswitchng.sdk.payment.model.ValidateCardResponse;
+import com.interswitchng.sdk.payment.model.AuthorizeCardRequest;
+import com.interswitchng.sdk.payment.model.AuthorizeCardResponse;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
@@ -159,14 +161,14 @@ public void run() {
JSONObject params = args.getJSONObject(0);
String customerId = params.getString("customerId");
options = RequestOptions.builder().setClientId(clientId).setClientSecret(clientSecret).build();
- ValidateCard validateCard = new ValidateCard(activity, customerId, options, new IswCallback() {
+ ValidateCard validateCard = new ValidateCard(activity, customerId, options, new IswCallback() {
@Override
public void onError(Exception error) {
callbackContext.error(error.getMessage());
}
@Override
- public void onSuccess(ValidateCardResponse response) {
+ public void onSuccess(AuthorizeCardResponse response) {
PluginUtils.getPluginResult(callbackContext, response);
}
});
diff --git a/plugins/com.interswitchng.sdk.payment/src/android/PaymentPlugin.java b/plugins/com.interswitchng.sdk.payment/src/android/PaymentPlugin.java
index 67a813c..5530237 100644
--- a/plugins/com.interswitchng.sdk.payment/src/android/PaymentPlugin.java
+++ b/plugins/com.interswitchng.sdk.payment/src/android/PaymentPlugin.java
@@ -59,12 +59,26 @@ public void run() {
});
return true;
}
- else if(action.equals("AuthorizeOTP")){
+ else if(action.equals("AuthorizePurchase")){
cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
- payWithOutUI.authorizeOtp(action, args, callbackContext); //asyncronous call
+ payWithOutUI.authorizePurchase(action, args, callbackContext); //asyncronous call
+ } catch (Exception error) {
+ callbackContext.error(error.toString());
+ }
+ // Call the success function of the .js file
+ }
+ });
+ return true;
+ }
+ else if(action.equals("AuthorizeCard")){
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ payWithOutUI.authorizeCard(action, args, callbackContext); //asyncronous call
} catch (Exception error) {
callbackContext.error(error.toString());
}
@@ -301,9 +315,6 @@ private void init(JSONArray args, CallbackContext callbackContext) {
options = RequestOptions.builder().setClientId(this.clientId).setClientSecret(this.clientSecret).build();
//callbackContext.success("Initialization was successfull");
}
- else{
- //callbackContext.error("Invalid ClientId or Client Secret : ");
- }
}
}
catch (JSONException jsonException){
diff --git a/plugins/com.interswitchng.sdk.payment/tests/plugin.xml b/plugins/com.interswitchng.sdk.payment/tests/plugin.xml
index fa63d0f..1fd4ed7 100644
--- a/plugins/com.interswitchng.sdk.payment/tests/plugin.xml
+++ b/plugins/com.interswitchng.sdk.payment/tests/plugin.xml
@@ -1,5 +1,4 @@
-
-
-
Cordova Device Plugin Tests
Apache 2.0
-
-
+
\ No newline at end of file
diff --git a/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js b/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js
index ba61c6a..70451e4 100644
--- a/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js
+++ b/plugins/com.interswitchng.sdk.payment/www/PaymentPlugin.js
@@ -13,6 +13,8 @@ function paymentAction (action) {
}
var PaymentPlugin = {};
+PaymentPlugin.SAFE_TOKEN_RESPONSE_CODE = "T0";
+PaymentPlugin.CARDINAL_RESPONSE_CODE = "S0";
PaymentPlugin.init = paymentAction("Init");
// Using Payment SDK UI
@@ -27,7 +29,8 @@ PaymentPlugin.makePayment = paymentAction("MakePayment");
PaymentPlugin.loadWallet = paymentAction("LoadWallet");
PaymentPlugin.payWithWalletSDK = paymentAction("PayWithWalletSDK");
PaymentPlugin.validateCard = paymentAction("ValidateCard");
-PaymentPlugin.authorizeOtp = paymentAction("AuthorizeOTP");
+PaymentPlugin.authorizePurchase = paymentAction("AuthorizePurchase");
+PaymentPlugin.authorizeCard = paymentAction("AuthorizeCard");
PaymentPlugin.paymentStatus = paymentAction("PaymentStatus");
module.exports = PaymentPlugin;
diff --git a/www/app.js b/www/app.js
index 8c06a9a..578edf8 100644
--- a/www/app.js
+++ b/www/app.js
@@ -213,25 +213,36 @@ function init() {
SpinnerDialog.show("", "Please wait ...", null);
var makePaymentSuccess = function(response) {
+ var responseObject ={};
+ if(response.responseCode !== undefined){
+ responseObject = response;
+ }else if (response.responseCode === undefined){
+ responseObject = JSON.parse(response);
+ }
+ console.log(responseObject);
SpinnerDialog.hide();
- var responseObject = JSON.parse(response);
-
- if(responseObject.otpTransactionIdentifier) {
- var transactionIdentifier = responseObject.transactionIdentifier;
-
- ons.notification.prompt(responseObject.message).then(
+ if(responseObject.responseCode) {
+ if (responseObject.responseCode === "T0") {
+ ons.notification.prompt(responseObject.message).then(
function(otp) {
+ responseObject.method = "makePayment";
responseObject.otpValue = otp;
- authorizeOtp(responseObject);
+ authorizePurchase(responseObject);
}
);
- } else {
- alert(responseObject.message);
- }
+ }
+ } else {
+ //console.log(responseObject);
+ if(responseObject.detailMessage !== undefined && responseObject.detailMessage !== null ){
+ alert(responseObject.detailMessage);
+ }else{
+ alert(responseObject);
+ }
+ }
}
var makePaymentFail = function(response) {
SpinnerDialog.hide();
-
+ console.log(response);
alert(response);
}
@@ -280,15 +291,36 @@ function init() {
var validateCardSuccess = function(response) {
SpinnerDialog.hide();
- var validateCardResponse = JSON.parse(response);
+ console.log(response);
+ //var validateCardResponse = JSON.parse(response);
+ if(response.responseCode) {
+ if (response.responseCode === "T0") {
+ ons.notification.prompt(response.message).then(
+ function(otp) {
+ response.method = "validateCard";
+ response.otpValue = otp;
+ authorizePurchase(response);
+ }
+ );
+ }
+ else if (response.responseCode === "S0") {
- var token = validateCardResponse.token;
- var tokenExpiryDate = validateCardResponse.tokenExpiryDate;
- var balance = validateCardResponse.balance;
- var panLast4Digits = validateCardResponse.panLast4Digits;
- var cardType = validateCardResponse.cardType;
-
- alert("Card Validation was successful");
+ }
+ } else {
+ var responseObject = JSON.parse(response);
+ if(responseObject.message !== undefined){
+ alert(responseObject.message);
+ }else{
+ alert(response);
+ }
+ }
+ /*var token = response.token;
+ var tokenExpiryDate = response.tokenExpiryDate;
+ var balance = response.balance;
+ var panLast4Digits = response.panLast4Digits;
+ var cardType = response.cardType;
+ */
+ //alert("Card Validation was successful");
}
var validateCardFail = function(response) {
@@ -300,31 +332,37 @@ function init() {
}
- function authorizeOtp(results) {
+ function authorizePurchase(results) {
if(results !== null && results.otpValue && results.otpValue.length > 0){
SpinnerDialog.show("", "Verifying One Time Password ...", null);
- var authorizeOtpRequest = {
+ var authorizePurchaseRequest = {
otp : results.otpValue,
- otpTransactionIdentifier: results.otpTransactionIdentifier,
- transactionRef: results.transactionRef
+ paymentId: results.paymentId,
+ transactionRef: results.transactionRef,
+ authData: results.authData
}
- var authorizeOtpSuccess = function(response) {
- SpinnerDialog.hide();
-
+ var authorizePurchaseSuccess = function(response) {
+ SpinnerDialog.hide();
var responseObject = JSON.parse(response);
var theTransactionRef = responseObject.transactionRef;
-
- alert("Success: Approved by Financial Institution");
+ console.log(responseObject);
+ alert(theTransactionRef);
}
- var authorizeOtpFail = function(response) {
- SpinnerDialog.hide();
- alert("Payment failed");
+ var authorizePurchaseFail = function(response) {
+ SpinnerDialog.hide();
+ console.log(response);
+ alert(response);
+ }
+ if(results.method ==="makePayment"){
+ PaymentPlugin.authorizePurchase(authorizePurchaseRequest, authorizePurchaseSuccess, authorizePurchaseFail);
+ }
+ else if (results.method ==="validateCard"){
+ PaymentPlugin.authorizeCard(authorizePurchaseRequest, authorizePurchaseSuccess, authorizePurchaseFail);
}
- PaymentPlugin.authorizeOtp(authorizeOtpRequest, authorizeOtpSuccess, authorizeOtpFail);
} else {
alert("Invalid OTP value!");
}
diff --git a/www/index.html b/www/index.html
index 3c4f34d..acfd385 100644
--- a/www/index.html
+++ b/www/index.html
@@ -203,7 +203,7 @@
Interswitch Cordova NoUI
-
+