I’m trying to follow this simple examples given in the google web store API docs.
Unfortunately their minimal PHP example contains a lot of stuff I dont need (and dont have setup).
So I’m looking at hardcoding the basic stuff into the HTML file, just to get communication with the google servers working:
My code looks like this:
<html>
<head>
</head>
<body>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
purchase = function() { console.log("Old purchase function"); }
generatedJwt = "..."; // I use a real JWT here....
google.load('payments', '1.0', {
'packages': ['sandbox_config'],
callback: function()
{
//Success handler
var successHandler = function(purchaseAction){
if (window.console != undefined) {
console.log("Purchase completed successfully.",purchaseAction);
}
}
//Failure handler
var failureHandler = function(purchaseActionError)
{
if (window.console != undefined)
{
console.log("Purchase did not complete.", purchaseActionError);
}
}
var purchase = function()
{
goog.payments.inapp.buy({
'jwt' : generatedJwt,
'success' : successHandler,
'failure' : failureHandler
});
}
}
});
</script>
<button class="buy-button" id="buybutton1" name="buy" type="button" onClick="purchase()">
Buy
</button>
</body>
When I click on the buy button I get an error message pop up from google, and the following error in the console:
Unsafe JavaScript attempt to access frame with URL
http://localhost/google_iap/buy_page.html
from frame with URL
https://sandbox.google.com/checkout/inapp/static/gwt/payments.html?viewportScreenCenterX=-857.5&viewportScreenCenterY=611#id=I1_1324454042050&parent=http%3A%2F%2Flocalhost&rpctoken=166967692&_methods=onPurchaseActionStatus%2CgetJwt%2C_ready%2C_close%2C_open%2C_resizeMe.
Domains, protocols and ports must match.
What do I need to do to make this simple example work?
Addendum:
I found a nicer example from google:
https://sandbox.google.com/checkout/customer/gadget/inapp/demo.html
However saving the source to my machine and accessing it locally ( as http://localhost/google_iap/google_demo.html ) gives the same cross-domain error.
It appears that the google sandbox was broken. This is now working again, so the example seems to functions correctly. However warnings about cross site access still exist.