Skip to content

Commit

Permalink
Readme's were updated to reflect the latest changes in Cordova.
Browse files Browse the repository at this point in the history
The Android plugin was updated to use the CordovaPlugin class.
  • Loading branch information
azicchetti committed Apr 11, 2013
1 parent 57498b6 commit 3c520a2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 33 deletions.
28 changes: 18 additions & 10 deletions Android/README
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@ in a phonegap/android application.
At the moment, only the "Method Sequence with the PayPal Button on Your Mobile Webpage"
is supported by the plugin (and this shouldn't be a big deal).

This plugin has been successfully tested with Cordova 2.6.0.
Hopefully it will also work with newer releases.


Adding the plugin to your project
=================================
Using this plugin requires Android PhoneGap/Cordova. Please refer to the PhoneGap
documentation to learn how to setup a new project ( http://docs.phonegap.com/en/2.0.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android ).
documentation to learn how to setup a new project ( http://docs.phonegap.com/en/2.6.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android ).

*** Please note that the PayPal MECL library requires internet access to contact
PayPal servers, therefore you must have
PayPal servers and the permission to get the device id, therefore you must have:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

in your project AndroidManifest.xml ***


1. To install the plugin, move www/js/MECLPayPalPlugin.js somewhere in your www folder
and include a reference to it in your html file, after cordova-VERSION.js.

<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8" src="path/to/cordova-2.6.0.js"></script>
<script type="text/javascript" charset="utf-8" src="path/to/MECLPayPalPlugin.js"></script>

2. Create a directory within your project called "src/com/phonegap/plugins/paypal" and move
Expand All @@ -30,7 +34,7 @@ the following java files into it:
src/com/phonegap/plugins/paypal/MECLBridge.java
src/com/phonegap/plugins/paypal/ResultDelegate.java

3. In your res/xml/plugins.xml file add the following line before the final </plugin> tag:
3. In your res/xml/config.xml file add the following line before the final </plugins> tag:

<plugin name="MECLPayPalPlugin" value="com.phonegap.plugins.paypal.MECLPayPalPlugin"/>

Expand All @@ -57,14 +61,15 @@ The plugin creates the window.plugins.meclPayPal object, with the following me

fetchDeviceReferenceTokenWithAppID(callback)

The callback argument is a function that takes a single argument:
The callback argument is a function that takes a single argument, for example:

function meclCallback(deviceToken){
...
}

The deviceToken argument can be the device reference token string returned by PayPal servers
or null if something went wrong.
The deviceToken argument can be:
* the device reference token string returned by PayPal servers
* null, if something went wrong.

As you have noticed, at the moment the only MECL API that's exposed to javascript by the plugin is:

Expand All @@ -77,14 +82,16 @@ You're encouraged to read the official documentation:
to fully understand how this API works.

It's worth noticing that the java code of this plugin uses some default settings that must be
changed before deploying and after submitting your app to PayPal.
changed before deploying and after submitting your app to PayPal and the Apple Store / Google Play.

These are:

Application ID: your live appID is sent by PayPal after their review of your application

Server: ENV_SANDBOX is the default setting of the plugin. Must be changed to ENV_LIVE
before going to production


To change these values, just open the

src/com/phonegap/plugins/paypal/MECLBridge.java
Expand All @@ -111,9 +118,10 @@ remember that you can find a lot of examples on www.x.com,
To sum it up in some basic steps:

* your app gets a device token
* your app opens a webview (with the childbrowser plugin) to a certain url
* your app opens a webview (with the InAppBrowser Cordova API) to a certain url
on YOUR backend server, providing the token and the "cart" info
* your app installs an handler on the webview location change event
* your app installs an handler on the webview location change event (this is
the "loadstop" event in the InAppBrowser documentation)
* your backend server calls SetExpressCheckout and gets the checkout token
* your backend server redirects to www.paypal.com and provides both the device
and the checkout token
Expand Down
25 changes: 15 additions & 10 deletions Android/src/com/phonegap/plugins/paypal/MECLPayPalPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,41 @@
import org.json.JSONArray;
import android.util.Log;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.apache.cordova.api.PluginResult.Status;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;

/**
* @author Andrea Zicchetti
*
*/
public class MECLPayPalPlugin extends Plugin {
public class MECLPayPalPlugin extends CordovaPlugin {
private static MECLBridge mecl;
private static MECLPayPalPlugin _instance;
private static CallbackContext _callbackContext;

@Override
public PluginResult execute(String action, JSONArray data, String callbackId) {
PluginResult result=null;
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
_instance=this;
_callbackContext=callbackContext;

try{
if (action.equals("fetchDeviceReferenceTokenWithAppID")){
mecl = new MECLBridge(cordova.getActivity().getApplicationContext());
mecl.initialize();
result = new PluginResult(Status.OK);
return true;
}
} catch (Exception e){
Log.d("MECLPayPalPlugin", "Got JSON Exception "+ e.getMessage());
result = new PluginResult(Status.JSON_EXCEPTION);
}
return result;
return false;
}

public static Plugin getInstance(){ return _instance; }
public static CordovaPlugin getInstance(){
return _instance;
}

public static CallbackContext getCallbackContext() {
return _callbackContext;
}

}
12 changes: 7 additions & 5 deletions Android/src/com/phonegap/plugins/paypal/ResultDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

import java.io.Serializable;

import android.util.Log;

import com.paypal.android.MECL.PayPalListener;

public class ResultDelegate implements PayPalListener, Serializable {

@Override
public void couldNotFetchDeviceReferenceToken() {
MECLPayPalPlugin.getInstance()
.sendJavascript("window.plugins.meclPayPal._callback(null);");
Log.d("MECLPayPalPlugin", "couldNotFetchDeviceReferenceToken");
MECLPayPalPlugin.getCallbackContext().error("couldNotFetchDeviceReferenceToken");
}


@Override
public void receivedDeviceReferenceToken(String token) {
MECLPayPalPlugin.getInstance()
.sendJavascript("window.plugins.meclPayPal._callback('"+token+"');");

Log.d("MECLPayPalPlugin", "Got token: "+token);
MECLPayPalPlugin.getCallbackContext().success(token);
}

}
7 changes: 5 additions & 2 deletions Android/www/js/MECLPayPalPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
function MECLPayPal() {};

MECLPayPal.prototype.fetchDeviceReferenceTokenWithAppID=function(callback){
window.plugins.meclPayPal._callback=callback;
cordova.exec(null,null,"MECLPayPalPlugin","fetchDeviceReferenceTokenWithAppID",[]);
cordova.exec(function(message){
callback(message); // the token
},function(error){
callback(null); // fail
}, "MECLPayPalPlugin", "fetchDeviceReferenceTokenWithAppID", []);
}

if (!window.plugins) window.plugins={};
Expand Down
12 changes: 8 additions & 4 deletions README
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
This plugin lets you use the PayPal Mobile Express Checkout Library (MECL)
in a phonegap/cordova application.
in a Phonegap/Cordova application.
This should not be confused with the Mobile Payment Libraries (MPL), for which
there's another cordova plugin available.

This plugin has been successfully tested with Cordova 2.6.0.
Hopefully it will also work with newer releases.


What's this MECL thing?
========================
Quoting the official documentation:

Mobile Express Checkout Library (MECL): If you want the PayPal checkout flow to be in a browser or webview, you can use our Mobile Express Checkout Library. This is useful if you already have a express checkout integration completed for your website or if app store policies require you to complete your checkout flow in a browser. This library will help you integrate the mobile web flow into your app.

These are the key features and benefits of the MECL library:
These are the key features and benefits of the MECL library provided by PayPal:
* In-app payments
* Quick integration
* Credit card checkout (no PayPal account needed)
* Supports auth/settle payments
* Supports Recurring Payments

In order to successfully exploit the Express Checkout flow, you should use
the ChildBrowser plugin in conjunction with this one.
In order to successfully exploit the Express Checkout flow, you can use
the InAppBrowser API provided by Cordova in conjunction with this plugin.

The MECLPayPalPlugin comes in two flavors: iOS and Android.

Expand Down
5 changes: 3 additions & 2 deletions iOS/README
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ remember that you can find a lot of examples on www.x.com,
To sum it up in some basic steps:

* your app gets a device token
* your app opens a webview (with the childbrowser plugin) to a certain url
* your app opens a webview (with the InAppBrowser Cordova API) to a certain url
on YOUR backend server, providing the token and the "cart" info
* your app installs an handler on the webview location change event
* your app installs an handler on the webview location change event (this is
the "loadstop" event in the InAppBrowser documentation)
* your backend server calls SetExpressCheckout and gets the checkout token
* your backend server redirects to www.paypal.com and provides both the device
and the checkout token
Expand Down

0 comments on commit 3c520a2

Please sign in to comment.