diff --git a/Android/README.md b/Android/README.md new file mode 100644 index 00000000..8b19498e --- /dev/null +++ b/Android/README.md @@ -0,0 +1,7 @@ + +Phonegap Plugins For Android +---------------------------- + +Phonegap plugins for android platform, developed by cubet technologies + +http://www.cubettechnologies.com diff --git a/Android/card.io/CardIOPGPlugin.js b/Android/card.io/CardIOPGPlugin.js new file mode 100755 index 00000000..d932a173 --- /dev/null +++ b/Android/card.io/CardIOPGPlugin.js @@ -0,0 +1,41 @@ +/** + * CardIOPGPlugin.js + * card.io phonegap plugin + * @Copyright 2013 Cubet Technologies http://www.cubettechnologies.com + * @author Robin + * @Since 28 June, 2013 + */ + +//Your response array contain these fields +// redacted_card_number, card_number, expiry_month,expiry_year, cvv, zip + +//set your configurations here +var cardIOConfig = { + 'apiKey': 'YOUR_API_KEY_HERE', + 'expiry': true, + 'cvv': true, + 'zip':false, +}; + + +var CardIOPGPlugin = function() {}; + +CardIOPGPlugin.prototype.scan = function(success, fail) { + return cordova.exec(function(args) { + console.log("card.io scanning completed"); + success(args[0]); + }, function(args) { + console.log("card.io scanning Failed"); + fail(args); + }, "CardIOPGPlugin", "execute", [cardIOConfig]); +}; + +if(!window.plugins) { + window.plugins = {}; +} +if (!window.plugins.CardIOPGPlugin) { + window.plugins.CardIOPGPlugin = new CardIOPGPlugin(); +} + + +//EOF diff --git a/Android/card.io/com/cubettech/plugins/cardio/CardIOMain.java b/Android/card.io/com/cubettech/plugins/cardio/CardIOMain.java new file mode 100644 index 00000000..8e8a7895 --- /dev/null +++ b/Android/card.io/com/cubettech/plugins/cardio/CardIOMain.java @@ -0,0 +1,91 @@ +/** + * CardIOPGPlugin.js + * card.io phonegap plugin + * @Copyright 2013 Cubet Technologies http://www.cubettechnologies.com + * @author Robin + * @Since 28 June, 2013 + */ + +package com.cubettech.plugins.cardio; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.cubet.pixsellit.R; + +import io.card.payment.CardIOActivity; +import io.card.payment.CreditCard; +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; + +public class CardIOMain extends Activity { + + private static int MY_SCAN_REQUEST_CODE=10; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + // TODO Auto-generated method stub + Intent scanIntent = new Intent(CardIOMain.this, CardIOActivity.class); + + // required for authentication with card.io + scanIntent.putExtra(CardIOActivity.EXTRA_APP_TOKEN, CardIOPGPlugin.cardIOAPIKey); + + // customize these values to suit your needs. + scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, CardIOPGPlugin.expiry); + scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, CardIOPGPlugin.cvv); + scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_ZIP, CardIOPGPlugin.zip); + + // MY_SCAN_REQUEST_CODE is arbitrary and is only used within this activity. + startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE); + } + + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == MY_SCAN_REQUEST_CODE) { + + if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) { + + CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT); + + // Never log a raw card number. Avoid displaying it, but if necessary use redacted number + JSONArray carddata = new JSONArray(); + JSONObject j = new JSONObject(); + + try { + j.put("card_number",scanResult.cardNumber); + j.put("redacted_card_number", scanResult.getFormattedCardNumber()); + if (scanResult.isExpiryValid()) { + j.put("expiry_month",scanResult.expiryMonth); + j.put("expiry_year",scanResult.expiryYear); + } + + if (scanResult.cvv != null) { + j.put("cvv",scanResult.cvv); + + } + + if (scanResult.zip != null) { + j.put("zip",scanResult.zip); + } + + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + carddata.put(j); + CardIOPGPlugin.mCreditcardNumber = carddata; + } + } + CardIOMain.this.finish(); + } + +} diff --git a/Android/card.io/com/cubettech/plugins/cardio/CardIOPGPlugin.java b/Android/card.io/com/cubettech/plugins/cardio/CardIOPGPlugin.java new file mode 100644 index 00000000..f6cb69ff --- /dev/null +++ b/Android/card.io/com/cubettech/plugins/cardio/CardIOPGPlugin.java @@ -0,0 +1,86 @@ +/** + * CardIOPGPlugin.js + * card.io phonegap plugin + * @Copyright 2013 Cubet Technologies http://www.cubettechnologies.com + * @author Robin + * @Since 28 June, 2013 + */ + +package com.cubettech.plugins.cardio; + +import io.card.payment.CardIOActivity; + +import org.apache.cordova.api.CallbackContext; +import org.apache.cordova.api.CordovaPlugin; +import org.apache.cordova.api.PluginResult; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + + +import android.content.Intent; + + +@SuppressWarnings("deprecation") +public class CardIOPGPlugin extends CordovaPlugin { + + public CallbackContext callbackContext; + public static JSONArray mCreditcardNumber=null; + public static String cardIOAPIKey; + public static Boolean expiry; + public static Boolean cvv; + public static Boolean zip; + + + @Override + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { + // TODO Auto-generated method stub + this.callbackContext = callbackContext; + + try { + //set configurations + JSONObject config = args.getJSONObject(0); + cardIOAPIKey = config.getString("apiKey"); + expiry = config.getBoolean("expiry"); + cvv = config.getBoolean("cvv"); + zip = config.getBoolean("zip"); + + Intent scanIntent = new Intent(cordova.getActivity(), CardIOMain.class); + cordova.getActivity().startActivity(scanIntent); + + PluginResult cardData = new PluginResult(PluginResult.Status.NO_RESULT); + cardData.setKeepCallback(true); + callbackContext.sendPluginResult(cardData); + return true; + + } catch (JSONException e) { + PluginResult res = new PluginResult(PluginResult.Status.JSON_EXCEPTION); + callbackContext.sendPluginResult(res); + return false; + } + + + + } + + @Override + public void onResume(boolean multitasking) { + // TODO Auto-generated method stub + super.onResume(multitasking); + + //send plugin result if success + JSONArray mImagepath = mCreditcardNumber; + if(mImagepath!=null) + { + PluginResult cardData = new PluginResult(PluginResult.Status.OK, mCreditcardNumber); + cardData.setKeepCallback(false); + callbackContext.sendPluginResult(cardData); + mCreditcardNumber = null; + } else { + PluginResult cardData = new PluginResult(PluginResult.Status.NO_RESULT); + cardData.setKeepCallback(false); + callbackContext.sendPluginResult(cardData); + } + + } +} diff --git a/Android/card.io/readme.md b/Android/card.io/readme.md new file mode 100644 index 00000000..e72264cb --- /dev/null +++ b/Android/card.io/readme.md @@ -0,0 +1,68 @@ +Card.io android plug-in for PhoneGap +--------------------------------- + +This plug-in exposes card.io's credit card scanning. (card.io also supports charging cards; that is not yet supported in this plug-in.) + + +Integration instructions +------------------------ + +* Add the card.io library: + * Sign up for an account at https://www.card.io/, create an app, and take note of your `app_token`. + * Download the Android SDK at https://www.card.io/integrate/android. + * Follow the instructions there to add the requisite classes, jars to your project. + +* Add this plug-in: + + * Register the plugin in the `res/xml/config.xml` file. + + ``` ``` + + * Add activity entry in `AndroidManifext.xml` + + ``` ``` + + * Add the package `com.cubettech.plugins.cardio` to your project's `src` folder. i.e, simply copy the `com` folder in your `src` directory + * Copy `CardIOPGPlugin.js` to your project's www folder. + * Add e.g. `` to your html. + * In `config.xml`, add an entry to `ExternalHosts` with value `*.card.io`, ignore this if you have set ``. + * See `CardIOPGPlugin.js` for detailed usage information. + * Sample `scan` usage: `window.plugins.CardIOPGPlugin.scan(onCardIOComplete, onCardIOCancel);` + * Your required fields & API key can be configure by modifying the array `cardIOConfig` in `CardIOPGPlugin.js` + +### Sample HTML + JS + +```html +

Scan Example

+

+ +``` + +License +------- +* This plug-in is released under the MIT license: http://www.opensource.org/licenses/MIT + +Notes +----- +* Generic Phone Gap plug-in installation instructions are available at https://build.phonegap.com/docs/plugins-using + +Questions? Contact `info@cubettech.com`.