Permalink
Browse files

Merge pull request #34 from shazron/android-paypal-plugin

Android paypal plugin
  • Loading branch information...
2 parents f9bd1ea + 7ca586f commit 82eff0ab1d49a3799ac0d732b8ff62bcfd40c166 @shazron shazron committed Jun 21, 2011
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.phonegap.plugin" android:versionCode="1"
+ android:versionName="1.0">
+
+
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+
+ <application android:debuggable="true" android:icon="@drawable/icon"
+ android:label="@string/app_name">
+ <activity android:configChanges="orientation|keyboardHidden"
+ android:name=".pppactivity" android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name="com.paypal.android.MEP.PayPalActivity"
+ android:theme="@android:style/Theme.Translucent.NoTitleBar"
+ android:configChanges="keyboardHidden|orientation" />
+
+ </application>
+ <uses-sdk android:minSdkVersion="2" />
+
+</manifest>
@@ -0,0 +1,23 @@
+The MIT License
+*****************
+
+Copyright (C) 2011 Mobile Developer Solutions
+Copyright (C) 2011, Appception, Inc.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
+# PhoneGap PayPal-Plugin #
+by Paul Beusterien, Mobile Developer Solutions and Carl Stehle, Appception Inc.
+
+
+## Adding the Plugin to your project ##
+
+Using this plugin requires Android PhoneGap and the PayPal Mobile Payments Library. The PayPal Mobile Payments Library can be downloaded [here](https://www.x.com/community/ppx/xspaces/mobile/mep).
+
+1. Create an Android PhoneGap project. Details at http://www.mobiledevelopersolutions.com/home/start
+2. Put PayPal_MPL.jar into your project's libs directory and add it to the build path. In Eclipse, right click on PayPal_MPL.jar and select Add to Build Path.
+3. Copy assets/www/ files into your project's assets/www/ directory
+4. Copy src/com/phonegap/plugin/ files into your project's src/com/phonegap/plugin/ directory
+5. Make sure your AndroidManifest.xml includes a superset of the permissions shown in the reference AndroidManifest.xml
+6. Add the com.paypal.android.MEP.PayPalActivity as shown in the reference AndroidManifest.xml
+7. Make sure the phonegap.{version}.js filename in index.html matches the filename in your www directory.
+8. Deploy and test the app. The default environment is ENV_NONE.
+
+## Using the PayPal Sandbox ##
+
+1. Set up a PayPal buyer and seller sandbox account from https://developer.paypal.com/
+2. Update demo.js to use ENV_SANDBOX instead of ENV_NONE. See comments near bottom of demo.js
+3. In index.html, update the pmt_recipient field to your sandbox seller account
+
+
+## RELEASE NOTES ##
+
+### 201100618 ###
+* Initial release
+* By default the PayPalPlugin-Host runs in ENV_NONE (offline) with a dummy PayPal ID. Change to ENV_SANDBOX or ENV_LIVE
+* Only tested with ENV_NONE and ENV_SANDBOX
+* The default payment type is HARD_GOODS. Change initializeMPL method in demo.js to one of the PayPalPaymentType's listed at the bottom of paypal.js
+* For API docs, see the assets/www/paypal.js. For sample code, see assets/www/demo.js and assets/www/index.html.
+
+## BUGS AND CONTRIBUTIONS ##
+
+Patches welcome! Send a pull request. Since this is not a part of PhoneGap Core (which requires a CLA), this should be easier.
+
+Post issues in the [PhoneGap Google Groups](http://groups.google.com/group/phonegap), include in the subject heading - "PayPalPlugin" or on [Github](http://github.com/phonegap/phonegap-plugins/issues)
+(preferred)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,186 @@
+/* PayPal PhoneGap Plugin - Demonstration JavaScript control
+*
+* Copyright (C) 2011, Appception, Inc.. All Rights Reserved.
+* Copyright (C) 2011, Mobile Developer Solutions All Rights Reserved.
+*/
+
+function isOpen(id) {
+ return document.getElementById(id).style.display === '' ? 1 : 0;
+}
+function setOpen(id) {
+ document.getElementById(id).style.display = '';
+}
+function setClosed(id) {
+ document.getElementById(id).style.display = 'none';
+}
+
+function runDemo() {
+ setClosed('pmt_container');
+ setClosed('pmt_show_initialize');
+ setClosed('pmt_show_loading');
+ setClosed('pmt_show_details');
+ setClosed('pmt_show_details_form');
+ setClosed('pmt_show_buttons');
+ setClosed('pmt_results');
+
+ setOpen('pmt_container');
+ setOpen('pmt_show_initialize');
+ return false;
+}
+
+function showDemoDetails() {
+ if (isOpen('pmt_details')) {
+ setClosed('pmt_details');
+ } else {
+ setOpen('pmt_details');
+ }
+}
+
+var getStatusTimeout = null;
+function pollStatus() {
+ mpl.getStatus();
+ getStatusTimeout = setTimeout(pollStatus, 1000);
+}
+
+var getStatusCallback = function(r) { // for the PhoneGap callback's asynchronous call
+ if (r.str === '1') {
+ clearTimeout(getStatusTimeout);
+ setClosed('pmt_show_loading');
+ setClosed('pmt_show_initialize');
+ setOpen('pmt_show_details');
+ }
+};
+
+var start_time;
+
+// JavaScript MPL library
+function initializeMPL() {
+
+ // Show loading image while waiting for initialization
+ setOpen('pmt_show_loading');
+
+ mpl.prepare(PayPalPaymentType.HARD_GOODS);
+
+ start_time = new Date().getTime();
+ pollStatus();
+}
+
+function closePaymentInfoForm() {
+ setClosed('pmt_show_details');
+ setClosed('pmt_show_details_form');
+ setOpen('pmt_show_buttons');
+ return false;
+}
+
+function submitPaymentInfo(obj) {
+ var str;
+ obj.ipnUrl = 'http://127.0.0.1';
+ obj.customID = '123';
+
+ str = JSON.stringify(obj);
+
+ // Call (with JSON arg)
+ mpl.setPaymentInfo(str);
+ return false;
+}
+
+function setPaymentInfoForm() {
+ var obj = {};
+
+ obj.paymentAmount = document.getElementById('pmt_subtotal').value;
+ obj.paymentCurrency = document.getElementById('pmt_currency').value;
+ obj.recipient = document.getElementById('pmt_recipient').value;
+ obj.merchantName = document.getElementById('pmt_merchant').value;
+ obj.itemDesc = document.getElementById('pmt_description').value;
+ obj.memo = document.getElementById('pmt_memo').value;
+ obj.tax = document.getElementById('pmt_tax').value;
+ obj.shipping = document.getElementById('pmt_shipping').value;
+
+ closePaymentInfoForm();
+
+ submitPaymentInfo(obj);
+ return false;
+}
+
+function showPaymentInfoForm() {
+ if (isOpen('pmt_show_details_form')) {
+ closePaymentInfoForm();
+ } else {
+ setOpen('pmt_show_details_form');
+ }
+}
+
+function payButton(btype) {
+ mpl.payButton(btype);
+}
+
+var displayPaymentResults = function(str) {
+ var obj = JSON.parse(str);
+ var ostr = obj.result_info;
+ ostr += '<br>';
+ ostr += obj.result_title;
+ ostr += '<br>';
+ ostr += obj.result_extra;
+ ostr += '<br>';
+ document.getElementById('pmt_results').innerHTML = ostr;
+
+ setOpen('pmt_results');
+};
+
+function onPaymentSuccess(evt)
+{
+ displayPaymentResults(evt.result);
+}
+
+function onPaymentCanceled(evt)
+{
+ navigator.notification.alert("Payment canceled.");
+ displayPaymentResults(evt.result);
+}
+
+function onPaymentFailed(evt)
+{
+ navigator.notification.alert("Payment failed, errorType: " + evt.errorType);
+ displayPaymentResults(evt.result);
+ // compare evt.errorType to PayPalFailureType enum values
+}
+
+/*
+ * When this function is called, PhoneGap has been initialized and is ready to roll
+ */
+function onDeviceReady() {
+ try {
+
+ // set up PayPal payment event callbacks
+
+ document.addEventListener(PaypalPaymentEvent.Success, onPaymentSuccess,
+ false);
+ document.addEventListener(PaypalPaymentEvent.Canceled,
+ onPaymentCanceled, false);
+ document.addEventListener(PaypalPaymentEvent.Failed, onPaymentFailed,
+ false);
+
+ // Construct the JavaScript MPL library
+ // Specify The PayPal server to be used - can also be ENV_NONE, ENV_SANDBOX or ENV_LIVE
+ // Specify the appId like "APP-80W284485P519543T" (can be empty string for ENV_NONE)
+
+ var obj = {
+ server : 'ENV_NONE',
+ appId : ''
+ };
+// var obj = {
+// server : 'ENV_SANDBOX',
+// appId : 'APP-80W284485P519543T'
+// };
+
+ mpl.construct(JSON.stringify(obj));
+
+ } catch (e) {
+ debug.error(e);
+ }
+}
+
+function onBodyLoad()
+{
+ document.addEventListener("deviceready", onDeviceReady,false);
+}
Oops, something went wrong.

0 comments on commit 82eff0a

Please sign in to comment.