Google Wallet Integration Through Custom Widget In Vaadin6
I need to integrate Google wallet into my Vaadin 6 application, downloaded wallet api/demo from here. First I was trying to run this given sample into vaadin but after a long effor
Solution 1:
After spending some more hours at least I got this demo running in my Vaadin 6 app, although now I am getting some issue in my server generated JWT but this demo is working is now working.
Following are the changes in the code
script.js
functionbuy(){
google.payments.inapp.buy({
'jwt' : "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxMDk3OTc5MTY0NTUxNTM4MDY2OSIsImF1ZCI6Ikdvb2dsZSIsInR5cCI6Imdvb2dsZS9wYXltZW50cy9pbmFwcC9pdGVtL3YxIiwiaWF0IjoxMzg4NDcwMzM5LCJleHAiOjEzODg0NzAzOTksInJlcXVlc3QiOnsibmFtZSI6IkNsb3VkU3RyZWFtMTUiLCJkZXNjcmlwdGlvbiI6IkNsb3VkU3RyZWFtIE9uZSBtb250aCBwYWNrYWdlIGZvciAxNSB1c2VycyIsInByaWNlIjoiMjUwLjAwIiwiY3VycmVuY3lDb2RlIjoiVVNEIiwic2VsbGVyRGF0YSI6InVzZXJfaWQ6MTIyNDI0NSxvZmZlcl9jb2RlOjMwOTg1NzY5ODcsYWZmaWxpYXRlOmFrc2RmYm92dTlqIn19.JoUUTcVilz8nBSPjbCVuESi-QUS7fN6f9PeEseE7CSY",
'success' : function(status){if (window.console != undefined) {console.log("Purchase completed successfully: ", status);}},
'failure' : function(status){if (window.console != undefined) {console.log("Purchase failed ", status);}}
});
}
client side widget VGoogleWallet.java
package com.example.testing.client.ui;
import com.example.testing.client.ui.MessageJSNI;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
import com.google.gwt.dom.client.Document;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Widget;
/**
* Client side widget which communicates with the server. Messages from the
* server are shown as HTML and mouse clicks are sent to the server.
*/publicclassVGoogleWallet extends Widget implements Paintable, ClickHandler {
/** Set the CSS class name to allow styling. */publicstaticfinal String CLASSNAME = "v-googlewallet";
/** The client side widget identifier */protected String paintableId;
/** Reference to the server connection object. */protected ApplicationConnection client;
/**
* The constructor should first call super() to initialize the component and
* then handle any initialization relevant to Vaadin.
*/publicVGoogleWallet(){
// TODO This example code is extending the GWT Widget class so it must set a root element.// Change to a proper element or remove this line if extending another widget.setElement(Document.get().createDivElement());
// This method call of the Paintable interface sets the component// style name in DOM tree"setStyleName(CLASSNAME);
}
/**
* Called whenever an update is received from the server
*/publicvoidupdateFromUIDL(UIDL uidl, ApplicationConnection client){
// This call should be made first. // It handles sizes, captions, tooltips, etc. automatically.if (client.updateComponent(this, uidl, true)) {
// If client.updateComponent returns true there has been no changes and we// do not need to update anything.return;
}
// Save reference to server connection object to be able to send// user interaction laterthis.client = client;
// Save the client side identifier (paintable id) for the widget
paintableId = uidl.getId();
MessageJSNI.buy();
}
}
TestingWidgetset.gwt.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE modulePUBLIC"-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN""http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd"><module><inheritsname="com.vaadin.terminal.gwt.DefaultWidgetSet" /><scriptsrc="script.js"></script><scriptsrc="https://sandbox.google.com/checkout/inapp/lib/buy.js"></script><!--
Uncomment the following to compile the widgetset for one browser only.
This can reduce the GWT compilation time significantly when debugging.
The line should be commented out before deployment to production
environments.
Multiple browsers can be specified for GWT 1.7 as a comma separated
list. The supported user agents at the moment of writing were:
ie6,ie8,gecko,gecko1_8,safari,opera
The value gecko1_8 is used for Firefox 3 and later and safari is used for
webkit based browsers including Google Chrome.
--><!-- <set-property name="user.agent" value="gecko1_8"/> --><!--
To enable SuperDevMode, uncomment this line and use the
Super Dev Mode for Vaadin 6 add-on.
SuperDevMode enables debugging of the client side of a Vaadin
application using the JavaScript debugger of a browser. Java code is
shown and debugging can take place on the Java level when using a browser
that support source maps (currently Chrome, implementation under work
for Firefox).
See https://vaadin.com/directory#addon/super-dev-mode-for-vaadin-6 for
more information and instructions.
--><!-- <set-configuration-property name="devModeRedirectEnabled" value="true" /> --></module>
MessageJSNI.java
package com.example.testing.client.ui;
publicclassMessageJSNI {
protectedMessageJSNI() {
}
public native staticvoidbuy()/*-{
$wnd.buy();
}-*/;
}
Post a Comment for "Google Wallet Integration Through Custom Widget In Vaadin6"