mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-01-09 15:48:00 -05:00
Merge pull request #1199 from cubettech/master
Card.io phonegap plugin for android, by cubet technologies
This commit is contained in:
7
Android/README.md
Normal file
7
Android/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
Phonegap Plugins For Android
|
||||
----------------------------
|
||||
|
||||
Phonegap plugins for android platform, developed by cubet technologies
|
||||
|
||||
http://www.cubettechnologies.com
|
||||
41
Android/card.io/CardIOPGPlugin.js
Executable file
41
Android/card.io/CardIOPGPlugin.js
Executable file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* CardIOPGPlugin.js
|
||||
* card.io phonegap plugin
|
||||
* @Copyright 2013 Cubet Technologies http://www.cubettechnologies.com
|
||||
* @author Robin <robin@cubettech.com>
|
||||
* @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
|
||||
91
Android/card.io/com/cubettech/plugins/cardio/CardIOMain.java
Normal file
91
Android/card.io/com/cubettech/plugins/cardio/CardIOMain.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* CardIOPGPlugin.js
|
||||
* card.io phonegap plugin
|
||||
* @Copyright 2013 Cubet Technologies http://www.cubettechnologies.com
|
||||
* @author Robin <robin@cubettech.com>
|
||||
* @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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* CardIOPGPlugin.js
|
||||
* card.io phonegap plugin
|
||||
* @Copyright 2013 Cubet Technologies http://www.cubettechnologies.com
|
||||
* @author Robin <robin@cubettech.com>
|
||||
* @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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
68
Android/card.io/readme.md
Normal file
68
Android/card.io/readme.md
Normal file
@@ -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.
|
||||
|
||||
``` <plugin name="CardIOPGPlugin" value="com.cubettech.plugins.cardio.CardIOPGPlugin"/>```
|
||||
|
||||
* Add activity entry in `AndroidManifext.xml`
|
||||
|
||||
``` <activity android:name="com.cubettech.plugins.cardio.CardIOMain" />```
|
||||
|
||||
* 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. `<script type="text/javascript" charset="utf-8" src="CardIOPGPlugin.js"></script>` to your html.
|
||||
* In `config.xml`, add an entry to `ExternalHosts` with value `*.card.io`, ignore this if you have set `<access origin=".*"/>`.
|
||||
* 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
|
||||
<h1>Scan Example</h1>
|
||||
<p><button id='scanBtn'>Scan now</button></p>
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
//Your response array contain these fields
|
||||
// redacted_card_number, card_number, expiry_month,expiry_year, cvv, zip
|
||||
|
||||
var onCardIOComplete = function(response) {
|
||||
console.log("card.io scan completed");
|
||||
console.log(JSON.stringify(response));
|
||||
|
||||
};
|
||||
|
||||
var onCardIOCancel = function() {
|
||||
console.log("card.io scan cancelled");
|
||||
};
|
||||
|
||||
$('#scanBtn').click(function() {
|
||||
window.plugins.CardIOPGPlugin.scan(onCardIOComplete, onCardIOCancel);
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
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`.
|
||||
Reference in New Issue
Block a user